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.
The current code for recognising a rectangular grid is simple, but broken:
All this does is:
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:
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.