Skip to content
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

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

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
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
23 changes: 13 additions & 10 deletions esmvalcore/cmor/_fixes/native6/era5.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,21 @@ def get_frequency(cube):
return "fx"

time.convert_units("days since 1850-1-1 00:00:00.0")
if len(time.points) == 1:
if cube.long_name != "Geopotential":
raise ValueError(
"Unable to infer frequency of cube "
f"with length 1 time dimension: {cube}"
)
return "fx"

interval = time.points[1] - time.points[0]
if interval - 1 / 24 < 1e-4:
return "hourly"
if len(time.points) == 1 and cube.long_name == "Geopotential":
return "fx"

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),
)
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 @@ -89,8 +89,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 _era5_latitude():
Expand Down