Skip to main content

Shuttle Radar Topography Mission (SRTM) Digital Elevation Model (DEM) search and download utility

Project description

NASADEM - Digital Elevation Model (DEM) Access Utility

This Python package provides utilities for accessing and downloading Digital Elevation Model (DEM) data from the NASADEM dataset, which is a reprocessed version of the Shuttle Radar Topography Mission (SRTM) data.

Version 2.0.0 modernizes the package to use NASA's official earthaccess library for reliable and efficient data access from NASA's Earthdata Cloud.

Gregory H. Halverson (they/them)
gregory.h.halverson@jpl.nasa.gov
NASA Jet Propulsion Laboratory 329G

What's New in v2.0.0

  • 🚀 Modern Data Access: Uses NASA's official earthaccess package
  • Reliable Downloads: Built-in retry logic and error handling
  • ☁️ Cloud-Optimized: Direct access to NASA Earthdata Cloud
  • 🔐 Simplified Authentication: Multiple authentication options (.netrc, environment variables, interactive)
  • 🗑️ Removed Legacy Code: Deprecated old LP DAAC connection methods

Installation

pip install NASADEM

Or install from source:

git clone https://github.com/gregory-halverson/NASADEM.git
cd NASADEM
pip install -e .

Prerequisites

You need a NASA Earthdata account to download NASADEM data.

Authentication

There are several ways to authenticate:

Option 1: Interactive Login (Recommended for first-time users)

import earthaccess
earthaccess.login()  # Will prompt for credentials and optionally save them

Option 2: .netrc File

Create a ~/.netrc file with your credentials:

machine urs.earthdata.nasa.gov
    login YOUR_USERNAME
    password YOUR_PASSWORD

Then set proper permissions:

chmod 600 ~/.netrc

Option 3: Environment Variables

export EARTHDATA_USERNAME=your_username
export EARTHDATA_PASSWORD=your_password

Option 4: Direct Credentials

from NASADEM import NASADEMConnection

nasadem = NASADEMConnection(
    username="your_username",
    password="your_password",
    persist_credentials=True  # Optionally save to .netrc
)

Usage

Basic Usage with Default Instance

from NASADEM import NASADEM
from rasters import RasterGrid

# Define target area
geometry = RasterGrid.from_bbox(
    xmin=-118.5, ymin=33.5, xmax=-117.5, ymax=34.5,
    cell_size=30, crs="EPSG:4326"
)

# Get elevation data
elevation = NASADEM.elevation_m(geometry)
print(f"Elevation range: {elevation.min():.1f} to {elevation.max():.1f} meters")

# Get surface water body mask
water = NASADEM.swb(geometry)

Custom Connection

from NASADEM import NASADEMConnection

# Create connection with custom download directory
nasadem = NASADEMConnection(
    download_directory="~/my_nasadem_data"
)

# Use it the same way
elevation = nasadem.elevation_m(geometry)

Point Extraction

from rasters import Point, MultiPoint
from NASADEM import NASADEM

# Single point
point = Point(-118.0, 34.0)
elevation = NASADEM.elevation_m(point)
print(f"Elevation at point: {elevation:.1f} m")

# Multiple points
points = MultiPoint([
    Point(-118.0, 34.0),
    Point(-117.5, 33.8),
    Point(-118.2, 34.2)
])
elevations = NASADEM.elevation_m(points)
print(f"Elevations: {elevations}")

Working with Tiles

from NASADEM import NASADEM

# Get tiles covering an area
tiles = NASADEM.tiles(geometry)
print(f"Tiles needed: {tiles}")

# Download a specific tile
granule = NASADEM.download_tile("n34w118")
elevation = granule.elevation_m
swb = granule.swb

API Reference

NASADEMConnection

Main class for accessing NASADEM data.

Methods:

  • elevation_m(geometry): Get elevation in meters
  • elevation_km(geometry): Get elevation in kilometers
  • swb(geometry): Get surface water body mask
  • download_tile(tile): Download a specific tile
  • tiles(geometry): Get list of tiles covering a geometry

