diff --git a/esmvalcore/cmor/_fixes/shared.py b/esmvalcore/cmor/_fixes/shared.py index f6f4400dcd..fbace5d1e7 100644 --- a/esmvalcore/cmor/_fixes/shared.py +++ b/esmvalcore/cmor/_fixes/shared.py @@ -72,9 +72,7 @@ def add_plev_from_altitude(cube): pressure_bounds = altitude_to_pressure(height_coord.core_bounds()) pressure_coord = iris.coords.AuxCoord(pressure_points, bounds=pressure_bounds, - var_name='plev', standard_name='air_pressure', - long_name='pressure', units='Pa') cube.add_aux_coord(pressure_coord, cube.coord_dims(height_coord)) return @@ -108,9 +106,7 @@ def add_altitude_from_plev(cube): altitude_bounds = pressure_to_altitude(plev_coord.core_bounds()) altitude_coord = iris.coords.AuxCoord(altitude_points, bounds=altitude_bounds, - var_name='alt', standard_name='altitude', - long_name='altitude', units='m') cube.add_aux_coord(altitude_coord, cube.coord_dims(plev_coord)) return diff --git a/esmvalcore/preprocessor/_multimodel.py b/esmvalcore/preprocessor/_multimodel.py index 800a035ab0..a724701beb 100644 --- a/esmvalcore/preprocessor/_multimodel.py +++ b/esmvalcore/preprocessor/_multimodel.py @@ -225,6 +225,12 @@ def _combine(cubes): coord.long_name = None coord.attributes = None + # Remove specific scalar coordinates which are not expected to be equal + scalar_coords_to_remove = ['p0', 'ptop'] + for scalar_coord in cube.coords(dimensions=()): + if scalar_coord.var_name in scalar_coords_to_remove: + cube.remove_coord(scalar_coord) + cubes = iris.cube.CubeList(cubes) merged_cube = cubes.merge_cube() diff --git a/tests/integration/cmor/_fixes/test_common.py b/tests/integration/cmor/_fixes/test_common.py index ace5cb5325..800ec736f5 100644 --- a/tests/integration/cmor/_fixes/test_common.py +++ b/tests/integration/cmor/_fixes/test_common.py @@ -156,9 +156,9 @@ def hybrid_height_coord_fix_metadata(nc_path, short_name, fix): air_pressure_coord = cube.coord('air_pressure') np.testing.assert_allclose(air_pressure_coord.points, PRESSURE_POINTS) np.testing.assert_allclose(air_pressure_coord.bounds, PRESSURE_BOUNDS) - assert air_pressure_coord.var_name == 'plev' + assert air_pressure_coord.var_name is None assert air_pressure_coord.standard_name == 'air_pressure' - assert air_pressure_coord.long_name == 'pressure' + assert air_pressure_coord.long_name is None assert air_pressure_coord.units == 'Pa' diff --git a/tests/integration/cmor/_fixes/test_shared.py b/tests/integration/cmor/_fixes/test_shared.py index 741c5e4233..a1a127066b 100644 --- a/tests/integration/cmor/_fixes/test_shared.py +++ b/tests/integration/cmor/_fixes/test_shared.py @@ -106,20 +106,15 @@ def test_add_aux_coords_from_cubes(coord_dict, output): ALT_COORD = iris.coords.AuxCoord([0.0], bounds=[[-100.0, 500.0]], - var_name='alt', long_name='altitude', standard_name='altitude', units='m') -ALT_COORD_NB = iris.coords.AuxCoord([0.0], var_name='alt', - long_name='altitude', - standard_name='altitude', units='m') +ALT_COORD_NB = iris.coords.AuxCoord([0.0], standard_name='altitude', units='m') ALT_COORD_KM = iris.coords.AuxCoord([0.0], bounds=[[-0.1, 0.5]], var_name='alt', long_name='altitude', standard_name='altitude', units='km') P_COORD = iris.coords.AuxCoord([101325.0], bounds=[[102532.0, 95460.8]], - var_name='plev', standard_name='air_pressure', - long_name='pressure', units='Pa') -P_COORD_NB = iris.coords.AuxCoord([101325.0], var_name='plev', - standard_name='air_pressure', - long_name='pressure', units='Pa') + standard_name='air_pressure', units='Pa') +P_COORD_NB = iris.coords.AuxCoord([101325.0], standard_name='air_pressure', + units='Pa') CUBE_ALT = iris.cube.Cube([1.0], var_name='x', aux_coords_and_dims=[(ALT_COORD, 0)]) CUBE_ALT_NB = iris.cube.Cube([1.0], var_name='x', diff --git a/tests/unit/preprocessor/_multimodel/test_multimodel.py b/tests/unit/preprocessor/_multimodel/test_multimodel.py index 7de15d6a0c..e15e0fd43b 100644 --- a/tests/unit/preprocessor/_multimodel/test_multimodel.py +++ b/tests/unit/preprocessor/_multimodel/test_multimodel.py @@ -8,6 +8,7 @@ import numpy as np import pytest from cf_units import Unit +from iris.coords import AuxCoord from iris.cube import Cube import esmvalcore.preprocessor._multimodel as mm @@ -371,6 +372,25 @@ def test_combine_inconsistent_var_names_fail(): _ = mm._combine(cubes) +@pytest.mark.parametrize('scalar_coord', ['p0', 'ptop']) +def test_combine_with_scalar_coords_to_remove(scalar_coord): + """Test _combine with scalar coordinates that should be removed.""" + num_cubes = 5 + cubes = [] + + for num in range(num_cubes): + cube = generate_cube_from_dates('monthly') + cubes.append(cube) + + scalar_coord_0 = AuxCoord(0.0, var_name=scalar_coord) + scalar_coord_1 = AuxCoord(1.0, var_name=scalar_coord) + cubes[0].add_aux_coord(scalar_coord_0, ()) + cubes[1].add_aux_coord(scalar_coord_1, ()) + + merged_cube = mm._combine(cubes) + assert merged_cube.shape == (5, 3) + + @pytest.mark.parametrize('span', SPAN_OPTIONS) def test_edge_case_different_time_offsets(span): cubes = (