Download and merge DEM tiles
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
. 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
:
- Clone this repository and navigate to it.
- Install the envrionment in
environment.yml
i.e.conda env update -f environment.yml
- Install with
pip
from PyPI:python -m pip install dem-stitcher
Currently, python versions 3.7 - 3.10 are supported.
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 we use requests
to obtain zipped data and load the data using rasterio
. An entry in the .netrc
will look like:
machine urs.earthdata.nasa.gov
login <username>
password <password>
Using 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.
Notebooks
We have notebooks to demonstrate common usage:
- Basic Demo
- Comparing DEMs
- Staging a DEM for ISCE2 - this notebook requires the installation of a few extra libraries including ISCE2 via
conda-forge
We also demonstrate how the tile database used by this package were generated in this notebook.
DEMs Supported
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_90_missing', 'glo_30', '3dep', 'glo_90', 'ned1']
glo_30
/glo_90
: Copernicus GLO-30/GLO-90 DEM. They are the 30 and 90 meter resolution, respectively [link].- The USGS DEMSs:
srtm_v3
: SRTM v3 [link]nasadem
: Nasadem [link]glo_90_missing
: these are tiles that are inglo_90
but not inglo_30
. They are over the countries Armenia and Azerbaijan. Used internally to help fill in gaps in coverage ofglo_30
.
DEM Transformations
Wherever possible, we do not resample the original DEMs unless specified by the user to do so. When extents are specified, we obtain the the minimum pixel extent within the merged tile DEMs that contain that extent. Any required resampling (e.g. updating the CRS or updating the resolution because the tiles have non-square resolution at high latitudes) is done after these required translations. We importantly note that order in which these transformations are done is crucial, i.e. 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 are not commutative). Here are some notes/discussions:
- All DEMs are resampled to
epsg:4326
(most DEMs are in this CRS except some of the USGS DEMs, which are inepsg:4269
and is an almost identical CRS over North America). - All DEM outputs will have origin and pixel spacing aligning with the original DEM tiles unless a resolution for the final product is specified, which will alter the pixel spacing.
- Georeferenced rasters can be tied to map coordintaes using either (a) upper-left corners of pixels or (b) the pixel centers i.e.
Point
andArea
tags ingdal
, respectively, and seen as{'AREA_OR_POINT: 'Point'}
. Note that tying a pixel to the upper-left cortner (i.e.Area
tag) is the default pixel reference forgdal
as indicated here. Some helpful resources in reference to DEMs about this book-keeping are below.- SRTM v3, NASADEM, and TDX are Pixel-centered, i.e.
{'AREA_OR_POINT: 'Point'}
. - The USGS DEMs are not, i.e.
{'AREA_OR_POINT: 'Area'}
.
- SRTM v3, NASADEM, and TDX are Pixel-centered, i.e.
- 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
- All DEMs are converted to
float32
and have nodatanp.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 inmerge_tiles
in thestitcher.py
. Other nodata values can be specified outside the stitcher as is frequently done (e.g. ISCE2 requires nodata to be filled as0
).
There are some notebooks that illustrate how tiles are merged by comparing the output of our stitcher with the original tiles.
As a performance note, when merging DEM tiles, we merge the all needed tiles in memory and this process has an associated overhead. An alternative approach would be to download the tiles to disk and use virtual warping. Ultimately, the accuracy of the final DEM is our prime focus and these minor performance tradeoffs are sidelined.
For Development
This is almost identical to normal installation:
- Clone this repo
git clone https://github.com/ACCESS-Cloud-Based-InSAR/dem-stitcher.git
- Navigate with your terminal to the repo.
- Create a new environment and install requirements using
conda env update --file environment.yml
(or usemamba
to speed the install up) - Install the package from cloned repo using
python -m pip install -e .
Testing
- Install
pytest
- 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:
- Create an GitHub issue ticket desrcribing what changes you need (e.g. issue-1)
- Fork this repo
- Make your modifications in your own fork
- Make a pull-request in this repo with the code in your fork and tag the repo owner or a relevant contributor.
We use flake8
and associated linting packages to ensure some basic code quality (see the environment.yml
). These will be checked upon pull request.
Support
- Create an GitHub issue ticket desrcribing what changes you would like to see or to report a bug.
- We will work on solving this issue (hopefully with you).
Acknowledgements
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. Since the utilization of this package for GUNW generation (see this repo), a subset of the ACCESS team, including Joseph (Joe) H. Kennedy, Simran Sangha, Grace Bato, Andrew Johnston, and Charlie Marshak, have improved this repository greatly. In particular, Joe Kennedy has lead the inclusion/development of actions, tests, packaging, distribution (including PyPI and conda-forge
) and all the things to make this package more reliable, accessible, readable, etc. Simran Sangha has helped make sure output rasters are compatible with ISCE2 and other important bug-fixes.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file dem_stitcher-2.3.0.tar.gz
.
File metadata
- Download URL: dem_stitcher-2.3.0.tar.gz
- Upload date:
- Size: 92.7 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e211e94e115e9c84fef7e2fb11f75b56076c940f31d04a2422be60c9db27e24c |
|
MD5 | 0b253d77297efd36d34963408ee13abf |
|
BLAKE2b-256 | 657d75ee6527353dcc09ec1ca33f1fa26ebedd87011922d3ee67bf9ac45c08a5 |
File details
Details for the file dem_stitcher-2.3.0-py3-none-any.whl
.
File metadata
- Download URL: dem_stitcher-2.3.0-py3-none-any.whl
- Upload date:
- Size: 25.4 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 539755424456fba8364fdde7184ea38a638f18c301f84a8e28be80f970e45e05 |
|
MD5 | 5388ab6af10ab7c157787b48ccb6952a |
|
BLAKE2b-256 | 812ffd226c5071254b32c47c243720b6e8bf519d03b1884a425e844337d36b91 |