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

add setup_lulcmaps_from_vector #320

Merged
merged 5 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
4 changes: 4 additions & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Setup components
WflowModel.setup_reservoirs
WflowModel.setup_glaciers
WflowModel.setup_lulcmaps
WflowModel.setup_lulcmaps_from_vector
WflowModel.setup_lulcmaps_with_paddy
WflowModel.setup_laimaps
WflowModel.setup_laimaps_from_lulc_mapping
Expand Down Expand Up @@ -160,6 +161,7 @@ Setup components
WflowSedimentModel.setup_lakes
WflowSedimentModel.setup_reservoirs
WflowSedimentModel.setup_lulcmaps
WflowSedimentModel.setup_lulcmaps_from_vector
WflowSedimentModel.setup_laimaps
WflowSedimentModel.setup_laimaps_from_lulc_mapping
WflowSedimentModel.setup_canopymaps
Expand Down Expand Up @@ -259,10 +261,12 @@ Wflow workflows
workflows.river_bathymetry
workflows.pet
workflows.landuse
workflows.landuse_from_vector
workflows.lai
workflows.create_lulc_lai_mapping_table
workflows.lai_from_lulc_mapping
workflows.add_paddy_to_landuse
workflows.add_planted_forest_to_landuse
workflows.ksathorfrac
workflows.ksatver_vegetation
workflows.soilgrids
Expand Down
1 change: 1 addition & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Unreleased
Added
-----
- **setup_ksatver_vegetation**: method to calculate KsatVer_vegetation to account for biologically-enhanced soil structure in KsatVer.
- **setup_lulcmaps_from_vector**: method to prepare LULC map and params from a vector input rather than raster. PR #320

