Skip to content

Commit

Permalink
fixed performance and deprecation warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Tjalling-dejong committed Nov 13, 2024
1 parent 3cc1c86 commit d40b914
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
17 changes: 8 additions & 9 deletions fm2prof/CrossSection.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import numpy as np
import pandas as pd
import scipy.optimize as so
from scipy.integrate import cumtrapz
from scipy.integrate import cumulative_trapezoid
from tqdm import tqdm

from fm2prof import Functions as FE
Expand Down Expand Up @@ -287,13 +287,12 @@ def get_timeseries(name: str):

# Convert area to a matrix for matrix operations
# (much more efficient than for-loops)
area_matrix = pd.DataFrame(index=area.index)
for t in waterdepth:
area_matrix[t] = area
area_matrix = pd.DataFrame({col: area for col in waterdepth.columns})
area_matrix.index = area.index

bedlevel_matrix = pd.DataFrame({col: area for col in waterdepth.columns})
bedlevel_matrix.index = bedlevel.index

bedlevel_matrix = pd.DataFrame(index=bedlevel.index)
for t in waterdepth:
bedlevel_matrix[t] = bedlevel

# Retrieve the water-depth
# & water level nearest to the cross-section location
Expand Down Expand Up @@ -374,10 +373,10 @@ def get_timeseries(name: str):

# Compute 1D volume as integral of width with respect to z times length
self._css_total_volume = np.append(
[0], cumtrapz(self._css_total_width, self._css_z) * self.length
[0], cumulative_trapezoid(self._css_total_width, self._css_z) * self.length
)
self._css_flow_volume = np.append(
[0], cumtrapz(self._css_flow_width, self._css_z) * self.length
[0], cumulative_trapezoid(self._css_flow_width, self._css_z) * self.length
)

# If sd correction is run, these attributes will be updated.
Expand Down
12 changes: 8 additions & 4 deletions fm2prof/Fm2ProfRunner.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import tqdm
from geojson import Feature, FeatureCollection, Polygon
from netCDF4 import Dataset
import pandas as pd
from scipy.spatial import ConvexHull

from fm2prof import Functions as FE
Expand Down Expand Up @@ -95,7 +96,7 @@ def run(self, overwrite: bool = False) -> None:
return

# Check for already existing output
if self._output_exists() & ~overwrite:
if self._output_exists() and not overwrite:
self.set_logger_message(
"Output already exists. Use overwrite option if you want to re-run the program",
"warning",
Expand Down Expand Up @@ -567,10 +568,13 @@ def _classify_roughness_sections_by_variance(self, data, variable):
splitpoint = split_candidates[np.nanargmin(variance_list)]

# High chezy values are assigned to section number '1' (Main channel)
data[key][end_values > splitpoint] = 1

# Low chezy values are assigned to section number '2' (Flood plain)
data[key][end_values <= splitpoint] = 2
if isinstance(data, pd.DataFrame):
data.loc[end_values > splitpoint, key] = 1
data.loc[end_values <= splitpoint, key] = 2
else:
data[key][end_values > splitpoint] = 1
data[key][end_values <= splitpoint] = 2
return data

def _get_region_map_file(self, polytype):
Expand Down
2 changes: 1 addition & 1 deletion fm2prof/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ def figure_cross_section(
os.mkdir(output_dir)

output_file = output_dir.joinpath(f"{css['id']}.png")
if output_file.is_file() & ~overwrite:
if output_file.is_file() and not overwrite:
self.set_logger_message("file already exists", "debug")
return
try:
Expand Down

0 comments on commit d40b914

Please sign in to comment.