Skip to content

Commit

Permalink
resolved errors
Browse files Browse the repository at this point in the history
  • Loading branch information
veenstrajelmer committed Oct 17, 2024
1 parent a8534ab commit 9de61d7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 22 deletions.
26 changes: 15 additions & 11 deletions hydromt_delft3dfm/dflowfm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1673,6 +1673,7 @@ def _snap_geom_to_branches_and_drop_nonsnapped(
self, branches: gpd.GeoDataFrame, geoms: gpd.GeoDataFrame, snap_offset=0.0
):
"""Snaps geoms to branches and drop the ones that are not snapped.
Returns snapped geoms with branchid and chainage.
branches must have branchid.
"""
Expand Down Expand Up @@ -2615,19 +2616,21 @@ def setup_2dboundary_from_lines(
boundary_type: str = "waterlevel",
tolerance: float = 3.0,
):
"""
Prepares the 2D boundaries from geodataset of line geometries.
E.g. `boundary_value` m3/s `boundary_type` boundary for all lines in `boundaries_geodataset_fn`.
"""Prepare the 2D boundaries from geodataset of line geometries.
E.g. `boundary_value` m3/s `boundary_type` boundary for all lines in
`boundaries_geodataset_fn`.
Use ``boundaries_geodataset_fn`` to set the boundary timeseries from a geodataset
of line geometries.
Support also geodataframe of line geometries in combination of ``boundary_value`` and ``boundary_type``.
Use ``boundaries_geodataset_fn`` to set the boundary timeseries from a
geodataset of line geometries.
Support also geodataframe of line geometries in combination of
``boundary_value`` and ``boundary_type``.
Only lines that are within a max distance defined in ``tolerance`` are used.
The timeseries are clipped to the model time based on the model config
tstart and tstop entries.
If the timeseries has missing values, the constant ``boundary_value`` will be used.
tstart and tstop entries. If the timeseries has missing values, the constant
``boundary_value`` will be used.
Adds/Updates model layers:
* **boundary2d_{boundary_name}** forcing: 2D boundaries DataArray
Expand All @@ -2637,7 +2640,8 @@ def setup_2dboundary_from_lines(
boundaries_geodataset_fn : str, Path
Path or data source name for geospatial point location file.
* Required variables if geodataset is provided [``boundary_type``]
NOTE: Use universal datetime format e.g. yyyy-mm-dd to avoid ambiguity when using a csv timeseries.
NOTE: Use universal datetime format e.g. yyyy-mm-dd to avoid ambiguity when
using a csv timeseries.
boundary_value : float, optional
Constant value to use for all boundaries, and to
fill in missing data. By default 0.0 m.
Expand Down Expand Up @@ -3474,7 +3478,7 @@ def read_mesh(self):
self.set_branches(branches)

def write_mesh(self, write_gui=True):
"""Write 1D branches and 2D mesh at <root/dflowfm/fm_net.nc> in model ready format."""
"""Write 1D branches and 2D mesh at <root/dflowfm/fm_net.nc>."""
self._assert_write_mode()
savedir = dirname(join(self.root, self._config_fn))
mesh_filename = "fm_net.nc"
Expand Down Expand Up @@ -3825,7 +3829,7 @@ def set_mesh(

def set_link1d2d(
self,
link1d2d: xr.Dataset(),
link1d2d: xr.Dataset,
):
"""
Add or replace the link1d2d in the model mesh.
Expand Down
19 changes: 8 additions & 11 deletions hydromt_delft3dfm/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,7 @@ def write_branches_gui(
return branchgui_fn


def read_crosssections(
gdf: gpd.GeoDataFrame, fm_model: FMModel
) -> tuple((gpd.GeoDataFrame, gpd.GeoDataFrame)):
def read_crosssections(gdf: gpd.GeoDataFrame, fm_model: FMModel) -> gpd.GeoDataFrame:
"""
Read crosssections from hydrolib-core crsloc and crsdef objects and add to branches.
Expand Down Expand Up @@ -1034,7 +1032,7 @@ def write_1dlateral(


def _forcingmodel_to_dataarray(forcing: ForcingModel):
"""read forcingfile timeseries into dataarray"""
"""Read forcingfile timeseries into dataarray."""
df_forcing = pd.DataFrame([f.__dict__ for f in forcing.forcing])

# Get data
Expand Down Expand Up @@ -1078,7 +1076,8 @@ def _forcingmodel_to_dataarray(forcing: ForcingModel):
# Else not implemented yet
else:
raise NotImplementedError(
"ForcingFile with several function for a single variable not implemented yet. Skipping reading forcing."
"ForcingFile with several function for a single variable "
"not implemented yet. Skipping reading forcing."
)

# Prep DataArray and add to forcing
Expand Down Expand Up @@ -1116,8 +1115,8 @@ def read_2dboundary(df: pd.DataFrame, workdir: Path = Path.cwd()) -> xr.DataArra
# location file
# assume one location file has only one location (hydromt writer) and read
locationfile = PolyFile(workdir.joinpath(df.locationfile.filepath))
boundary_name = locationfile.objects[0].metadata.name
boundary_points = pd.DataFrame([f.__dict__ for f in locationfile.objects[0].points])
locationfile.objects[0].metadata.name
pd.DataFrame([f.__dict__ for f in locationfile.objects[0].points])

# Assume one forcing file (hydromt writer) and read
forcing = df.forcingfile
Expand Down Expand Up @@ -1263,8 +1262,7 @@ def _write_ncdicts(ncdicts: Dict[str, xr.DataArray], savedir: str):


def _create_pliobj_from_xy(xs: list, ys: list, name: str):
"""Creates hydrolib-core pli objecti from list of x and y coordinates"""

"""Create hydrolib-core pli objecti from list of x and y coordinates."""
xs = [x for x in xs if not np.isnan(x)]
ys = [y for y in ys if not np.isnan(y)]
_points = [{"x": x, "y": y, "data": []} for x, y in zip(xs, ys)]
Expand Down Expand Up @@ -1293,7 +1291,6 @@ def write_2dboundary(forcing: Dict, savedir: str, ext_fn: str = None) -> list[di
Path of the external forcing file (.ext) in which this function will append to.
"""

_bcfilename = "boundary2d.bc"

# filter for 2d boundary
Expand Down Expand Up @@ -1337,7 +1334,7 @@ def write_2dboundary(forcing: Dict, savedir: str, ext_fn: str = None) -> list[di
# check if only one support point
if da_i_tsvalid.sizes["numcoordinates"] > 1:
raise NotImplementedError(
f"Timeseries at multiple support points are not yet implemented."
"Timeseries at multiple support points are not yet implemented."
)
else:
# flaten data for bc file
Expand Down

0 comments on commit 9de61d7

Please sign in to comment.