Skip to content

Commit

Permalink
Merge pull request #183 from Deltares/small_fixes
Browse files Browse the repository at this point in the history
Small fixes
  • Loading branch information
dalmijn authored Jul 25, 2023
2 parents e5de468 + c848648 commit dbc9402
Show file tree
Hide file tree
Showing 8 changed files with 449 additions and 22 deletions.
400 changes: 400 additions & 0 deletions docs/_static/hydromt-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed docs/_static/hydromt-logo.jpg
Binary file not shown.
10 changes: 7 additions & 3 deletions docs/_static/theme-deltares.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@
html[data-theme="light"] {
/* NOTE: added after pydata v0.9 */
--pst-color-primary: #080c80 !important;

/* hyperlinks */
--pst-color-link: rgb(13, 56, 224);

/* panels */
--pst-color-preformatted-border: #080c80 !important;
--pst-color-panel-background: #f0f0f075;

/* navbar */
/* NOTE: does not work since v0.9 */
--pst-color-navbar-link: rgb(237, 237, 255);
--pst-color-navbar-link-hover: #fff;
--pst-color-navbar-link-active: #fff;

/* sphinx design */
/* NOTE: does not work since v0.9 */
--sd-color-card-border-hover: #080c80;
Expand All @@ -28,4 +28,8 @@ html[data-theme="light"] {
/* enlarge deltares & github icon size; only works with local/url svg files; not with fa icons */
img.icon-link-image {
height: 2.5em !important;
}

i.fa-github {
font-size: 2.5em;
}
1 change: 0 additions & 1 deletion docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ Setup components
WflowModel.setup_laimaps
WflowModel.setup_rootzoneclim
WflowModel.setup_soilmaps
WflowModel.setup_hydrodem
WflowModel.setup_outlets
WflowModel.setup_gauges
WflowModel.setup_areamap
Expand Down
2 changes: 2 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ Fixed
- write_forcing with time cftime.DatetimeNoLeap #138 by removing slicing forcing if missings (not needed)
- write_forcing automatic adjustment of starttime and endtime based on forcing content
- When clipping a model from a model with multiple forcing files, a single netcdf is made in write_forcing and the * is removed from the filename.
- Remove deprecated basin_shape method `PR #183 <https://github.com/Deltares/hydromt_wflow/pull/183>`_
- Remove FillValue Nan for lat/lon in staticmaps and forcing `PR #183 <https://github.com/Deltares/hydromt_wflow/pull/183>`_
- Fix compatibility with HydroMT v0.8.0, with updated `clip_geom/mask` functionality `PR #189 <https://github.com/Deltares/hydromt_wflow/pull/189>`_

Deprecated
Expand Down
9 changes: 5 additions & 4 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ def remove_dir_content(path: str) -> None:
# a list of builtin themes.
#
html_theme = "pydata_sphinx_theme"
html_logo = "_static/hydromt-logo.jpg"
html_logo = "_static/hydromt-icon.svg"
html_favicon = "_static/hydromt-icon.svg"
autodoc_member_order = "bysource" # overwrite default alphabetical sort
autoclass_content = "both"

Expand All @@ -132,8 +133,8 @@ def remove_dir_content(path: str) -> None:
{
"name": "GitHub",
"url": "https://github.com/Deltares/hydromt_wflow", # required
"icon": "https://upload.wikimedia.org/wikipedia/commons/9/91/Octicons-mark-github.svg",
"type": "url",
"icon": "fab fa-github",
"type": "fontawesome",
},
{
"name": "Wflow",
Expand Down Expand Up @@ -280,7 +281,7 @@ def remove_dir_content(path: str) -> None:
.. raw:: html
<div>
For an interactive online version click here:
For an interactive online version click here:
<a href="https://mybinder.org/v2/gh/Deltares/hydromt_wflow/main?urlpath=lab/tree/examples/{{ docname|e }}" target="_blank" rel="noopener noreferrer"><img alt="Binder badge" src="https://mybinder.org/badge_logo.svg"></a>
</div>
"""
4 changes: 1 addition & 3 deletions docs/user_guide/wflow_model_setup.rst
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ a specific method see its documentation.
* - :py:func:`~WflowModel.setup_soilmaps`
- This component derives several (layered) soil parameters based on a database with physical soil properties using available point-scale (pedo)transfer functions (PTFs) from literature with upscaling rulesto ensure flux matching across scales.
* - :py:func:`~WflowModel.setup_rootzoneclim`
- This component derives an estimate of the rooting depth from hydroclimatic data (as an alternative from the look-up table). The method can be applied for current conditions and future climate change conditions.
* - :py:func:`~WflowModel.setup_hydrodem`
- This component adds a hydrologically conditioned elevation (hydrodem) map for river and/or land local-inertial routing.
- This component derives an estimate of the rooting depth from hydroclimatic data (as an alternative from the look-up table). The method can be applied for current conditions and future climate change conditions.
* - :py:func:`~WflowModel.setup_outlets`
- This method sets the default gauge map based on basin outlets.
* - :py:func:`~WflowModel.setup_gauges`
Expand Down
45 changes: 34 additions & 11 deletions hydromt_wflow/wflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,7 @@ def setup_lulcmaps(
This component derives several wflow maps are derived based on landuse-
landcover (LULC) data.
Currently, ``lulc_fn`` can be set to the "vito", "globcover"
Currently, ``lulc_fn`` can be set to the "vito", "globcover", "esa_worldcover"
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
Expand Down Expand Up @@ -1506,6 +1506,7 @@ def setup_reservoirs(
if np.all(np.isin(resattributes, gdf_org.columns)):
intbl_reservoirs = gdf_org[resattributes]
reservoir_accuracy = None
reservoir_timeseries = None
# else compute
else:
(
Expand Down Expand Up @@ -2385,6 +2386,12 @@ def write_staticmaps(self):
ds_out.rio.write_transform(self.staticmaps.raster.transform, inplace=True)
ds_out.raster.set_spatial_dims()

# Remove FillValue Nan for x_dim, y_dim
encoding = dict()
for v in [ds_out.raster.x_dim, ds_out.raster.y_dim]:
ds_out[v].attrs.pop("_FillValue", None)
encoding[v] = {"_FillValue": None}

# filename
fn_default = join(self.root, "staticmaps.nc")
fn = self.get_config("input.path_static", abs_path=True, fallback=fn_default)
Expand All @@ -2403,7 +2410,7 @@ def write_staticmaps(self):
# nodata is required for all but boolean fields
if ds_out[v].dtype != "bool":
ds_out[v] = ds_out[v].where(mask, ds_out[v].raster.nodata)
ds_out.to_netcdf(fn)
ds_out.to_netcdf(fn, encoding=encoding)
# self.write_staticmaps_pcr()

def read_staticmaps_pcr(self, crs=4326, **kwargs):
Expand Down Expand Up @@ -2665,10 +2672,11 @@ def write_forcing(
v: {"zlib": True, "dtype": "float32", "chunksizes": chunksizes}
for v in ds.data_vars.keys()
}
# make sure no _FillValue is written to the time dimension
# make sure no _FillValue is written to the time / x_dim / y_dim dimension
# For several forcing files add common units attributes to time
ds["time"].attrs.pop("_FillValue", None)
encoding["time"] = {"_FillValue": None}
for v in ["time", ds.raster.x_dim, ds.raster.y_dim]:
ds[v].attrs.pop("_FillValue", None)
encoding[v] = {"_FillValue": None}

# Check if all sub-folders in fn_out exists and if not create them
if not isdir(dirname(fn_out)):
Expand Down Expand Up @@ -2894,11 +2902,20 @@ def basins(self):
"""Returns a basin(s) geometry as a geopandas.GeoDataFrame."""
if "basins" in self.staticgeoms:
gdf = self.staticgeoms["basins"]
else:
gdf = flw.basin_shape(
self.staticmaps, self.flwdir, basin_name=self._MAPS["basins"]
elif self._MAPS["basins"] in self.staticmaps:
gdf = (
self.staticmaps[self._MAPS["basins"]]
.raster.vectorize()
.set_index("value")
.sort_index()
)
gdf.index.name = self._MAPS["basins"]
self.set_staticgeoms(gdf, name="basins")
else:
self.logger.warning(
f"Basin map {self._MAPS['basins']} not found in staticmaps."
)
gdf = None
return gdf

@property
Expand Down Expand Up @@ -2974,7 +2991,7 @@ def clip_staticmaps(
)
ds_staticmaps.coords["mask"] = ds_staticmaps.raster.geometry_mask(geom)
ds_staticmaps[basins_name] = ds_staticmaps[basins_name].where(
ds_staticmaps["mask"], self.staticmaps[basins_name].raster.nodata
ds_staticmaps.coords["mask"], self.staticmaps[basins_name].raster.nodata
)
ds_staticmaps[basins_name].attrs.update(
_FillValue=self.staticmaps[basins_name].raster.nodata
Expand All @@ -3001,10 +3018,16 @@ def clip_staticmaps(
# self.rivers
# now staticgeoms links to geoms which does not exist in every hydromt version
# remove when updating wflow to new objects
basins = flw.basin_shape(
self.staticmaps, self.flwdir, basin_name=self._MAPS["basins"]
# Basin shape
basins = (
self.staticmaps[basins_name]
.raster.vectorize()
.set_index("value")
.sort_index()
)
basins.index.name = basins_name
self.set_staticgeoms(basins, name="basins")

rivmsk = self.staticmaps[self._MAPS["rivmsk"]].values != 0
# Check if there are river cells in the model before continuing
if np.any(rivmsk):
Expand Down

0 comments on commit dbc9402

Please sign in to comment.