Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions esmvalcore/cmor/_fixes/cordex/cordex_fixes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
7 changes: 7 additions & 0 deletions esmvalcore/cmor/_fixes/cordex/mohc_hadgem2_es/cclm4_8_17.py
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions esmvalcore/cmor/_fixes/cordex/mpi_m_mpi_esm_lr/cclm4_8_17.py
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions tests/integration/cmor/_fixes/cordex/test_cnrm_cerfacs_cnrm_cm5.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
4 changes: 4 additions & 0 deletions tests/integration/cmor/_fixes/cordex/test_cordex_fixes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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",
Expand Down
12 changes: 12 additions & 0 deletions tests/integration/cmor/_fixes/cordex/test_mohc_hadgem2_es.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
12 changes: 12 additions & 0 deletions tests/integration/cmor/_fixes/cordex/test_mpi_m_mpi_esm_lr.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import pytest

from esmvalcore.cmor._fixes.cordex.cordex_fixes import CLMcomCCLM4817
from esmvalcore.cmor.fix import Fix


Expand Down Expand Up @@ -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)