xproj

raw JSON →
0.2.1 verified Sat May 09 auth: no python

xproj is an extension for xarray that adds support for coordinate reference systems (CRS) and map projections. It provides CRS-aware indexes, accessors, and integration with pyproj. The current version is 0.2.1, with an active development cadence.

pip install xproj
error AttributeError: 'Dataset' object has no attribute 'xproj'
cause xproj module not imported before accessing the accessor.
fix
Add import xproj at the top of your script.
error ImportError: cannot import name 'CRS' from 'xproj'
cause Incorrect import path; CRS class is from pyproj, not xproj.
fix
Use from pyproj import CRS instead.
breaking Version 0.2.0 removed the abstract method `_proj_get_crs()` from the CRS-aware index base class. Third-party custom indexes must define a `crs` property instead.
fix Replace `_proj_get_crs()` with a `crs` abstract property in your custom index class.
gotcha The CRS accessor `ds.xproj` is only available if xproj is imported. Forgetting to import xproj will result in an AttributeError.
fix Always run `import xproj` before using the `.xproj` accessor.
deprecated The `map_crs` method's `allow_override` parameter may be deprecated in future versions. Use explicit CRS assignment instead.
fix Set CRS directly using `ds.xproj.set_crs(crs)` rather than relying on `allow_override`.

Quick example: load a dataset and retrieve its CRS via the xproj accessor.

import xarray as xr
import xproj

ds = xr.tutorial.open_dataset('air_temperature')
# assuming lat/lon coordinates with CF attributes
crs = ds.xproj.get_crs()
print(crs)