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

Load fx variables as cube cell measures / ancillary variables #999

Merged
merged 63 commits into from
Apr 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
77d9075
Load areacella/o and volcello as cell measures
sloosvel Feb 3, 2021
7c47aa5
Fix tests
sloosvel Feb 4, 2021
72f16f8
Add tests
sloosvel Feb 5, 2021
3347682
Restore original test
sloosvel Feb 5, 2021
6bc7b8a
Fix tests
sloosvel Feb 5, 2021
42e62db
Move to separate preproc step
sloosvel Feb 8, 2021
158537b
Fix tests
sloosvel Feb 8, 2021
a92cbbf
Fix return statement
sloosvel Feb 8, 2021
5e370bf
Fix flake
sloosvel Feb 8, 2021
707baff
Do not push
sloosvel Feb 8, 2021
5023bdd
Fix format
sloosvel Feb 8, 2021
1c23f19
Call fx variables with yaml dicts
sloosvel Feb 9, 2021
2ebbe59
Fix bug when only dealing with a single file
sloosvel Feb 9, 2021
04c4331
Fix tests
sloosvel Feb 9, 2021
6fa2513
Add integration tests
sloosvel Feb 9, 2021
ffc7996
Fix flake
sloosvel Feb 9, 2021
28d7bb1
Fix flake again
sloosvel Feb 9, 2021
5a1d009
Add more tests
sloosvel Feb 10, 2021
576ca7e
Fix flake
sloosvel Feb 10, 2021
9a09475
Use fx var info instead of cube attrs
sloosvel Feb 19, 2021
cb57d8c
Fix some codacy errors
sloosvel Feb 19, 2021
a46e15b
Merge remote-tracking branch 'origin/master' into dev_load_cell_measu…
sloosvel Feb 19, 2021
3e9e2c2
Accept fx_variables as list of dicts
sloosvel Mar 11, 2021
7bf59cd
First attempt at adding ancillary vars
sloosvel Mar 11, 2021
034706f
Add docstrings
sloosvel Mar 11, 2021
6367c5f
Move tests
sloosvel Mar 12, 2021
f68e407
Merge remote-tracking branch 'origin/master' into dev_load_cell_measu…
sloosvel Mar 12, 2021
de337ef
Update test and fix flake
sloosvel Mar 12, 2021
c92cce7
Remove old tests
sloosvel Mar 12, 2021
392b6c0
Update documentation
sloosvel Mar 12, 2021
1ba36ae
Broadcast ancillary vars to shape
sloosvel Mar 12, 2021
298606e
Remove fx_variables attribute
sloosvel Mar 12, 2021
c41dbdf
Use ancillary vars in mask and weighting preprocs
sloosvel Mar 12, 2021
641e611
Fix tests due to fx_variables argument removal
sloosvel Mar 13, 2021
004cca4
Fix flake
sloosvel Mar 13, 2021
796b3f1
Skip uneeded broadcast
sloosvel Mar 13, 2021
0882274
Remove zonal_stats from fx_steps
sloosvel Mar 13, 2021
763ee9c
Make functions public
sloosvel Mar 13, 2021
d0fb5cd
Improve documentation
sloosvel Mar 13, 2021
d9cacbc
Improve documentation
sloosvel Mar 13, 2021
584edf1
Fix bug
sloosvel Mar 15, 2021
f1272c7
Merge remote-tracking branch 'origin/master' into dev_load_cell_measu…
sloosvel Mar 15, 2021
b1a16d7
Fix flake
sloosvel Mar 15, 2021
9e62deb
Attempt to fix codacy
sloosvel Mar 24, 2021
54a0f67
Merge remote-tracking branch 'origin/master' into dev_load_cell_measu…
sloosvel Mar 24, 2021
dd5f396
Apply suggestions from code review
sloosvel Mar 24, 2021
6eda1f2
Update esmvalcore/preprocessor/_ancillary_vars.py
sloosvel Mar 24, 2021
eab43f5
Improve documentations
sloosvel Mar 26, 2021
45738f8
Merge branch 'dev_load_cell_measures_in_cube' of https://github.com/E…
sloosvel Mar 26, 2021
bb3ece4
Update message in test
sloosvel Mar 26, 2021
c7a913d
Update test properly
sloosvel Mar 26, 2021
a78d76a
Print cube in log
sloosvel Mar 26, 2021
17aa93e
Fix condition
sloosvel Mar 29, 2021
61e0a51
Fix previous commit mess
sloosvel Mar 29, 2021
93a9afd
fix test
valeriupredoi Mar 29, 2021
28a88ee
run a full dev test; I will remove this after test runs
valeriupredoi Mar 30, 2021
bd2af40
removed temporary call to run GA test on this branch
valeriupredoi Mar 30, 2021
aa493f6
install in CWD
valeriupredoi Mar 30, 2021
2545a4b
print which esmvalcore is used
valeriupredoi Mar 30, 2021
6b48a10
revert changes done for testing only
valeriupredoi Mar 30, 2021
40d6184
Update test
sloosvel Mar 30, 2021
b5945c0
Merge remote-tracking branch 'origin/master' into dev_load_cell_measu…
sloosvel Apr 20, 2021
cedcdac
Remove fx_vars before saving
sloosvel Apr 20, 2021
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
136 changes: 124 additions & 12 deletions doc/recipe/preprocessor.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ roughly following the default order in which preprocessor functions are applied:

