API reference#

This page provides a summary of xDEM’s API. For more details and examples, refer to the relevant chapters in the main part of the documentation.

Examples using xdem.DEM#

Blockwise coregistration

Blockwise coregistration

Working with a collection of DEMs

Working with a collection of DEMs

Bias-correction with deramping

Bias-correction with deramping

Estimation and modelling of heteroscedasticity

Estimation and modelling of heteroscedasticity

Normalized regional hypsometric interpolation

Normalized regional hypsometric interpolation

Slope and aspect methods

Slope and aspect methods

Standardization for stable terrain as error proxy

Standardization for stable terrain as error proxy

Estimation and modelling of spatial variograms

Estimation and modelling of spatial variograms

DEM differencing

DEM differencing

Iterative closest point coregistration

Iterative closest point coregistration

Elevation error map

Elevation error map

Spatial correlation of errors

Spatial correlation of errors

Configuring verbosity level

Configuring verbosity level

Nuth and Kääb coregistration

Nuth and Kääb coregistration

Spatial propagation of elevation errors

Spatial propagation of elevation errors

Terrain attributes

Terrain attributes

DEM#

Important

A DEM inherits all raster methods and attributes from the Raster object of GeoUtils. Below, we only repeat some core attributes and methods of GeoUtils, see the Raster API in GeoUtils for the full list.

Opening or saving#

DEM(filename_or_dataset[, vcrs, load_data, ...])

The digital elevation model.

DEM.to_file(filename[, driver, dtype, ...])

Write the raster to file.

Plotting or summarize info#

DEM.info([stats, verbose])

DEM.plot([bands, cmap, vmin, vmax, alpha, ...])

Create from an array#

DEM.from_array(data, transform, crs[, ...])

Create a DEM from a numpy array and the georeferencing information.

Unique attributes#

Inherited from Raster#

DEM.data

Array of the raster.

DEM.crs

Coordinate reference system of the raster.

DEM.transform

Geotransform of the raster.

DEM.nodata

Nodata value of the raster.

DEM.area_or_point

Pixel interpretation of the raster.

Specific to DEM#

DEM.vcrs

Vertical coordinate reference system of the DEM.

Other attributes#

Inherited from Raster#

See the full list in the Raster API of GeoUtils.

DEM.res

Resolution (X, Y) of the raster in georeferenced units.

DEM.bounds

Bounding coordinates of the raster.

DEM.width

Width of the raster in pixels.

DEM.height

Height of the raster in pixels.

DEM.shape

Shape (i.e., height, width) of the raster in pixels.

Georeferencing#

Inherited from Raster#

DEM.set_nodata(new_nodata[, update_array, ...])

Set a new nodata value for all bands.

DEM.set_area_or_point(new_area_or_point[, ...])

Set new pixel interpretation of the raster.

DEM.info([stats, verbose])

DEM.reproject([ref, crs, res, grid_size, ...])

DEM.crop(bbox[, mode, inplace])

Vertical referencing for DEM#

DEM.set_vcrs(new_vcrs)

Set the vertical coordinate reference system of the DEM.

DEM.to_vcrs(vcrs[, force_source_vcrs, inplace])

Raster-vector interface#

Note

See the full list of vector methods in GeoUtils’ documentation.

DEM.polygonize([target_values, data_column_name])

Polygonize the raster into a vector.

DEM.proximity([vector, target_values, ...])

Compute proximity distances to the raster target pixels, or to a vector geometry on the raster grid.

DEM.to_pointcloud([data_column_name, ...])

Convert raster to point cloud.

DEM.interp_points(points[, method, ...])

Statistics#

DEM.get_stats([stats_name, inlier_mask, ...])

Terrain attributes#

DEM.slope([method, surface_fit, degrees, ...])

Generate a slope map for a DEM, returned in degrees by default.

DEM.aspect([method, surface_fit, degrees, ...])

Calculate the aspect of each cell in a DEM, returned in degrees by default.

DEM.hillshade([method, surface_fit, ...])

Generate a hillshade from the given DEM.

DEM.profile_curvature([surface_fit, ...])

Calculates profile curvature in units of m-1 multiplied by 100.

DEM.tangential_curvature([surface_fit, ...])

Calculates tangential curvature in units of m-1 multiplied by 100.

DEM.planform_curvature([surface_fit, ...])

Calculates planform (or plan) curvature in units of m-1 multiplied by 100., defined as the curvature of a projection of the contour line onto a horizontal plane.

DEM.flowline_curvature([surface_fit, ...])

Calculates flow line curvature in units of m-1 multiplied by 100.

DEM.max_curvature([surface_fit, ...])

Calculate the maximal (geometric) or maximum (directional derivative) curvature in units of m-1 multiplied by 100.

DEM.min_curvature([surface_fit, ...])

Calculate the minimal (geometric) or minimum (directional derivative) curvature in units of m-1 multiplied by 100.

