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

873 add except for varkey list loop in dfmtpreprocess merge meteofiles era5 #889

Merged
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
2 changes: 1 addition & 1 deletion dfm_tools/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def download_ERA5(varkey,
'p140209':'air_density_over_the_oceans', # TODO: paramID might be replaced with shortname rhoao: https://jira.ecmwf.int/plugins/servlet/desk/portal/4/SD-82050
}
if varkey not in variables_dict.keys(): #TODO: how to get list of available vars? mean_sea_level_pressure and msl both return a dataset with msl varkey, but standard_name air_pressure_at_mean_sea_level returns an error
raise KeyError(f'"{varkey}" not available, choose from: {list(variables_dict.keys())}')
raise KeyError(f'"{varkey}" not available, choose from: {", ".join(variables_dict.keys())}')

period_range = pd.period_range(date_min,date_max,freq='M')
print(f'retrieving data from {period_range[0]} to {period_range[-1]} (freq={period_range.freq})')
Expand Down
4 changes: 4 additions & 0 deletions dfm_tools/modelbuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,10 @@ def preprocess_merge_meteofiles_era5(ext_old, varkey_list, dir_data, dir_output,
operand=hcdfm.Operand.add, #+
)
ext_old.forcing.append(forcing_meteo)
else:
# TODO: add support for other quantities: https://github.com/Deltares/dfm_tools/issues/887
raise KeyError(f"'{varkey_list}' is not supported by dfmt.preprocess_merge_meteofiles_era5(), "
"the files were merged but the ExtModel Forcing cannot be appended.")

return ext_old

Expand Down
16 changes: 16 additions & 0 deletions tests/test_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,22 @@ def test_download_era5(file_nc_era5_pattern):
assert ds.time.to_pandas().iloc[-1] == pd.Timestamp('2010-02-28 23:00')


@pytest.mark.requiressecrets
@pytest.mark.unittest
@pytest.mark.timeout(60) # useful since CDS downloads are terribly slow sometimes, so skip in that case
def test_download_era5_unsupported_varkey():
date_min = '2010-01-31'
date_max = '2010-02-01'
longitude_min, longitude_max, latitude_min, latitude_max = 2, 3, 51, 52 #test domain
varkey = 'unexisting'
with pytest.raises(KeyError) as e:
dfmt.download_ERA5(varkey,
longitude_min=longitude_min, longitude_max=longitude_max, latitude_min=latitude_min, latitude_max=latitude_max,
date_min=date_min, date_max=date_max,
dir_output='.', overwrite=True)
assert '"unexisting" not available' in str(e.value)


@pytest.mark.requiressecrets
@pytest.mark.unittest
def test_download_cmems_my(tmp_path):
Expand Down
17 changes: 17 additions & 0 deletions tests/test_modelbuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,20 @@ def test_make_paths_relative(tmp_path):
with open(ext_file_new, 'r') as file:
filedata = file.read()
assert "locationFile = test_model.pli" in filedata


@pytest.mark.unittest
def test_preprocess_merge_meteofiles_era5_unsupported_varlist(file_nc_era5_pattern, tmp_path):
ext_old = None # this won't be reached, so not relevant what to supply
date_min = '2010-01-31'
date_max = '2010-02-01'
varlist_list = ['msl']
dir_output_data_era5 = os.path.dirname(file_nc_era5_pattern)
with pytest.raises(KeyError) as e:
ext_old = dfmt.preprocess_merge_meteofiles_era5(ext_old=ext_old,
varkey_list=varlist_list,
dir_data=dir_output_data_era5,
dir_output=tmp_path,
time_slice=slice(date_min, date_max))
assert "is not supported by dfmt.preprocess_merge_meteofiles_era5" in str(e.value)

Loading