Skip to content

Commit

Permalink
added cmor variable kwargs (#282)
Browse files Browse the repository at this point in the history
* added cmor variable kwargs

* Update cmor.py

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update whats_new.rst

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
larsbuntemeyer and pre-commit-ci[bot] authored Oct 28, 2024
1 parent 8299066 commit 91fc7ca
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
13 changes: 11 additions & 2 deletions cordex/cmor/cmor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -618,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 <https://cmor.llnl.gov/mydoc_cmor3_api/#cmor_variable>`_, e.g.,
``positive``, ``missing_value``, ``original_name``, ``history`` or ``comment``.
Parameters
----------
Expand Down
1 change: 1 addition & 0 deletions docs/whats_new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 91fc7ca

Please sign in to comment.