API Reference#

Dataset proj extension#

XProj extends xarray.Dataset with the properties and methods below. To enable it, be sure to import xproj after xarray:

>>> import xarray as xr
>>> import xproj

CRS properties

Dataset.proj.crs_indexes

Return an immutable dictionary of coordinate names as keys and CRSIndex objects as values.

Dataset.proj.crs_aware_indexes

Return an immutable dictionary of coordinate names as keys and xarray Index objects that are CRS-aware.

Dataset.proj.crs

Return the coordinate reference system as a pyproj.crs.CRS object, or None if there isn't any.

CRS methods

Dataset.proj.assign_crs([spatial_ref_crs, ...])

Assign one or more spatial reference coordinate variables, each with a given coordinate reference system (CRS).

Dataset.proj.map_crs([spatial_ref_coords, ...])

Map spatial reference coordinate(s) to other indexed coordinates.

Dataset.proj.write_crs_info([spatial_ref, func])

Write CRS information as attributes to one or all spatial reference coordinates.

Dataset.proj.clear_crs_info([spatial_ref])

Convenient method to clear all attributes of one or all spatial reference coordinates.

DataArray proj extension#

XProj extends xarray.DataArray with the properties and methods below. To enable it, be sure to import xproj after xarray:

>>> import xarray as xr
>>> import xproj

CRS properties

DataArray.proj.crs_indexes

Return an immutable dictionary of coordinate names as keys and CRSIndex objects as values.

DataArray.proj.crs_aware_indexes

Return an immutable dictionary of coordinate names as keys and xarray Index objects that are CRS-aware.

DataArray.proj.crs

Return the coordinate reference system as a pyproj.crs.CRS object, or None if there isn't any.

CRS methods

DataArray.proj.assign_crs([spatial_ref_crs, ...])

Assign one or more spatial reference coordinate variables, each with a given coordinate reference system (CRS).

DataArray.proj.map_crs([spatial_ref_coords, ...])

Map spatial reference coordinate(s) to other indexed coordinates.

DataArray.proj.write_crs_info([spatial_ref, ...])

Write CRS information as attributes to one or all spatial reference coordinates.

DataArray.proj.clear_crs_info([spatial_ref])

Convenient method to clear all attributes of one or all spatial reference coordinates.

CRS utility functions#

format_crs(crs[, max_width])

Format CRS as a string.

get_common_crs(crs_objs[, on_undefined_crs, ...])

Try getting a common, unique CRS from an input sequence of (possibly undefined) CRS objects.

3rd-party Xarray extensions#

XProj provides some utilities (Mixin classes, decorators) for easier integration with 3rd-party Xarray geospatial extensions.

ProjAccessorMixin()

Mixin class that marks XProj support for an Xarray accessor.

ProjIndexMixin()

Mixin class that marks XProj support for an Xarray index.

register_accessor(accessor_cls)

Decorator for registering a geospatial, CRS-dependent Xarray (Dataset and/or DataArray) accessor.