Skip to content

Commit 06ce74d

Browse files
authored
Add a fix for differing index coord long names in NorESM2-MM and EC-Earth3-Veg-LR (#2667)
1 parent 434e65e commit 06ce74d

File tree

4 files changed

+110
-14
lines changed

4 files changed

+110
-14
lines changed
Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,29 @@
11
"""Fixes for EC-Earth3-Veg-LR model."""
22

3-
from ..common import OceanFixGrid
3+
from collections.abc import Sequence
4+
5+
import iris.cube
6+
7+
from esmvalcore.cmor._fixes.common import OceanFixGrid
8+
from esmvalcore.cmor._fixes.fix import Fix
9+
10+
11+
class AllVars(Fix):
12+
"""Fixes for all variables."""
13+
14+
def fix_metadata(
15+
self,
16+
cubes: Sequence[iris.cube.Cube],
17+
) -> Sequence[iris.cube.Cube]:
18+
"""Use the same long name for horizontal index coordinates."""
19+
for cube in cubes:
20+
# Use the same long name for index coordinates in all files to avoid
21+
# problems when concatenating.
22+
for var_name, dim_name in [("i", "first"), ("j", "second")]:
23+
if coords := cube.coords(var_name=var_name, dim_coords=True):
24+
long_name = f"cell index along {dim_name} dimension"
25+
coords[0].long_name = long_name
26+
return cubes
27+
428

529
Siconc = OceanFixGrid

esmvalcore/cmor/_fixes/cmip6/noresm2_mm.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
"""Fixes for NorESM2-MM model."""
22

3-
from ..common import ClFixHybridPressureCoord
3+
from esmvalcore.cmor._fixes.cmip6.ec_earth3_veg_lr import (
4+
AllVars as BaseAllVars,
5+
)
6+
from esmvalcore.cmor._fixes.common import ClFixHybridPressureCoord
7+
8+
AllVars = BaseAllVars
49

510
Cl = ClFixHybridPressureCoord
611

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,53 @@
11
"""Test fixes for EC-Earth3-Veg-LR."""
22

3-
from esmvalcore.cmor._fixes.cmip6.ec_earth3_veg_lr import Siconc
3+
import iris.coords
4+
import iris.cube
5+
import pytest
6+
7+
from esmvalcore.cmor._fixes.cmip6.ec_earth3_veg_lr import AllVars, Siconc
48
from esmvalcore.cmor._fixes.common import OceanFixGrid
5-
from esmvalcore.cmor._fixes.fix import Fix, GenericFix
9+
from esmvalcore.cmor._fixes.fix import Fix
610

711

812
def test_get_siconc_fix():
913
"""Test getting of fix."""
10-
fix = Fix.get_fixes("CMIP6", "EC-Earth3-Veg-LR", "SImon", "siconc")
11-
assert fix == [Siconc(None), GenericFix(None)]
14+
assert Siconc(None) in Fix.get_fixes(
15+
"CMIP6", "EC-Earth3-Veg-LR", "SImon", "siconc"
16+
)
1217

1318

1419
def test_siconc_fix():
1520
"""Test fix for ``siconc``."""
1621
assert Siconc is OceanFixGrid
22+
23+
24+
def test_get_allvars_fix():
25+
"""Test getting of fix."""
26+
assert AllVars(None) in Fix.get_fixes(
27+
"CMIP6", "EC-Earth3-Veg-LR", "Omon", "tos"
28+
)
29+
30+
31+
@pytest.mark.parametrize("has_index_coord", [True, False])
32+
def test_grid_fix(has_index_coord):
33+
"""Test fix for differing grid index coordinate long names."""
34+
cube = iris.cube.Cube([1, 2])
35+
if has_index_coord:
36+
i_coord = iris.coords.DimCoord(
37+
[0.0, 1.0],
38+
var_name="i",
39+
long_name="first spatial index for variables stored on an unstructured grid",
40+
units=1,
41+
)
42+
cube.add_dim_coord(i_coord, 0)
43+
44+
cubes = [cube]
45+
for fix in Fix.get_fixes("CMIP6", "NorESM2-MM", "Omon", "tos"):
46+
cubes = fix.fix_metadata(cubes)
47+
48+
assert len(cubes) == 1
49+
if has_index_coord:
50+
assert (
51+
cubes[0].coord(var_name="i").long_name
52+
== "cell index along first dimension"
53+
)

tests/integration/cmor/_fixes/cmip6/test_noresm2_mm.py

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,47 @@
11
"""Tests for the fixes of NorESM2-MM."""
22

3-
from esmvalcore.cmor._fixes.cmip6.noresm2_mm import Cl, Cli, Clw
3+
import iris.coords
4+
import iris.cube
5+
import pytest
6+
7+
from esmvalcore.cmor._fixes.cmip6.noresm2_mm import AllVars, Cl, Cli, Clw
48
from esmvalcore.cmor._fixes.common import ClFixHybridPressureCoord
5-
from esmvalcore.cmor._fixes.fix import GenericFix
69
from esmvalcore.cmor.fix import Fix
710

811

12+
def test_get_allvars_fix():
13+
"""Test getting of fix."""
14+
assert AllVars(None) in Fix.get_fixes("CMIP6", "NorESM2-MM", "Omon", "tos")
15+
16+
17+
@pytest.mark.parametrize("has_index_coord", [True, False])
18+
def test_grid_fix(has_index_coord):
19+
"""Test fix for differing grid index coordinate long names."""
20+
cube = iris.cube.Cube([1, 2])
21+
if has_index_coord:
22+
i_coord = iris.coords.DimCoord(
23+
[0.0, 1.0],
24+
var_name="i",
25+
long_name="first spatial index for variables stored on an unstructured grid",
26+
units=1,
27+
)
28+
cube.add_dim_coord(i_coord, 0)
29+
30+
cubes = [cube]
31+
for fix in Fix.get_fixes("CMIP6", "NorESM2-MM", "Omon", "tos"):
32+
cubes = fix.fix_metadata(cubes)
33+
34+
assert len(cubes) == 1
35+
if has_index_coord:
36+
assert (
37+
cubes[0].coord(var_name="i").long_name
38+
== "cell index along first dimension"
39+
)
40+
41+
942
def test_get_cl_fix():
1043
"""Test getting of fix."""
11-
fix = Fix.get_fixes("CMIP6", "NorESM2-MM", "Amon", "cl")
12-
assert fix == [Cl(None), GenericFix(None)]
44+
assert Cl(None) in Fix.get_fixes("CMIP6", "NorESM2-MM", "Amon", "cl")
1345

1446

1547
def test_cl_fix():
@@ -19,8 +51,7 @@ def test_cl_fix():
1951

2052
def test_get_cli_fix():
2153
"""Test getting of fix."""
22-
fix = Fix.get_fixes("CMIP6", "NorESM2-MM", "Amon", "cli")
23-
assert fix == [Cli(None), GenericFix(None)]
54+
assert Cli(None) in Fix.get_fixes("CMIP6", "NorESM2-MM", "Amon", "cli")
2455

2556

2657
def test_cli_fix():
@@ -30,8 +61,7 @@ def test_cli_fix():
3061

3162
def test_get_clw_fix():
3263
"""Test getting of fix."""
33-
fix = Fix.get_fixes("CMIP6", "NorESM2-MM", "Amon", "clw")
34-
assert fix == [Clw(None), GenericFix(None)]
64+
assert Clw(None) in Fix.get_fixes("CMIP6", "NorESM2-MM", "Amon", "clw")
3565

3666

3767
def test_clw_fix():

0 commit comments

Comments
 (0)