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
andx
as coordinates variables given thecrs
- Parameters
y (np.ndarray) – Y coordinate
x (np.ndarray) – X coordinate
crs (rasterio.crs.CRS) – Coordinate reference system of
y
andx
- Returns
xr.Variable (y_coord) – X coordinate
xr.Variable (x_coord) – Y coordinate
References
-
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
-
stems.gis.conventions.
georeference
(xarr, crs, transform=None, grid_mapping='crs', inplace=False)[source]¶ Georeference XArray data with the CRS and Affine transform
- Parameters
xarr (xarray.DataArray or xarray.Dataset) – XArray data to georeference
crs (rasterio.crs.CRS) – Rasterio CRS
transform (affine.Affine, optional) – Affine transform of the data. Will be calculated using
stems.gis.coords.coords_to_transform()
if not providedgrid_mapping (str, optional) – Name to use for grid mapping variable
inplace (bool, optional) – If
False
, returns a modified shallow copy ofxarr
- Returns
Georeferenced data (type depending on input)
- Return type
-
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
- 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