Skip to content

Commit

Permalink
included the option to extract a specific model_level_number
Browse files Browse the repository at this point in the history
  • Loading branch information
FranziskaWinterstein committed Sep 14, 2023
1 parent baa8fbe commit c693079
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 16 deletions.
20 changes: 5 additions & 15 deletions esmvalcore/cmor/_fixes/emac/_base_fixes.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,10 @@ def add_additional_cubes(self, cubes):
output file.
Currently, the following cubes can be added:
- 'hyam'
- 'hybm'
- 'hyai'
- 'hybi'
Code Delphi start here
- `zg` (`geometric_height_at_full_level_center`) from facet `zg_file`.
This can be used as vertical coordinate.
- `zghalf` (`geometric_height_at_half_level_center`) from facet
`zghalf_file`. This can be used as bounds for the vertical
coordinate.
- 'hyam' from facet `vct_table`
- 'hybm' from facet `vct_table`
- 'hyai' from facet `vct_table`
- 'hybi' from facet `vct_table`
Note
----
Expand All @@ -91,8 +82,7 @@ def add_additional_cubes(self, cubes):
"""
facets_to_consider = [
'zg_file',
'zghalf_file',
'vct_table',
]
for facet in facets_to_consider:
if facet not in self.extra_facets:
Expand Down
21 changes: 21 additions & 0 deletions esmvalcore/cmor/_fixes/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,27 @@ def add_altitude_from_plev(cube):
"Cannot add 'altitude' coordinate, 'air_pressure' coordinate not "
"available")

def add_model_level(cube):
"""Add a simplified level coordinate
Parameters
----------
cube : iris.cube.Cube
Input cube.
Raises
------
"""
z_coord = cube.coord(axis='z', dim_coords=True)
n_levels = list(z_coord.shape)[0]
levels = np.array(range(n_levels+1, 1, -1),
ndmin=1)
level_coords = iris.coords.AuxCoord(levels,
bounds=None,
standard_name='model_level_number',
units='1')
cube.add_aux_coord(level_coords, cube.coord_dims(z_coord))
return

def add_scalar_depth_coord(cube, depth=0.0):
"""Add scalar coordinate 'depth' with value of `depth`m."""
Expand Down
6 changes: 5 additions & 1 deletion esmvalcore/preprocessor/_regrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from iris.analysis import AreaWeighted, Linear, Nearest, UnstructuredNearest
from iris.util import broadcast_to_shape

from ..cmor._fixes.shared import add_altitude_from_plev, add_plev_from_altitude
from ..cmor._fixes.shared import add_altitude_from_plev, add_plev_from_altitude, add_model_level
from ..cmor.table import CMOR_TABLES
from ._other import get_array_module
from ._regrid_esmpy import ESMF_REGRID_METHODS
Expand Down Expand Up @@ -988,6 +988,10 @@ def extract_levels(cube,
if coordinate == 'altitude' and 'air_pressure' in coord_names:
# Calculate altitude coordinate from pressure levels.
add_altitude_from_plev(cube)
if coordinate == 'model_level_number':
# Add simple model_level_number coordinate
add_model_level(cube)

src_levels = cube.coord(coordinate)
else:
src_levels = cube.coord(axis='z', dim_coords=True)
Expand Down

0 comments on commit c693079

Please sign in to comment.