Skip to main content

Download and merge DEM tiles for processing interferograms with ISCE2.

Project description

dem-stitcher

This tool aims to (a) provide a continuous raster of Digital Elevation Raster over an area of interest and (b) perform some standard transformations for processing. Such transformations include:

  • converting the vertical datum from a reference geoid to the WGS84 ellipsoidal
  • ensuring a coordinate reference system centered at either the upper-left corner (Area tag) or center of the pixel (Point tag).

We utilize the GIS formats from rasterio. This tool was developed to support cloud SAR processing using ISCE2 and various research. The early work of this repository was done by Charlie Marshak, David Bekaert, Michael Denbina, and Marc Simard.

The API can be summarized as

bounds = [-119.085, 33.402, -118.984, 35.435]
X, p = stitch_dem(bounds,
                  dem_name='glo_30',
                  dst_ellipsoidal_height=False,
                  dst_area_or_point='Point')
# X is an m x n numpy array
# p is a dictionary (or a rasterio profile) including relevant GIS metadata

Then, to save the DEM:

import rasterio

with rasterio.open('dem.tif', 'w', **p) as ds:
   ds.write(X, 1)
   ds.update_tags(AREA_OR_POINT='Point')

Installation

To install dem-stitcher:

  1. Clone this repository and navigate to it.
  2. Install the envrionment in environment.yml i.e. conda env update -f environment.yml
  3. Install with pip from PyPI: python -m pip install dem-stitcher

Currently, python 3.7 - 3.9 is supported.

With ISCE2 or gdal

Although the thrust of using this package is for staging DEMs for InSAR, testing and maintaining suitable environments to use with InSAR processors (particularly ISCE2) is beyond the scope of what we are attempting to accomplish here. We provide an example notebook here that demonstrates how to stage a DEM for ISCE2, which requires additional packages than required for the package on its own. For the notebook, we use the environment found in environment.yml of the Dockerized TopsApp repository, used to generate interferograms (GUNWs) in the cloud.

Credentials

The accessing of NASADEM and SRTM require earthdata login credentials to be put into the ~/.netrc file. If these are not present, the stitcher will fail with BadZipFile Error as the request is made behind the secnes with rasterio. Specifically,

machine urs.earthdata.nasa.gov
    login <username>
    password <password>

Notebooks

We have notebooks to demonstrate common usage:

We also demonstrate how the tiles used to organize the urls for the DEMs were generated for this tool were generated in this notebook.

DEMs

The DEMs that can currently be used with this tool are:

In [1]: from dem_stitcher.datasets import DATASETS; DATASETS
Out[1]: ['srtm_v3', 'nasadem', 'glo_30', '3dep', 'ned1']
  1. glo-30: Copernicus GLO-30 DEM 30 meter [link]
  2. The USGS DEMSs:
    • ned1: Ned 1 arc-second (deprecated by USGS) [link]
    • 3dep: 3Dep 1 arc-second[link]
  3. srtm_v3: SRTM v3 [link]
  4. nasadem: Nasadem [link]

Transformations

