xarray .pdt accessor#

class pdemtools.DemAccessor(xarray_obj)#

This class provides rioaxarray-compatible DataArray objects with access to custom functions and methods.

Functions are accessible via the pdt accessor: for instance, if you have a DEM loaded as the variable dem, you are able to access the terrain function via dem.pdt.terrain().

coregister(reference: DataArray, stable_mask: DataArray | None = None, return_stats: bool | None = False, max_horiz_offset: float = 50, rmse_step_thresh: float = -0.001, max_iterations: int = 5) DataArray#

Coregisters the scene against a reference DEM based on the Nuth and Kääb (2011) method, as implemented by the PGC.

Original code available here: PolarGeospatialCenter/setsm_postprocessing_python

Parameters:
  • reference – reference DEM DataArray of same extent and resolution.

  • stable_mask – Mask dataarray where 1 = stable region to be used for coregistration. If none, coregisters based on the entire scene.

  • return_stats – If true, returns the transformation parameter, the translation error, and the RMS error alongside the coregistered DEM dataarray, defaults to False

  • max_horiz_offset – maximum horizontal offset, beyond which XY coregistration is ignored and only Z values are corrected. Defaults to 15.

  • rmse_step_thresh – break coregistration loop if rmse step is above threshold, defaults to -0.001.

  • max_iterations – max iterations to attempt, defaults to 5.

Returns:

coregistered (rio)xarray dataarray

Return type:

DataArray

geoid_correct(geoid: DataArray) DataArray#

Geoid correct the DEM, given a geoid as an xarray DataArray. The function will attempt to reproject the geoid to match if it does not already to do.

Parameters:

geoid – A suitable geoid, as a (rio)xarray dataarray

Returns:

geoid-corrected (rio)xarray dataarray

Return type:

DataArray

get_sea_level(candidate_height_thresh_m: float | None = 10, candidate_area_thresh_km2: float | None = 1) float#

Returns estimated sea level following method of Shiggins _et al._ (2023). If no candidate sea level is identified, None is returned. DEM must be geoid-corrected.

Parameters:
  • candidate_height_thresh_m (float) – Maximum value relative to geoid to be considered as SL, in m, defaults to 10

  • candidate_area_thresh_km2 (float) – Minimum area beneath candidate_height_thresh_m to be considered for sea level assessment, in km^2, defaults to 1

Returns:

Estimated sea level

Return type:

float

mask_icebergs(area_thresh_m2: float | int | None = 1000000.0, retain_icebergs: bool | None = False, return_mask: bool | None = False, connectivity: Literal[4, 8] = 4) DataArray#

After masking the ocean using the mask_ocean() function, icebergs will remain. This function gives you the opportunity to mask them as well by identifying the size of connected groups of pixels and masking above/below a threshold.

By default, this function masks icebergs and retains terrestrial ice/land. However, by setting retain_icebergs = True, the function will instead mask ice/land and retain icebergs, allowing iceberg area and volume to be assessed. For accurate volume assessment, the DEM 0 m value must be set to the estimated sea level height from the get_sea_level() function. This can be automated by setting return_sealevel_as_zero = True in the mask_ocean() function.

Parameters:
  • area_thresh_m2 (float | int) – Size threshold between icebergs and terrestrial ice/land, in m2. Defaults to 1e6 m2 (1 km2)

  • retain_icerbergs – By default, this function masks icebergs and retains terrestrial ice/land (by masking pixel groups below the threshold area). By switching the parameter to True, the function will instead mask out larger pixel groups and retain the smaller icebergs.

  • return_mask (bool) – If True, returns mask of icebergs (where icebergs = 1). If False, returns input DEM with icebergs masked. Defaults to False.

  • connectivity (int) – Connectivity with which to calculate iceberg regions. Must be 4 or 8. Defaults to 4.

Returns:

Either masked DEM or mask as xarray DataArray, depending on the input value of return_mask.

Return type:

DataArray

mask_ocean(candidate_height_thresh_m: float | None = 10, candidate_area_thresh_km2: float | None = 1, near_sealevel_thresh_m: float | None = 5, return_sealevel_as_zero: bool | None = False, return_mask: bool | None = False) DataArray#

Returns a DEM with mélange/ocean regions filtered out, adapting the method of Shiggins _et al._ (2023). If no likely sea level is identified, returns the original DEM.

WARNING: The DEM must be geoid-corrected for this function to work correctly.

Parameters:
  • candidate_height_thresh_m (float) – Maximum value relative to geoid to be considered as SL, in m, defaults to 10

  • candidate_area_thresh_km2 (float) – Minimum area beneath candidate_height_thresh_m to be considered for sea level assessment, in km^2. Defaults to 1

  • near_sealevel_thresh_m (float) – Filter out regions below this value, in metres above sea level. Defaults to 5

  • return_sealevel_as_zero (bool) – If True, subtracts that estimated sea level from the DEM, returning new height values with the estimated sea level set to 0 m. Necessary for calculating accurate iceberg heights. Defaults to False.

  • return_mask (bool) – Return the sea level mask rather than the masked DEM. Defaults to False.

Returns:

Filtered DEM as xarray DataArray

Return type:

DataArray

terrain(attribute: str | list[str] | None, method: Literal['Florinsky', 'ZevenbergThorne'] = 'Florinsky', degrees: bool | None = True, resolution: float | None = None, hillshade_multidirectional: bool | None = False, hillshade_altitude: float | None = 45.0, hillshade_azimuth: float | None = 315.0, hillshade_z_factor: float | None = 2.0) DataArray | Dataset#

Returns terrain attributes as an xarray DataSet. Available attributes are as follows:

  • Slope

  • Aspect

  • Hillshade

  • Horizontal curvature

  • Vertical curvature

  • Mean curvature

  • Gaussian curvature

  • Unsphericity curvature

  • Minimal curvature

  • Maximal curvature

By default, computation of partial derivatives for geomorphometric variable calculation is performed following Florinsky (2009), who calculate the third- order partial derivative from a 5 x 5 window, which may be more appropriate for high-resolution DEMs with some amount of noise. The method parameter allows for the selection of a more traditional method using a second-order derivative from a 3 x 3 window, as outlined by Zevenbergen and Throrne (1987).

Parameters:
  • attribute – The attribute(s) to calculate, as a string or list.

  • method – Method to calculate geomorphometric parameters: “Florisnky” or “ZevenbergThorne”, defaults to “Florinsky”.

  • resolution – The DEM resolution. Calculated if empty, defaults to None

  • degrees – Outputs degrees if True, radians if False, defaults to True

  • hillshade_multidirectional – Calculates multidirectional hillshade following USGS/GDAL method (Mark, 1992). Defaults to False.

  • hillshade_altitude – Hillshade altitude in degrees (0-90°) from vertical, defaults to 45˚

  • hillshade_azimuth – Hillshade azimuth in degrees (0-360°) clockwise from North, defaults to 315

  • hillshade_z_factor – Vertical exaggeration factor, defaults to 1

Returns:

selected terrain attributes as a (rio)xarray DataSet

Return type:

DataSet