Skip to content

Commit

Permalink
saveCenterlineMAT() -> save_centerline_mat()
Browse files Browse the repository at this point in the history
  • Loading branch information
cyschneck committed Aug 17, 2024
1 parent 600c19a commit 2e34c49
Show file tree
Hide file tree
Showing 10 changed files with 108 additions and 77 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
| ------------- | ------------- |
Expand Down Expand Up @@ -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"
Expand All @@ -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)`

Expand Down
2 changes: 1 addition & 1 deletion centerline_width/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion centerline_width/error_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand Down
56 changes: 28 additions & 28 deletions centerline_width/pytests/test_errorSaveOutput.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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():
Expand All @@ -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",
Expand All @@ -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():
Expand All @@ -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")
Expand All @@ -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():
Expand All @@ -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")
Expand All @@ -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():
Expand All @@ -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():
Expand All @@ -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",
Expand All @@ -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)
52 changes: 28 additions & 24 deletions centerline_width/pytests/test_verifySaveOutput.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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


Expand Down Expand Up @@ -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


Expand Down Expand Up @@ -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


Expand Down Expand Up @@ -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


Expand Down Expand Up @@ -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


Expand Down Expand Up @@ -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


Expand Down Expand Up @@ -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


Expand Down
23 changes: 22 additions & 1 deletion centerline_width/riverCenterlineClass.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(

Check warning on line 394 in centerline_width/riverCenterlineClass.py

View check run for this annotation

Codecov / codecov/patch

centerline_width/riverCenterlineClass.py#L394

Added line #L394 was not covered by tests
"saveCenterlineMAT() has been replaced with save_centerline_mat() and will be removed in the future",
FutureWarning,
stacklevel=2)

return centerline_width.save_centerline_mat(

Check warning on line 399 in centerline_width/riverCenterlineClass.py

View check run for this annotation

Codecov / codecov/patch

centerline_width/riverCenterlineClass.py#L399

Added line #L399 was not covered by tests
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,
Expand Down
14 changes: 7 additions & 7 deletions centerline_width/saveOutput.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 #
# #
# #
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Loading

0 comments on commit 2e34c49

Please sign in to comment.