Skip to content

Commit

Permalink
error handling for incremental sinuosity
Browse files Browse the repository at this point in the history
  • Loading branch information
cyschneck committed Jun 10, 2024
1 parent 38e14df commit e5bf8d3
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 4 deletions.
1 change: 1 addition & 0 deletions centerline_width/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,4 @@
from .error_handling import errorHandlingSaveCenterlineMAT
from .error_handling import errorHandlingExtractPointsToTextFile
from .error_handling import errorHandlingRiverCenterlineClass
from .error_handling import errorHandlingCalculateIncrementalSinuosity
42 changes: 42 additions & 0 deletions centerline_width/error_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,3 +578,45 @@ def errorHandlingRiverCenterlineClass(csv_data: str = None,
raise ValueError(
f"[ellipsoid]: Must be an available option in {ellipsoid_options}, current option = '{ellipsoid}'"
)


## Error Handling: riverFeatures.py
def errorHandlingCalculateIncrementalSinuosity(
river_object: centerline_width.riverCenterline = None,
incremental_points: int = 10,
save_to_csv: str = None) -> None:
# Error Handling for calculateIncrementalSinuosity()
if river_object is None:
raise ValueError(
"[river_object]: Requires a river object (see: centerline_width.riverCenterline)"
)
else:
if not isinstance(river_object, centerline_width.riverCenterline):
raise ValueError(
f"[river_object]: Must be a river object (see: centerline_width.riverCenterline), current type = '{type(river_object)}'"
)

if type(incremental_points) != int:
raise ValueError(
f"[incremental_points]: Must be a int, current type = '{type(incremental_points)}'"
)
if incremental_points <= 0:
raise ValueError(
f"[incremental_points]: Must be a positive value, greater than 0, currently = '{incremental_points}'"
)

if river_object.interpolate_n_centerpoints < incremental_points:
raise ValueError(
f"[incremental_points]: length of centerline points must be greater than incremental_points, currently `{river_object.interpolate_n_centerpoints} < {incremental_points}'"
)

if save_to_csv is not None:
if type(save_to_csv) != str:
raise ValueError(
f"[save_to_csv]: Must be a str, current type = '{type(save_to_csv)}'"
)
else:
if not save_to_csv.lower().endswith(".csv"):
raise ValueError(
f"[save_to_csv]: Extension must be a .csv file, current extension = '{save_to_csv.split('.')[1]}'"
)
9 changes: 5 additions & 4 deletions centerline_width/riverFeatures.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,12 @@ def calculateIncrementalSinuosity(
incremental_points: int = 10,
save_to_csv: str = None) -> dict:
# Return the sinuosity of the river in increments
# (Centerline Coordinate Start, Centerline Coordinate End Longtiude, Sinuosity)

if river_object.interpolate_n_centerpoints < incremental_points:
print(
"\tERROR: (TODO) interpolate_n_centerpoints < incremental_points")
centerline_width.errorHandlingCalculateIncrementalSinuosity(
river_object=river_object,
incremental_points=incremental_points,
save_to_csv=save_to_csv)

if river_object.centerlineEvenlySpaced is None:
return {}
Expand All @@ -79,7 +81,6 @@ def calculateIncrementalSinuosity(
ellipsoid=river_object.ellipsoid)

# Save width dictionary to a csv file
# (Centerline Coordinate Start, Centerline Coordinate End Longtiude, Sinuosity)
if save_to_csv:
with open(save_to_csv, "w") as csv_file_output:
writer = csv.writer(csv_file_output)
Expand Down

0 comments on commit e5bf8d3

Please sign in to comment.