Skip to content

concatenate_cube fails too early when concatenating multiple dimensions #6533

@stephenworsley

Description

@stephenworsley

🐛 Bug Report

When a CubeList can be concatenated along two different axes, concatenate_cube will error before a cube can be returned

How To Reproduce

import numpy as np
from iris.cube import Cube, CubeList
from iris.coords import DimCoord

lat = DimCoord(np.arange(20), standard_name="latitude")
lon = DimCoord(np.arange(20), standard_name="longitude")

cube = Cube(np.zeros([20, 20]))
cube.add_dim_coord(lat, 0)
cube.add_dim_coord(lon, 1)

cube_quarters = CubeList([cube[:10, :10], cube[:10, 10:], cube[10:, :10], cube[10:, 10:]])

print(cube_quarters.concatenate())  # contains a single cube
print(cube_quarters.concatenate_cube())  # errors

Expected behaviour

A single cube should be returned here.

Additional context

I believe this is happening due to the fact that concatenate happens iteratively here:

# Perform concatenation until we've reached an equilibrium.
count = len(concatenated_cubes)
if count != 1 and count != len(cubes):
concatenated_cubes = concatenate(concatenated_cubes)

However, an error is thrown if any of these iterations fails to return a single cube. It would be better if an error could be held onto and thrown only after the last iteration.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions