diff --git a/README.md b/README.md index 70ca036..36da940 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/pyproject.toml b/pyproject.toml index fb6e438..80ad3db 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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" diff --git a/xnemogcm/__init__.py b/xnemogcm/__init__.py index 95f48e3..50d7a5c 100644 --- a/xnemogcm/__init__.py +++ b/xnemogcm/__init__.py @@ -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 diff --git a/xnemogcm/domcfg.py b/xnemogcm/domcfg.py index c4e7f0f..8879be1 100644 --- a/xnemogcm/domcfg.py +++ b/xnemogcm/domcfg.py @@ -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) @@ -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 diff --git a/xnemogcm/test/test_domcfg.py b/xnemogcm/test/test_domcfg.py index 8180281..09870ab 100644 --- a/xnemogcm/test/test_domcfg.py +++ b/xnemogcm/test/test_domcfg.py @@ -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" diff --git a/xnemogcm/test/test_nemo.py b/xnemogcm/test/test_nemo.py index 696c9ec..c0bd52e 100644 --- a/xnemogcm/test/test_nemo.py +++ b/xnemogcm/test/test_nemo.py @@ -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", ) @@ -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"