Skip to content

Commit

Permalink
show_plot optional arg for plotCenterline and plotCenterlineWidth
Browse files Browse the repository at this point in the history
  • Loading branch information
cyschneck committed Feb 24, 2024
1 parent 283be3e commit 21fa65a
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 7 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@ plotCenterline(centerline_type="Voronoi",
plot_title=None,
save_plot_name=None,
display_voronoi=False,
show_plot=True,
coordinate_unit="Decimal Degrees")
```
* [OPTIONAL] centerline_type (string): Centerline type graph within river (not case-sensitive), options: ["Voronoi", "Evenly Spaced", "Smoothed", "Equal Distance"], defaults to "Voronoi"
Expand All @@ -396,6 +397,7 @@ plotCenterline(centerline_type="Voronoi",
* [OPTIONAL] plot_title (string): Change plot title, defaults to "River Coordinates: Valid Centerline = True/False, Valid Polygon = True/False"
* [OPTIONAL] save_plot_name (string): Save the plot with a given name and location
* [OPTIONAL] display_voronoi (boolean): Overlay Voronoi diagram used to generate centerline, defaults to False
* [OPTIONAL] show_plot (boolean): display and open plots (plt.show() in Matplotlib), defaults to True
* [OPTIONAL] coordinate_unit (string): Coordinates of the river are return as "Decimal Degrees" (latitude/longitude) or converted to a distance from the first point on the left bank as "Relative Distance", defaults to "Decimal Degrees"

```python
Expand All @@ -421,6 +423,7 @@ plotCenterlineWidth(plot_title=None,
remove_intersections=False,
dark_mode=False,
equal_axis=False,
show_plot=True,
coordinate_unit="Decimal Degrees")
```
* [OPTIONAL] plot_title (string): Change plot title, defaults to "River Coordinates: Valid Centerline = True/False, Valid Polygon = True/False"
Expand All @@ -433,6 +436,7 @@ plotCenterlineWidth(plot_title=None,
* [OPTIONAL] remove_intersections (boolean): Remove intersecting lines (but maintain the most width lines as possible) and only return non-intersecting width lines, defaults to False
* [OPTIONAL] dark_mode (bool): Change plot to a black ground (and override if `centerline_color="black"` to `centerline_color="white"`), defaults to False
* [OPTIONAL] equal_axis (bool): Set x/y axes in plot to be equal, defaults to False
* [OPTIONAL] show_plot (boolean): display and open plots (plt.show() in Matplotlib), defaults to True
* [OPTIONAL] coordinate_unit (string): Coordinates of the river are return as "Decimal Degrees" (latitude/longitude) or converted to a distance from the first point on the left bank as "Relative Distance", defaults to "Decimal Degrees"

**display_true_centerline**
Expand Down
8 changes: 8 additions & 0 deletions centerline_width/error_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def errorHandlingPlotCenterline(river_object=None,
plot_title=None,
save_plot_name=None,
display_voronoi=None,
show_plot=None,
coordinate_unit=None):
# Error handling for plotCenterline()
if river_object is None:
Expand Down Expand Up @@ -86,6 +87,9 @@ def errorHandlingPlotCenterline(river_object=None,
if type(display_voronoi) != bool:
raise ValueError(f"[display_voronoi]: Must be a bool, current type = '{type(display_voronoi)}'")

if type(show_plot) != bool:
raise ValueError(f"[show_plot]: Must be a bool, current type = '{type(show_plot)}'")

if type(coordinate_unit) != str:
raise ValueError(f"[coordinate_unit]: Must be a str, current type = '{type(coordinate_unit)}'")
else:
Expand All @@ -104,6 +108,7 @@ def errorHandlingPlotCenterlineWidth(river_object=None,
remove_intersections=None,
dark_mode=None,
equal_axis=None,
show_plot=None,
coordinate_unit=None):
# Error handling for plotCenterlineWidth()
if river_object is None:
Expand Down Expand Up @@ -150,6 +155,9 @@ def errorHandlingPlotCenterlineWidth(river_object=None,
if type(equal_axis) != bool:
raise ValueError(f"[equal_axis]: Must be a bool, current type = '{type(equal_axis)}'")

if type(show_plot) != bool:
raise ValueError(f"[show_plot]: Must be a bool, current type = '{type(show_plot)}'")

if type(coordinate_unit) != str:
raise ValueError(f"[coordinate_unit]: Must be a str, current type = '{type(coordinate_unit)}'")
else:
Expand Down
8 changes: 6 additions & 2 deletions centerline_width/plotDiagrams.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ def plotCenterline(river_object=None,
plot_title=None,
save_plot_name=None,
display_voronoi=False,
show_plot=True,
coordinate_unit="Decimal Degrees"):
# Plot Centerline of River
centerline_width.errorHandlingPlotCenterline(river_object=river_object,
Expand All @@ -144,6 +145,7 @@ def plotCenterline(river_object=None,
plot_title=plot_title,
save_plot_name=save_plot_name,
display_voronoi=display_voronoi,
show_plot=show_plot,
coordinate_unit=coordinate_unit)

fig, ax, valid_path_through = plotCenterlineBackend(river_object=river_object,
Expand Down Expand Up @@ -187,7 +189,7 @@ def plotCenterline(river_object=None,
plt.ylabel("Relative Distance Y (m)")

plt.legend(loc="upper right")
plt.show()
if show_plot: plt.show()
if save_plot_name: fig.savefig(save_plot_name)

def plotCenterlineWidth(river_object=None,
Expand All @@ -201,6 +203,7 @@ def plotCenterlineWidth(river_object=None,
remove_intersections=False,
dark_mode=False,
equal_axis=False,
show_plot=True,
coordinate_unit="Decimal Degrees"):
# Plot Width Lines based on Centerline
centerline_width.errorHandlingPlotCenterlineWidth(river_object=river_object,
Expand All @@ -214,6 +217,7 @@ def plotCenterlineWidth(river_object=None,
remove_intersections=remove_intersections,
dark_mode=dark_mode,
equal_axis=equal_axis,
show_plot=show_plot,
coordinate_unit=coordinate_unit)

fig, ax, valid_path_through = plotCenterlineBackend(river_object=river_object,
Expand Down Expand Up @@ -305,5 +309,5 @@ def plotCenterlineWidth(river_object=None,
plt.ylabel("Distance Distance Y (m)")

plt.legend(loc="upper right")
plt.show()
if show_plot: plt.show()
if save_plot_name: fig.savefig(save_plot_name)
20 changes: 16 additions & 4 deletions centerline_width/pytests/test_plotDiagrams.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,12 @@ def test_plotCenterline_displayVoronoiInvalidTypes(invalid_input, error_output):
centerline_width.plotCenterline(river_object=river_class_example,
display_voronoi=invalid_input)

@pytest.mark.parametrize("invalid_input, error_output", invalid_non_bool_options)
def test_plotCenterline_showPlotInvalidTypes(invalid_input, error_output):
with pytest.raises(ValueError, match=re.escape(f"[show_plot]: Must be a bool, current type = '{error_output}'")):
centerline_width.plotCenterline(river_object=river_class_example,
show_plot=invalid_input)

def test_plotCenterline_coordinateUnitInvalidOption():
with pytest.raises(ValueError, match=re.escape("[coordinate_unit]: Must be an available option in ['Decimal Degrees', 'Relative Distance'], current option = 'Invalid Option'")):
centerline_width.plotCenterline(river_object=river_class_example,
Expand Down Expand Up @@ -199,16 +205,22 @@ def test_plotCenterlineWidth_darkModeInvalidTypes(invalid_input, error_output):
@pytest.mark.parametrize("invalid_input, error_output", invalid_non_bool_options)
def test_plotCenterline_equalAxisInvalidTypes(invalid_input, error_output):
with pytest.raises(ValueError, match=re.escape(f"[equal_axis]: Must be a bool, current type = '{error_output}'")):
centerline_width.plotCenterline(river_object=river_class_example,
equal_axis=invalid_input)
centerline_width.plotCenterlineWidth(river_object=river_class_example,
equal_axis=invalid_input)

@pytest.mark.parametrize("invalid_input, error_output", invalid_non_bool_options)
def test_plotCenterline_showPlotInvalidTypes(invalid_input, error_output):
with pytest.raises(ValueError, match=re.escape(f"[show_plot]: Must be a bool, current type = '{error_output}'")):
centerline_width.plotCenterlineWidth(river_object=river_class_example,
show_plot=invalid_input)

def test_plotCenterlineWidth_coordinateUnitInvalidOption():
with pytest.raises(ValueError, match=re.escape("[coordinate_unit]: Must be an available option in ['Decimal Degrees', 'Relative Distance'], current option = 'Invalid Option'")):
centerline_width.plotCenterlineWidth(river_object=river_class_example,
coordinate_unit="Invalid Option")
coordinate_unit="Invalid Option")

@pytest.mark.parametrize("invalid_input, error_output", invalid_non_str_options)
def test_plotCenterlineWidth_coordinateUnitInvalidTypes(invalid_input, error_output):
with pytest.raises(ValueError, match=re.escape(f"[coordinate_unit]: Must be a str, current type = '{error_output}'")):
centerline_width.plotCenterlineWidth(river_object=river_class_example,
coordinate_unit=invalid_input)
coordinate_unit=invalid_input)
4 changes: 4 additions & 0 deletions centerline_width/riverCenterlineClass.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ def plotCenterline(self,
display_all_possible_paths=False,
plot_title=None,
save_plot_name=None,
show_plot=True,
display_voronoi=False,
coordinate_unit="Decimal Degrees"):
centerline_width.plotCenterline(river_object=self,
Expand All @@ -124,6 +125,7 @@ def plotCenterline(self,
plot_title=plot_title,
save_plot_name=save_plot_name,
display_voronoi=display_voronoi,
show_plot=show_plot,
coordinate_unit=coordinate_unit)

def plotCenterlineWidth(self,
Expand All @@ -137,6 +139,7 @@ def plotCenterlineWidth(self,
remove_intersections=False,
dark_mode=False,
equal_axis=False,
show_plot=True,
coordinate_unit="Decimal Degrees"):
centerline_width.plotCenterlineWidth(river_object=self,
plot_title=plot_title,
Expand All @@ -149,6 +152,7 @@ def plotCenterlineWidth(self,
remove_intersections=remove_intersections,
dark_mode=dark_mode,
equal_axis=equal_axis,
show_plot=show_plot,
coordinate_unit=coordinate_unit)

def riverWidthFromCenterline(self,
Expand Down
4 changes: 3 additions & 1 deletion river_centerline_width_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
plot_title=None,
dark_mode=True,
equal_axis=True,
show_plot=True,
coordinate_unit=coord_type)

transect = 2
Expand All @@ -86,8 +87,9 @@
remove_intersections=True,
dark_mode=True,
equal_axis=False,
show_plot=True,
coordinate_unit=coord_type)
exit()

# Return width line for each centerline coordinates
river_width_dict = river.riverWidthFromCenterline(transect_span_distance=transect,
transect_slope=slope_type,
Expand Down

0 comments on commit 21fa65a

Please sign in to comment.