Skip to content
5 changes: 2 additions & 3 deletions docs/src/whatsnew/latest.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,8 @@ This document explains the changes made to Iris for this release

#. `@ESadek-MO`_ added functionality to allow :func:`~iris.cube.Cube.extract`,
:func:`~iris.cube.Cube.collapsed`, :func:`~iris.cube.Cube.aggregated_by`,
:func:`~iris.cube.Cube.convert_units`, :func:`~iris.cube.Cube.subset` and
:func:`~iris.cube.Cube.slices` to work with dataless cubes.
(:issue:`6725`, :pull:`6724`)
and other single cube operations to work with dataless cubes.
(:issue:`6725`, :pull:`6724`, :pull:`6757`)


🐛 Bugs Fixed
Expand Down
77 changes: 45 additions & 32 deletions lib/iris/cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -3276,8 +3276,8 @@ def intersection(self, *args, **kwargs) -> Cube:
which intersects with the requested coordinate intervals.

"""
if self.is_dataless():
raise iris.exceptions.DatalessError("intersection")
# if self.is_dataless():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remember to nuke this. 🙂

# raise iris.exceptions.DatalessError("intersection")
result = self
ignore_bounds = kwargs.pop("ignore_bounds", False)
threshold = kwargs.pop("threshold", 0)
Expand Down Expand Up @@ -3349,9 +3349,20 @@ def make_chunk(key):
if len(chunks) == 1:
result = chunks[0]
else:
chunk_data = [chunk.core_data() for chunk in chunks]
data = _lazy.concatenate(chunk_data, axis=dim)
result = iris.cube.Cube(data)
if self.is_dataless():
dim_shape = 0
old_shape = list(self.shape)
for chunk in chunks:
# sum the shape of the relevant dimension of each chunk together
dim_shape += len(chunk.coord(coord).points)
old_shape[dim] = dim_shape
new_shape = tuple(old_shape)
data = None
else:
chunk_data = [chunk.core_data() for chunk in chunks]
data = _lazy.concatenate(chunk_data, axis=dim)
new_shape = None
result = iris.cube.Cube(data=data, shape=new_shape)
result.metadata = deepcopy(self.metadata)

# Record a mapping from old coordinate IDs to new coordinates,
Expand Down Expand Up @@ -4952,8 +4963,7 @@ def rolling_window(
""" # noqa: D214, D406, D407, D410, D411
# Update weights kwargs (if necessary) to handle different types of
# weights
if self.is_dataless():
raise iris.exceptions.DatalessError("rolling_window")
dataless = self.is_dataless()
weights_info = None
if kwargs.get("weights") is not None:
weights_info = _Weights(kwargs["weights"], self)
Expand Down Expand Up @@ -4992,13 +5002,13 @@ def rolling_window(
key = [slice(None, None)] * self.ndim
key[dimension] = slice(None, self.shape[dimension] - window + 1)
new_cube = new_cube[tuple(key)]

# take a view of the original data using the rolling_window function
# this will add an extra dimension to the data at dimension + 1 which
# represents the rolled window (i.e. will have a length of window)
rolling_window_data = iris.util.rolling_window(
self.core_data(), window=window, axis=dimension
)
if not dataless:
# take a view of the original data using the rolling_window function
# this will add an extra dimension to the data at dimension + 1 which
# represents the rolled window (i.e. will have a length of window)
rolling_window_data = iris.util.rolling_window(
self.core_data(), window=window, axis=dimension
)

# now update all of the coordinates to reflect the aggregation
for coord_ in self.coords(dimensions=dimension):
Expand Down Expand Up @@ -5047,27 +5057,30 @@ def rolling_window(
)
# and perform the data transformation, generating weights first if
# needed
if isinstance(
aggregator, iris.analysis.WeightedAggregator
) and aggregator.uses_weighting(**kwargs):
if "weights" in kwargs:
weights = kwargs["weights"]
if weights.ndim > 1 or weights.shape[0] != window:
raise ValueError(
"Weights for rolling window aggregation "
"must be a 1d array with the same length "
"as the window."
if not dataless:
if isinstance(
aggregator, iris.analysis.WeightedAggregator
) and aggregator.uses_weighting(**kwargs):
if "weights" in kwargs:
weights = kwargs["weights"]
if weights.ndim > 1 or weights.shape[0] != window:
raise ValueError(
"Weights for rolling window aggregation "
"must be a 1d array with the same length "
"as the window."
)
kwargs = dict(kwargs)
kwargs["weights"] = iris.util.broadcast_to_shape(
weights, rolling_window_data.shape, (dimension + 1,)
)
kwargs = dict(kwargs)
kwargs["weights"] = iris.util.broadcast_to_shape(
weights, rolling_window_data.shape, (dimension + 1,)
)

if aggregator.lazy_func is not None and self.has_lazy_data():
agg_method = aggregator.lazy_aggregate
if aggregator.lazy_func is not None and self.has_lazy_data():
agg_method = aggregator.lazy_aggregate
else:
agg_method = aggregator.aggregate
data_result = agg_method(rolling_window_data, axis=dimension + 1, **kwargs)
else:
agg_method = aggregator.aggregate
data_result = agg_method(rolling_window_data, axis=dimension + 1, **kwargs)
data_result = None
result = aggregator.post_process(new_cube, data_result, [coord], **kwargs)
return result

Expand Down
Loading
Loading