Wherever possible, we do not resample the original DEMs unless necessary. When extents are specified, we obtain the the minimum square pixel extent within the merged tile DEMs that contain that extent and return this. Any required resampling (e.g. updating the CRS or updating the resolution because the tiles have non-square resolution at high latitudes) is done at the end of the translations. We importantly note that first translating the DEM (to either pixel or area center coordinates) and then resampling is different than first resampling and then translation (as affine transformations like this are not commutative). As indicated above, all resampling (if required) is done at the end. Here are some notes:

  1. All DEMs are resampled to epsg:4326 (most DEMs are in this CRS except some of the USGS DEMs, which are in epsg:4269 and is very similar CRS)
  2. All DEMs meant to align with the original DEM pixels unless a resolution for the final product is specified
  3. Rasters can be transformed into reference system either referring to upper-left corners of pixels or their centers (i.e. Point and Area tags in gdal, respectively, and seen as {'AREA_OR_POINT: 'Point'}. Note that Area is the default pixel reference for gdal as indicated here. Some helpful resources about this book-keeping are below.
    • SRTM v3 and TDX are Pixel-centered, i.e. {'AREA_OR_POINT: 'Point'}.
    • The USGS DEMs are not, i.e. {'AREA_OR_POINT: 'Area'}.
  4. Transform geoid heights to WGS84 Ellipsoidal height. This is done using the rasters here. We:
    • Adjust the geoid to pixel/area coordinates
    • resample the geoids into the DEM reference frame
    • Adjust the vertical datum.
  5. All DEMs are converted to float32 and have nodata np.nan. Although this can increase data size of certain rasters (SRTM is distributed as integers), this ensures (a) easy comparison across DEMs and (b) no side-effects of the stitcher due to unusual nodata values. Note, this datatype is done in merge_tiles in the stitcher.py. Other nodata values can be specified outside the stitcher as is frequently done (e.g. ISCE2 requires nodata to be filled as 0).

There are some notebooks that illustrate how tiles are merged by comparing the output of our stitcher with the original tiles.

Currently, as a performance note, when merging tiles, we merge the all needed tiles into memory and this creates overhead on this front. Of course, one may elect to physically download the tiles and use virtual warping. Ultimately, the accuracy of the final DEM is our prime focus.

For Development

Almost identical to normal installation:

  1. Clone this repo git clone https://github.com/ACCESS-Cloud-Based-InSAR/dem-stitcher.git
  2. Navigate with your terminal to the repo.
  3. Create a new environment and install requirements using conda env update --file environment.yml (or use mamba to speed the install up)
  4. Install the package from cloned repo using python -m pip install -e .

Testing

  1. Install pytest
  2. Run pytest .

We have an integration test (marked as integration) which ensures all the datasets are downloaded and can be transformed (not validated for correctness at this time). Otherwise, all tests have basic tests with mock data to illustrate how the DEM stitcher is working. The non-integration tests are as github actions via pytest tests -m "not integration".

Contributing

We welcome contributions to this open-source package. To do so:

  1. Create an GitHub issue ticket desrcribing what changes you need (e.g. issue-1)
  2. Fork this repo
  3. Make your modifications in your own fork
  4. Make a pull-request in this repo with the code in your fork and tag the repo owner or a relevant contributor.

Support

  1. Create an GitHub issue ticket desrcribing what changes you would like to see or to report a bug
  2. We will work on solving this issue (hopefully with you)

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

dem_stitcher-2.2.0.tar.gz (91.7 MB view details)

Uploaded Source

Built Distribution

dem_stitcher-2.2.0-py3-none-any.whl (25.3 MB view details)

Uploaded Python 3

File details

Details for the file dem_stitcher-2.2.0.tar.gz.

File metadata

  • Download URL: dem_stitcher-2.2.0.tar.gz
  • Upload date:
  • Size: 91.7 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for dem_stitcher-2.2.0.tar.gz
Algorithm Hash digest
SHA256 68a368bf3cfa3ebb2aba9c197bdd1cdc4d1ca5db208bc3cb3856b93287a4e9fe
MD5 b29e6085256423707d497e2b8d061d0b
BLAKE2b-256 2e701a53aa195c5ed23bf822dae168d575f74aad5fed29a2336f0a920c7bf48e

See more details on using hashes here.

File details

Details for the file dem_stitcher-2.2.0-py3-none-any.whl.

File metadata

  • Download URL: dem_stitcher-2.2.0-py3-none-any.whl
  • Upload date:
  • Size: 25.3 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for dem_stitcher-2.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 057685728b3b66cc5cc5f3d3f9f034e33e2341508c71b4ab12c80fcc46452c5d
MD5 5c912abb4e12a1db7a508faf4179e1bf
BLAKE2b-256 c8dac0df44c85c735a91787ca5c51d38fe68c707a1713b56c10eda856f83e905

See more details on using hashes here.

Supported by

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