stems.gis.conventions module

CF conventions for referencing xarray/NetCDF data

Includes functions useful for managing CF conventions (variable and coordinating naming, grid mapping variables, etc)

stems.gis.conventions.create_coordinates(y, x, crs)[source]

Return y and x as coordinates variables given the crs

Parameters
  • y (np.ndarray) – Y coordinate

  • x (np.ndarray) – X coordinate

  • crs (rasterio.crs.CRS) – Coordinate reference system of y and x

Returns

  • xr.Variable (y_coord) – X coordinate

  • xr.Variable (x_coord) – Y coordinate

References

1

http://cfconventions.org/cf-conventions/v1.6.0/cf-conventions.html#coordinate-types

stems.gis.conventions.create_grid_mapping(crs, transform=None, grid_mapping='crs', gdal_compat=True)[source]

Return an xarray.DataArray of CF-compliant CRS info

Parameters
  • crs (rasterio.crs.CRS) – Coordinate reference system information

  • transform (affine.Affine, optional) – Affine transform. Will be written if writing GDAL compatibility attributes and if provided

  • grid_mapping (str, optional) – Name of grid mapping variable. Defaults to ‘crs’

  • gdal_compat (bool, optional) – Write GDAL compatibility attribute data (“spatial_ref” and “GeoTransform”)

Returns

“crs” variable holding CRS information

Return type

xarray.DataArray

stems.gis.conventions.georeference(xarr, crs, transform=None, grid_mapping='crs', inplace=False)[source]

Georeference XArray data with the CRS and Affine transform

Parameters
Returns

Georeferenced data (type depending on input)

Return type

xarray.DataArray or xarray.Dataset

stems.gis.conventions.get_grid_mapping(xarr, grid_mapping='crs')[source]

Return grid mapping variable

Parameters

xarr (xarray.Dataset or xarray.DataArray) – XArray data

Returns

XArray grid mapping variable

Return type

xarray.Variable

Raises

KeyError – Raised if grid mapping variable does not exist

stems.gis.conventions.is_georeferenced(xarr, grid_mapping='crs', required_gdal=False)[source]

Determine if XArray data is georeferenced

Parameters
  • xarr (xarray.DataArray or xarray.Dataset) – XArray data to check for georeferencing

  • grid_mapping (str, optional) – Name to use for grid mapping variable

  • require_gdal (bool, optional) – Require presence of attributes GDAL uses to georeference as backup (“spatial_ref” and “GeoTransform”)

Returns

True if is georeferenced

Return type

bool