Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/Deltares/hydromt_sfincs int…
Browse files Browse the repository at this point in the history
…o 94-bug-memory-error-when-loading-large-raster-datasets-clipped-to-a-geometry
  • Loading branch information
roeldegoede committed Jul 12, 2023
2 parents 7ad16a2 + 6e5f078 commit 16f655a
Show file tree
Hide file tree
Showing 18 changed files with 599 additions and 92 deletions.
6 changes: 6 additions & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,16 @@ Setup components
SfincsModel.setup_river_outflow
SfincsModel.setup_observation_points
SfincsModel.setup_structures
SfincsModel.setup_drainage_structures
SfincsModel.setup_waterlevel_forcing
SfincsModel.setup_waterlevel_bnd_from_mask
SfincsModel.setup_discharge_forcing
SfincsModel.setup_discharge_forcing_from_grid
SfincsModel.setup_precip_forcing
SfincsModel.setup_precip_forcing_from_grid
SfincsModel.setup_pressure_forcing_from_grid
SfincsModel.setup_wind_forcing
SfincsModel.setup_wind_forcing_from_grid
SfincsModel.setup_tiles

Plot methods
Expand Down Expand Up @@ -182,6 +186,8 @@ Input/Output methods
utils.write_xyn
utils.read_geoms
utils.write_geoms
utils.read_drn
utils.write_drn
utils.read_sfincs_map_results
utils.read_sfincs_his_results

Expand Down
13 changes: 10 additions & 3 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,24 @@ The format is based on `Keep a Changelog`_, and this project adheres to
v1.0.1 (unreleased)
===================


Bugfix
------
- bugfix in `SfincsModel.write_forcing` to ensure all NetCDF files are written instead of only the first one. PR #86
- bugfix in `SfincsModel.read_config` & `SfincsInput.read` for relative paths in inp file. PR #88
- bugfix in `SfincsModel.setup_subgrid` to ensure that a 'big geotiff' will be written by default when 'write_dep_tif' or 'write_man_tif' are True
- fix memory issues caused by rasterizing the model region and reprojecting before clipping of rasters. PR #94
- bugfix in `Sfincs.read_forcing` when combining attributes from the locations stored in the gis folder with the actual forcing locations. PR #99
- bugfix in `SfincsModel.setup_discharge_from_grid` when snapping based on upstream area in case a src points is outside of the uparea grid domain. PR #99

New
-----------
- `SfincsModel.setup_cn_infiltration_with_kr` to setup three layers related to the curve number (maximum and effective infiltration capacity; seff and smax) and recovery rate (kr)
- `SfincsModel.setup_cn_infiltration_with_kr` to setup three layers related to the curve number (maximum and effective infiltration capacity; seff and smax) and recovery rate (kr). PR#87
- `SfincsModelsetup_drainage_structures` to setup drainage structures (pumps,culverts) from a geodataframe. PR#90
- Added `SfincsModel.setup_wind_forcing`, `SfincsModel.setup_wind_forcing_from_grid` and `SfincsModel.setup_pressure_forcing_from_grid` methods to easily add wind and pressure forcing. PR #92
- `SfincsModel.read_config` allows to use a template input file from a directory different than the model root. PR #102
- Added the option to use landuse/landcover data combined with a reclass table to `SfincsModel.setup_constant_infiltration`. PR #103
- Enabled to provide locations only (so no timeseries) for `SfincsModel.setup_waterlevel_forcing` and `SfincsModel.setup_discharge_forcing` PR #104
- New optional buffer argument in `SfincsModel.setup_discharge_forcing` to select gauges around boundary only. PR #104

Changed
-------
Expand Down Expand Up @@ -206,4 +213,4 @@ Documentation