* :ref:`Variable derivation`
* :ref:`CMOR check and dataset-specific fixes`
* :ref:`Fx variables as cell measures or ancillary variables`
* :ref:`Vertical interpolation`
* :ref:`Weighting`
* :ref:`Land/Sea/Ice masking`
Expand Down Expand Up @@ -175,6 +176,34 @@ steps:
To get an overview on data fixes and how to implement new ones, please go to
:ref:`fixing_data`.

.. _Fx variables as cell measures or ancillary variables:

Fx variables as cell measures or ancillary variables
====================================================
Preprocessor steps related to spatial statistics or masking may require
the use of ``fx_variables`` to be able to perform the computations.
The preprocessor step ``add_fx_variables`` loads the required ``fx_variables``,
checks them against CMOR standards and adds them either as ``cell_measure``
or ``ancillary_variable`` inside the cube data. This ensures that the
defined preprocessor chain is applied to both ``variables`` and ``fx_variables``.

Note that when calling steps that require ``fx_variables`` inside diagnostic
scripts, the variables are expected to contain the required ``cell_measures`` or
``ancillary_variables``. If missing, they can be added using the following functions:

.. code-block::

from esmvalcore.preprocessor import (add_cell_measure, add_ancillary_variable)

cube_with_area_measure = add_cell_measure(cube, area_cube, 'area')

