Set of tools to manipulate Digital Elevation Models (DEMs)
More documentation to come!
$ git clone https://github.com/GlacioHack/xdem.git
$ cd ./xdem
$ conda env create -f environment.yml
$ conda activate xdem
$ pip install .
or
pip install git+https://github.com/GlacioHack/xdem.gitTo update, please use the --force-reinstall flag for conda or pip to ensure the latest version is installed (geoutils and xdem do not yet have proper release schedules as of 2021-05-13).
xdem are for now composed of three libraries:
coreg.pywith tools covering differet aspects of DEM coregistrationspatial_tools.pyfor spatial operations on DEMsdem.pyfor DEM-specific operations, such as vertical datum correction.
You can find ways to improve the libraries in the issues section. All contributions are welcome. To avoid conflicts, it is suggested to use separate branches for each implementation. All changes must then be submitted to the dev branch using pull requests. Each PR must be reviewed by at least one other person.
See the documentation at https://xdem.readthedocs.io
These tools are only valuable if we can rely on them to perform exactly as we expect. So, we need testing. Please create tests for every function that you make, as much as you are able. Guidance/examples here for the moment: https://github.com/GeoUtils/georaster/blob/master/test/test_georaster.py https://github.com/corteva/rioxarray/blob/master/test/integration/test_integration__io.py
Coregister a DEM to another DEM
import xdem
reference_dem = xdem.DEM("path/to/reference.tif")
dem_to_be_aligned = xdem.DEM("path/to/dem.tif")
nuth_kaab = xdem.coreg.NuthKaab()
nuth_kaab.fit(reference_dem.data, dem_to_be_aligned.data, transform=reference_dem.transform)
aligned_dem = xdem.DEM.from_array(
nuth_kaab.apply(dem_to_be_aligned.data, transform=dem_to_be_aligned.transform),
transform=dem_to_be_aligned.transform,
crs=dem_to_be_aligned.crs
)
aligned_dem.save("path/to/coreg.tif")This is an implementation of the Nuth and Kääb (2011) approach. Please see the documentation for more approaches.
Subtract one DEM with another
import xdem
first_dem = "path/to/first.tif"
second_dem = "path/to/second.tif"
difference = xdem.spatial_tools.subtract_rasters(first_dem, second_dem)
difference.save("path/to/difference.tif")By default, second_dem is reprojected to fit first_dem.
This can be switched with the keyword argument reference="second".
The resampling method can also be changed (e.g. resampling_method="nearest") from the default "cubic_spline".