Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not realize cell measures and ancillary variables in concatenate #6010

Merged
merged 3 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 3 additions & 0 deletions docs/src/whatsnew/latest.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ This document explains the changes made to Iris for this release
#. `@bouweandela`_ made :meth:`iris.cube.Cube.rolling_window` work with lazy
data. (:pull:`5795`)

#. `@bouweandela`_ updated :meth:`iris.cube.CubeList.concatenate` so it keeps
ancillary variables and cell measures lazy. (:pull:`6010`)

🔥 Deprecations
===============

Expand Down
4 changes: 2 additions & 2 deletions lib/iris/_concatenate.py
Original file line number Diff line number Diff line change
Expand Up @@ -1145,7 +1145,7 @@ def _build_cell_measures(self):
# Concatenate the data together.
dim = dims.index(self.axis)
data = [
skton.signature.cell_measures_and_dims[i].coord.data
skton.signature.cell_measures_and_dims[i].coord.core_data()
for skton in skeletons
]
data = concatenate_arrays(tuple(data), axis=dim)
Expand Down Expand Up @@ -1185,7 +1185,7 @@ def _build_ancillary_variables(self):
# Concatenate the data together.
dim = dims.index(self.axis)
data = [
skton.signature.ancillary_variables_and_dims[i].coord.data
skton.signature.ancillary_variables_and_dims[i].coord.core_data()
for skton in skeletons
]
data = concatenate_arrays(tuple(data), axis=dim)
Expand Down
21 changes: 21 additions & 0 deletions lib/iris/tests/integration/concatenate/test_concatenate.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import iris.tests as tests # isort:skip

import cf_units
import dask.array as da
import numpy as np

from iris._concatenate import _DerivedCoordAndDims, concatenate
Expand Down Expand Up @@ -157,6 +158,16 @@ def test_ignore_diff_cell_measure(self):
self.assertEqual(len(result), 1)
self.assertEqual(result[0].shape, (4, 2))

def test_lazy_cell_measure(self):
cube_a = self.create_cube()
cube_a.cell_measure("volume").data = da.array([0, 15])
trexfeathers marked this conversation as resolved.
Show resolved Hide resolved
cube_b = cube_a.copy()
cube_b.coord("time").points = [12, 18]

result = concatenate([cube_a, cube_b])
assert len(result) == 1
assert result[0].cell_measure("volume").has_lazy_data()


class Test_cubes_with_ancillary_variables(tests.IrisTest):
def create_cube(self):
Expand Down Expand Up @@ -194,6 +205,16 @@ def test_ignore_diff_ancillary_variables(self):
self.assertEqual(len(result), 1)
self.assertEqual(result[0].shape, (4, 2))

def test_lazy_ancillary_variables(self):
cube_a = self.create_cube()
cube_a.ancillary_variable("quality").data = da.array([0, 15])
cube_b = cube_a.copy()
cube_b.coord("time").points = [12, 18]

result = concatenate([cube_a, cube_b])
assert len(result) == 1
assert result[0].ancillary_variable("quality").has_lazy_data()


class Test_cubes_with_derived_coord(tests.IrisTest):
def create_cube(self):
Expand Down
Loading