cube_with_volume_measure = add_cell_measure(cube, volume_cube, 'volume)

cube_with_ancillary_sftlf = add_ancillary_variable(cube, sftlf_cube)

cube_with_ancillary_sftgif = add_ancillary_variable(cube, sftgif_cube)

Details on the arguments needed for each step can be found in the following sections.

.. _Vertical interpolation:

Expand Down Expand Up @@ -325,8 +354,25 @@ experiment is preferred for fx data retrieval:
weighting_landsea_fraction:
area_type: land
exclude: ['CanESM2', 'reference_dataset']
fx_variables: [{'short_name': 'sftlf', 'exp': 'piControl'}, {'short_name': 'sftof', 'exp': 'piControl'}]
fx_variables:
sftlf:
exp: piControl
sftof:
exp: piControl

or alternatively:

.. code-block:: yaml

preprocessors:
preproc_weighting:
weighting_landsea_fraction:
area_type: land
exclude: ['CanESM2', 'reference_dataset']
fx_variables: [
{'short_name': 'sftlf', 'exp': 'piControl'},
{'short_name': 'sftof', 'exp': 'piControl'}
]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

last time I coded up this fx_variables dicts (or list of dicts) could accept the same number of data parameters as dataset - is this still the case? If so, it's prob good to mention it (unless I missed it)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's still the case. Otherwise some tests would not be passing, but I can add more examples in the documentation.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just one example with a mention of this (eg "you can include all manners of data parameters to better describe your fx variable...") would be grand 👍


See also :func:`esmvalcore.preprocessor.weighting_landsea_fraction`.

Expand Down Expand Up @@ -379,16 +425,35 @@ missing. Conversely, it retrieves the ``fx: sftlf`` mask when land needs to be
masked out, respectively.

Optionally you can specify your own custom fx variable to be used in cases when e.g. a certain
experiment is preferred for fx data retrieval:
experiment is preferred for fx data retrieval. Note that it is possible to specify as many tags
for the fx variable as required:


.. code-block:: yaml

preprocessors:
landmask:
mask_landsea:
mask_out: sea
fx_variables:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the new syntax, but could you make it backward compatible so the old syntax keeps working, at least for a while?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe until version 2.4 or 2.5?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can try, but it won't look too good I think.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yesh, I was asking a related question in my previous comment. I agree with @bouweandela on this one, when a new functional feature is implemented it's always nice to have a temporary overlap with its previous syntax 👍

sftlf:
exp: piControl
sftof:
exp: piControl
ensemble: r2i1p1f1

or alternatively:

.. code-block:: yaml

preprocessors:
landmask:
mask_landsea:
mask_out: sea
fx_variables: [{'short_name': 'sftlf', 'exp': 'piControl'}, {'short_name': 'sftof', 'exp': 'piControl'}]
fx_variables: [
{'short_name': 'sftlf', 'exp': 'piControl'},
{'short_name': 'sftof', 'exp': 'piControl', 'ensemble': 'r2i1p1f1'}
]

If the corresponding fx file is not found (which is
the case for some models and almost all observational datasets), the
Expand Down Expand Up @@ -428,8 +493,19 @@ experiment is preferred for fx data retrieval:
landseaicemask:
mask_landseaice:
mask_out: sea
fx_variables: [{'short_name': 'sftgif', 'exp': 'piControl'}]
fx_variables:
sftgif:
exp: piControl

or alternatively:

.. code-block:: yaml

preprocessors:
landseaicemask:
mask_landseaice:
mask_out: sea
fx_variables: [{'short_name': 'sftgif', 'exp': 'piControl'}]

See also :func:`esmvalcore.preprocessor.mask_landseaice`.

Expand Down Expand Up @@ -1332,18 +1408,36 @@ region, depth layer or time period is required, then those regions need to be
removed using other preprocessor operations in advance.

The ``fx_variables`` argument specifies the fx variables that the user wishes to input to the function;
the user may specify it as a list of variables e.g.
the user may specify it calling the variables e.g.

.. code-block:: yaml

fx_variables: ['areacello', 'volcello']
fx_variables:
areacello:
volcello:

or as list of dictionaries, with specific variable parameters (they key-value pair may be as specific
or calling the variables and adding specific variable parameters (the key-value pair may be as specific
as a CMOR variable can permit):

.. code-block:: yaml

fx_variables: [{'short_name': 'areacello', 'mip': 'Omon'}, {'short_name': 'volcello, mip': 'fx'}]
fx_variables:
areacello:
mip: Omon
volcello:
mip: fx

Alternatively, the ``fx_variables`` argument can also be specified as a list:

.. code-block:: yaml

fx_variables: ['areacello', 'volcello']

or as a list of dictionaries:

.. code-block:: yaml

fx_variables: [{'short_name': 'areacello', 'mip': 'Omon'}, {'short_name': 'volcello', 'mip': 'fx'}]

The recipe parser will automatically find the data files that are associated with these
variables and pass them to the function for loading and processing.
Expand Down Expand Up @@ -1392,18 +1486,36 @@ No depth coordinate is required as this is determined by Iris. This function
works best when the ``fx_variables`` provide the cell volume.

The ``fx_variables`` argument specifies the fx variables that the user wishes to input to the function;
the user may specify it as a list of variables e.g.
the user may specify it calling the variables e.g.

.. code-block:: yaml

fx_variables: ['areacello', 'volcello']
fx_variables:
areacello:
volcello:

or as list of dictionaries, with specific variable parameters (they key-value pair may be as specific
or calling the variables and adding specific variable parameters (the key-value pair may be as specific
as a CMOR variable can permit):

.. code-block:: yaml

fx_variables: [{'short_name': 'areacello', 'mip': 'Omon'}, {'short_name': 'volcello, mip': 'fx'}]
fx_variables:
areacello:
mip: Omon
volcello:
mip: fx

Alternatively, the ``fx_variables`` argument can also be specified as a list:

.. code-block:: yaml

fx_variables: ['areacello', 'volcello']

or as a list of dictionaries:

.. code-block:: yaml

fx_variables: [{'short_name': 'areacello', 'mip': 'Omon'}, {'short_name': 'volcello', 'mip': 'fx'}]

The recipe parser will automatically find the data files that are associated with these
variables and pass them to the function for loading and processing.
Expand Down
Loading