diff --git a/src/CSET/operators/read.py b/src/CSET/operators/read.py index 6c30af1e7..775e0b115 100644 --- a/src/CSET/operators/read.py +++ b/src/CSET/operators/read.py @@ -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 @@ -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") @@ -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: diff --git a/tests/operators/test_read.py b/tests/operators/test_read.py index 716362ee8..a9a7ebcfa 100644 --- a/tests/operators/test_read.py +++ b/tests/operators/test_read.py @@ -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(