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

Regular subgrid #160

Merged
merged 35 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
d34f99a
updated subgridregular and added subgridquadtree
maartenvanormondt Dec 14, 2023
35774a9
Merge branch 'quadtree_subgrid' of https://github.com/Deltares/hydrom…
Leynse Dec 15, 2023
d95d376
- Cherrypick changes by mvo in branch quadtree_subgrid, and remove ad…
Leynse Dec 15, 2023
c5d4a47
- patch 'added correct subgrid_q_table' from 'quadtree-subgrid'
Leynse Dec 15, 2023
b0a7191
- to overcome error that np.size is not supported in numba
Leynse Dec 15, 2023
0d3ea9b
black formatting
roeldegoede Dec 20, 2023
fef5d6a
bugfixes in subgrid.py
roeldegoede Dec 20, 2023
64d2d87
and now with numba on again
roeldegoede Dec 20, 2023
50b20e6
enable read/write netcdf subgrid file, should be backward compatible
roeldegoede Dec 20, 2023
99f9f1a
bugfix in workflows.bathymetry
roeldegoede Dec 20, 2023
557d79d
write output according to what SFINCS (fortran expects)
roeldegoede Dec 22, 2023
f025e81
major speed-up in writing the netcdf subgrid tables (now not a bottle…
roeldegoede Dec 22, 2023
69bdd48
delete old code
roeldegoede Dec 22, 2023
b48f339
Merge branch 'main' of https://github.com/Deltares/hydromt_sfincs int…
roeldegoede Dec 22, 2023
4631307
Merge branch 'main' of https://github.com/Deltares/hydromt_sfincs int…
roeldegoede Jan 3, 2024
24a9e52
Changed bins to levels. Update of volume table method to reflect this.
maartenvanormondt Feb 7, 2024
096dcd5
nlevels now input argument for setup_subgrid
roeldegoede Feb 14, 2024
300d41e
fix tests subgrid rivers; order of geodataframe provided by hydromt c…
roeldegoede Feb 23, 2024
d72cfdd
Merge branch 'main' of https://github.com/Deltares/hydromt_sfincs int…
roeldegoede Feb 23, 2024
7113c3b
pre commit formatting
roeldegoede Feb 23, 2024
4f91249
Merge branch 'fix-test_subgrid_rivers' of https://github.com/Deltares…
roeldegoede Feb 23, 2024
bea8eee
now really according to black, but my version looked prettier ...
roeldegoede Feb 23, 2024
b807f98
bugfix in reading binary subgrids
roeldegoede Feb 23, 2024
00c8d20
add version to subgrid to make distinction between binary and netcdf
roeldegoede Mar 19, 2024
a4ea5f6
Merge main into regular_subgrid
roeldegoede Mar 19, 2024
af1fbad
Merge branch 'main' of https://github.com/Deltares/hydromt_sfincs int…
roeldegoede Mar 19, 2024
9b68d45
add proper reading of netcdf subgrid
roeldegoede Mar 20, 2024
491fabb
update subgrid file and fix last test
roeldegoede Mar 20, 2024
8c54dd1
update changelog
roeldegoede Mar 20, 2024
afe6cf3
pre-commit
roeldegoede Mar 20, 2024
dfd2032
Update docs/changelog.rst
roeldegoede Mar 21, 2024
15898c6
improved readability of new subgrid methods
roeldegoede Mar 21, 2024
9409382
removed extrapolate option since that is not supported by xarray
keesnederhoff Mar 26, 2024
2361eae
Revert "removed extrapolate option since that is not supported by xar…
keesnederhoff Mar 26, 2024
4357b8e
Merge branch 'main' of https://github.com/Deltares/hydromt_sfincs int…
roeldegoede Apr 10, 2024
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
17 changes: 17 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,23 @@ Distinction is made between new methods (Added), changes to existing methods (Ch
The format is based on `Keep a Changelog`_, and this project adheres to
`Semantic Versioning`_.

v1.0.4 (Unreleased)
===================

Added
-----
- improved subgrid tables that account for the wet fraction of the cell (#160)

Changed
-------
- improved subgrid tables are saved as NetCDF (#160)

Fixed
-----
- rounding errors in `workflows.tile_window` which resulted in erronuous slippy-tiles (#178)
- "active geometry column to use has not been set" error for GeoDataFrame (#180)


v1.0.3 (3 January 2024)
=======================
This release contains several changes and fixes. Most notably, models with a geographical CRS can now be build.
Expand Down
44 changes: 37 additions & 7 deletions hydromt_sfincs/sfincs.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

from . import DATADIR, plots, utils, workflows
from .regulargrid import RegularGrid
from .subgrid import SubgridTableRegular
from .sfincs_input import SfincsInput

__all__ = ["SfincsModel"]
Expand Down Expand Up @@ -614,7 +615,8 @@ def setup_subgrid(
datasets_rgh: List[dict] = [],
datasets_riv: List[dict] = [],
buffer_cells: int = 0,
nbins: int = 10,
nlevels: int = 10,
nbins: int = None,
nr_subgrid_pixels: int = 20,
nrmax: int = 2000, # blocksize
max_gradient: float = 5.0,
Expand Down Expand Up @@ -695,6 +697,9 @@ def setup_subgrid(
by default 0
nbins : int, optional
Number of bins in which hypsometry is subdivided, by default 10
Note that this keyword is deprecated and will be removed in future versions.
nlevels: int, optional
DirkEilander marked this conversation as resolved.
Show resolved Hide resolved
Number of levels to describe hypsometry, by default 10
nr_subgrid_pixels : int, optional
Number of subgrid pixels per computational cell, by default 20
nrmax : int, optional
Expand Down Expand Up @@ -742,14 +747,20 @@ def setup_subgrid(
else:
highres_dir = None

if nbins is not None:
logger.warning(
"Keyword nbins is deprecated and will be removed in future versions. Please use nlevels instead."
)
nlevels = nbins

if self.grid_type == "regular":
self.reggrid.subgrid.build(
da_mask=self.mask,
datasets_dep=datasets_dep,
datasets_rgh=datasets_rgh,
datasets_riv=datasets_riv,
buffer_cells=buffer_cells,
nbins=nbins,
nlevels=nlevels,
nr_subgrid_pixels=nr_subgrid_pixels,
nrmax=nrmax,
max_gradient=max_gradient,
Expand All @@ -768,8 +779,11 @@ def setup_subgrid(
elif self.grid_type == "quadtree":
pass

if "sbgfile" not in self.config: # only add sbgfile if not already present
self.config.update({"sbgfile": "sfincs.sbg"})
# when building a new subgrid table, always update config
# NOTE from now onwards, netcdf subgrid tables are used
self.config.update({"sbgfile": "sfincs_subgrid.nc"})
# if "sbgfile" not in self.config: # only add sbgfile if not already present
# self.config.update({"sbgfile": "sfincs.sbg"})
# subgrid is used so no depfile or manningfile needed
if "depfile" in self.config:
self.config.pop("depfile") # remove depfile from config
Expand Down Expand Up @@ -2852,7 +2866,16 @@ def read_subgrid(self):
self.logger.warning(f"sbgfile not found at {fn}")
return

self.reggrid.subgrid.load(file_name=fn, mask=self.mask)
# re-initialize subgrid (different variables for old/new version)
# TODO: come up with a better way to handle this
self.reggrid.subgrid = SubgridTableRegular()
self.subgrid = xr.Dataset()
roeldegoede marked this conversation as resolved.
Show resolved Hide resolved

# read subgrid file
if fn.parts[-1].endswith(".sbg"): # read binary file
self.reggrid.subgrid.read_binary(file_name=fn, mask=self.mask)
else: # read netcdf file
self.reggrid.subgrid.read(file_name=fn, mask=self.mask)
self.subgrid = self.reggrid.subgrid.to_xarray(
dims=self.mask.raster.dims, coords=self.mask.raster.coords
)
Expand All @@ -2863,9 +2886,16 @@ def write_subgrid(self):

if self.subgrid:
if "sbgfile" not in self.config:
self.set_config("sbgfile", "sfincs.sbg")
# apparently no subgrid was read, so set default filename
self.set_config("sbgfile", "sfincs_subgrid.nc")

fn = self.get_config("sbgfile", abs_path=True)
self.reggrid.subgrid.save(file_name=fn, mask=self.mask)
if fn.parts[-1].endswith(".sbg"):
# write binary file
self.reggrid.subgrid.write_binary(file_name=fn, mask=self.mask)
else:
# write netcdf file
self.reggrid.subgrid.write(file_name=fn, mask=self.mask)

def read_geoms(self):
"""Read geometry files and save to `geoms` attribute.
Expand Down
Loading
Loading