DEM.topographic_position_index([...])

Calculates the Topographic Position Index, the difference to the average of neighbouring pixels.

DEM.terrain_ruggedness_index([method, ...])

Calculates the Terrain Ruggedness Index, the cumulated differences to neighbouring pixels.

DEM.roughness([window_size, mp_config])

Calculates the roughness, the maximum difference between neighbouring pixels, for any window size.

DEM.rugosity([mp_config])

Calculates the rugosity, the ratio between real area and planimetric area.

DEM.fractal_roughness([window_size, mp_config])

Calculates the fractal roughness, the local 3D fractal dimension.

DEM.texture_shading([alpha, mp_config])

Generate a texture shaded relief map using fractional Laplacian operator.

Or to get multiple related terrain attributes at once (for performance):

DEM.get_terrain_attribute(attribute, **kwargs)

Derive one or multiple terrain attributes from a DEM.

Coregistration and bias corrections#

Tip

To build and pass your coregistration pipeline to coregister_3d(), see the API of Coreg.

DEM.coregister_3d(reference_elev, coreg_method)

Coregister DEM to a reference DEM in three dimensions.

Uncertainty analysis#

DEM.estimate_uncertainty(other_elev[, ...])

Estimate the uncertainty of DEM.

EPC#

Important

An EPC inherits all point cloud methods and attributes from the PointCloud object of GeoUtils. Below, we only repeat some core attributes and methods of GeoUtils, see the PointCloud API in GeoUtils for the full list.

Opening or saving#

EPC(filename_or_dataset[, data_column, vcrs])

The georeferenced elevation point cloud.

EPC.to_file(filename[, driver, schema, index])

Write the Vector to a file.

Plotting or summarize info#

EPC.info([verbose])

EPC.plot([column, ref_crs, cmap, vmin, ...])

Plot the point cloud.

Create from arrays or tuples#

EPC.from_xyz(x, y, z, crs[, data_column, use_z])

Create point cloud from three 1D array-like coordinates for X/Y/Z.

EPC.from_tuples(tuples_xyz, crs[, ...])

Create point cloud from an iterable of 3-tuples (X coordinate, Y coordinate, Z value).

EPC.from_array(data, crs[, data_column, use_z])

Create point cloud from a 3 x N or N x 3 array of X coordinates, Y coordinates and Z values.

Unique attributes#

Inherited from PointCloud#

EPC.ds

Geodataframe of the point cloud.

EPC.data_column

Name of data column of the point cloud.

Specific to EPC#

EPC.vcrs

Vertical coordinate reference system of the elevation point cloud.

Other attributes#

Inherited from PointCloud#

See the full list in the PointCloud API of GeoUtils.

EPC.point_count

Number of points in the point cloud.

EPC.bounds

Total bounding box of the vector.

EPC.crs

Coordinate reference system of the vector.

Georeferencing#

Inherited from PointCloud#

EPC.info([verbose])

EPC.reproject([ref, crs, inplace])

EPC.crop(crop_geom[, clip, inplace])

EPC.subsample(subsample[, return_indices, ...])

Vertical referencing for DEM#

EPC.set_vcrs(new_vcrs)

Set the vertical coordinate reference system of the elevation point cloud.

EPC.to_vcrs(vcrs[, force_source_vcrs, inplace])

Interface with rasters and vectors#

Note

See the full list of vector methods in GeoUtils’ documentation.

EPC.grid([ref, grid_coords, res, ...])

Grid point cloud into a raster.

EPC.rasterize([raster, crs, xres, yres, ...])

Rasterize vector to a raster or mask, with input geometries burned in.

Statistics#

EPC.get_stats([stats_name])

Coregistration and bias corrections#

Tip

To build and pass your coregistration pipeline to coregister_3d(), see the API of Coreg.

EPC.coregister_3d(reference_elev, coreg_method)

Coregister elevation point cloud to a reference elevation data in three dimensions.

Coreg#

Overview of co-registration class structure:

Inheritance diagram of xdem.coreg.base.Coreg, xdem.coreg.affine, xdem.coreg.biascorr

Coregistration, pipeline and blockwise#

coreg.Coreg([meta])

Generic co-registration processing class.

coreg.CoregPipeline(pipeline)

A sequential set of co-registration processing steps.

coreg.BlockwiseCoreg(step[, mp_config, ...])

A processing class of choice is run on a subdivision of the raster.

Fitting and applying transforms#

coreg.Coreg.fit_and_apply(reference_elev, ...)

coreg.Coreg.fit(reference_elev, ...[, ...])

Estimate the coregistration transform on the given DEMs.

coreg.Coreg.apply(elev[, bias_vars, ...])

Extracting metadata#

coreg.Coreg.info([as_str])

coreg.Coreg.meta

Metadata dictionary of the coregistration.

Affine coregistration#

Parent object (to define custom methods)#

