Skip to content
Open
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
8 changes: 4 additions & 4 deletions docs/notebooks/cross_section_data.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@
"import matplotlib.pyplot as plt\n",
"\n",
"variable = 'bedlevel' # other variables to plot: bedlevel, section, region, area\n",
"x = data.get('fm_data').get('x')\n",
"y = data.get('fm_data').get('y')\n",
"z = data.get('fm_data').get(variable)\n",
"x = data.get('model_data').get('x')\n",
"y = data.get('model_data').get('y')\n",
"z = data.get('model_data').get(variable)\n",
"\n",
"fig, ax = plt.subplots(1)\n",
"sc = ax.scatter(x/1000, y/1000, c=z)\n",
Expand Down Expand Up @@ -162,7 +162,7 @@
"\n",
"variable = 'velocity' # try also: waterlevel, waterdepth\n",
"\n",
"z = data.get('fm_data').get(variable)\n",
"z = data.get('model_data').get(variable)\n",
"fig, ax = plt.subplots(1)\n",
"\n",
"sc = ax.scatter(x/1000, y/1000, c=z.iloc[6])\n",
Expand Down
70 changes: 35 additions & 35 deletions fm2prof/cross_section.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,9 @@ def __init__(
logger: Logger | None = None,
inifile: IniFile | None = None,
) -> None:
"""Derive cross-sections from fm_data (2D model results).
"""Derive cross-sections from model_data (2D model results).

See docs how to acquire fm_data and how to prepare a proper 2D model.
See docs how to acquire model_data and how to prepare a proper 2D model.


