-
Notifications
You must be signed in to change notification settings - Fork 39
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 derivation of surface concentrations for additional trace gases (CH4 and N2O) #2611
Comments
Yes, you can take that bit of code and put it into a new preprocessor function. That would avoid the need for these derived variables altogether. It might be nice to also make it work with ocean variables, e.g. so people could use it to extract the sea floor. |
In this case, can the additional required data be handled similarly to the |
You could probably register ESMValCore/esmvalcore/preprocessor/_mask.py Lines 151 to 155 in 6532a0a
It will then automatically get added in the recipe and will be available on the loaded Iris cube that gets passed to the preprocessor as an ancillary variable. Documentation on supplementary variables in the recipe is available here and from the Python API here. |
I implemented the derivation of the variable in the way you mentioned but ran into the problem that for the variable I have made some tests using new dedicated derivation files for |
You could update this code so it provides the correct dimensions: |
Do you know how to do that? Or could you use some help? |
I have partly reworked the
if you have any recommendations to improve that @bouweandela. From what I gathered otherwise, I added the preprocessing function in https://github.com/ESMValGroup/ESMValCore/blob/main/esmvalcore/preprocessor/_volume.py and its mention in https://github.com/ESMValGroup/ESMValCore/blob/main/esmvalcore/preprocessor/__init__.py#L86. Not sure if any other modification if needed somewhere else but for now it seems to work! |
From looking at the code, I think that may only work for 1D coordinates. Maybe something like this would be more general? ancillary_var = iris.coords.AncillaryVariable(
ancillary_cube.core_data(),
standard_name=ancillary_cube.standard_name,
units=ancillary_cube.units,
var_name=ancillary_cube.var_name,
attributes=ancillary_cube.attributes,
)
data_dims = [None] * ancillary_cube.ndim
for coord in ancillary_cube.coords():
for ancillary_dim, cube_dim in zip(ancillary_cube.coord_dims(coord), cube.coord_dims(coord)):
data_dims[ancillary_dim] = cube_dim
if None in data_dims:
none_dims = ", ".join(str(i) for i, d in enumerate(data_dims) if d is None)
msg = (
f"Failed to add {ancillary_cube} to {cube} as ancillary variable. "
f"No coordinate associated with ancillary cube dimensions {none_dims}"
)
raise ValueError(msg)
cube.add_ancillary_variable(ancillary_var, data_dims) |
The only problem I would have with this solution is that we only check the name and not the actual values of the coordinates (even though most of the preprocessing is handled through ESMValCore similarly for the input cube and ancillary variable so it should be fine I guess). |
Yes, I think so. It will be a bit slow. Maybe it would be sufficient to only loop over |
So replace |
The variables
ch4
andn2o
are 3D variables providing trace gas concentrations on pressure levels. The related surface quantities are often useful in order to compare to surface measurements (see cmorizer and diagnostics in development in ESMValTool repo Issue 3838 and Issue 3839 ). In the spirit of what was done forco2s
#587 , a dedicated preprocessor could be added to create the corresponding surface variables.Is there a way to make this surface derivation method somewhat standard or potentially used as a standalone preprocessor ? As it currently looks like, a dedicated preprocessing file would be needed in the esmvalcore//preprocessor/_derive folder for each variable
ch4s
andn2os
.The text was updated successfully, but these errors were encountered: