Skip to content
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
2 changes: 1 addition & 1 deletion dfm_tools/meshkernel_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def meshkernel_delete_withgdf(mk:meshkernel.MeshKernel, coastlines_gdf:gpd.GeoDa
xx = np.array(xx)
yy = np.array(yy)

delete_pol_geom = meshkernel.GeometryList(x_coordinates=xx, y_coordinates=yy) #TODO: .copy()/to_numpy() makes the array contiguous in memory, which is necessary for meshkernel.mesh2d_delete()
delete_pol_geom = meshkernel.GeometryList(x_coordinates=xx, y_coordinates=yy)
mk.mesh2d_delete(geometry_list=delete_pol_geom,
delete_option=meshkernel.DeleteMeshOption.INSIDE_NOT_INTERSECTED,
invert_deletion=False)
Expand Down
11 changes: 10 additions & 1 deletion dfm_tools/modelbuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ def preprocess_merge_meteofiles_era5(

# TODO: align with variables_dict from dfmt.download_ERA5()
dict_varkey_quantities = {
'ssr':'solarradiation',
'ssr':'netsolarradiation',
# 'sst':'sea_surface_temperature',
'strd':'longwaveradiation',
# 'slhf':'surface_latent_heat_flux',
Expand All @@ -280,6 +280,7 @@ def preprocess_merge_meteofiles_era5(
'rhoao':'airdensity',
}


for varkey in varkey_list:
if isinstance(varkey, list):
raise TypeError(
Expand All @@ -294,6 +295,14 @@ def preprocess_merge_meteofiles_era5(
"issue if you need this."
)

# TODO: remove this warning after a while, it was implemented in
# https://github.com/Deltares/dfm_tools/issues/1253
if varkey == "ssr":
logger.warning(
"you are using ssr/netsolarradiation, beware that this "
"quantity only exists in Delft3D-FM 2026.01 and above."
)

fn_match_pattern = f'era5_{varkey}_*.nc'
file_nc = os.path.join(dir_data, fn_match_pattern)

Expand Down
4 changes: 0 additions & 4 deletions dfm_tools/xarray_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,10 +370,6 @@ def get_unit(da):
# 3600s/h #TODO: 1W = 1J/s, so does not make sense?
ds[varkey_sel] = ds[varkey_sel] / 3600
ds[varkey_sel].attrs['units'] = new_unit
#solar influx increase for beta=6% subtraction in DFM
if 'ssr' in varkeys:
print('ssr (solar influx) increase for beta=6% subtraction in DflowFM')
ds['ssr'] = ds['ssr'] / 0.94

# restore attrs and encoding of data_vars
for varkey in varkeys:
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ dependencies = [
"rws-ddlpy>=0.8.0",
#pooch>=1.1.0 has attribute retrieve
"pooch>=1.1.0",
#hydrolib-core>=0.9.9 removed obsolete keywords to avoid model crash with 2026.01
"hydrolib-core>=0.9.9",
#hydrolib-core>=0.10.0 added support for quantity netsolarradiation
"hydrolib-core>=0.10.0",
#meshkernel>=8.2.1 supports illegalcells via the face-node-connectivity
"meshkernel>=8.2.1",
]
Expand Down
29 changes: 29 additions & 0 deletions tests/test_modelbuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import xarray as xr
import numpy as np
from dfm_tools.modelbuilder import get_quantity_list, get_ncvarname
import logging


@pytest.mark.unittest
Expand Down Expand Up @@ -420,3 +421,31 @@ def test_preprocess_merge_meteofiles_era5_missing_files(tmp_path, ds_era5_empty)
dir_output=tmp_path,
time_slice=slice(date_min, date_max))
assert "No files found for pattern" in str(e.value)


@pytest.mark.unittest
def test_preprocess_merge_meteofiles_era5_ssr_warning(tmp_path, ds_era5_empty, caplog):
"""
this test is to make sure this code emits a warning about ssr
without caplog the code actually raises an error, which is not considered here.
this is due to the fact that we are trying to concatenate an empty dataset here
ValueError "Could not find any dimension coordinates to use to order the datasets for concatenation"
"""
file_nc = os.path.join(tmp_path,"era5_ssr_empty.nc")
ds_era5_empty = ds_era5_empty.rename_vars(msl="ssr")
ds_era5_empty.to_netcdf(file_nc)

ext_old = hcdfm.ExtOldModel()
date_min = ds_era5_empty.time.to_pandas().iloc[0]
date_max = ds_era5_empty.time.to_pandas().iloc[-1]
varlist_list = ['ssr']
# with pytest.raises(ValueError) as e:
with caplog.at_level(logging.WARNING):
ext_old = dfmt.preprocess_merge_meteofiles_era5(
ext_old=ext_old,
varkey_list=varlist_list,
dir_data=tmp_path,
dir_output=tmp_path,
time_slice=slice(date_min, date_max),
)
assert "you are using ssr/netsolarradiation, beware that this quantity only exists in Delft3D-FM 2026.01 and above" in caplog.text
Loading