ioos / ioos/xarray-subset-grid
How to recognise a rectangular grid?
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 9
- Forks
- 11
- Avg merge
- 3d 7h
- Merged PRs (30d)
- 4
Description
The current code for recognising a rectangular grid is simple, but broken:
def recognize(ds: xr.Dataset) -> bool:
"""Recognize if the dataset matches the given grid."""
lat = ds.cf.coordinates.get("latitude", None)
lon = ds.cf.coordinates.get("longitude", None)
if lat is None or lon is None:
return False
# Make sure the coordinates are 1D and match
lat_ndim = ds[lat[0]].ndim
lon_ndim = ds[lon[0]].ndim
return lat_ndim == lon_ndim and lon_ndim == 1
All this does is:
- make sure there are a latitude and longitude coordinate -- fair enough
- make sure that the first of such are 1-D -- god start, but ....
If you run this code in an unstructured grid, it returns True -- not good.
Why?
Because UGRids have a bunch of 1-D lat and long coords:
In [18]: ds.cf.coordinates
Out[18]:
{'longitude': ['mesh_boundary_lon',
'mesh_edge_lon',
'mesh_face_lon',
'mesh_node_lon'],
'latitude': ['mesh_boundary_lat',
'mesh_edge_lat',
'mesh_face_lat',
'mesh_node_lat']}
and they are all 1D.
So: what do I test for?
-
this code looks at the zeroth lat-lon only -- is that OK? in my examples there are only one of each, but would that always be the case?
-
if above, it seem we should look and see if variables are using both the lat and lon coordinates ...
But this does seem fragile ...
Anyone have a better idea?
@ocefpaf: any thoughts on this?
@davidhassell: Sorry to ling you on this, but I thught you might have some ideas.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the recognize(ds) function shown in the issue and inspect how ds.cf.coordinates represents structured and unstructured grids in the reported examples. Determine a reliable recognition criterion that does not classify UGrid datasets as rectangular, then document the expected behavior and add or update tests if the repository provides relevant coverage.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- data
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100