From 35258bbea864a9b9fbe1601e33154ed6b52b1380 Mon Sep 17 00:00:00 2001 From: Bouwe Andela Date: Thu, 30 Apr 2026 18:17:21 +0200 Subject: [PATCH] Add fixes for Aladin models --- .../cordex/cnrm_cerfacs_cnrm_cm5/aladin53.py | 67 +++++++++++++++++++ .../cordex/cnrm_cerfacs_cnrm_cm5/aladin63.py | 40 +++++++++++ 2 files changed, 107 insertions(+) create mode 100644 esmvalcore/cmor/_fixes/cordex/cnrm_cerfacs_cnrm_cm5/aladin53.py diff --git a/esmvalcore/cmor/_fixes/cordex/cnrm_cerfacs_cnrm_cm5/aladin53.py b/esmvalcore/cmor/_fixes/cordex/cnrm_cerfacs_cnrm_cm5/aladin53.py new file mode 100644 index 0000000000..4acbc1c4c0 --- /dev/null +++ b/esmvalcore/cmor/_fixes/cordex/cnrm_cerfacs_cnrm_cm5/aladin53.py @@ -0,0 +1,67 @@ +"""Fixes for rcm ALADIN53 driven by CNRM-CERFACS-CNRM-CM5.""" + +from __future__ import annotations + +from typing import TYPE_CHECKING + +import numpy as np +from iris.util import promote_aux_coord_to_dim_coord + +from esmvalcore.cmor.fix import Fix + +if TYPE_CHECKING: + from collections.abc import Sequence + + from iris.cube import Cube + + +class AllVars(Fix): + """Fixes for all variables.""" + + def fix_metadata(self, cubes: Sequence[Cube]) -> Sequence[Cube]: + domain_step = { + "-11": 12500, + "-22": 25000, + "-44": 50000, + } + + for cube in cubes: + domain_resolution = self.extra_facets["domain"][-3:] + step = domain_step[domain_resolution] + + for coord_name in [ + "projection_x_coordinate", + "projection_y_coordinate", + ]: + coord = cube.coord(coord_name) + n_steps = coord.shape[0] + coord.points = step * np.linspace( + -(n_steps - 1) / 2, + (n_steps - 1) / 2, + n_steps, + ) + coord.units = "m" + coord.guess_bounds() + promote_aux_coord_to_dim_coord(cube, coord_name) + + return cubes + + +class Sftlf(Fix): + """Fixes for sftlf.""" + + def fix_metadata(self, cubes: Sequence[Cube]) -> Sequence[Cube]: + for cube in cubes: + cube.units = "1" + cube.convert_units(self.vardef.units) + return cubes + + +class Ts(Fix): + """Fixes for ts.""" + + def fix_metadata(self, cubes: Sequence[Cube]) -> Sequence[Cube]: + for cube in cubes: + cube.units = "deg_C" + cube.convert_units(self.vardef.units) + return cubes diff --git a/esmvalcore/cmor/_fixes/cordex/cnrm_cerfacs_cnrm_cm5/aladin63.py b/esmvalcore/cmor/_fixes/cordex/cnrm_cerfacs_cnrm_cm5/aladin63.py index d192e3709b..6e2804cdb2 100644 --- a/esmvalcore/cmor/_fixes/cordex/cnrm_cerfacs_cnrm_cm5/aladin63.py +++ b/esmvalcore/cmor/_fixes/cordex/cnrm_cerfacs_cnrm_cm5/aladin63.py @@ -1,11 +1,51 @@ """Fixes for rcm ALADIN63 driven by CNRM-CERFACS-CNRM-CM5.""" +from __future__ import annotations + +from typing import TYPE_CHECKING + import numpy as np from esmvalcore.cmor._fixes.cordex.cordex_fixes import TimeLongName as BaseFix from esmvalcore.cmor._fixes.shared import add_scalar_height_coord from esmvalcore.cmor.fix import Fix +if TYPE_CHECKING: + from collections.abc import Sequence + + from iris.cube import Cube + + +class AllVars(Fix): + """Fixes for all variables.""" + + def fix_metadata(self, cubes: Sequence[Cube]) -> Sequence[Cube]: + domain_step = { + "-11": 12500, + "-22": 25000, + "-44": 50000, + } + + for cube in cubes: + domain_resolution = self.extra_facets["domain"][-3:] + step = domain_step[domain_resolution] + + for coord_name in [ + "projection_x_coordinate", + "projection_y_coordinate", + ]: + coord = cube.coord(coord_name) + n_steps = coord.shape[0] + coord.points = step * np.linspace( + -(n_steps - 1) / 2, + (n_steps - 1) / 2, + n_steps, + ) + coord.units = "m" + coord.guess_bounds() + + return cubes + class Tas(Fix): """Fixes for tas."""