You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Right now, Dataset.dggs.cell_centers returns a Dataset containing the geographical coordinates. However, since we return a Dataset we have to use the lengthy ds.pipe(lambda ds: ds.merge(ds.dggs.cell_centers())) to assign the result to the original object (and this won't even work for DataArray).
Another option would be ds.pipe(lambda ds: ds.assign_coords(ds.dggs.cell_centers().coords)), which at least works for DataArray objects, but otherwise is slightly longer than the code with merge.
For this to work, ds.dggs.cell_centers() would have to return a Coordinates object (or a dict, or we make the geographic coordinates data variables), and assign_coords would have to accept a Callable[[Dataset | DataArray], dict | Coordinates].
# return cell centers as (shapely) point geometriesds.dggs.cell_centers() ->xr.DataArray# return cell centers as lat/lon coordinates ds.dggs.cell_centers_latlon() ->tuple[xr.DataArray, xr.DataArray]
# return cell boundaries as (shapely) polygon geometriesds.dggs.cell_boundaries() ->xr.DataArray
always use DataArray as the xarray object return type (maybe within tuple or dict)
cell_xxx() would always return shapely geometries
cell_centers_latlon() as an additional but common special case
_latlon is also used in other xdggs method names
a tuple of DataArrays seems the simplest and the most intuitive here to me. This is what I would expect from most Python scientific libraries. A dictionary repeats the information that we already have in the DataArrays (i.e., their names) and we may not want to be too opinionated about the names of the lat-lon coordinates.
Personally I wouldn't mind doing an extra step to assign lat-lon coordinates:
Right now,
Dataset.dggs.cell_centers
returns aDataset
containing the geographical coordinates. However, since we return aDataset
we have to use the lengthyds.pipe(lambda ds: ds.merge(ds.dggs.cell_centers()))
to assign the result to the original object (and this won't even work forDataArray
).Another option would be
ds.pipe(lambda ds: ds.assign_coords(ds.dggs.cell_centers().coords))
, which at least works forDataArray
objects, but otherwise is slightly longer than the code withmerge
.Ideally, we'd allow something like this:
For this to work,
ds.dggs.cell_centers()
would have to return aCoordinates
object (or adict
, or we make the geographic coordinates data variables), andassign_coords
would have to accept aCallable[[Dataset | DataArray], dict | Coordinates]
.What do you think, @benbovy?
The text was updated successfully, but these errors were encountered: