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

Add preprocessor to extract surface values from 3D atmospheric variables #2641

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

jlenh
Copy link

@jlenh jlenh commented Jan 21, 2025

Description

This pull request introduces a new preprocessor function to extract the surface values from 3D atmospheric variables and corresponding surface pressure ps. The preprocessor function is largely based on the implementation done for the derivation of surface CO2 co2s at https://github.com/ESMValGroup/ESMValCore/blob/main/esmvalcore/preprocessor/_derive/co2s.py. It thus avoids having to create either at standalone _derive preprocessor or a new entry in the relevant CMOR tables. The attributes of the 3D atmospheric variables are transferred to the newly created cube and the variable name is changed to f'{var_name}s'.

Closes #2611


Before you get started

Checklist

It is the responsibility of the author to make sure the pull request is ready to review. The icons indicate whether the item will be subject to the 🛠 Technical or 🧪 Scientific review.


To help with the number pull requests:

@jlenh jlenh self-assigned this Jan 21, 2025
@jlenh jlenh added enhancement New feature or request preprocessor Related to the preprocessor variable derivation Related to variable derivation functions labels Jan 21, 2025
@jlenh
Copy link
Author

jlenh commented Jan 21, 2025

@bouweandela if you could point me to where in the documentation I should add relevant information ? Thanks 🙂

@bouweandela
Copy link
Member

@bouweandela if you could point me to where in the documentation I should add relevant information

In this file, please: https://github.com/ESMValGroup/ESMValCore/blob/main/doc/recipe/preprocessor.rst

You can find this, and much more useful information on contributing, under the links in the checklist above and in our contribution guidelines: https://docs.esmvaltool.org/projects/ESMValCore/en/latest/contributing.html

var_cube.coord_dims(air_pressure_coord),
)
target_levels = np.expand_dims(ps_cube.data, axis=z_axis)
sfc_data = stratify.interpolate(
Copy link
Member

Choose a reason for hiding this comment

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

Have you looked into using the esmvalcore.preprocessor.extract_levels function?

Copy link
Author

Choose a reason for hiding this comment

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

I tried to make it work but couldn't manage to. To replace the interpolation step I tried with

sfc_data = extract_levels(
            cube=cube,
            levels=ps_cube.data,
            scheme="linear",
            coordinate="air_pressure",
            rtol=1e-7,
            atol=None
            )

but I always get the following error TypeError: extract_levels() missing 1 required positional argument: 'data' which I don't really understand where it comes from. In case you have any insights on that.

Copy link
Member

Choose a reason for hiding this comment

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

This seems to be caused by the preserve_float_dtype decorator around extract_levels. Using

sfc_data = extract_levels(
    cube,
    levels=ps_cube.data,
    scheme="linear",
    coordinate="air_pressure",
    rtol=1e-7,
    atol=None
)

avoids this problem. @schlunma Since you introduced the wrapper, would you have time to take a look at improving it to avoid this puzzling error?

@bouweandela
Copy link
Member

Here is an interesting example of doing something similar for ocean data: https://cosima-recipes.readthedocs.io/en/latest/Recipes/Extract_Variables_at_Ocean_Bottom.html

I guess the ocean equivalent of ps would be pbo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request preprocessor Related to the preprocessor variable derivation Related to variable derivation functions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add derivation of surface concentrations for additional trace gases (CH4 and N2O)
2 participants