nd.warp package

class nd.warp.Alignment(target=None, crs=None, extent=None)[source]

Bases: nd.algorithm.Algorithm

Align a list of datasets to the same coordinate grid.

Parameters
  • target (xarray.Dataset, optional) – Align the datasets with respect to the target dataset.

  • crs (str or dict, optional) – The coordinate reference system as proj-string or dictionary. By default, use the CRS of the datasets.

  • extent (tuple, optional) – The bounding box of the output dataset. By default, use the common extent of all datasets.

apply(datasets, path, *, njobs=1)[source]

Resample datasets to common extent and resolution.

Parameters
  • datasets (str, list of str, list of xarray.Dataset) – The input datasets. Can be either a glob expression, a list of filenames, or a list of opened datasets.

  • path (str) – The output path to store the aligned datasets.

  • njobs (int, optional) – Number of jobs to run in parallel. Setting njobs to -1 uses the number of available cores. Disable parallelism by setting njobs to 1 (default).

class nd.warp.Coregistration(reference=0, upsampling=10)[source]

Bases: nd.algorithm.Algorithm

Coregister a time series (stack) of images to a master image.

At the moment only supports coregistration by translation.

Parameters
  • reference (int, optional) – The time index to use as reference for coregistration (default: 0).

  • upsampling (int, optional) – The upsampling factor for shift estimation (default: 10).

apply(ds)[source]

Apply the projection to a dataset.

Parameters

ds (xarray.Dataset) – The input dataset.

Returns

The coregistered dataset.

Return type

xarray.Dataset

class nd.warp.Reprojection(target=None, src_crs=None, dst_crs=None, crs=None, extent=None, res=None, width=None, height=None, transform=None, **kwargs)[source]

Bases: nd.algorithm.Algorithm

Reprojection of the dataset to the given coordinate reference system (CRS) and extent.

Parameters
  • target (xarray.Dataset or xarray.DataArray, optional) – A reference to which a dataset will be aligned.

  • src_crs (dict or str, optional) – The coordinate system of the input data (default: infer from data).

  • dst_crs (dict or str, optional) – The output coordinate reference system as dictionary or proj-string

  • crs (dict or str, optional) – Alias for dst_crs for backwards compatiblity.

  • extent (tuple, optional) – The output extent. By default this is inferred from the input data.

  • res (tuple, optional) – The output resolution. By default this is inferred from the input data.

  • width (tuple, optional) – The output width. By default this is inferred from the input data.

  • height (tuple, optional) – The output height. By default this is inferred from the input data.

  • transform (tuple, optional) – The output coordinate transform. By default this is inferred from the input data.

  • **kwargs (dict, optional) – Extra keyword arguments for rasterio.warp.reproject.

apply(ds, *, njobs=1)[source]

Apply the projection to a dataset.

Parameters
  • ds (xarray.Dataset) – The input dataset.

  • njobs (int, optional) – Number of jobs to run in parallel. Setting njobs to -1 uses the number of available cores. Disable parallelism by setting njobs to 1 (default).

Returns

The reprojected dataset.

Return type

xarray.Dataset

class nd.warp.Resample(res=None, width=None, height=None, **kwargs)[source]

Bases: nd.algorithm.Algorithm

Resample a dataset to the specified resolution or width and height.

Parameters
  • res (float or tuple, optional) – The desired resolution in the dataset coordinates.

  • width (int, optional) – The desired output width. Ignored if the resolution is specified. If only the height is given, the width is calculated automatically.

  • height (int, optional) – The desired output height. Ignored if the resolution is specified. If only the width is given, the height is calculated automatically.

  • **kwargs (dict, optional) – Extra keyword arguments for rasterio.warp.reproject.

apply(ds, *, njobs=1)[source]

Resample the dataset.

Parameters
  • ds (xarray.Dataset or xarray.DataArray) – The input dataset

  • njobs (int, optional) – Number of jobs to run in parallel. Setting njobs to -1 uses the number of available cores. Disable parallelism by setting njobs to 1 (default).

Returns

The resampled dataset.

Return type

xarray.Dataset or xarray.DataArray

nd.warp.align(datasets, path, target=None, crs=None, extent=None, *, njobs=1)[source]

Wrapper for nd.warp.Alignment.

Align a list of datasets to the same coordinate grid.

Parameters
  • datasets (str, list of str, list of xarray.Dataset) – The input datasets. Can be either a glob expression, a list of filenames, or a list of opened datasets.

  • path (str) – The output path to store the aligned datasets.

  • target (xarray.Dataset, optional) – Align the datasets with respect to the target dataset.

  • crs (str or dict, optional) – The coordinate reference system as proj-string or dictionary. By default, use the CRS of the datasets.

  • extent (tuple, optional) – The bounding box of the output dataset. By default, use the common extent of all datasets.

  • njobs (int, optional) – Number of jobs to run in parallel. Setting njobs to -1 uses the number of available cores. Disable parallelism by setting njobs to 1 (default).

nd.warp.coregister(ds, reference=0, upsampling=10)[source]

Wrapper for nd.warp.Coregistration.

Coregister a time series (stack) of images to a master image.

At the moment only supports coregistration by translation.

Parameters
  • ds (xarray.Dataset) – The input dataset.

  • reference (int, optional) – The time index to use as reference for coregistration (default: 0).

  • upsampling (int, optional) – The upsampling factor for shift estimation (default: 10).

Returns

The coregistered dataset.

Return type

xarray.Dataset