coreg.AffineCoreg([subsample, matrix, meta, ...])

Generic affine coregistration class.

Coregistration methods#

coreg.VerticalShift([vshift_reduc_func, ...])

Vertical translation alignment.

coreg.NuthKaab([max_iterations, ...])

Nuth and Kääb (2011) coregistration, https://doi.org/10.5194/tc-5-271-2011.

coreg.DhMinimize([fit_minimizer, ...])

Elevation difference minimization coregistration.

coreg.LZD([only_translation, fit_minimizer, ...])

Least Z-difference coregistration.

coreg.ICP([method, picky, only_translation, ...])

Iterative closest point registration.

coreg.CPD([weight, only_translation, ...])

Coherent Point Drift coregistration, based on Myronenko and Song (2010), https://doi.org/10.1109/TPAMI.2010.46.

Manipulating affine transforms#

coreg.apply_matrix(elev, matrix[, invert, ...])

coreg.invert_matrix(matrix[, atol])

Invert a transformation matrix.

coreg.matrix_from_translations_rotations([...])

Build rigid affine matrix based on 3 translations (unit of coordinates) and 3 rotations (degrees or radians).

coreg.translations_rotations_from_matrix(matrix)

Extract 3 translations (unit of coordinates) and 3 rotations (degrees or radians) from rigid affine matrix.

Bias-correction#

Parent object (to define custom methods)#

coreg.BiasCorr([fit_or_bin, fit_func, ...])

Bias-correction (non-rigid alignment) simultaneously with any number and type of variables.

Bias-correction methods#

coreg.Deramp([poly_order, fit_or_bin, ...])

Correct for a 2D polynomial along X/Y coordinates, for example from residual camera model deformations (dome-like errors) or tilts (rotational errors).

coreg.DirectionalBias([angle, fit_or_bin, ...])

Bias correction for directional biases, for example along- or across-track of satellite angle.

coreg.TerrainBias([terrain_attribute, ...])

Correct a bias according to terrain, such as elevation or curvature.

Uncertainty analysis#

Important

Several uncertainty functionalities of xDEM are being implemented directly in SciKit-GStat for spatial statistics (e.g., fitting a sum of variogram models, pairwise subsampling for grid data). This will allow to simplify several function inputs and outputs, by relying on a single Variogram() object.

This will trigger API changes in future package versions.

Core routines for heteroscedasticity, spatial correlations, error propagation#

spatialstats.infer_heteroscedasticity_from_stable(...)

spatialstats.infer_spatial_correlation_from_stable(...)

Infer spatial correlation of errors from differenced values on stable terrain and a list of variogram model to fit as a sum.

spatialstats.spatial_error_propagation(...)

Spatial propagation of elevation errors to an area using the estimated heteroscedasticity and spatial correlations.

Sub-routines for heteroscedasticity#

spatialstats.nd_binning(values, list_var, ...)

N-dimensional binning of values according to one or several explanatory variables with computed statistics in each bin.

spatialstats.interp_nd_binning(df, ...[, ...])

Estimate an interpolant function for an N-dimensional binning.

spatialstats.two_step_standardization(...[, ...])

Standardize the proxy differenced values using the modelled heteroscedasticity, re-scaled to the spread statistic, and generate the final standardization function.

Sub-routines for spatial correlations#

spatialstats.sample_empirical_variogram(values)

Sample empirical variograms with binning adaptable to multiple ranges and spatial subsampling adapted for raster data.

spatialstats.fit_sum_model_variogram(...[, ...])

Fit a sum of variogram models to an empirical variogram, with weighted least-squares based on sampling errors.

spatialstats.correlation_from_variogram(...)

Construct the spatial correlation function from a dataframe of variogram parameters.

Sub-routines for error propagation#

spatialstats.number_effective_samples(area, ...)

Compute the number of effective samples, i.e. the number of uncorrelated samples, in an area accounting for spatial correlations described by a sum of variogram models.

Empirical validation#

spatialstats.patches_method(values, areas[, ...])

Plotting for uncertainty analysis#

spatialstats.plot_variogram(df[, ...])

Plot empirical variogram, and optionally also plot one or several model fits.

spatialstats.plot_1d_binning(df, var_name, ...)

Plot a statistic and its count along a single binning variable.

spatialstats.plot_2d_binning(df, var_name_1, ...)

Plot one statistic and its count along two binning variables.

Stand-alone functions (moved)#

spatialstats.nmad(data[, nfact])

Calculate the normalized median absolute deviation (NMAD) of an array.

Development classes (removal or re-factoring)#

Caution

The xdem.dDEM and xdem.DEMCollection classes will be removed or re-factored in the near future.

dDEM#

dDEM(raster, start_time, end_time[, error])

A difference-DEM object.

DEMCollection#

DEMCollection(dems[, timestamps, outlines, ...])

A temporal collection of DEMs.