Skip to content

Commit 98742f2

Browse files
fix if ERA5.1 data missing (#230)
* fix ERA5.1 missing * Update whats_new.rst
1 parent 5f87177 commit 98742f2

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

docs/whats_new.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@ What's New
88
99
import pyremo
1010
11+
12+
v0.8.1 (10 April 2025)
13+
----------------------
14+
15+
Internal Changes
16+
~~~~~~~~~~~~~~~~
17+
18+
- Use ERA5 data instead of ERA5.1 if it is missing (:pull:`230`).
19+
1120
v0.8.0 (9 April 2025)
1221
---------------------
1322

pyremo/preproc/era5.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from pprint import pprint
1313
from warnings import warn
1414
from importlib.resources import files
15+
import copy
1516

1617
import pandas as pd
1718
import xarray as xr
@@ -144,7 +145,10 @@ def get_file_from_template(
144145
date = "INVARIANT"
145146
else:
146147
date = pd.to_datetime(date).strftime("%Y-%m-%d")
147-
return op.join(path_template, file_template).format(
148+
149+
filepath_template = op.join(path_template, file_template)
150+
151+
return filepath_template.format(
148152
date=date,
149153
era_id=era_id,
150154
frequency=frequency,
@@ -159,8 +163,10 @@ def get_files_from_template(params, date, template=None):
159163
files = {}
160164
for k, v in params.items():
161165
f = get_file_from_template(date=date, template=template, **v)
162-
if not f:
163-
warn(f"no result for {k} --> params: {v}")
166+
if not op.isfile(f) and v.get("era_id") == "E1":
167+
warn(f"file not found: {f}, will try E5")
168+
v["era_id"] = "E5"
169+
f = get_file_from_template(date=date, template=template, **v)
164170
files[k] = f
165171
return files
166172

@@ -529,11 +535,12 @@ def era5_gfile_from_dkrz(date, path, expid="000000"):
529535
str
530536
The path to the computed gfile.
531537
"""
532-
global era5_params
538+
params = copy.deepcopy(era5_params)
533539

534-
params = era5_params.copy()
535540
if date.year in range(2000, 2007):
536541
for k, v in params.items():
542+
# if v["level_type"] == "model_level":
537543
v["era_id"] = "E1"
544+
538545
era5 = ERA5(params, gridfile=era5_grid_file)
539546
return era5.gfile(date.strftime("%Y-%m-%dT%H:%M:%S"), path, expid)

0 commit comments

Comments
 (0)