Skip to content

Commit

Permalink
Core _io.concatenate() may fail due to case when one of the cubes i…
Browse files Browse the repository at this point in the history
…s scalar - this fixes that (#1715)

* fix concatenation when component becomes scalar cube

* add test case/change test case

* reinstate logger debug message
  • Loading branch information
valeriupredoi authored Sep 6, 2022
1 parent ed81a3c commit 2397641
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
4 changes: 3 additions & 1 deletion esmvalcore/preprocessor/_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ def load(file, callback=None, ignore_warnings=None):
------
ValueError
Cubes are empty.
"""
logger.debug("Loading:\n%s", file)
if ignore_warnings is None:
Expand Down Expand Up @@ -501,6 +500,9 @@ def _concatenate_overlapping_cubes(cubes):
data_start_1.month, data_start_1.day,
start_overlap.year, start_overlap.month,
start_overlap.day)
# convert c1_delta scalar cube to vector cube, if needed
if c1_delta.data.shape == ():
c1_delta = iris.util.new_axis(c1_delta, scalar_coord="time")
cubes = iris.cube.CubeList([c1_delta, cubes[1]])
logger.debug("Attempting concatenatenation of %s with %s",
c1_delta, cubes[1])
Expand Down
7 changes: 4 additions & 3 deletions tests/integration/preprocessor/_io/test_concatenate.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
)
from iris.coords import AuxCoord, DimCoord
from iris.cube import Cube, CubeList
from iris.exceptions import ConcatenateError

from esmvalcore.preprocessor import _io

Expand Down Expand Up @@ -375,8 +374,10 @@ def test_concatenate_with_iris_exception(self):
var_name='sample',
dim_coords_and_dims=((time_coord_2, 0), ))
cubes_single_ovlp = [cube2, cube1]
with self.assertRaises(ConcatenateError):
_io.concatenate(cubes_single_ovlp)
cubess = _io.concatenate(cubes_single_ovlp)
# this tests the scalar to vector cube conversion too
time_points = cubess.coord("time").core_points()
np.testing.assert_array_equal(time_points, [1., 1.5, 5., 7.])

def test_concatenate_no_time_coords(self):
"""Test a more generic case."""
Expand Down

0 comments on commit 2397641

Please sign in to comment.