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 6 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
17 changes: 10 additions & 7 deletions esmvalcore/cmor/_fixes/native6/era5.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,18 @@
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}')

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

interval = time.points[1] - time.points[0]
if interval - 1 / 24 < 1e-4:
return 'hourly'
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 "

Check notice on line 34 in esmvalcore/cmor/_fixes/native6/era5.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

esmvalcore/cmor/_fixes/native6/era5.py#L34

Use lazy % formatting in logging functions (logging-fstring-interpolation)
f"with length 1 time dimension: {cube},"
"assuming 'monthly' frequency")

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 @@ -86,8 +86,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