demcompare.dataset_tools

This module contains functions associated to Demcompare’s DEM dataset

Module Contents

Functions

create_dataset(→ xarray.Dataset)

Creates dataset from input array and transform,

reproject_dataset(→ xarray.Dataset)

Reproject dataset on the from_dataset's georeference origin and grid,

compute_offset_adapting_factor(→ Tuple[float, float])

Compute the factor to adapt the coregistration offsets

_get_geoid_offset(→ numpy.ndarray)

Computes the geoid offset of the input DEM. If no geoid_path is

_interpolate_geoid(→ numpy.ndarray)

Bilinear interpolation of the given geoid to the input coordinates.

demcompare.dataset_tools.create_dataset(data: numpy.ndarray, transform: numpy.ndarray | rasterio.Affine = None, img_crs: rasterio.crs.CRS | None = None, input_img: str | None = None, bounds: rasterio.coords.BoundingBox = None, nodata: float = None, geoid_path: str | None = None, plani_unit: astropy.units = None, zunit: str = 'm', source_rasterio: Dict[str, rasterio.DatasetReader] = None, classification_layer_masks: Dict | xarray.DataArray = None) xarray.Dataset[source]

Creates dataset from input array and transform, and return the corresponding xarray.DataSet.

The demcompare dataset is an xarray Dataset containing: :image: 2D (row, col) image as xarray.DataArray, :georef_transform: 1D (trans_len) xarray.DataArray with the parameters:

  • c: x-coordinate of the upper left pixel,

  • a: pixel size in the x-direction in map units/pixel,

  • b: rotation about x-axis,

  • f: y-coordinate of the upper left pixel,

  • d: rotation about y-axis,

  • e: pixel size in the y-direction in map units, negative

Classification_layer_masks:

3D (row, col, indicator) xarray.DataArray:

It contains the maps of all classification layers, being the indicator a list with each classification_layer name.

Attributes:
  • nodata : image nodata value. float

  • input_img : image input path. str or None

  • crs : image crs. rasterio.crs.CRS

  • xres : x resolution (value of transform[1]). float

  • yres : y resolution (value of transform[5]). float

  • plani_unit : georefence’s planimetric unit. astropy.units

  • zunit : input image z unit value. astropy.units

  • bounds : image bounds. rasterio.coords.BoundingBox

  • geoid_path : geoid path. str or None

  • source_rasterio : rasterio’s DatasetReader object or None.

Parameters:
  • data (xr.Dataset) – image data

  • transform (np.ndarray or rasterio.Affine) – rasterio georeferencing transformation matrix

  • input_img (str) – image path

  • bounds (rasterio.coords.BoundingBox or None) – dem bounds

  • nodata (float or None) – nodata value in the image

  • geoid_path (str or None) – optional path to local geoid, default is EGM96

  • zunit (str) – unit

  • source_rasterio (Dict[str,rasterio.DatasetReader] or None) – rasterio dataset reader object

  • classification_layer_masks (Dict, xr.DataArray or None) – classification layers

Returns:

xr.DataSet containing :

  • image : 2D (row, col) xr.DataArray float32

  • georef_transform: 1D (trans_len) xr.DataArray

  • classification_layer_masks : 3D (row, col, indicator) xr.DataArray

demcompare.dataset_tools.reproject_dataset(dataset: xarray.Dataset, from_dataset: xarray.Dataset, interp: str = 'bilinear') xarray.Dataset[source]

Reproject dataset on the from_dataset’s georeference origin and grid, and return the corresponding xarray.DataSet. If no interp is given, default “bilinear” resampling is considered. Another available resampling is “nearest”.

Parameters:
  • dataset (xr.Dataset) –

    Dataset to reproject xr.DataSet containing :

    • image : 2D (row, col) xr.DataArray float32

    • georef_transform: 1D (trans_len) xr.DataArray

    • classification_layer_masks : 3D (row, col, indicator) xr.DataArray

  • from_dataset (xr.Dataset) –

    Dataset to get projection from xr.DataSet containing :

    • image : 2D (row, col) xr.DataArray float32

    • georef_transform: 1D (trans_len) xr.DataArray

    • classification_layer_masks : 3D (row, col, indicator) xr.DataArray

  • interp (str) – interpolation method

Returns:

reprojected xr.DataSet containing :

  • image : 2D (row, col) xr.DataArray float32

  • georef_transform: 1D (trans_len) xr.DataArray

  • classification_layer_masks : 3D (row, col, indicator) xr.DataArray

Return type:

xr.Dataset

demcompare.dataset_tools.compute_offset_adapting_factor(sec: xarray.Dataset, ref: xarray.Dataset) Tuple[float, float][source]

Compute the factor to adapt the coregistration offsets to the dem resolution

The name is too generic to know the usage quickly. Is the function in dem_tools or here ?

Parameters:
  • sec (xr.Dataset) – sec

  • ref (xr.Dataset) – ref

Returns:

x and y factors

Return type:

Tuple[float, float]

demcompare.dataset_tools._get_geoid_offset(dataset: xarray.Dataset, geoid_path: str | None) numpy.ndarray[source]

Computes the geoid offset of the input DEM. If no geoid_path is given, the default geoid/egm96_15.gtx if used.

Parameters:
  • dataset (xr.Dataset) –

    xr.DataSet containing :

    • image : 2D (row, col) xr.DataArray float32

    • georef_transform: 1D (trans_len) xr.DataArray

    • classification_layer_masks : 3D (row, col, indicator) xr.DataArray

  • geoid_path (str or None) – optional absolut geoid_path, if None egm96 is used

Returns:

offset as array

Return type:

np.ndarray

demcompare.dataset_tools._interpolate_geoid(geoid_filename: str, coords: numpy.ndarray, interpol_method: str = 'linear') numpy.ndarray[source]

Bilinear interpolation of the given geoid to the input coordinates. If no interpol_method is given, a “linear” interpolation is considered. If the input coordinates are outside of the geoid scope, an exception is raised.

Parameters:
  • geoid_filename (str) – coord geoid_filename

  • coords (np.ndarray) – coords matrix 2xN [lon,lat]

  • interpol_method (str) – interpolation type

Returns:

interpolated position [lon,lat,estimate geoid]

Return type:

3D np.array