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

Fix all pre-commit hooks #116

Merged
merged 7 commits into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
defaults:
run:
shell: bash -l {0}

strategy:
fail-fast: false
max-parallel: 5
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- uses: actions/setup-python@v4
name: Install Python
with:
Expand Down Expand Up @@ -114,4 +114,4 @@ jobs:
with:
user: __token__
password: ${{ secrets.PYPI_TOKEN }}
verbose: true
verbose: true
2 changes: 1 addition & 1 deletion docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -297,4 +297,4 @@ GIS methods
gis_utils.cut_pieces
gis_utils.check_gpd_attributes
gis_utils.update_data_columns_attributes_based_on_filter
gis_utils.get_gdf_from_branches
gis_utils.get_gdf_from_branches
12 changes: 6 additions & 6 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ Added

Changed
-------
- Upgraded meshkernel dependency to version 3.0.0. (PR#109)
- Upgraded xugrid dependency to version 0.7.1. (PR#109)
- Upgraded hydrolib-core dependency to version 0.6.0. (PR#109)
- Upgraded meshkernel dependency to version 3.0.0. (PR#109)
- Upgraded xugrid dependency to version 0.7.1. (PR#109)
- Upgraded hydrolib-core dependency to version 0.6.0. (PR#109)
- Support multiple structures at the same location. (PR#113)

v0.1.2 (20 October 2023)
Expand All @@ -43,16 +43,16 @@ Added

Changed
-------
- Upgraded hydromt dependency to version 0.9.0. (PR#100)
- Upgraded hydromt dependency to version 0.9.0. (PR#100)
- Updated documentation. (PR #97)

v0.1.1 (13 October 2023)
========================
Dependencies upgrade.
Dependencies upgrade.

Changed
-------
- Upgraded meshkernel dependency to version 2.1.0. (PR#94)
- Upgraded meshkernel dependency to version 2.1.0. (PR#94)

v0.1.0 (22 September 2023)
==========================
Expand Down
2 changes: 1 addition & 1 deletion docs/getting_started/faq.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Updating a dflowfm model
| **Q**: Can I select a specific dflowfm MDU config file when updating my model ?

It is possible. In that case, you need to start your HydroMT configuration with a **global** section
where you can specify which MDU file to use using the *config_fn* argument.
where you can specify which MDU file to use using the *config_fn* argument.
Use relative path to the current working directory;.

Others
Expand Down
879 changes: 583 additions & 296 deletions hydromt_delft3dfm/dflowfm.py

Large diffs are not rendered by default.

24 changes: 14 additions & 10 deletions hydromt_delft3dfm/gis_utils.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# -*- coding: utf-8 -*-
"""Utilities GIS functions for Delft3D-FM model."""

import configparser
import logging
import pathlib

import geopandas as gpd
import numpy as np
Expand Down Expand Up @@ -40,7 +38,8 @@ def cut_pieces(line, distances):


def cut(line, distance):
"""Cuts a line in two at a distance from its starting point
"""Cut a line in two at a distance from its starting point.

ref: https://shapely.readthedocs.io/en/stable/manual.html.
"""
if distance <= 0.0 or distance >= line.length:
Expand Down Expand Up @@ -118,11 +117,13 @@ def check_gpd_attributes(
if not (set(required_columns).issubset(gdf.columns)):
if raise_error:
raise ValueError(
f"GeoDataFrame do not contains all required attributes: {required_columns}."
"GeoDataFrame does not contain all required attributes:"
f"{required_columns}."
)
else:
logger.warning(
f"GeoDataFrame do not contains all required attributes: {required_columns}."
"GeoDataFrame does not contain all required attributes:"
f"{required_columns}."
)
return False
return True
Expand All @@ -135,16 +136,18 @@ def update_data_columns_attributes_based_on_filter(
filter_value: str = None,
):
"""
Add or update columns in the geodataframe based on column and values in attributes dataframe.
Add or update columns in gdf based on column and values in df.

If filter_column and filter_value is set, only update the attributes of the filtered geodataframe.
If filter_column and filter_value is set, only update the attributes of the filtered
geodataframe.

Parameters
----------
gdf : gpd.GeoDataFrame
geodataframe containing user input
df : attribute DataFrame
a pd.DataFrame with attribute columns and values (e.g. width = 1) per filter_value in the filter_column (e.g. branch_type = pipe)
a pd.DataFrame with attribute columns and values (e.g. width = 1) per
filter_value in the filter_column (e.g. branch_type = pipe)
filter_column : str
Name of the column linking df to gdf.
filter_value: str
Expand Down Expand Up @@ -191,6 +194,7 @@ def get_gdf_from_branches(
branches: gpd.GeoDataFrame, df: pd.DataFrame
) -> gpd.GeoDataFrame:
"""Get geodataframe from dataframe.

Based on interpolation of branches, using columns ["branchid", "chainage" in df].

Parameters
Expand All @@ -213,7 +217,7 @@ def get_gdf_from_branches(

df["geometry"] = None

# Iterate over each point and interpolate a point along the corresponding line feature
# Iterate over each point and interpolate a point along the corresponding line
for i, row in df.iterrows():
line_geometry = branches.loc[row.branchid, "geometry"]
new_point_geometry = line_geometry.interpolate(row.chainage)
Expand Down
13 changes: 8 additions & 5 deletions hydromt_delft3dfm/graph_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# -*- coding: utf-8 -*-
"""Utilities graph functions for Delft3D-FM model."""

import logging

Expand All @@ -14,7 +14,10 @@


def gpd_to_digraph(data: gpd.GeoDataFrame) -> nx.DiGraph():
"""Convert a `gpd.GeoDataFrame` to a `nx.DiGraph` by taking the first and last coordinate in a row as source and target, respectively.
"""Convert a `gpd.GeoDataFrame` to a `nx.DiGraph`.

This is done by taking the first and last coordinate in a row as source and target,
respectively.

Parameters
----------
Expand Down Expand Up @@ -49,13 +52,13 @@ def get_endnodes_from_lines(
----------
where : {'both', 'upstream', 'downstream'}
Where at the branches should the boundaries be derived.
An upstream end node is defined as a node which has 0 incoming branches and 1 outgoing branch.
A downstream end node is defined as a node which has 1 incoming branch and 0 outgoing branches.
An upstream end node: 0 incoming branches and 1 outgoing branch.
A downstream end node: 1 incoming branch and 0 outgoing branches.

Returns
-------
gpd.GeoDataFrame
A data frame containing all the upstream and downstream end nodes of the branches
A dataframe containing all the upstream and downstream end nodes of the branches
"""
# convert branches to graph
G = gpd_to_digraph(lines)
Expand Down
24 changes: 13 additions & 11 deletions hydromt_delft3dfm/mesh_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# -*- coding: utf-8 -*-
"""Utilities mesh functions for Delft3D-FM model."""

import logging
from typing import Tuple
Expand Down Expand Up @@ -26,7 +26,7 @@ def hydrolib_network_from_mesh(
mesh: xu.UgridDataset,
) -> Network:
"""
Converts from xugrid mesh to hydrolib-core network object.
Convert from xugrid mesh to hydrolib-core network object.

Parameters
----------
Expand Down Expand Up @@ -83,7 +83,7 @@ def mesh1d_network1d_from_hydrolib_network(
crs: CRS,
) -> Tuple[xu.UgridDataset, xu.UgridDataset]:
"""
Creates xugrid mesh1d and network1d UgridDataset from hydrolib-core network object.
Create xugrid mesh1d and network1d UgridDataset from hydrolib-core network object.

Parameters
----------
Expand Down Expand Up @@ -130,10 +130,11 @@ def mesh1d_network1d_from_hydrolib_network(
uds_mesh1d = xu.UgridDataset(ds, grids=grid_mesh1d)

# derive network1d
# The 1D network topology serves as the coordinate space in which a 1D mesh discretization
# will later be defined. The network is largely based on the UGRID conventions for its topology
# (i.e., nodes and edges) and additionally uses an optional edge_geometry to define the
# precise network branch geometries (more about this in the next Section).
# The 1D network topology serves as the coordinate space in which a 1D mesh
# discretization will later be defined. The network is largely based on the
# UGRID conventions for its topology (i.e., nodes and edges) and additionally
# uses an optional edge_geometry to define the precise network branch geometries
# (more about this in the next Section).

grid_network1d = xu.Ugrid1d(
node_x=mesh1d.network1d_node_x,
Expand Down Expand Up @@ -184,7 +185,8 @@ def mesh1d_network1d_from_hydrolib_network(
network_edge_dim,
mesh1d.network1d_branch_order,
)
# might be supported in the future https://github.com/Deltares/HYDROLIB-core/issues/561
# might be supported in the future
# https://github.com/Deltares/HYDROLIB-core/issues/561
# ds["network1d_branch_type"] = (
# edge_dim,
# mesh1d.network1d_branch_type,
Expand Down Expand Up @@ -238,7 +240,7 @@ def mesh2d_from_hydrolib_network(
crs: CRS,
) -> xu.UgridDataset:
"""
Creates xugrid mesh2d UgridDataset from hydrolib-core network object.
Create xugrid mesh2d UgridDataset from hydrolib-core network object.

Parameters
----------
Expand Down Expand Up @@ -276,7 +278,7 @@ def mesh_from_hydrolib_network(
crs: CRS,
) -> xu.UgridDataset:
"""
Creates xugrid mesh from hydrolib-core network object.
Create xugrid mesh from hydrolib-core network object.

Parameters
----------
Expand Down Expand Up @@ -339,7 +341,7 @@ def mesh1d_nodes_geodataframe(
branches: gpd.GeoDataFrame,
) -> gpd.GeoDataFrame:
"""
Returns the nodes of mesh 1D as geodataframe.
Return the nodes of mesh 1D as geodataframe.

Parameters
----------
Expand Down
Loading
Loading