diff --git a/centerline_width/__init__.py b/centerline_width/__init__.py index 0dc42be..fb3fc16 100644 --- a/centerline_width/__init__.py +++ b/centerline_width/__init__.py @@ -57,3 +57,4 @@ from .error_handling import errorHandlingSaveCenterlineMAT from .error_handling import errorHandlingExtractPointsToTextFile from .error_handling import errorHandlingRiverCenterlineClass +from .error_handling import errorHandlingCalculateIncrementalSinuosity diff --git a/centerline_width/error_handling.py b/centerline_width/error_handling.py index 32c763a..2fbd9fb 100644 --- a/centerline_width/error_handling.py +++ b/centerline_width/error_handling.py @@ -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]}'" + ) diff --git a/centerline_width/riverFeatures.py b/centerline_width/riverFeatures.py index 27d78f7..d558d23 100644 --- a/centerline_width/riverFeatures.py +++ b/centerline_width/riverFeatures.py @@ -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 {} @@ -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)