Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add standard names and units when possible in domcfg #61

Merged
merged 3 commits into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,10 @@ the latest version of the code, and publish them to `example` when commiting to

## What's new

### not released yet
### v0.4.2 (2023-08-07)
* Allow additional dimension names occurring when variables on inner grid are diagnosed, e.g. `x_grid_U_inner` or `x_grid_U`.
* Add coordinates into the DataArrays
* Add some standard names and units in domcfg

### v0.4.1 (2023-03-29)
* Allow to open files if time bounds are missing
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "xnemogcm"
version = "0.4.1"
version = "0.4.2"
description = "Interface to open NEMO global circulation model output dataset and create a xgcm grid."
license = "MIT"
homepage = "https://github.com/rcaneill/xnemogcm"
Expand Down
2 changes: 1 addition & 1 deletion xnemogcm/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "0.4.1"
__version__ = "0.4.2"

from .domcfg import open_domain_cfg
from .nemo import open_nemo, process_nemo
Expand Down
32 changes: 32 additions & 0 deletions xnemogcm/domcfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,34 @@
from .tools import get_domcfg_points, _dir_or_files_to_files


def _add_cf(domcfg):
"""
Add cf standard_name and units when possible
"""
for i in domcfg.variables:
if "glam" in i:
domcfg[i].attrs.update(
{"standard_name": "longitude", "units": "degrees_east"}
)
if "gphi" in i:
domcfg[i].attrs.update(
{"standard_name": "latitude", "units": "degrees_north"}
)
if "gdep" in i:
domcfg[i].attrs.update(
{"standard_name": "depth", "units": "m", "positive": "down"}
)
if "e1" in i or "e2" in i:
domcfg[i].attrs.update({"units": "m"})
if "e3" in i:
domcfg[i].attrs.update({"standard_name": "cell_thickness", "units": "m"})
if i in ["ff", "ff_f", "ff_t"]:
domcfg[i].attrs.update(
{"standard_name": "coriolis_parameter", "units": "s-1"}
)
return domcfg


def domcfg_preprocess(ds):
"""
Preprocess domcfg / meshmask files when needed to be recombined (= 1 file per processor)
Expand Down Expand Up @@ -197,4 +225,8 @@ def open_domain_cfg(datadir=None, files=None, add_coordinates=True):
# adding variables as coordinates
if add_coordinates:
domcfg = _add_coordinates(domcfg)
# Remove nav_lon and nav_lat
domcfg = domcfg.drop_vars(["nav_lon", "nav_lat"], errors="ignore")
# Add cf
domcfg = _add_cf(domcfg)
return domcfg
21 changes: 21 additions & 0 deletions xnemogcm/test/test_domcfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,24 @@ def test_compare_domcfg_mesh_mask(data_path):
domcfg_1 = open_domain_cfg(datadir=(data_path / "mesh_mask_1_file"))
domcfg_multi = open_domain_cfg(datadir=(data_path / "mesh_mask_multi_files"))
assert (domcfg_1 == domcfg_multi).all()


def test_coordinates_horizontal(data_path):
"""Test that coordinates are added to nemo files"""
domcfg = open_domain_cfg(
datadir=data_path / "mesh_mask_1_file",
)
assert "glamt" in domcfg.e1t.coords
if "ff_f" in domcfg:
assert "glamf" in domcfg.ff_f.coords
else:
# NEMO 3.6
assert "glamf" in domcfg.ff.coords


def test_attributes(data_path):
"""Test that coordinates are added to nemo files"""
domcfg = open_domain_cfg(
datadir=data_path / "mesh_mask_1_file",
)
assert domcfg.glamt.attrs.get("standard_name") == "longitude"
4 changes: 2 additions & 2 deletions xnemogcm/test/test_nemo.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def test_use_preprocess(data_path):


def test_coordinates_horizontal(data_path):
"""Test opening of nemo files"""
"""Test that coordinates are added to nemo files"""
domcfg = open_domain_cfg(
datadir=data_path / "mesh_mask_1_file",
)
Expand All @@ -162,7 +162,7 @@ def test_coordinates_horizontal(data_path):


def test_coordinates_vertical(data_path, request):
"""Test opening of nemo files"""
"""Test that coordinates are added to nemo files"""
if request.node.callspec.id == "3.6":
pytest.xfail(
"Failing for nemo <= 3.6 as gdept_0 and gdepw_0 are not in mesh mask"
Expand Down
Loading