Skip to content

Commit

Permalink
Add docstring
Browse files Browse the repository at this point in the history
  • Loading branch information
dcherian committed Jul 17, 2024
1 parent 0d40b44 commit c88ea9c
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion xvec/accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1259,7 +1259,19 @@ def extract_points(
return result

def encode_cf(self) -> xr.Dataset:
"""Encode geometry variables and associated CRS with CF conventions"""
"""
Encode all geometry variables and associated CRS with CF conventions.
Use this method prior to writing an Xarray dataset to any array format
(e.g. netCDF or Zarr).
The following invariant is satisfied:
`assert ds.xvec.encode_cf().xvec.decode_cf().identical(ds) is True`
Returns
-------
Dataset
"""
import cf_xarray as cfxr

ds = self._obj.copy()
Expand Down Expand Up @@ -1308,6 +1320,16 @@ def encode_cf(self) -> xr.Dataset:
return encoded

def decode_cf(self) -> xr.Dataset:
"""
Decode geometries stored as CF-compliant arrays to shapely geometries.
The following invariant is satisfied:
`assert ds.xvec.encode_cf().xvec.decode_cf().identical(ds) is True`
Returns
-------
Dataset
"""
import cf_xarray as cfxr

decoded = cfxr.geometry.decode_geometries(self._obj.copy())
Expand Down

0 comments on commit c88ea9c

Please sign in to comment.