nd.warp.get_bounds(ds)[source]

Extract the bounding box in projection coordinates.

Parameters

ds (xarray.Dataset) – The input dataset

Returns

The bounding box in projection coordinates (left, bottom, right, top).

Return type

tuple

nd.warp.get_common_bounds(datasets)[source]

Calculate the common bounding box of the input datasets.

Parameters

datasets (list of xarray.Dataset) – The input datasets.

Returns

The common bounding box (left, bottom, right, top) in projected coordinates.

Return type

tuple

nd.warp.get_common_extent(datasets)[source]

Calculate the smallest extent that contains all of the input datasets.

Parameters

datasets (list of xarray.Dataset) – The input datasets.

Returns

The common extent (left, bottom, right, top) in latitude and longitude coordinates.

Return type

tuple

nd.warp.get_common_resolution(datasets, mode='min')[source]

Determine the common resolution of a list of datasets.

Parameters
  • datasets (list of xarray.Dataset) – The input datasets.

  • mode (str {'min', 'max', 'mean'}) –

    How to determine the common resolution if the individual resolutions differ.

    • min: Return the smallest (best) resolution.

    • max: Return the largest (worst) resolution.

    • mean: Return the average resolution.

Returns

Returns the common resolution as (x, y).

Return type

tuple

nd.warp.get_crs(ds, format='crs')[source]

Extract the Coordinate Reference System from a dataset.

Parameters
  • ds (xarray.Dataset) – The input dataset

  • format (str {'crs', 'proj', 'dict', 'wkt'}) –

    The format in which to return the CRS.

    • ’proj’: A proj-string, e.g. +init=epsg:4326

    • ’dict’: e.g. {'init': 'EPSG:4326'}

    • ’wkt’: e.g. GEOGCS["WGS 84", ...]

Returns

The CRS.

Return type

CRS, str, or dict

nd.warp.get_extent(ds)[source]

Extract the extent (bounding box) from the dataset.

Parameters

ds (xarray.Dataset) – The input dataset

Returns

The extent (left, bottom, right, top) in latitude and longitude coordinates.

Return type

tuple

nd.warp.get_geometry(ds, crs={'init': 'epsg:4326'})[source]

Get the shapely geometry of the dataset bounding box in any coordinate system (EPSG:4326 by default).

Parameters
  • ds (xr.Dataset or xr.DataArray) – The dataset whose geometry to return.

  • crs (dict, optional) – The desired CRS as keywords arguments to be passed to pyproj.Proj.

Returns

The bounds of the dataset in the desired coordinate system.

Return type

shapely.geometry.Polygon

nd.warp.get_resolution(ds)[source]

Extract the resolution of the dataset in projection coordinates.

Parameters

ds (xarray.Dataset) – The input dataset

Returns

The raster resolution as (x, y)

Return type

tuple

nd.warp.get_transform(ds)[source]

Extract the geographic transform from a dataset.

Parameters

ds (xarray.Dataset) – The input dataset

Returns

The affine transform

Return type

affine.Affine

nd.warp.ncols(ds)[source]
nd.warp.nrows(ds)[source]
nd.warp.reproject(ds, target=None, src_crs=None, dst_crs=None, crs=None, extent=None, res=None, width=None, height=None, transform=None, *, njobs=1, **kwargs)[source]

Wrapper for nd.warp.Reprojection.

Reprojection of the dataset to the given coordinate reference system (CRS) and extent.

Parameters
  • ds (xarray.Dataset) – The input dataset.

  • target (xarray.Dataset or xarray.DataArray, optional) – A reference to which a dataset will be aligned.

  • src_crs (dict or str, optional) – The coordinate system of the input data (default: infer from data).

  • dst_crs (dict or str, optional) – The output coordinate reference system as dictionary or proj-string

  • crs (dict or str, optional) – Alias for dst_crs for backwards compatiblity.

  • extent (tuple, optional) – The output extent. By default this is inferred from the input data.

  • res (tuple, optional) – The output resolution. By default this is inferred from the input data.

  • width (tuple, optional) – The output width. By default this is inferred from the input data.

  • height (tuple, optional) – The output height. By default this is inferred from the input data.

  • transform (tuple, optional) – The output coordinate transform. By default this is inferred from the input data.

  • njobs (int, optional) – Number of jobs to run in parallel. Setting njobs to -1 uses the number of available cores. Disable parallelism by setting njobs to 1 (default).

  • **kwargs (dict, optional) – Extra keyword arguments for rasterio.warp.reproject.

Returns

The reprojected dataset.

Return type

xarray.Dataset

nd.warp.resample(ds, res=None, width=None, height=None, *, njobs=1, **kwargs)[source]

Wrapper for nd.warp.Resample.

Resample a dataset to the specified resolution or width and height.

Parameters
  • ds (xarray.Dataset or xarray.DataArray) – The input dataset

  • res (float or tuple, optional) – The desired resolution in the dataset coordinates.

  • width (int, optional) – The desired output width. Ignored if the resolution is specified. If only the height is given, the width is calculated automatically.

  • height (int, optional) – The desired output height. Ignored if the resolution is specified. If only the width is given, the height is calculated automatically.

  • njobs (int, optional) – Number of jobs to run in parallel. Setting njobs to -1 uses the number of available cores. Disable parallelism by setting njobs to 1 (default).

  • **kwargs (dict, optional) – Extra keyword arguments for rasterio.warp.reproject.

Returns

The resampled dataset.

Return type

xarray.Dataset or xarray.DataArray