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

added cmor variable kwargs #282

Merged
merged 4 commits into from
Oct 28, 2024
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
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
Loading