Skip to content

Commit b867a68

Browse files
authored
Add results component (#533)
* add outputs components * update docs and notebooks * add unit tests * forgot to actually add them... * move common grid functionnality to utils * fix some typos * changes from review
1 parent 36674ed commit b867a68

20 files changed

+1196
-232
lines changed

docs/api.rst

Lines changed: 58 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ High level and I/O methods
9494
WflowModel.write_states
9595
WflowModel.clip_states
9696

97-
WflowModel.read_results
97+
WflowModel.read_outputs
9898

9999
WflowModel.read_tables
100100
WflowModel.write_tables
@@ -106,11 +106,14 @@ Components
106106
:toctree: _generated
107107

108108
WflowModel.config
109-
WflowModel.forcing
110109
WflowModel.staticmaps
110+
WflowModel.forcing
111111
WflowModel.states
112+
WflowModel.tables
112113
WflowModel.geoms
113-
114+
WflowModel.output_grid
115+
WflowModel.output_scalar
116+
WflowModel.output_csv
114117

115118
Attributes
116119
----------
@@ -208,7 +211,7 @@ High level and I/O methods
208211
WflowSedimentModel.read_states
209212
WflowSedimentModel.write_states
210213

211-
WflowSedimentModel.read_results
214+
WflowSedimentModel.read_outputs
212215

213216
Components
214217
----------
@@ -217,8 +220,14 @@ Components
217220
:toctree: _generated
218221

219222
WflowSedimentModel.config
220-
WflowSedimentModel.forcing
221223
WflowSedimentModel.staticmaps
224+
WflowSedimentModel.forcing
225+
WflowSedimentModel.states
226+
WflowSedimentModel.tables
227+
WflowSedimentModel.geoms
228+
WflowSedimentModel.output_grid
229+
WflowSedimentModel.output_scalar
230+
WflowSedimentModel.output_csv
222231

223232
Attributes
224233
----------
@@ -260,6 +269,16 @@ WflowConfigComponent
260269
components.WflowConfigComponent.get_value
261270
components.WflowConfigComponent.remove
262271

272+
WflowStaticmapsComponent
273+
------------------------
274+
275+
.. autosummary::
276+
:toctree: _generated
277+
278+
components.WflowStaticmapsComponent
279+
components.WflowStaticmapsComponent.data
280+
components.WflowStaticmapsComponent.drop_vars
281+
263282
WflowForcingComponent
264283
------------------------
265284

@@ -287,15 +306,44 @@ WflowStatesComponent
287306
components.WflowStatesComponent
288307
components.WflowStatesComponent.data
289308

290-
WflowStaticmapsComponent
309+
WflowTablesComponent
310+
--------------------
311+
312+
.. autosummary::
313+
:toctree: _generated
314+
315+
components.WflowTablesComponent
316+
components.WflowTablesComponent.data
317+
318+
WflowOutputGridComponent
291319
------------------------
292320

293321
.. autosummary::
294322
:toctree: _generated
295323

296-
components.WflowStaticmapsComponent
297-
components.WflowStaticmapsComponent.data
298-
components.WflowStaticmapsComponent.drop_vars
324+
components.WflowOutputGridComponent
325+
components.WflowOutputGridComponent.data
326+
components.WflowOutputGridComponent.read
327+
328+
WflowOutputScalarComponent
329+
---------------------------
330+
331+
.. autosummary::
332+
:toctree: _generated
333+
334+
components.WflowOutputScalarComponent
335+
components.WflowOutputScalarComponent.data
336+
components.WflowOutputScalarComponent.read
337+
338+
WflowOutputCsvComponent
339+
------------------------
340+
341+
.. autosummary::
342+
:toctree: _generated
343+
344+
components.WflowOutputCsvComponent
345+
components.WflowOutputCsvComponent.data
346+
components.WflowOutputCsvComponent.read
299347

300348
.. _workflows:
301349

@@ -355,7 +403,7 @@ Input/Output methods
355403
.. autosummary::
356404
:toctree: _generated
357405

358-
utils.read_csv_results
406+
utils.read_csv_output
359407

360408
Utility methods
361409
---------------

docs/changelog.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ Added
1414
-----
1515
- config component ``WflowConfigComponent``: represents the Wflow configuration TOML file.
1616
- staticmaps component ``WflowStaticMapsComponent``: represents Wflow static and cyclic data (used to be grid).
17+
- forcing component ``WflowForcingComponent``: represents Wflow input forcing data.
1718
- states component ``WflowStatesComponent``: represents Wflow input states data.
1819
- geoms component ``WflowGeomsComponent``: represents Wflow staticgeoms data.
20+
- output_grid ``WflowOutputGridComponent``, output_scalar ``WflowOutputScalarComponent`` and output_csv ``WflowOutputCsvComponent`` components: represent Wflow outputs (used to be results).
1921
- **write_geoms**: added function arguments ``to_wgs84`` to convert the geometry to WGS84 before writing it to file. PR #432
2022

2123
Changed
@@ -27,6 +29,7 @@ Changed
2729
Eg wflow.config.data, wflow.staticmaps.data
2830
- The names of some of the model components have changed: ``grid`` to ``staticmaps``.
2931
- **setup_config**: the method now explicitly uses a dictionary with the options to add/update.
32+
- **utils.read_csv_results** has been renamed to **utils.read_csv_output**.
3033
- Reverted the use of TOMLkit dependency
3134

3235

docs/user_guide/sediment_model_setup.rst

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,35 +74,35 @@ a specific method see its documentation.
7474

7575
.. _model_components_sed:
7676

77-
model components
77+
Model components
7878
================
7979

8080
The following table provides an overview of which :py:class:`~hydromt_wflow.WflowSedimentModel`
81-
component contains which Wflow Sediment in- and output files. The files are read and written with the associated
81+
components contains which Wflow Sediment in- and output files. The files are read and written with the associated
8282
read- and write- methods, i.e. :py:func:`~hydromt_wflow.WflowSedimentModel.read_config`
8383
and :py:func:`~hydromt_wflow.WflowSedimentModel.write_config` for the
8484
:py:attr:`~hydromt_wflow.WflowSedimentModel.config` component.
8585

8686

87-
.. list-table:: Wflow Sediment mdel data
87+
.. list-table:: Wflow Sediment model data
8888
:widths: 30 70
8989
:header-rows: 1
9090

91-
* - :py:class:`~hydromt_wflow.WflowSedimentModel` component
91+
* - :py:class:`~hydromt_wflow.WflowSedimentModel` model
9292
- Wflow sediment files
9393
* - :py:attr:`~hydromt_wflow.WflowSedimentModel.config`
9494
- wflow_sediment.toml
95-
* - :py:attr:`~hydromt_wflow.WflowSedimentModel.grid`
95+
* - :py:attr:`~hydromt_wflow.WflowSedimentModel.staticmaps`
9696
- staticmaps.nc
9797
* - :py:attr:`~hydromt_wflow.WflowSedimentModel.geoms`
9898
- geometries from the staticgeoms folder (basins.geojson, rivers.geojson etc.)
9999
* - :py:attr:`~hydromt_wflow.WflowSedimentModel.forcing`
100100
- inmaps.nc
101101
* - :py:attr:`~hydromt_wflow.WflowSedimentModel.states`
102102
- instates.nc
103-
* - :py:attr:`~hydromt_wflow.WflowSedimentModel.results`
104-
- output.nc, output_scalar.nc, output.csv
105-
* - :py:attr:`~hydromt_wflow.WflowSedimentModel.staticmaps` (deprecated, removed in hydromt_wflow v0.6.0)
106-
- staticmaps.nc
107-
* - :py:attr:`~hydromt_wflow.WflowSedimentModel.staticgeoms` (deprecated, removed in hydromt_wflow v0.6.0)
108-
- geometries from the staticgeoms folder (basins.geojson, rivers.geojson etc.)
103+
* - :py:attr:`~hydromt_wflow.WflowSedimentModel.output_grid`
104+
- output.nc (defined in [output.netcdf_grid] TOML section)
105+
* - :py:attr:`~hydromt_wflow.WflowSedimentModel.output_scalar`
106+
- output_scalar.nc (defined in [output.netcdf_scalar] TOML section)
107+
* - :py:attr:`~hydromt_wflow.WflowSedimentModel.output_csv`
108+
- output.csv (defined in [output.csv] TOML section)

docs/user_guide/wflow_model_setup.rst

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -112,21 +112,21 @@ Model components
112112
================
113113

114114
The following table provides an overview of which :py:class:`~hydromt_wflow.WflowModel`
115-
component contains which Wflow in- and output files. The files are read and written with the associated
115+
components contains which Wflow in- and output files. The files are read and written with the associated
116116
read- and write- methods, i.e. :py:func:`~WflowModel.read_config`
117117
and :py:func:`~WflowModel.write_config` for the
118118
:py:attr:`~WflowModel.config` component.
119119

120120

121-
.. list-table::
121+
.. list-table:: Wflow model data
122122
:widths: 30 70
123123
:header-rows: 1
124124

125-
* - :py:class:`~hydromt_wflow.WflowModel` component
125+
* - :py:class:`~hydromt_wflow.WflowModel` model
126126
- Wflow files
127127
* - :py:attr:`~hydromt_wflow.WflowModel.config`
128128
- wflow_sbm.toml
129-
* - :py:attr:`~hydromt_wflow.WflowModel.grid`
129+
* - :py:attr:`~hydromt_wflow.WflowModel.staticmaps`
130130
- staticmaps.nc
131131
* - :py:attr:`~hydromt_wflow.WflowModel.geoms`
132132
- geometries from the staticgeoms folder (basins.geojson, rivers.geojson etc.)
@@ -136,9 +136,9 @@ and :py:func:`~WflowModel.write_config` for the
136136
- instates.nc
137137
* - :py:attr:`~hydromt_wflow.WflowModel.tables`
138138
- tabular data (csv format, e.g. lake_hq.csv, lake_sh.csv)
139-
* - :py:attr:`~hydromt_wflow.WflowModel.results`
140-
- output.nc, output_scalar.nc, output.csv
141-
* - :py:attr:`~hydromt_wflow.WflowModel.staticmaps` (deprecated, removed in hydromt_wflow v0.6.0)
142-
- staticmaps.nc
143-
* - :py:attr:`~hydromt_wflow.WflowModel.staticgeoms` (deprecated, removed in hydromt_wflow v0.6.0)
144-
- geometries from the staticgeoms folder (basins.geojson, rivers.geojson etc.)
139+
* - :py:attr:`~hydromt_wflow.WflowModel.output_grid`
140+
- output.nc (defined in [output.netcdf_grid] TOML section)
141+
* - :py:attr:`~hydromt_wflow.WflowModel.output_scalar`
142+
- output_scalar.nc (defined in [output.netcdf_scalar] TOML section)
143+
* - :py:attr:`~hydromt_wflow.WflowModel.output_csv`
144+
- output.csv (defined in [output.csv] TOML section)

examples/plot_wflow_results.ipynb

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,20 @@
44
"cell_type": "markdown",
55
"metadata": {},
66
"source": [
7-
"## Plot Wflow results"
7+
"## Plot Wflow outputs"
88
]
99
},
1010
{
1111
"cell_type": "markdown",
1212
"metadata": {},
1313
"source": [
14-
"**HydroMT** provides a simple interface to model results from which we can make beautiful plots:\n",
14+
"**HydroMT** provides a simple interface to model outputs from which we can make beautiful plots:\n",
1515
"\n",
16-
"- Results layers are saved to the model `results` component as a dictionnary of `xarray.Dataset` or `xarray.DataArray`.\n",
16+
"- Wflow gridded outputs are saved to the model `output_grid` component as a `xarray.Dataset`.\n",
17+
"- Wflow netcdf scalar outputs are saved to the model `output_scalar` component as a `xarray.Dataset`.\n",
18+
"- Wflow csv outputs are saved to the model `output_csv` component as a dict of `xarray.DataArray`.\n",
1719
"\n",
18-
"These plots can be useful to analyze the model results or also compare model runs with different settings (different precipitation source or different parameters values)."
20+
"These plots can be useful to analyze the model outputs or also compare model runs with different settings (different precipitation source or different parameters values)."
1921
]
2022
},
2123
{
@@ -40,14 +42,14 @@
4042
"cell_type": "markdown",
4143
"metadata": {},
4244
"source": [
43-
"### Read the model run(s) results"
45+
"### Read the model run(s) outputs"
4446
]
4547
},
4648
{
4749
"cell_type": "markdown",
4850
"metadata": {},
4951
"source": [
50-
"The **wflow_piave_subbasin** model was run using the default global data sources of the hydromt_wflow plugin. The different variables to save after the wflow were set in a separate wflow configuration file: *wflow_sbm_results.toml*.\n",
52+
"The **wflow_piave_subbasin** model was run using the default global data sources of the hydromt_wflow plugin. The different variables to save were set in a separate wflow configuration file: *wflow_sbm_results.toml*.\n",
5153
"\n",
5254
"A second run of the model was also done, where the KsatHorFrac parameter of wflow was set to 10 (instead of the default 100 value) using an alternative configuration file: *wflow_sbm_results2.toml*.\n",
5355
"\n",
@@ -95,13 +97,13 @@
9597
"cell_type": "markdown",
9698
"metadata": {},
9799
"source": [
98-
"Wflow can save different types of outputs (netcdf gridded output, netcdf scalar netcdf, csv scalar timeseries) that are also reflected in the organisation of the HydroMT `results` component:\n",
100+
"Wflow can save different types of outputs (netcdf gridded output, netcdf scalar netcdf, csv scalar timeseries) that are also reflected in the organisation of the HydroMT-Wflow different `output` components:\n",
99101
"\n",
100-
"* a **\"output\" xarray.Dataset** for the gridded netcdf file (output section of the TOML)\n",
101-
"* a **\"netcdf\" xarray.Dataset** for the netcdf point timeseries file (netcdf section of the TOML)\n",
102-
"* different **hydromt.GeoDataArrays for the csv file** , one per column (csv section and csv.column sections of the TOML). The xy coordinates are the coordinates of the station or of the representative point of the subcatch/area. The variable name in the GeoDataArray corresponds to the csv header attribute or header_map when available.\n",
102+
"* a **\"output_grid\" hydromt.RasterDataset** for the gridded netcdf file (output.netcdf_grid section of the TOML)\n",
103+
"* a **\"output_scalar\" xarray.Dataset** for the netcdf point timeseries file (output.netcdf_scalar section of the TOML)\n",
104+
"* different **hydromt.GeoDataArrays for the csv file** , one per column (output.csv section and csv.column sections of the TOML). The xy coordinates are the coordinates of the station or of the representative point of the subcatch/area. The variable name in the GeoDataArray corresponds to the csv header attribute or header_map when available.\n",
103105
"\n",
104-
"Below you can see how to access to the results of *run1* and its contents:"
106+
"Below you can see how to access to the different outputs of *run1* and its contents:"
105107
]
106108
},
107109
{
@@ -111,7 +113,25 @@
111113
"outputs": [],
112114
"source": [
113115
"model1 = runs[\"run1\"][\"model\"]\n",
114-
"model1.results"
116+
"model1.output_grid.data"
117+
]
118+
},
119+
{
120+
"cell_type": "code",
121+
"execution_count": null,
122+
"metadata": {},
123+
"outputs": [],
124+
"source": [
125+
"model1.output_scalar.data"
126+
]
127+
},
128+
{
129+
"cell_type": "code",
130+
"execution_count": null,
131+
"metadata": {},
132+
"outputs": [],
133+
"source": [
134+
"model1.output_csv.data"
115135
]
116136
},
117137
{
@@ -188,7 +208,7 @@
188208
"# Plots\n",
189209
"from hydromt.stats import skills\n",
190210
"\n",
191-
"station_ids = list(runs[mainrun][\"model\"].results[result_name].index.values)\n",
211+
"station_ids = list(runs[mainrun][\"model\"].output_csv.data[result_name].index.values)\n",
192212
"\n",
193213
"for i, st in enumerate(station_ids):\n",
194214
" n = 2\n",
@@ -201,7 +221,7 @@
201221
"\n",
202222
" for r in runs_subset:\n",
203223
" run = runs[r]\n",
204-
" run_i = run[\"model\"].results[result_name].sel(index=st)\n",
224+
" run_i = run[\"model\"].output_csv.data[result_name].sel(index=st)\n",
205225
" # Stats\n",
206226
" nse_i = skills.nashsutcliffe(run_i, obs_i).values.round(2)\n",
207227
" kge_i = skills.kge(run_i, obs_i)[\"kge\"].values.round(2)\n",
@@ -224,7 +244,7 @@
224244
"\n",
225245
" for r in runs_subset:\n",
226246
" run = runs[r]\n",
227-
" run_i = run[\"model\"].results[result_name].sel(index=st)\n",
247+
" run_i = run[\"model\"].output_csv.data[result_name].sel(index=st)\n",
228248
" run_i.cumsum().plot.line(\n",
229249
" ax=axes[1],\n",
230250
" x=\"time\",\n",
@@ -242,11 +262,11 @@
242262
"cell_type": "markdown",
243263
"metadata": {},
244264
"source": [
245-
"You can see on the discharge plots legends that some statistical criteria were computed using the fictional observations and the model runs results.\n",
265+
"You can see on the discharge plots legends that some statistical criteria were computed using the fictional observations and the model runs outputs.\n",
246266
"\n",
247-
"These statistics were computed using the **stats** module of HydroMT. You can find the available statisctics functions in the [documentation](https://deltares.github.io/hydromt/latest/user_guide/methods_stats.html).\n",
267+
"These statistics were computed using the **stats** module of HydroMT. You can find the available statisctics functions in the [documentation](https://deltares.github.io/hydromt/stable/guides/advanced_user/methods_stats.html).\n",
248268
"\n",
249-
"And finally once the `results` are loaded, you can use them to derive more statistics or plots to further analyze your model."
269+
"And finally once the `outputs` are loaded, you can use them to derive more statistics or plots to further analyze your model."
250270
]
251271
}
252272
],

hydromt_wflow/components/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
from hydromt_wflow.components.config import WflowConfigComponent
44
from hydromt_wflow.components.forcing import WflowForcingComponent
55
from hydromt_wflow.components.geoms import WflowGeomsComponent
6+
from hydromt_wflow.components.output_csv import WflowOutputCsvComponent
7+
from hydromt_wflow.components.output_grid import WflowOutputGridComponent
8+
from hydromt_wflow.components.output_scalar import WflowOutputScalarComponent
69
from hydromt_wflow.components.states import WflowStatesComponent
710
from hydromt_wflow.components.staticmaps import WflowStaticmapsComponent
811
from hydromt_wflow.components.tables import WflowTablesComponent
@@ -14,4 +17,7 @@
1417
"WflowStatesComponent",
1518
"WflowStaticmapsComponent",
1619
"WflowTablesComponent",
20+
"WflowOutputGridComponent",
21+
"WflowOutputScalarComponent",
22+
"WflowOutputCsvComponent",
1723
]

0 commit comments

Comments
 (0)