From 73076c2b26d8c726db2b6132b0f4df4d071bd44d Mon Sep 17 00:00:00 2001 From: Bouwe Andela Date: Fri, 27 Mar 2026 18:02:30 +0100 Subject: [PATCH 1/2] Fix endianness of CORDEX CCLM4-8-17 data --- .../cmor/_fixes/cordex/cnrm_cerfacs_cnrm_cm5/cclm4_8_17.py | 7 +++++++ esmvalcore/cmor/_fixes/cordex/cordex_fixes.py | 7 +++++++ .../cmor/_fixes/cordex/mohc_hadgem2_es/cclm4_8_17.py | 7 +++++++ .../cmor/_fixes/cordex/mpi_m_mpi_esm_lr/cclm4_8_17.py | 7 +++++++ 4 files changed, 28 insertions(+) create mode 100644 esmvalcore/cmor/_fixes/cordex/cnrm_cerfacs_cnrm_cm5/cclm4_8_17.py create mode 100644 esmvalcore/cmor/_fixes/cordex/mohc_hadgem2_es/cclm4_8_17.py create mode 100644 esmvalcore/cmor/_fixes/cordex/mpi_m_mpi_esm_lr/cclm4_8_17.py diff --git a/esmvalcore/cmor/_fixes/cordex/cnrm_cerfacs_cnrm_cm5/cclm4_8_17.py b/esmvalcore/cmor/_fixes/cordex/cnrm_cerfacs_cnrm_cm5/cclm4_8_17.py new file mode 100644 index 0000000000..e5eb16990b --- /dev/null +++ b/esmvalcore/cmor/_fixes/cordex/cnrm_cerfacs_cnrm_cm5/cclm4_8_17.py @@ -0,0 +1,7 @@ +"""Fixes for rcm CCLM4-8-17 driven by CNRM-CERFACS-CNRM-CM5.""" + +from esmvalcore.cmor._fixes.cordex.cordex_fixes import ( + CLMcomCCLM4817 as BaseFix, +) + +AllVars = BaseFix diff --git a/esmvalcore/cmor/_fixes/cordex/cordex_fixes.py b/esmvalcore/cmor/_fixes/cordex/cordex_fixes.py index ed0d76190a..ae189c76b1 100644 --- a/esmvalcore/cmor/_fixes/cordex/cordex_fixes.py +++ b/esmvalcore/cmor/_fixes/cordex/cordex_fixes.py @@ -5,6 +5,7 @@ import cordex as cx import iris +import iris.coords import numpy as np from cf_units import Unit from iris.coord_systems import LambertConformal, RotatedGeogCS @@ -95,6 +96,12 @@ def fix_metadata(self, cubes): if time_unit.calendar == "standard": new_unit = time_unit.change_calendar("proleptic_gregorian") cube.coord("time").units = new_unit + # Fix the endianness of the data. + if cube.core_data().dtype == np.dtype(">f4"): + cube.data = cube.core_data().astype( + np.float32, + casting="same_kind", + ) for coord in cube.coords(): if coord.dtype in [">f8", ">f4"]: coord.points = coord.core_points().astype( diff --git a/esmvalcore/cmor/_fixes/cordex/mohc_hadgem2_es/cclm4_8_17.py b/esmvalcore/cmor/_fixes/cordex/mohc_hadgem2_es/cclm4_8_17.py new file mode 100644 index 0000000000..ebd246f5ce --- /dev/null +++ b/esmvalcore/cmor/_fixes/cordex/mohc_hadgem2_es/cclm4_8_17.py @@ -0,0 +1,7 @@ +"""Fixes for rcm CCLM4-8-17 driven by MOHC-HadGEM2-ES.""" + +from esmvalcore.cmor._fixes.cordex.cordex_fixes import ( + CLMcomCCLM4817 as BaseFix, +) + +AllVars = BaseFix diff --git a/esmvalcore/cmor/_fixes/cordex/mpi_m_mpi_esm_lr/cclm4_8_17.py b/esmvalcore/cmor/_fixes/cordex/mpi_m_mpi_esm_lr/cclm4_8_17.py new file mode 100644 index 0000000000..838a471e1b --- /dev/null +++ b/esmvalcore/cmor/_fixes/cordex/mpi_m_mpi_esm_lr/cclm4_8_17.py @@ -0,0 +1,7 @@ +"""Fixes for rcm CCLM4-8-17 driven by MPI-M-MPI-ESM-LR.""" + +from esmvalcore.cmor._fixes.cordex.cordex_fixes import ( + CLMcomCCLM4817 as BaseFix, +) + +AllVars = BaseFix From a4e6358e1f2e283e2c604a237a703799460d63e8 Mon Sep 17 00:00:00 2001 From: Bouwe Andela Date: Mon, 30 Mar 2026 15:56:23 +0200 Subject: [PATCH 2/2] Add tests --- .../cmor/_fixes/cordex/test_cnrm_cerfacs_cnrm_cm5.py | 12 ++++++++++++ .../cmor/_fixes/cordex/test_cordex_fixes.py | 4 ++++ .../cmor/_fixes/cordex/test_mohc_hadgem2_es.py | 12 ++++++++++++ .../cmor/_fixes/cordex/test_mpi_m_mpi_esm_lr.py | 12 ++++++++++++ 4 files changed, 40 insertions(+) diff --git a/tests/integration/cmor/_fixes/cordex/test_cnrm_cerfacs_cnrm_cm5.py b/tests/integration/cmor/_fixes/cordex/test_cnrm_cerfacs_cnrm_cm5.py index 92dc3bc7eb..ab9ca18e61 100644 --- a/tests/integration/cmor/_fixes/cordex/test_cnrm_cerfacs_cnrm_cm5.py +++ b/tests/integration/cmor/_fixes/cordex/test_cnrm_cerfacs_cnrm_cm5.py @@ -7,6 +7,7 @@ aladin63, wrf381p, ) +from esmvalcore.cmor._fixes.cordex.cordex_fixes import CLMcomCCLM4817 from esmvalcore.cmor.fix import Fix from esmvalcore.cmor.table import get_var_info @@ -99,3 +100,14 @@ def test_wrf381p_height_fix(): fix = wrf381p.Tas(vardef) out_cubes = fix.fix_metadata([cube]) assert out_cubes[0].coord("height").points == 2.0 + + +def test_get_cclm4_8_17fix() -> None: + fixes = Fix.get_fixes( + "CORDEX", + "CCLM4-8-17", + "Amon", + "ts", + extra_facets={"driver": "CNRM-CERFACS-CNRM-CM5"}, + ) + assert any(isinstance(fix, CLMcomCCLM4817) for fix in fixes) diff --git a/tests/integration/cmor/_fixes/cordex/test_cordex_fixes.py b/tests/integration/cmor/_fixes/cordex/test_cordex_fixes.py index 0f0fc93966..beeaa203b4 100644 --- a/tests/integration/cmor/_fixes/cordex/test_cordex_fixes.py +++ b/tests/integration/cmor/_fixes/cordex/test_cordex_fixes.py @@ -152,6 +152,8 @@ def test_clmcomcclm4817_fix_metadata(cubes): "days since 1850-1-1 00:00:00", calendar="standard", ) + for cube in cubes: + cube.data = cube.lazy_data().astype(">f4", casting="same_kind") for coord in cubes[1].coords(): coord.points = coord.core_points().astype(">f8", casting="same_kind") lat = cubes[1].coord("latitude") @@ -162,6 +164,8 @@ def test_clmcomcclm4817_fix_metadata(cubes): out_cubes = fix.fix_metadata(cubes) assert cubes is out_cubes for cube in out_cubes: + assert cube.has_lazy_data() + assert cube.lazy_data().dtype == np.float32 assert cube.coord("time").units == Unit( "days since 1850-1-1 00:00:00", calendar="proleptic_gregorian", diff --git a/tests/integration/cmor/_fixes/cordex/test_mohc_hadgem2_es.py b/tests/integration/cmor/_fixes/cordex/test_mohc_hadgem2_es.py index bddd232fbd..fd85412cc4 100644 --- a/tests/integration/cmor/_fixes/cordex/test_mohc_hadgem2_es.py +++ b/tests/integration/cmor/_fixes/cordex/test_mohc_hadgem2_es.py @@ -3,6 +3,7 @@ import iris import pytest +from esmvalcore.cmor._fixes.cordex.cordex_fixes import CLMcomCCLM4817 from esmvalcore.cmor._fixes.cordex.mohc_hadgem2_es import hirham5, wrf381p from esmvalcore.cmor.fix import Fix from esmvalcore.cmor.table import get_var_info @@ -156,3 +157,14 @@ def test_wrf381p_height_fix(): fix = wrf381p.Tas(vardef) out_cubes = fix.fix_metadata([cube]) assert out_cubes[0].coord("height").points == 2.0 + + +def test_get_cclm4_8_17fix() -> None: + fixes = Fix.get_fixes( + "CORDEX", + "CCLM4-8-17", + "Amon", + "ts", + extra_facets={"driver": "MOHC-HadGEM2-ES"}, + ) + assert any(isinstance(fix, CLMcomCCLM4817) for fix in fixes) diff --git a/tests/integration/cmor/_fixes/cordex/test_mpi_m_mpi_esm_lr.py b/tests/integration/cmor/_fixes/cordex/test_mpi_m_mpi_esm_lr.py index eb7c303333..e68301660c 100644 --- a/tests/integration/cmor/_fixes/cordex/test_mpi_m_mpi_esm_lr.py +++ b/tests/integration/cmor/_fixes/cordex/test_mpi_m_mpi_esm_lr.py @@ -2,6 +2,7 @@ import pytest +from esmvalcore.cmor._fixes.cordex.cordex_fixes import CLMcomCCLM4817 from esmvalcore.cmor.fix import Fix @@ -38,3 +39,14 @@ def test_get_hadrem3ga705_fix(short_name): extra_facets={"driver": "MPI-M-MPI-ESM-LR"}, ) assert isinstance(fix[0], Fix) + + +def test_get_cclm4_8_17fix() -> None: + fixes = Fix.get_fixes( + "CORDEX", + "CCLM4-8-17", + "Amon", + "ts", + extra_facets={"driver": "MPI-M-MPI-ESM-LR"}, + ) + assert any(isinstance(fix, CLMcomCCLM4817) for fix in fixes)