Skip to content
Open
Show file tree
Hide file tree
Changes from 10 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
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