.. _Keep a Changelog: https://keepachangelog.com/en/1.0.0/
.. _Semantic Versioning: https://semver.org/spec/v2.0.0.html
.. _Semantic Versioning: https://semver.org/spec/v2.0.0.html
12 changes: 10 additions & 2 deletions docs/user_guide/sfincs_model_setup.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ For more information about each file, see the `SFINCS documentation <https://sfi
* - :py:attr:`~hydromt_sfincs.SfincsModel.subgrid`
- sbgfile
* - :py:attr:`~hydromt_sfincs.SfincsModel.geoms`
- obsfile, thdfile, weirfile
- obsfile, thdfile, weirfile, drnfile
* - :py:attr:`~hydromt_sfincs.SfincsModel.forcing`
- bndfile, bzsfile, srcfile, disfile, precipfile, netbndbzsbzifile, netsrcdisfile, netamprfile, netampfile, netamuamvfile
* - :py:attr:`~hydromt_sfincs.SfincsModel.states`
Expand Down Expand Up @@ -122,6 +122,8 @@ Geoms setup methods
- This component adds observation points to the model (obsfile).
* - :py:func:`~hydromt_sfincs.SfincsModel.setup_structures`
- This component adds line element structures to the model (thdfile, weirfile).
* - :py:func:`~hydromt_sfincs.SfincsModel.setup_drainage_structures`
- This component adds drainage structures (pump, culvert) to the model (drnfile).

Forcing setup methods
---------------------
Expand All @@ -145,9 +147,15 @@ Forcing setup methods
* - :py:func:`~hydromt_sfincs.SfincsModel.setup_discharge_forcing_from_grid`
- This component adds discharge forcing (srcfile, disfile) based on a gridded discharge dataset.
* - :py:func:`~hydromt_sfincs.SfincsModel.setup_precip_forcing`
- This component adds spatially uniform precipitation forcing (precipfile).
- This component adds spatially uniform precipitation forcing from timeseries/constants (precipfile).
* - :py:func:`~hydromt_sfincs.SfincsModel.setup_precip_forcing_from_grid`
- This component adds precipitation forcing from a gridded spatially varying data source (netamprfile).
* - :py:func:`~hydromt_sfincs.SfincsModel.setup_pressure_forcing_from_grid`
- This component adds pressure forcing from a gridded spatially varying data source (netampfile).
* - :py:func:`~hydromt_sfincs.SfincsModel.setup_wind_forcing`
- This component adds spatially uniform wind forcing from timeseries/constants (wndfile).
* - :py:func:`~hydromt_sfincs.SfincsModel.setup_wind_forcing_from_grid`
- This component adds wind forcing from a gridded spatially varying data source (netamuamvfile).

Other setup methods
-------------------
Expand Down
25 changes: 23 additions & 2 deletions hydromt_sfincs/plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,15 @@ def plot_forcing(forcing: Dict, **kwargs):
unit = da.attrs.get("unit", "")
prefix = ""
if da.ndim == 3:
da = da.mean(dim=[da.raster.x_dim, da.raster.y_dim])
prefix = "mean "
if name.startswith("press"):
da = da.min(dim=[da.raster.x_dim, da.raster.y_dim])
prefix = "min "
elif name.startswith("wind_u") or name.startswith("wind_v"):
da = da.max(dim=[da.raster.x_dim, da.raster.y_dim])
prefix = "max "
else:
da = da.mean(dim=[da.raster.x_dim, da.raster.y_dim])
prefix = "mean "
# convert to Single index dataframe (bar plots don't work with xarray)
df = da.to_pandas()
if isinstance(df.index, pd.MultiIndex):
Expand All @@ -62,6 +69,20 @@ def plot_forcing(forcing: Dict, **kwargs):
df.index = mdates.date2num(df.index)
if name.startswith("precip"):
axes[i].bar(df.index, df.values, facecolor="darkblue")
elif (
name.startswith("press")
or name.startswith("wind_u")
or name.startswith("wind_v")
):
df.plot.line(ax=axes[i])
elif name.startswith("wnd"):
df.plot(ax=axes[i], kind="line", secondary_y="dir", legend=False)
# set tick color for y-axis of variable 1
axes[i].tick_params(axis="y", labelcolor="C0")
axes[i].right_ax.set_ylabel("Wind direction [degrees]")
# set tick color and label for y-axis of variable 2
axes[i].right_ax.tick_params(axis="y", labelcolor="C1")

else:
df.plot.line(ax=axes[i]).legend(
title="index",
Expand Down
Loading

0 comments on commit 16f655a

Please sign in to comment.