Skip to content

Fix ERA5 native6 fix to handle single monthly-averaged NetCDF files. #2512

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

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
28 changes: 13 additions & 15 deletions esmvalcore/cmor/_fixes/native6/era5.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,22 @@ def get_frequency(cube):
return "fx"

time.convert_units("days since 1850-1-1 00:00:00.0")
if len(time.points) == 1:
acceptable_long_names = (
"Geopotential",
"Percentage of the Grid Cell Occupied by Land (Including Lakes)",
)
if cube.long_name not in acceptable_long_names:
raise ValueError(
"Unable to infer frequency of cube "
f"with length 1 time dimension: {cube}"
)

if len(time.points) == 1 and cube.long_name == "Geopotential":
return "fx"

interval = time.points[1] - time.points[0]
if len(time.points) > 1:
interval = time.points[1] - time.points[0]
if interval - 1 / 24 < 1e-4:
return "hourly"
else:
logger.warning(
"Unable to infer frequency of cube "
"with length 1 time dimension: %s,"
"assuming 'monthly' frequency",
str(cube),
)

if interval - 1 / 24 < 1e-4:
return "hourly"
if interval - 1.0 < 1e-4:
return "daily"
return "monthly"


Expand Down
3 changes: 1 addition & 2 deletions tests/integration/cmor/_fixes/native6/test_era5.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,7 @@ def test_get_frequency_fx():
assert get_frequency(cube) == "fx"

cube.long_name = "Not geopotential"
with pytest.raises(ValueError):
get_frequency(cube)
assert get_frequency(cube) == "monthly"


def test_fix_accumulated_units_fail():
Expand Down