diff --git a/README.md b/README.md index 8465277..ebe568f 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ Find the centerline and width of rivers based on the latitude and longitude posi * incremental_sinuosity() * **Export centerline to .CSV and .MAT files** * save_centerline_csv() - * saveCenterlineMAT() + * save_centerline_mat() | River Outlined in Google Earth Pro | Generated Centerline for the Riverbank | | ------------- | ------------- | @@ -361,7 +361,7 @@ Returns a csv with the Latitude and Longitude coordinates of the specified cente Save the centerline coordinates to a .mat file with columns for latitude and longitude ``` -saveCenterlineMAT(save_to_mat=None, centerline_type="Voronoi", coordinate_unit="Decimal Degrees") +save_centerline_mat(save_to_mat=None, centerline_type="Voronoi", coordinate_unit="Decimal Degrees") ``` * **[REQUIRED]** save_to_mat (string): MAT filename, requires a .mat extension * [OPTIONAL] centerline_type (string): Centerline type to save to MAT (not case-sensitive), options: ["Voronoi", "Evenly Spaced", "Smoothed", "Equal Distance"], defaults to "Voronoi" @@ -372,7 +372,7 @@ saveCenterlineMAT(save_to_mat=None, centerline_type="Voronoi", coordinate_unit=" ```python import centerline_width river_object = centerline_width.riverCenterline(csv_data="data/river_coords.csv") -river_object.saveCenterlineMAT(save_to_mat="centerline_coordinates.mat", centerline_type="Smoothed") +river_object.save_centerline_mat(save_to_mat="centerline_coordinates.mat", centerline_type="Smoothed") ``` Returns a .mat file with the Latitude and Longitude coordinates of the specified centerline with column headers with centerline type: `Smoothed_Centerline_Latitude_(Deg), Smoothed_Centerline_Longitude_(Deg)` diff --git a/centerline_width/__init__.py b/centerline_width/__init__.py index 8c4d8e2..7277255 100644 --- a/centerline_width/__init__.py +++ b/centerline_width/__init__.py @@ -41,7 +41,7 @@ # saveOutput.py function calls from .saveOutput import save_centerline_csv -from .saveOutput import saveCenterlineMAT +from .saveOutput import save_centerline_mat # plotDiagrams.py function calls from .plotDiagrams import plot_centerline diff --git a/centerline_width/error_handling.py b/centerline_width/error_handling.py index a8fe60b..676db20 100644 --- a/centerline_width/error_handling.py +++ b/centerline_width/error_handling.py @@ -379,7 +379,7 @@ def errorHandlingSaveCenterlineMAT( save_to_mat: str = None, centerline_type: str = None, coordinate_unit: str = None) -> None: - # Error Handling for saveCenterlineMAT() + # Error Handling for save_centerline_mat() if river_object is None: raise ValueError( "[river_object]: Requires a river object (see: centerline_width.riverCenterline)" diff --git a/centerline_width/pytests/test_errorSaveOutput.py b/centerline_width/pytests/test_errorSaveOutput.py index 7290853..4a5e77e 100644 --- a/centerline_width/pytests/test_errorSaveOutput.py +++ b/centerline_width/pytests/test_errorSaveOutput.py @@ -158,22 +158,22 @@ def test_saveCenterlineCSV_coordinateTypeInvalidTypes(invalid_input, coordinate_unit=invalid_input) -## saveCenterlineMAT() ##################################################### +## save_centerline_mat() ##################################################### def test_saveCenterlineMAT_riverObjectRequired(): with pytest.raises( ValueError, match=re.escape( "[river_object]: Requires a river object (see: centerline_width.riverCenterline)" )): - centerline_width.saveCenterlineMAT(river_object=None) + centerline_width.save_centerline_mat(river_object=None) def test_saveCenterlineMAT_matInvalidExtension(): with pytest.raises( ValueError, match=re.escape("[save_to_mat]: Requires mat filename")): - centerline_width.saveCenterlineMAT(river_object=river_class_example, - save_to_mat=None) + centerline_width.save_centerline_mat(river_object=river_class_example, + save_to_mat=None) @pytest.mark.parametrize("invalid_input, error_output", @@ -184,8 +184,8 @@ def test_saveCenterlineMAT_matInvalidType(invalid_input, error_output): match=re.escape( f"[save_to_mat]: Must be a str, current type = '{error_output}'" )): - centerline_width.saveCenterlineMAT(river_object=river_class_example, - save_to_mat=invalid_input) + centerline_width.save_centerline_mat(river_object=river_class_example, + save_to_mat=invalid_input) def test_saveCenterlineMAT_matRequired(): @@ -194,8 +194,8 @@ def test_saveCenterlineMAT_matRequired(): match=re.escape( "[save_to_mat]: Extension must be a .mat file, current extension = 'txt'" )): - centerline_width.saveCenterlineMAT(river_object=river_class_example, - save_to_mat="filename.txt") + centerline_width.save_centerline_mat(river_object=river_class_example, + save_to_mat="filename.txt") @pytest.mark.parametrize("invalid_input, error_output", @@ -207,9 +207,9 @@ def test_saveCenterlineMAT_latitudeHeaderTypeInvalidTypes( match=re.escape( f"[latitude_header]: Must be a str, current type = '{error_output}'" )): - centerline_width.saveCenterlineMAT(river_object=river_class_example, - save_to_mat="testing.mat", - latitude_header=invalid_input) + centerline_width.save_centerline_mat(river_object=river_class_example, + save_to_mat="testing.mat", + latitude_header=invalid_input) def test_saveCenterlineMAT_latitudeHeaderTypeInvalidAlphanumeric(): @@ -218,7 +218,7 @@ def test_saveCenterlineMAT_latitudeHeaderTypeInvalidAlphanumeric(): match=re.escape( "[latitude_header]: Column names cannot contain any whitespace or non-alphanumeric characters, currently = 'invalid whitespace'" )): - centerline_width.saveCenterlineMAT( + centerline_width.save_centerline_mat( river_object=river_class_example, save_to_mat="testing.mat", latitude_header="invalid whitespace") @@ -233,9 +233,9 @@ def test_saveCenterlineMAT_longitudeHeaderTypeInvalidTypes( match=re.escape( f"[longitude_header]: Must be a str, current type = '{error_output}'" )): - centerline_width.saveCenterlineMAT(river_object=river_class_example, - save_to_mat="testing.mat", - longitude_header=invalid_input) + centerline_width.save_centerline_mat(river_object=river_class_example, + save_to_mat="testing.mat", + longitude_header=invalid_input) def test_saveCenterlineMAT_longitudeHeaderTypeInvalidAlphanumeric(): @@ -244,7 +244,7 @@ def test_saveCenterlineMAT_longitudeHeaderTypeInvalidAlphanumeric(): match=re.escape( "[longitude_header]: Column names cannot contain any whitespace or non-alphanumeric characters, currently = 'invalid whitespace'" )): - centerline_width.saveCenterlineMAT( + centerline_width.save_centerline_mat( river_object=river_class_example, save_to_mat="testing.mat", longitude_header="invalid whitespace") @@ -259,9 +259,9 @@ def test_saveCenterlineMAT_centerlineTypeInvalidTypes(invalid_input, match=re.escape( f"[centerline_type]: Must be a str, current type = '{error_output}'" )): - centerline_width.saveCenterlineMAT(river_object=river_class_example, - save_to_mat="testing.mat", - centerline_type=invalid_input) + centerline_width.save_centerline_mat(river_object=river_class_example, + save_to_mat="testing.mat", + centerline_type=invalid_input) def test_saveCenterlineMAT_centerlineTypeInvalidOptions(): @@ -270,9 +270,9 @@ def test_saveCenterlineMAT_centerlineTypeInvalidOptions(): match=re.escape( "[centerline_type]: Must be an available option in ['Voronoi', 'Evenly Spaced', 'Smoothed', 'Equal Distance'], current option = 'not valid'" )): - centerline_width.saveCenterlineMAT(river_object=river_class_example, - save_to_mat="testing.mat", - centerline_type="not valid") + centerline_width.save_centerline_mat(river_object=river_class_example, + save_to_mat="testing.mat", + centerline_type="not valid") def test_saveCenterlineMAT_coordinateUnitInvalidOption(): @@ -281,9 +281,9 @@ def test_saveCenterlineMAT_coordinateUnitInvalidOption(): match=re.escape( "[coordinate_unit]: Must be an available option in ['Decimal Degrees', 'Relative Distance'], current option = 'Invalid Option'" )): - centerline_width.saveCenterlineMAT(river_object=river_class_example, - save_to_mat="testing.mat", - coordinate_unit="Invalid Option") + centerline_width.save_centerline_mat(river_object=river_class_example, + save_to_mat="testing.mat", + coordinate_unit="Invalid Option") @pytest.mark.parametrize("invalid_input, error_output", @@ -295,6 +295,6 @@ def test_saveCenterlineMAT_coordinateUnitInvalidTypes(invalid_input, match=re.escape( f"[coordinate_unit]: Must be a str, current type = '{error_output}'" )): - centerline_width.saveCenterlineMAT(river_object=river_class_example, - save_to_mat="testing.mat", - coordinate_unit=invalid_input) + centerline_width.save_centerline_mat(river_object=river_class_example, + save_to_mat="testing.mat", + coordinate_unit=invalid_input) diff --git a/centerline_width/pytests/test_verifySaveOutput.py b/centerline_width/pytests/test_verifySaveOutput.py index 753b077..a91c7f1 100644 --- a/centerline_width/pytests/test_verifySaveOutput.py +++ b/centerline_width/pytests/test_verifySaveOutput.py @@ -482,9 +482,9 @@ def test_saveOutput_centerlineRelativeDistanceSmoothedCSV( @pytest.fixture(scope="session") def generate_mat_centerlineDecimalDegreesVoronoi(tmpdir_factory): temp_path = tmpdir_factory.mktemp("temp_data").join("pytest.mat") - river_class_example.saveCenterlineMAT(save_to_mat=str(temp_path), - centerline_type="Voronoi", - coordinate_unit="Decimal Degrees") + river_class_example.save_centerline_mat(save_to_mat=str(temp_path), + centerline_type="Voronoi", + coordinate_unit="Decimal Degrees") return temp_path @@ -525,9 +525,9 @@ def test_saveOutput_centerlineDecimalDegreesVoronoiMAT( @pytest.fixture(scope="session") def generate_mat_centerlineDecimalDegreesEqualDistance(tmpdir_factory): temp_path = tmpdir_factory.mktemp("temp_data").join("pytest.mat") - river_class_example.saveCenterlineMAT(save_to_mat=str(temp_path), - centerline_type="Equal Distance", - coordinate_unit="Decimal Degrees") + river_class_example.save_centerline_mat(save_to_mat=str(temp_path), + centerline_type="Equal Distance", + coordinate_unit="Decimal Degrees") return temp_path @@ -562,9 +562,9 @@ def test_saveOutput_centerlineDecimalDegreesEqualDistanceMAT( @pytest.fixture(scope="session") def generate_mat_centerlineDecimalDegreesEvenlySpaced(tmpdir_factory): temp_path = tmpdir_factory.mktemp("temp_data").join("pytest.mat") - river_class_example.saveCenterlineMAT(save_to_mat=str(temp_path), - centerline_type="Evenly Spaced", - coordinate_unit="Decimal Degrees") + river_class_example.save_centerline_mat(save_to_mat=str(temp_path), + centerline_type="Evenly Spaced", + coordinate_unit="Decimal Degrees") return temp_path @@ -613,9 +613,9 @@ def test_saveOutput_centerlineDecimalDegreesEvenlySpacedMAT( @pytest.fixture(scope="session") def generate_mat_centerlineDecimalDegreesSmoothed(tmpdir_factory): temp_path = tmpdir_factory.mktemp("temp_data").join("pytest.mat") - river_class_example.saveCenterlineMAT(save_to_mat=str(temp_path), - centerline_type="Smoothed", - coordinate_unit="Decimal Degrees") + river_class_example.save_centerline_mat(save_to_mat=str(temp_path), + centerline_type="Smoothed", + coordinate_unit="Decimal Degrees") return temp_path @@ -662,9 +662,10 @@ def test_saveOutput_centerlineDecimalDegreesSmoothedMAT( @pytest.fixture(scope="session") def generate_mat_centerlineRelativeDistanceVoronoi(tmpdir_factory): temp_path = tmpdir_factory.mktemp("temp_data").join("pytest.mat") - river_class_example.saveCenterlineMAT(save_to_mat=str(temp_path), - centerline_type="Voronoi", - coordinate_unit="Relative Distance") + river_class_example.save_centerline_mat( + save_to_mat=str(temp_path), + centerline_type="Voronoi", + coordinate_unit="Relative Distance") return temp_path @@ -709,9 +710,10 @@ def test_saveOutput_centerlineRelativeDistanceVoronoiMAT( @pytest.fixture(scope="session") def generate_mat_centerlineRelativeDistanceEqualDistance(tmpdir_factory): temp_path = tmpdir_factory.mktemp("temp_data").join("pytest.mat") - river_class_example.saveCenterlineMAT(save_to_mat=str(temp_path), - centerline_type="Equal Distance", - coordinate_unit="Relative Distance") + river_class_example.save_centerline_mat( + save_to_mat=str(temp_path), + centerline_type="Equal Distance", + coordinate_unit="Relative Distance") return temp_path @@ -748,9 +750,10 @@ def test_saveOutput_centerlineRelativeDistanceEqualDistanceMAT( @pytest.fixture(scope="session") def generate_mat_centerlineRelativeDistanceEvenlySpaced(tmpdir_factory): temp_path = tmpdir_factory.mktemp("temp_data").join("pytest.mat") - river_class_example.saveCenterlineMAT(save_to_mat=str(temp_path), - centerline_type="Evenly Spaced", - coordinate_unit="Relative Distance") + river_class_example.save_centerline_mat( + save_to_mat=str(temp_path), + centerline_type="Evenly Spaced", + coordinate_unit="Relative Distance") return temp_path @@ -801,9 +804,10 @@ def test_saveOutput_centerlineRelativeDistanceEvenlySpacedMAT( @pytest.fixture(scope="session") def generate_mat_centerlineRelativeDistanceSmoothed(tmpdir_factory): temp_path = tmpdir_factory.mktemp("temp_data").join("pytest.mat") - river_class_example.saveCenterlineMAT(save_to_mat=str(temp_path), - centerline_type="Smoothed", - coordinate_unit="Relative Distance") + river_class_example.save_centerline_mat( + save_to_mat=str(temp_path), + centerline_type="Smoothed", + coordinate_unit="Relative Distance") return temp_path diff --git a/centerline_width/riverCenterlineClass.py b/centerline_width/riverCenterlineClass.py index 1f808d6..c8897e0 100644 --- a/centerline_width/riverCenterlineClass.py +++ b/centerline_width/riverCenterlineClass.py @@ -389,7 +389,28 @@ def saveCenterlineMAT(self, longitude_header: str = None, centerline_type: str = "Voronoi", coordinate_unit: str = "Decimal Degrees"): - return centerline_width.saveCenterlineMAT( + ### Pending Deprecation for function name replaced with save_centerline_mat() + ## To be removed + warnings.warn( + "saveCenterlineMAT() has been replaced with save_centerline_mat() and will be removed in the future", + FutureWarning, + stacklevel=2) + + return centerline_width.save_centerline_mat( + river_object=self, + save_to_mat=save_to_mat, + latitude_header=latitude_header, + longitude_header=longitude_header, + centerline_type=centerline_type, + coordinate_unit=coordinate_unit) + + def save_centerline_mat(self, + save_to_mat: str = None, + latitude_header: str = None, + longitude_header: str = None, + centerline_type: str = "Voronoi", + coordinate_unit: str = "Decimal Degrees"): + return centerline_width.save_centerline_mat( river_object=self, save_to_mat=save_to_mat, latitude_header=latitude_header, diff --git a/centerline_width/saveOutput.py b/centerline_width/saveOutput.py index 1ecc13e..f1bf435 100644 --- a/centerline_width/saveOutput.py +++ b/centerline_width/saveOutput.py @@ -8,7 +8,7 @@ # - save_centerline_csv: saves the centerline # # coordinates to a .csv file # # # -# - saveCenterlineMAT: saves the centerline # +# - save_centerline_mat: saves the centerline # # coordinates to a .mat file # # # # # @@ -95,12 +95,12 @@ def save_centerline_csv(river_object: centerline_width.riverCenterline = None, ) -def saveCenterlineMAT(river_object: centerline_width.riverCenterline = None, - save_to_mat: str = None, - latitude_header: str = None, - longitude_header: str = None, - centerline_type: str = "Voronoi", - coordinate_unit: str = "Decimal Degrees") -> None: +def save_centerline_mat(river_object: centerline_width.riverCenterline = None, + save_to_mat: str = None, + latitude_header: str = None, + longitude_header: str = None, + centerline_type: str = "Voronoi", + coordinate_unit: str = "Decimal Degrees") -> None: # Save Centerline Coordinates generated by Voronoi Diagram to .MAT centerline_width.errorHandlingSaveCenterlineMAT( diff --git a/data/example_script_outputs/centerline_width_example_script.py b/data/example_script_outputs/centerline_width_example_script.py index c70f06e..a23d638 100644 --- a/data/example_script_outputs/centerline_width_example_script.py +++ b/data/example_script_outputs/centerline_width_example_script.py @@ -56,10 +56,10 @@ def main(): longitude_header="lon") # save to mat to import into matlab - ro.saveCenterlineMAT(save_to_mat="equal_distance_coordinates.mat", - centerline_type="Equal Distance", - latitude_header="lat", - longitude_header="lon") + ro.save_centerline_mat(save_to_mat="equal_distance_coordinates.mat", + centerline_type="Equal Distance", + latitude_header="lat", + longitude_header="lon") # plot width lines ro.plot_centerline_width( diff --git a/river_centerline_width_example.py b/river_centerline_width_example.py index d75be4f..9c885a1 100644 --- a/river_centerline_width_example.py +++ b/river_centerline_width_example.py @@ -67,15 +67,18 @@ coord_type = "decimal degrees" center_type = "VorOnoi" - river.save_centerline_csv(save_to_csv="centerline_for_csv.csv", - centerline_type=center_type, - coordinate_unit=coord_type) + #river.save_centerline_csv(save_to_csv="centerline_for_csv.csv", + # centerline_type=center_type, + # coordinate_unit=coord_type) #river.saveCenterlineMAT(save_to_mat="centerline_for_matlab.mat", centerline_type=center_type, coordinate_unit=coord_type) river.save_centerline_csv(save_to_csv="centerline_for_csv.csv", latitude_header="lat", longitude_header="long", centerline_type="Equal Distance") - #river.saveCenterlineMAT(save_to_mat="centerline_for_matlab.mat", latitude_header="lat", longitude_header="long", centerline_type="Evenly Spaced") + river.save_centerline_mat(save_to_mat="centerline_for_matlab.mat", + latitude_header="lat", + longitude_header="long", + centerline_type="Evenly Spaced") river.plot_centerline(centerline_type="Evenly Spaced", centerline_color="fuchsia", diff --git a/river_centerline_width_example_deprecation.py b/river_centerline_width_example_deprecation.py index f7ca6e9..df6bbea 100644 --- a/river_centerline_width_example_deprecation.py +++ b/river_centerline_width_example_deprecation.py @@ -69,15 +69,18 @@ coord_type = "decimal degrees" center_type = "VorOnoi" - river.saveCenterlineCSV(save_to_csv="centerline_for_csv.csv", - centerline_type=center_type, - coordinate_unit=coord_type) + #river.saveCenterlineCSV(save_to_csv="centerline_for_csv.csv", + # centerline_type=center_type, + # coordinate_unit=coord_type) #river.saveCenterlineMAT(save_to_mat="centerline_for_matlab.mat", centerline_type=center_type, coordinate_unit=coord_type) river.saveCenterlineCSV(save_to_csv="centerline_for_csv.csv", latitude_header="lat", longitude_header="long", centerline_type="Equal Distance") - #river.saveCenterlineMAT(save_to_mat="centerline_for_matlab.mat", latitude_header="lat", longitude_header="long", centerline_type="Evenly Spaced") + river.saveCenterlineMAT(save_to_mat="centerline_for_matlab.mat", + latitude_header="lat", + longitude_header="long", + centerline_type="Evenly Spaced") river.plotCenterline(centerline_type="Evenly Spaced", centerline_color="fuchsia",