Args:
Expand All @@ -147,7 +147,7 @@ def __init__(

if not all(
key in data
for key in ["id", "length", "xy", "branchid", "chainage", "fm_data"]
for key in ["id", "length", "xy", "branchid", "chainage", "model_data"]
):
err_msg = "Input data does not have all required keys"
raise KeyError(err_msg)
Expand All @@ -158,7 +158,7 @@ def __init__(
self.location = data.get("xy") # (x,y)
self.branch = data.get("branchid") # name of 1D branch for cross-section
self.chainage = data.get("chainage") # offset from beginning of branch
self._fm_data: dict = data.get("fm_data") # dictionary with fmdata
self._model_data: dict = data.get("model_data") # dictionary with fmdata

# Cross-section geometry
self.z = []
Expand Down Expand Up @@ -243,12 +243,12 @@ def build_geometry(self) -> None: # noqa: PLR0915
_css_flow_width

"""
fm_data: dict = self._fm_data
model_data: dict = self._model_data

# Unpack FM data
def get_timeseries(name: str) -> np.array:
"""Return data from fm_data after applying the skip_maps and checking for missing numbers."""
data = fm_data[name].iloc[
"""Return data from model_data after applying the skip_maps and checking for missing numbers."""
data = model_data[name].iloc[
:,
self.get_parameter(self.__cs_parameter_skip_maps) :,
]
Expand All @@ -262,8 +262,8 @@ def get_timeseries(name: str) -> np.array:
waterdepth = get_timeseries("waterdepth")
velocity = get_timeseries("velocity")

area = fm_data["area"]
bedlevel = fm_data["bedlevel"]
area = model_data["area"]
bedlevel = model_data["bedlevel"]

# Convert area to a matrix for matrix operations
# (much more efficient than for-loops)
Expand All @@ -278,8 +278,8 @@ def get_timeseries(name: str) -> np.array:
self.set_logger_message("Retrieving centre point values")
(centre_depth, centre_level) = nearest_neighbour.get_centre_values(
self.location,
fm_data["x"],
fm_data["y"],
model_data["x"],
model_data["y"],
waterdepth,
waterlevel,
)
Expand Down Expand Up @@ -548,7 +548,7 @@ def assign_roughness(self) -> None:

def get_number_of_faces(self) -> int:
"""Return the number of 2D faces within control volume."""
return len(self._fm_data.get("x"))
return len(self._model_data.get("x"))

def get_number_of_vertices(self) -> int:
"""Return the current number of geometry vertices."""
Expand Down Expand Up @@ -618,7 +618,7 @@ def reduce_points(self, count_after: int = 20) -> None:

def set_face_output_list(self) -> None:
"""Generate a list of output mask points based on their values in the mask."""
fm_data = self._fm_data
model_data = self._model_data

# Properties keys
cross_section_id_key = "cross_section_id"
Expand All @@ -629,12 +629,12 @@ def set_face_output_list(self) -> None:

try:
# Normalize np arrays to list for correct access
x_coords = fm_data.get("x").tolist()
y_coords = fm_data.get("y").tolist()
region_list = fm_data.get("region").tolist()
section_list = fm_data.get("section").tolist()
bedlevel_list = fm_data.get("bedlevel").tolist()
is_lake_mask_list = fm_data.get("islake").tolist()
x_coords = model_data.get("x").tolist()
y_coords = model_data.get("y").tolist()
region_list = model_data.get("region").tolist()
section_list = model_data.get("section").tolist()
bedlevel_list = model_data.get("bedlevel").tolist()
is_lake_mask_list = model_data.get("islake").tolist()

# Assume same length for x and y coords.
for i in range(len(x_coords)):
Expand Down Expand Up @@ -672,17 +672,17 @@ def set_edge_output_list(self) -> None:

writes to self.__output_mask_list
"""
fm_data = self._fm_data
model_data = self._model_data

# Properties keys
cross_section_id_key = "cross_section_id"
roughness_section_key = "section"

try:
# Normalize np arrays to list for correct access
x_coords = fm_data.get("edge_x").tolist()
y_coords = fm_data.get("edge_y").tolist()
section_list = fm_data.get("edge_section").tolist()
x_coords = model_data.get("edge_x").tolist()
y_coords = model_data.get("edge_y").tolist()
section_list = model_data.get("edge_section").tolist()
# Assume same length for x and y coords.
for i in range(len(x_coords)):
mask_properties = {
Expand Down Expand Up @@ -886,15 +886,15 @@ def _check_increasing_order(self, list_points: list) -> list:

def _build_roughness_tables(self) -> None:
# Find roughness tables for each section
chezy_fm = self._fm_data.get("chezy").iloc[
chezy_fm = self._model_data.get("chezy").iloc[
:,
self.get_parameter(self.__cs_parameter_skip_maps) :,
]

sections = np.unique(self._fm_data.get("edge_section"))
sections = np.unique(self._model_data.get("edge_section"))

for section in sections:
chezy_section = chezy_fm[self._fm_data["edge_section"] == section]
chezy_section = chezy_fm[self._model_data["edge_section"] == section]
if self.get_parameter(self.__cs_parameter_Frictionweighing) == 0:
friction = self._friction_weighing_simple(chezy_section)
elif self.get_parameter(self.__cs_parameter_Frictionweighing) == 1:
Expand Down Expand Up @@ -934,9 +934,9 @@ def _friction_weighing_area(
# Remove chezy where zero
link_chezy = link_chezy.replace(0, np.nan)
# efs are the two faces the edge connects to
efs = self._fm_data["edge_faces"][self._fm_data["edge_section"] == section]
efs = self._model_data["edge_faces"][self._model_data["edge_section"] == section]
# compute the mean area for the two connecting faces
link_area = [self._fm_data.get("area_full").reindex(ef).mean() for ef in efs]
link_area = [self._model_data.get("area_full").reindex(ef).mean() for ef in efs]
# the weight of one link is defined as the sum of the linked areas
link_weight = link_area / np.sum(link_area)

Expand All @@ -954,7 +954,7 @@ def _compute_section_widths(self) -> None:
maximum width of the geometry, or a very small width that may lead
to numerical instability.
"""
unassigned_area = sum(self._fm_data["area"][self._fm_data["section"] == NODATA])
unassigned_area = sum(self._model_data["area"][self._model_data["section"] == NODATA])
if unassigned_area > 0:
self.set_logger_message(
f"{unassigned_area} m2 was not assigned to any section in input files, and"
Expand All @@ -965,12 +965,12 @@ def _compute_section_widths(self) -> None:
for section in ["main", "floodplain1", "floodplain2"]:
if section == "main":
section_area = (
np.sum(self._fm_data["area"][self._fm_data["section"] == section])
np.sum(self._model_data["area"][self._model_data["section"] == section])
+ unassigned_area
) / self.length
else:
section_area = (
np.sum(self._fm_data["area"][self._fm_data["section"] == section])
np.sum(self._model_data["area"][self._model_data["section"] == section])
/ self.length
)
self.section_widths[section] = section_area
Expand All @@ -983,10 +983,10 @@ def _compute_floodplain_base(self) -> None:
"""
tolerance = self.get_inifile().get_parameter("sdfloodplainbase")
# Mean bed level in section 2 (floodplain)
floodplain_mask = self._fm_data.get("section") == "floodplain1"
floodplain_mask = self._model_data.get("section") == "floodplain1"
if floodplain_mask.sum():
mean_floodplain_elevation = np.nanmean(
self._fm_data["bedlevel"][floodplain_mask],
self._model_data["bedlevel"][floodplain_mask],
)

# Tolerance. Base level must at least be some below the crest to prevent
Expand Down Expand Up @@ -1288,8 +1288,8 @@ def _extend_css_below_z0(
_fm_total_volume

"""
bedlevel = self._fm_data.get("bedlevel").to_numpy()
cell_area = self._fm_data.get("area").to_numpy()
bedlevel = self._model_data.get("bedlevel").to_numpy()
cell_area = self._model_data.get("area").to_numpy()
flow_area_at_z0 = self._fm_flow_area[0]
lowest_level_of_css = (
centre_level[0] - centre_depth[0]
Expand Down
Loading
Loading