Parameters:

  • username (str, optional): NASA Earthdata username
  • password (str, optional): NASA Earthdata password
  • working_directory (str, optional): Working directory for temporary files
  • download_directory (str, optional): Directory for downloaded tiles (default: ~/data/NASADEM)
  • persist_credentials (bool, optional): Save credentials to .netrc (default: False)
  • skip_auth (bool, optional): Skip authentication (useful for testing, default: False)

NASADEMGranule

Represents a single NASADEM tile.

Properties:

  • elevation_m: Elevation raster in meters
  • swb: Surface water body mask
  • geometry: Raster geometry of the tile
  • tile: Tile identifier (e.g., "n34w118")

Data Description

NASADEM provides:

  • Elevation data: 1 arc-second (~30m) resolution global coverage (60°N to 56°S)
  • Surface water body mask: Boolean mask of water bodies
  • Void-filled: Improved version of SRTM with fewer data voids
  • Accuracy: Vertical accuracy typically better than 16m (absolute), 10m (relative)

Tile Naming Convention

Tiles are named using latitude/longitude: {n|s}XX{e|w}XXX

Examples:

  • n34w118: 34°N to 35°N, 118°W to 117°W (Los Angeles area)
  • s10e142: 10°S to 9°S, 142°E to 143°E (Northern Australia)

Migration from v1.x

If you're upgrading from v1.x:

  1. Authentication: Update to use earthaccess authentication methods
  2. No more URL construction: The package now handles data discovery automatically
  3. Deprecated: LPDAACDataPool class is no longer used
  4. Same API: The main elevation_m(), elevation_km(), and swb() methods work the same

Old code (v1.x):

from NASADEM import NASADEMConnection

nasadem = NASADEMConnection(
    username="user",
    password="pass",
    remote="https://e4ftl01.cr.usgs.gov"  # Old URL
)

New code (v2.0):

from NASADEM import NASADEMConnection

# Simpler - earthaccess handles the URLs
nasadem = NASADEMConnection(
    username="user",
    password="pass"
)

Troubleshooting

Authentication Issues

If you get authentication errors:

import earthaccess
earthaccess.login(persist=True)  # Save credentials

Download Failures

The package automatically retries failed downloads. If problems persist:

Tile Not Available

Some areas may not be covered by NASADEM (latitudes > 60°N or < 56°S). The error message will indicate this.

References

License

See LICENSE file.

Documentation

Contributing

Issues and pull requests are welcome at https://github.com/gregory-halverson/NASADEM

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nasadem-2.1.0.tar.gz (619.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nasadem-2.1.0-py3-none-any.whl (13.5 kB view details)

Uploaded Python 3

File details

Details for the file nasadem-2.1.0.tar.gz.

File metadata

  • Download URL: nasadem-2.1.0.tar.gz
  • Upload date:
  • Size: 619.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for nasadem-2.1.0.tar.gz
Algorithm Hash digest
SHA256 d3a73029ef44f7b98db732e8fd04314f87781df6af90df47a86a6b3a378ff7d1
MD5 a4ce1e94c1733a64dded9c23dd001650
BLAKE2b-256 3ab6c9d2e2aea2e67b94a516d951f262050a76b9532f89cabf8165e414e4036f

See more details on using hashes here.

File details

Details for the file nasadem-2.1.0-py3-none-any.whl.

File metadata

  • Download URL: nasadem-2.1.0-py3-none-any.whl
  • Upload date:
  • Size: 13.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for nasadem-2.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1091e17bfc97951afc6351bb0a37613e781496baf4188cb8eb71fd14d4378e3a
MD5 7de3b63ec505c312f1829d9594ae21cf
BLAKE2b-256 ae36882c877bd792762da66d6d215ac7fc9a92f3186592fc135e2605275a2ed6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page