From b39135c71057500f16ff767509d8f623116a758a Mon Sep 17 00:00:00 2001 From: JoostBuitink <44062204+JoostBuitink@users.noreply.github.com> Date: Wed, 16 Nov 2022 12:15:09 +0100 Subject: [PATCH 1/9] remove None to skip from example .ini files --- examples/wflow_build.ini | 10 +++++----- examples/wflow_sediment_build.ini | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/examples/wflow_build.ini b/examples/wflow_build.ini index 4fa6af75..08c3a5f0 100644 --- a/examples/wflow_build.ini +++ b/examples/wflow_build.ini @@ -28,16 +28,16 @@ smooth_len = 5000 # length over which to smooth river depth an # land_routing = kinematic-wave # {'kinematic-wave', 'local-inertial'} [setup_reservoirs] -reservoirs_fn = hydro_reservoirs # source for reservoirs based on GRAND: {hydro_reservoirs}; None to skip +reservoirs_fn = hydro_reservoirs # source for reservoirs based on GRAND: {hydro_reservoirs} min_area = 1.0 # minimum lake area to consider [km2] -priority_jrc = True # if True then JRC data from hydroengine is used to calculate some reservoir attributes instead of the GRanD and HydroLAKES db. +priority_jrc = True # if True then JRC data from hydroengine is used to calculate some reservoir attributes instead of the GRanD and HydroLAKES db. [setup_lakes] -lakes_fn = hydro_lakes # source for lakes based on hydroLAKES: {hydro_lakes}; None to skip +lakes_fn = hydro_lakes # source for lakes based on hydroLAKES: {hydro_lakes} min_area = 10.0 # minimum reservoir area to consider [km2] [setup_glaciers] -glaciers_fn = rgi # source for glaciers based on Randolph Glacier Inventory {rgi}; None to skip +glaciers_fn = rgi # source for glaciers based on Randolph Glacier Inventory {rgi} min_area = 1.0 # minimum glacier area to consider [km2] [setup_lulcmaps] @@ -73,7 +73,7 @@ Cfmax = 3.75653 cf_soil = 0.038 EoverR = 0.11 InfiltCapPath = 5 -InfiltCapSoil = 600 +InfiltCapSoil = 600 MaxLeakage = 0 rootdistpar = -500 TT = 0 diff --git a/examples/wflow_sediment_build.ini b/examples/wflow_sediment_build.ini index 13f40720..08ec7d35 100644 --- a/examples/wflow_sediment_build.ini +++ b/examples/wflow_sediment_build.ini @@ -22,12 +22,12 @@ slope_len = 2000 # length over which tp calculate river slope smooth_len = 5000 # length over which to smooth river depth and river width [m] [setup_reservoirs] -reservoirs_fn = hydro_reservoirs # source for reservoirs based on GRAND: {hydro_reservoirs}; None to skip +reservoirs_fn = hydro_reservoirs # source for reservoirs based on GRAND: {hydro_reservoirs} min_area = 1.0 # minimum lake area to consider [km2] -priority_jrc = True # if True then JRC data from hydroengine is used to calculate some reservoir attributes instead of the GRanD and HydroLAKES db. +priority_jrc = True # if True then JRC data from hydroengine is used to calculate some reservoir attributes instead of the GRanD and HydroLAKES db. [setup_lakes] -lakes_fn = hydro_lakes # source for lakes based on hydroLAKES: {hydro_lakes}; None to skip +lakes_fn = hydro_lakes # source for lakes based on hydroLAKES: {hydro_lakes} min_area = 1.0 # minimum reservoir area to consider [km2] [setup_riverbedsed] From c2e9c6f6f33315072ffd84c60de728ef836ad8ee Mon Sep 17 00:00:00 2001 From: JoostBuitink <44062204+JoostBuitink@users.noreply.github.com> Date: Wed, 16 Nov 2022 12:15:30 +0100 Subject: [PATCH 2/9] Add freq_out to example update forcing ini --- examples/wflow_update_forcing.ini | 3 +++ 1 file changed, 3 insertions(+) diff --git a/examples/wflow_update_forcing.ini b/examples/wflow_update_forcing.ini index 50ebba30..bdb2c566 100644 --- a/examples/wflow_update_forcing.ini +++ b/examples/wflow_update_forcing.ini @@ -15,3 +15,6 @@ temp_correction = True # if True pressure is corrected with elevation l dem_forcing_fn = era5_orography # source of elevation grid corresponding to temp_pet_fn. Used for lapse rate correction. pet_method = debruin # method to compute PET: {debruin, makkink} skip_pet = False # if True, only temperature is prepared. + +[write_forcing] +freq_out = M # Set frequency at which forcing files are written, following pandas offset aliases From 7a7f7641a4962949dc4666e5c35b8e90805cd9f9 Mon Sep 17 00:00:00 2001 From: JoostBuitink <44062204+JoostBuitink@users.noreply.github.com> Date: Wed, 16 Nov 2022 12:15:41 +0100 Subject: [PATCH 3/9] fix typo in docstring --- hydromt_wflow/wflow.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/hydromt_wflow/wflow.py b/hydromt_wflow/wflow.py index 82af2c1d..c8ba24dd 100644 --- a/hydromt_wflow/wflow.py +++ b/hydromt_wflow/wflow.py @@ -586,17 +586,17 @@ def setup_lulcmaps( ): """ This component derives several wflow maps are derived based on landuse- - landcover (LULC) data. - + landcover (LULC) data. + Currently, ``lulc_fn`` can be set to the "vito", "globcover" or "corine", fo which lookup tables are constructed to convert lulc classses to model parameters based on literature. The data is remapped at its original resolution and then resampled to the model resolution using the average value, unless noted differently. - + Adds model layers: - * **landuse** map: Landuse class [-] + * **landuse** map: Landuse class [-] * **Kext** map: Extinction coefficient in the canopy gap fraction equation [-] * **Sl** map: Specific leaf storage [mm] * **Swood** map: Fraction of wood in the vegetation/plant [-] @@ -1798,7 +1798,7 @@ def write_forcing( For more options, see https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#offset-aliases chunksize: int, optional Chunksize on time dimension when saving to disk. By default 1. - decimals, int, optional + decimals: int, optional Round the ouput data to the given number of decimals. time_units: str, optional Common time units when writting several netcdf forcing files. By default "days since 1900-01-01T00:00:00". From 7671214b8281164a26b62e8dea4bd312e180a394 Mon Sep 17 00:00:00 2001 From: JoostBuitink <44062204+JoostBuitink@users.noreply.github.com> Date: Wed, 16 Nov 2022 14:56:30 +0100 Subject: [PATCH 4/9] Update wflow_update_forcing.ini --- examples/wflow_update_forcing.ini | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/examples/wflow_update_forcing.ini b/examples/wflow_update_forcing.ini index bdb2c566..7841d8dd 100644 --- a/examples/wflow_update_forcing.ini +++ b/examples/wflow_update_forcing.ini @@ -2,7 +2,7 @@ starttime = 2010-02-01T00:00:00 endtime = 2010-02-10T00:00:00 timestepsecs = 86400 -input.path_forcing = inmaps-chirps-2010.nc +input.path_forcing = inmaps-chirps.nc [setup_precip_forcing] precip_fn = chirps_global # source for precipitation. @@ -18,3 +18,7 @@ skip_pet = False # if True, only temperature is prepared. [write_forcing] freq_out = M # Set frequency at which forcing files are written, following pandas offset aliases + +[write_staticmaps] # to make sure that the staticmaps are written as well + +[write_config] # to make sure the config is updated with the new forcing file \ No newline at end of file From 634a5e965da50f6f040434fda5ad8536bbadf026 Mon Sep 17 00:00:00 2001 From: JoostBuitink <44062204+JoostBuitink@users.noreply.github.com> Date: Wed, 16 Nov 2022 14:57:09 +0100 Subject: [PATCH 5/9] fix reading forcing when freq_out is used --- hydromt_wflow/wflow.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/hydromt_wflow/wflow.py b/hydromt_wflow/wflow.py index c8ba24dd..1db74a72 100644 --- a/hydromt_wflow/wflow.py +++ b/hydromt_wflow/wflow.py @@ -1769,6 +1769,14 @@ def read_forcing(self): ds = xr.open_dataset(fn, chunks={"time": 30}, decode_coords="all") for v in ds.data_vars: self.set_forcing(ds[v]) + elif fn.match("*"): + self.logger.info(f"Read multiple forcing files using {fn}") + fns = list(fn.parent.glob(fn.name)) + if len(fns) == 0: + raise IOError(f"No forcing files found using {fn}") + ds = xr.open_mfdataset(fns, chunks={"time": 30}, decode_coords="all") + for v in ds.data_vars: + self.set_forcing(ds[v]) def write_forcing( self, From dd2919ab998cf950a6cca44af5feac1910c1d59d Mon Sep 17 00:00:00 2001 From: JoostBuitink <44062204+JoostBuitink@users.noreply.github.com> Date: Wed, 16 Nov 2022 15:11:12 +0100 Subject: [PATCH 6/9] bugfix filechecking --- hydromt_wflow/wflow.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hydromt_wflow/wflow.py b/hydromt_wflow/wflow.py index 1db74a72..ef5ce019 100644 --- a/hydromt_wflow/wflow.py +++ b/hydromt_wflow/wflow.py @@ -1769,7 +1769,7 @@ def read_forcing(self): ds = xr.open_dataset(fn, chunks={"time": 30}, decode_coords="all") for v in ds.data_vars: self.set_forcing(ds[v]) - elif fn.match("*"): + elif "*" in str(fn): self.logger.info(f"Read multiple forcing files using {fn}") fns = list(fn.parent.glob(fn.name)) if len(fns) == 0: From 1190c3cd02a4c603a211917e86ed2ce2b5bcbe2f Mon Sep 17 00:00:00 2001 From: JoostBuitink <44062204+JoostBuitink@users.noreply.github.com> Date: Wed, 16 Nov 2022 15:25:36 +0100 Subject: [PATCH 7/9] Update .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index c9fd11b9..b4b69bab 100644 --- a/.gitignore +++ b/.gitignore @@ -77,6 +77,7 @@ target/ # Jupyter Notebook / examples .ipynb_checkpoints +examples/wflow_piave_subbasin/staticmaps examples/wflow_piave_subbasin_updated examples/wflow_test_base examples/wflow_test_full From 09e676924f9740b284ab0b2c27e2da9a66b647b9 Mon Sep 17 00:00:00 2001 From: JoostBuitink <44062204+JoostBuitink@users.noreply.github.com> Date: Mon, 21 Nov 2022 11:12:56 +0100 Subject: [PATCH 8/9] fix write_config and update example ini --- examples/wflow_update_forcing.ini | 2 +- hydromt_wflow/wflow.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/wflow_update_forcing.ini b/examples/wflow_update_forcing.ini index 7841d8dd..66e6f73e 100644 --- a/examples/wflow_update_forcing.ini +++ b/examples/wflow_update_forcing.ini @@ -21,4 +21,4 @@ freq_out = M # Set frequency at which forcing files are writt [write_staticmaps] # to make sure that the staticmaps are written as well -[write_config] # to make sure the config is updated with the new forcing file \ No newline at end of file +[write_staticgeoms] # to make sure that the staticgeoms are written as well \ No newline at end of file diff --git a/hydromt_wflow/wflow.py b/hydromt_wflow/wflow.py index ef5ce019..d4444c64 100644 --- a/hydromt_wflow/wflow.py +++ b/hydromt_wflow/wflow.py @@ -1936,6 +1936,7 @@ def write_forcing( fns_out = os.path.relpath(fn_out, self.root) fns_out = f"{str(fns_out)[0:-3]}_*.nc" self.set_config("input.path_forcing", fns_out) + self.write_config() # re-write config for label, ds_gr in ds.resample(time=freq_out): # ds_gr = group[1] start = ds_gr["time"].dt.strftime("%Y%m%d")[0].item() From 8fcf286baf16dbb82bf30f68611ec26b6b364fbc Mon Sep 17 00:00:00 2001 From: hboisgon Date: Tue, 22 Nov 2022 10:01:34 +0800 Subject: [PATCH 9/9] update changelog --- docs/changelog.rst | 4 ++++ examples/wflow_update_forcing.ini | 6 +++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index a6ec6b66..573c0eea 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -15,13 +15,17 @@ Added Changed ------- +- update forcing example with multiple forcing files #122 Fixed ----- - write_forcing with time of type cftime.DatetimeNoLeap #109 +- write_forcing: re-write config in case of multiple forcing files +- read_forcing with multiple files (* key in toml) - bug in setup_gauges in update mode with crs.is_epsg_code #108 - bug in self.rivers if no staticgeoms and rivmsk is found #113 - bug in wflow_build_sediment.ini template in examples +- wrong defaults in wflow_build.ini teamplate in examples #116 - temporary fix to update staticgeoms basins+rivers in clip_staticmaps (update when moving away from deprecated staticgeoms). - fix wrong default value for lai_fn in setup_laimaps #119 diff --git a/examples/wflow_update_forcing.ini b/examples/wflow_update_forcing.ini index 66e6f73e..50824d7b 100644 --- a/examples/wflow_update_forcing.ini +++ b/examples/wflow_update_forcing.ini @@ -16,9 +16,9 @@ dem_forcing_fn = era5_orography # source of elevation grid corresponding to tem pet_method = debruin # method to compute PET: {debruin, makkink} skip_pet = False # if True, only temperature is prepared. -[write_forcing] +[write_forcing] # Write forcing and re-write config if forcing filename or times are updated freq_out = M # Set frequency at which forcing files are written, following pandas offset aliases -[write_staticmaps] # to make sure that the staticmaps are written as well +[write_staticmaps] # to make sure that the staticmaps are written as well, can be skipped if update in the same model folder -[write_staticgeoms] # to make sure that the staticgeoms are written as well \ No newline at end of file +[write_staticgeoms] # to make sure that the staticgeoms are written as well, can be skipped if update in the same model folder \ No newline at end of file