Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose odc.{crs_coord,grid_mapping} #167

Merged
merged 1 commit into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions odc/geo/_xr_interop.py
Original file line number Diff line number Diff line change
Expand Up @@ -953,6 +953,18 @@ def map_bounds(self) -> Tuple[Tuple[float, float], Tuple[float, float]]:

return gbox.map_bounds()

@property
def crs_coord(self) -> xarray.DataArray | None:
"""Return CRS coordinate DataArray."""
return self._state.crs_coord

@property
def grid_mapping(self) -> str | None:
"""Return name of the grid mapping coordinate."""
if c := self.crs_coord:
return str(c.name)
return None

mask = _wrap_op(mask)
crop = _wrap_op(crop)

Expand Down
5 changes: 5 additions & 0 deletions tests/test_xr_interop.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,9 @@ def test_odc_extension(xx_epsg4326: xr.DataArray, geobox_epsg4326: GeoBox):
assert xx.odc.map_bounds() == gbox.map_bounds()
assert xx.odc.output_geobox("utm").crs.epsg is not None
assert xx.odc.aspect == gbox.aspect
assert xx.odc.grid_mapping == xx.encoding["grid_mapping"]
assert xx.odc.crs_coord == xx.spatial_ref
assert xx.odc.crs_coord.attrs == xx.spatial_ref.attrs

# this drops encoding/attributes, but crs/geobox should remain the same
_xx = xx * 10.0
Expand Down Expand Up @@ -299,6 +302,8 @@ def test_odc_extension_ds(xx_epsg4326: xr.DataArray, geobox_epsg4326: GeoBox):
def test_assign_crs(xx_epsg4326: xr.DataArray):
xx = purge_crs_info(xx_epsg4326)
assert xx.odc.crs is None
assert xx.odc.grid_mapping is None
assert xx.odc.crs_coord is None
yy = xx.odc.assign_crs("epsg:4326")
assert xx.odc.uncached.crs is None
assert yy.odc.crs == "epsg:4326"
Expand Down
Loading