Skip to content
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
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