Changed
-------
Expand Down
4 changes: 3 additions & 1 deletion docs/user_guide/sediment_model_setup.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ a specific method see its documentation.
* - :py:func:`~WflowSedimentModel.setup_reservoirs`
- This component generates maps of lake areas and outlets as well as parameters with average reservoir area, demand, min and max target storage capacities and discharge capacity values.
* - :py:func:`~WflowSedimentModel.setup_lulcmaps`
- This component derives several wflow maps are derived based on landuse- landcover (LULC) data.
- This component derives several wflow maps based on landuse- landcover (LULC) raster data.
* - :py:func:`~WflowModel.setup_lulcmaps_from_vector`
- This component derives several wflow maps based on landuse- landcover (LULC) vector data.
* - :py:func:`~WflowSedimentModel.setup_laimaps`
- This component sets leaf area index (LAI) climatology maps per month.
* - :py:func:`~WflowSedimentModel.setup_laimaps_from_lulc_mapping`
Expand Down
6 changes: 4 additions & 2 deletions docs/user_guide/wflow_model_setup.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@ a specific method see its documentation.
* - :py:func:`~WflowModel.setup_glaciers`
- This component generates maps of glacier areas, area fraction and volume fraction, as well as tables with temperature threshold, melting factor and snow-to-ice conversion fraction.
* - :py:func:`~WflowModel.setup_lulcmaps`
- This component derives several wflow maps based on landuse- landcover (LULC) data.
- This component derives several wflow maps based on landuse- landcover (LULC) raster data.
* - :py:func:`~WflowModel.setup_lulcmaps_from_vector`
- This component derives several wflow maps based on landuse- landcover (LULC) vector data.
* - :py:func:`~WflowModel.setup_lulcmaps_with_paddy`
- This component derives several wflow maps based on landuse- landcover (LULC) data with paddy rice.
- This component derives several wflow maps based on landuse- landcover (LULC) raster data with paddy rice.
* - :py:func:`~WflowModel.setup_laimaps`
- This component sets leaf area index (LAI) climatology maps per month.
* - :py:func:`~WflowModel.setup_laimaps_from_lulc_mapping`
Expand Down
129 changes: 129 additions & 0 deletions hydromt_wflow/wflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -947,6 +947,135 @@ def setup_lulcmaps(
if name in WFLOW_NAMES and WFLOW_NAMES[name] is not None:
self.set_config(WFLOW_NAMES[name], name)

def setup_lulcmaps_from_vector(
self,
lulc_fn: Union[str, gpd.GeoDataFrame],
lulc_mapping_fn: Union[str, Path, pd.DataFrame] = None,
lulc_vars: List = [
"landuse",
"Kext",
"N",
"PathFrac",
"RootingDepth",
"Sl",
"Swood",
"WaterFrac",
"kc",
"alpha_h1",
"h1",
"h2",
"h3_high",
"h3_low",
"h4",
],
lulc_res: Optional[Union[float, int]] = None,
all_touched: bool = False,
save_raster_lulc: bool = False,
):
"""
Derive several wflow maps based on vector landuse-landcover (LULC) data.

The vector lulc data is first rasterized to a raster map at the model resolution
or at a higher resolution specified in ``lulc_res`` (recommended).

Lookup table `lulc_mapping_fn` columns are converted to lulc classes 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 [-]
* **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 [-]
* **RootingDepth** map: Length of vegetation roots [mm]
* **PathFrac** map: The fraction of compacted or urban area per grid cell [-]
* **WaterFrac** map: The fraction of open water per grid cell [-]
* **N** map: Manning Roughness [-]
* **kc** map: Crop coefficient [-]
* **alpha_h1** map: Root water uptake reduction at soil water pressure head h1
(0 or 1) [-]
* **h1** map: Soil water pressure head h1 at which root water uptake is reduced
(Feddes) [cm]
* **h2** map: Soil water pressure head h2 at which root water uptake is reduced
(Feddes) [cm]
* **h3_high** map: Soil water pressure head h3 at which root water uptake is
reduced (Feddes) [cm]
* **h3_low** map: Soil water pressure head h3 at which root water uptake is
reduced (Feddes) [cm]
* **h4** map: Soil water pressure head h4 at which root water uptake is reduced
(Feddes) [cm]

Parameters
----------
lulc_fn : str, gpd.GeoDataFrame
GeoDataFrame or name in data catalog / path to (vector) landuse map.

* Required columns: 'landuse' [-]
lulc_mapping_fn : str, Path, pd.DataFrame
Path to a mapping csv file from landuse in source name to parameter values
in lulc_vars. If lulc_fn is one of {"globcover", "vito", "corine",
"esa_worldcover", "glmnco"}, a default mapping is used and this argument
becomes optional.
lulc_vars : dict
List of landuse parameters to prepare.
By default ["landuse","Kext","N","PathFrac","RootingDepth","Sl","Swood",
"WaterFrac"]
lulc_res : float, int, optional
Resolution of the intermediate rasterized landuse map. The unit (meter or
degree) depends on the CRS of lulc_fn (projected or not). By default None,
which uses the model resolution.
all_touched : bool, optional
If True, all pixels touched by the vector will be burned in the raster,
by default False.
save_raster_lulc : bool, optional
If True, the high resolution rasterized landuse map will be saved to
maps/landuse_raster.tif, by default False.

See Also
--------
workflows.landuse_from_vector
"""
hboisgon marked this conversation as resolved.
Show resolved Hide resolved
self.logger.info("Preparing LULC parameter maps.")
# Read mapping table
if lulc_mapping_fn is None:
lulc_mapping_fn = f"{lulc_fn}_mapping_default"
df_map = self.data_catalog.get_dataframe(
lulc_mapping_fn,
driver_kwargs={"index_col": 0}, # only used if fn_map is a file path
)
# read landuse map
gdf = self.data_catalog.get_geodataframe(
lulc_fn,
geom=self.region,
buffer=2,
variables=["landuse"],
)
if save_raster_lulc:
lulc_out = join(self.root, "maps", "landuse_raster.tif")
hboisgon marked this conversation as resolved.
Show resolved Hide resolved
else:
lulc_out = None

# process landuse
ds_lulc_maps = workflows.landuse_from_vector(
gdf=gdf,
ds_like=self.grid,
df=df_map,
params=lulc_vars,
lulc_res=lulc_res,
all_touched=all_touched,
lulc_out=lulc_out,
logger=self.logger,
)
rmdict = {k: v for k, v in self._MAPS.items() if k in ds_lulc_maps.data_vars}
self.set_grid(ds_lulc_maps.rename(rmdict))

# Add entries to the config
for name in ds_lulc_maps.data_vars:
if name in WFLOW_NAMES and WFLOW_NAMES[name] is not None:
self.set_config(WFLOW_NAMES[name], name)

def setup_laimaps(
self,
lai_fn: Union[str, xr.DataArray],
Expand Down
Loading
Loading