Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
11 changes: 10 additions & 1 deletion src/CSET/operators/read.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class NoDataError(FileNotFoundError):

def read_cube(
file_paths: list[str] | str,
constraint: iris.Constraint = None,
constraint: iris.Constraint | None = None,
model_names: list[str] | str | None = None,
subarea_type: str | None = None,
subarea_extent: list[float] | None = None,
Expand Down Expand Up @@ -405,6 +405,7 @@ def _cutout_cubes(
def _loading_callback(cube: iris.cube.Cube, field, filename: str) -> iris.cube.Cube:
"""Compose together the needed callbacks into a single function."""
# Most callbacks operate in-place, but save the cube when returned!
_remove_cset_comparison_base_attribute_callback(cube)
_realization_callback(cube)
_um_normalise_callback(cube)
_lfric_normalise_callback(cube)
Expand All @@ -427,6 +428,14 @@ def _loading_callback(cube: iris.cube.Cube, field, filename: str) -> iris.cube.C
return cube


def _remove_cset_comparison_base_attribute_callback(cube):
"""Remove ``cset_comparison_base`` attribute if present.

This allows for reprocessing output previously saved by CSET.
"""
cube.attributes.pop("cset_comparison_base", None)


def _realization_callback(cube):
"""Add a realization coordinate initialised to 0 if missing.

Expand Down
7 changes: 7 additions & 0 deletions tests/operators/test_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -856,6 +856,13 @@ def test_lfric_forecast_period_convert_units_callback(cube):
assert cube.coord("forecast_period").units == "hours"


def test_remove_cset_comparison_base_attribute_callback():
"""Ensure ``cset_comparison_base`` attribute is removed."""
cube = iris.cube.Cube(shape=(1,), attributes={"cset_comparison_base": 1})
read._remove_cset_comparison_base_attribute_callback(cube)
assert "cset_comparison_base" not in cube.attributes


def test_read_cubes_extract_cells():
"""Read cube and ensure appropriate number of cells are trimmed from domain edges."""
cube = read.read_cubes(
Expand Down