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: 8 additions & 3 deletions src/CSET/operators/read.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ def _loading_callback(cube: iris.cube.Cube, field, filename: str) -> iris.cube.C
_fix_lfric_cloud_base_altitude(cube)
_proleptic_gregorian_fix(cube)
_lfric_time_callback(cube)
_lfric_forecast_period_standard_name_callback(cube)
_lfric_forecast_period_callback(cube)
return cube


Expand Down Expand Up @@ -430,6 +430,9 @@ def _lfric_normalise_callback(cube: iris.cube.Cube, field, filename):
cube.attributes.pop("timeStamp", None)
cube.attributes.pop("uuid", None)
cube.attributes.pop("name", None)
cube.attributes.pop("source", None)
cube.attributes.pop("analysis_source", None)
cube.attributes.pop("history", None)

# Sort STASH code list.
stash_list = cube.attributes.get("um_stash_source")
Expand Down Expand Up @@ -964,10 +967,12 @@ def _lfric_time_callback(cube: iris.cube.Cube):
logging.warning("No time coordinate on cube.")


def _lfric_forecast_period_standard_name_callback(cube: iris.cube.Cube):
"""Add forecast_period standard name if missing."""
def _lfric_forecast_period_callback(cube: iris.cube.Cube):
"""Check forecast_period name and units."""
try:
coord = cube.coord("forecast_period")
if coord.units != "hours":
cube.coord("forecast_period").convert_units("hours")
if not coord.standard_name:
coord.standard_name = "forecast_period"
except iris.exceptions.CoordinateNotFoundError:
Expand Down
10 changes: 9 additions & 1 deletion tests/operators/test_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -788,10 +788,18 @@ def test_normalise_var0_varname(model_level_cube):
def test_lfric_forecast_period_standard_name_callback(cube):
"""Ensure forecast period coordinates have a standard name."""
cube.coord("forecast_period").standard_name = None
read._lfric_forecast_period_standard_name_callback(cube)
read._lfric_forecast_period_callback(cube)
assert cube.coord("forecast_period").standard_name == "forecast_period"


def test_lfric_forecast_period_convert_units_callback(cube):
"""Ensure forecast period coordinates have a standard name."""
cube.coord("forecast_period").convert_units("seconds")
assert cube.coord("forecast_period").units == "seconds"
read._lfric_forecast_period_callback(cube)
assert cube.coord("forecast_period").units == "hours"


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
Loading