Conversation
- is_structured - is_vertex - is_layered
- add method to get empty data array with new layer coord but maintaining other dims/coords from source data array
- only drop datavars with layer coord - add the other datavars back to final combined result - lazy formatting in logging
- specificies dimensions for grid types
- no longer add reindexer to attributes (this was annoying when saving the dataset)
|
test fail related to codacy api outage: https://status.codacy.com/ |
rubencalje
left a comment
There was a problem hiding this comment.
Looks good. The use of Enum looks a bit complicated to me, but maybe you can show me what is the benefit of this at a later time.
Good question. My reasoning so far: it's fancy, and it autocompletes nicely in your editor across files. It has a nice representation:
You can do a reverse lookup, like this:
Or even nicer: class GridTypeDims(Enum):
"""Enum for grid dimensions."""
STRUCTURED_LAYERED = ("layer", "y", "x")
VERTEX_LAYERED = ("layer", "icell2d")
STRUCTURED = ("y", "x")
VERTEX = ("icell2d",)
@classmethod
def parse_dims(cls, ds):
"""Get GridTypeDim from dataset or dataarray.
Parameters
----------
ds : xr.Dataset or xr.DataArray
Dataset or DataArray to parse.
"""
for gridtype in GridTypeDims:
if set(gridtype.value).issubset(ds.dims):
return gridtypeWhich allows
or
|
OnnoEbbens
left a comment
There was a problem hiding this comment.
Nice improvement! I also didn't know about the enum inheritance but it looks nice. I think we should implement this for all the gridtype checks. We can maybe even remove the gridtype attribute.
Especially looking forward to replace this code in the resample module for a decent gridtype check:
if len(da.shape) > 1 and len(da.y) == da.shape[-2] and len(da.x) == da.shape[-1]
Allow combining layers in vertex datasets.
Add methods to check dataset or dataarray type:
nlmod.grid.is_structured(ds)nlmod.grid.is_vertex(ds)nlmod.grid.is_layered(ds)Added a
GridTypeDimsenum that specifies the dimensions for different grid types. Perhaps this and the above methods can be used across nlmod for consistency in how we check for different types of inputs. But that is best left to another PR if we agree this is the way to go.