From 94296f17db48ca35445c17bfbf112502ec5e5d62 Mon Sep 17 00:00:00 2001 From: Lars Buntemeyer Date: Fri, 27 Sep 2024 14:37:04 +0200 Subject: [PATCH 1/4] added cmor variable kwargs --- cordex/cmor/cmor.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/cordex/cmor/cmor.py b/cordex/cmor/cmor.py index 2a24455..276651c 100644 --- a/cordex/cmor/cmor.py +++ b/cordex/cmor/cmor.py @@ -278,7 +278,14 @@ def _cmor_write(da, table_id, cmorTime, cmorZ, cmorGrid, file_name=True): coords.append(cmorZ) coords.append(cmorGrid) - cmor_var = cmor.variable(da.name, da.units, coords) + cmor_var_kwargs = {} + for kwarg in ["positive", "missing_value", "original_name", "history", "comment"]: + if kwarg in da.attrs: + cmor_var_kwargs[kwarg] = da.attrs[kwarg] + + cmor_var = cmor.variable( + table_entry=da.name, units=da.units, axis_ids=coords, **cmor_var_kwargs + ) if "time" in da.coords: ntimes_passed = da.time.size From 8addc6c81ab17dbcdd679dabb1a2a016a633414d Mon Sep 17 00:00:00 2001 From: Lars Buntemeyer Date: Fri, 25 Oct 2024 12:12:44 +0200 Subject: [PATCH 2/4] Update cmor.py --- cordex/cmor/cmor.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cordex/cmor/cmor.py b/cordex/cmor/cmor.py index 276651c..2f0612c 100644 --- a/cordex/cmor/cmor.py +++ b/cordex/cmor/cmor.py @@ -625,7 +625,9 @@ def cmorize_variable( follow basic CF conventions. If a vertical coordinate is available, it should have an ``axis="Z"`` attribute so it can be understood by ``cf_xarray`` and it should be named after the unique key of the coordinate in the cmor grids table (not the out_name), e.g., name it ``sdepth`` if you - need a soil layer coordinate instead of ``depth``. + need a soil layer coordinate instead of ``depth``. Variables may have one of the following attributes + that are used as keyword arguments in the call to `cmor_variable `_, e.g., + ``positive``, ``missing_value``, ``original_name``, ``history`` or ``comment``. Parameters ---------- From 10a6b928cf9909a3d31da2101901cdee07e6540b Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 25 Oct 2024 10:14:32 +0000 Subject: [PATCH 3/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- cordex/cmor/cmor.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cordex/cmor/cmor.py b/cordex/cmor/cmor.py index 2f0612c..94ebd5b 100644 --- a/cordex/cmor/cmor.py +++ b/cordex/cmor/cmor.py @@ -625,8 +625,8 @@ def cmorize_variable( follow basic CF conventions. If a vertical coordinate is available, it should have an ``axis="Z"`` attribute so it can be understood by ``cf_xarray`` and it should be named after the unique key of the coordinate in the cmor grids table (not the out_name), e.g., name it ``sdepth`` if you - need a soil layer coordinate instead of ``depth``. Variables may have one of the following attributes - that are used as keyword arguments in the call to `cmor_variable `_, e.g., + need a soil layer coordinate instead of ``depth``. Variables may have one of the following attributes + that are used as keyword arguments in the call to `cmor_variable `_, e.g., ``positive``, ``missing_value``, ``original_name``, ``history`` or ``comment``. Parameters From 072aae1b00d556cb1c516afba187c96fcff401b8 Mon Sep 17 00:00:00 2001 From: Lars Buntemeyer Date: Fri, 25 Oct 2024 20:14:43 +0200 Subject: [PATCH 4/4] Update whats_new.rst --- docs/whats_new.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/whats_new.rst b/docs/whats_new.rst index 4a5b81c..2052994 100644 --- a/docs/whats_new.rst +++ b/docs/whats_new.rst @@ -9,6 +9,7 @@ What's new New Features ~~~~~~~~~~~~ +- Variables attributes are recognized for cmorization in :py:meth:`cmor.cmorize_variable` (:pull:`282`). - New function :py:meth:`derotate_vector` to transform vector components from rotated coordinate systems (:pull:`264`). Internal Changes