Skip to content

Commit

Permalink
normalization: Add support for Schism's new IO
Browse files Browse the repository at this point in the history
In the new IO, `nSCHISM_vgrid_layers" is missing from the 2D output.
Therefore, we can't assume its existence + we need to rename it only if it is available.
  • Loading branch information
pmav99 committed May 12, 2023
1 parent 228c215 commit c07ffc1
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions thalassa/normalization.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ class THALASSA_FORMATS(enum.Enum):
"nSCHISM_hgrid_edge",
"nSCHISM_hgrid_face",
"nSCHISM_hgrid_node",
"nSCHISM_vgrid_layers",
"nMaxSCHISM_hgrid_face_nodes",
}
_SCHISM_VARS = {
Expand Down Expand Up @@ -82,7 +81,8 @@ def is_generic(ds: xr.Dataset) -> bool:


def is_schism(ds: xr.Dataset) -> bool:
return _SCHISM_DIMS.issubset(ds.dims) and _SCHISM_VARS.issubset(ds.data_vars)
total_vars = list(ds.data_vars.keys()) + list(ds.coords.keys())
return _SCHISM_DIMS.issubset(ds.dims) and _SCHISM_VARS.issubset(total_vars)


def is_pyposeidon(ds: xr.Dataset) -> bool:
Expand Down Expand Up @@ -132,13 +132,19 @@ def normalize_schism(ds: xr.Dataset) -> xr.Dataset:
"nSCHISM_hgrid_edge": "edge",
"nSCHISM_hgrid_face": "face",
"nSCHISM_hgrid_node": "node",
"nSCHISM_vgrid_layers": "layer",
"SCHISM_hgrid_face_nodes": "face_nodes",
"nMaxSCHISM_hgrid_face_nodes": "max_no_vertices",
"SCHISM_hgrid_node_x": "lon",
"SCHISM_hgrid_node_y": "lat",
},
)
if "nSCHISM_vgrid_layers" in ds.dims:
# I.e. OLD Schism IO or "merged" new IO
ds = ds.rename(
{
"nSCHISM_vgrid_layers": "layer",
},
)
# SCHISM output uses one-based indices for `face_nodes`
# Let's ensure that we use zero-based indices everywhere.
ds["face_nodes"] -= 1
Expand Down

0 comments on commit c07ffc1

Please sign in to comment.