Skip to content

Commit

Permalink
README plots for some invalid outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
cyschneck committed Apr 12, 2024
1 parent 91f33fe commit 7d13907
Show file tree
Hide file tree
Showing 18 changed files with 52 additions and 12 deletions.
10 changes: 5 additions & 5 deletions README.md
Expand Up @@ -623,14 +623,14 @@ Points that only have one connection are removed, but limiting the number of con
## Debugging, Error Handling, and Edge Cases
### Wide Start/End of River
If the data starts or ends with a large width, it is possible for the starting/ending nodes to end up in the wrong position
![example+png](https://raw.githubusercontent.com/cyschneck/centerline-width/main/data/doc_examples/invalid_example3.png)
![invalid_too_wide+png](https://raw.githubusercontent.com/cyschneck/centerline-width/main/data/doc_examples/invalid_too_wide.png)
Currently, the starting node is determined by the closest node on the path to the top of the bank (in green) and the ending node is determined by the closest node on the path to the bottom of the bank (in red) that sits along the longest path

### Invalid Polygon
A polygon is formed to encapsulate the river with the given data (to determine the inside and outside of the river). The top and bottom are connected by a straight line from the start/end of the available data. As a result, it is possible for this straight line to overlap and create an invalid polygon.

A polygon is invalid if it overlaps within itself:
![example+png](https://raw.githubusercontent.com/cyschneck/centerline-width/main/data/doc_examples/invalid_example1.png)
![invalid_minor_polygon+png](https://raw.githubusercontent.com/cyschneck/centerline-width/main/data/doc_examples/invalid_minor_polygon.png)
In this example, the polygon is invalid, but with such a small overlap it is still able to find a valid path

With limited data, the polygon will overlap more dramatically and will struggle to find a valid centerline:
Expand All @@ -639,8 +639,8 @@ With limited data, the polygon will overlap more dramatically and will struggle
### Invalid Centerline
If the data is too small, a centerline and its coordinates cannot be found (since only a single Voronoi vertex exists within the polygon and after dead ends are filtered)

`CRITICAL ERROR, Polygon too short for the Voronoi diagram generated (no starting node found), unable to plot centerline. Set displayVoronoi=True to view vertices. Can typically be fixed by adding more data to expand range.`
![example+png](https://raw.githubusercontent.com/cyschneck/centerline-width/main/data/doc_examples/invalid_example2.png)
`CRITICAL ERROR, Polygon too short for the Voronoi diagram generated (no starting node found), unable to plot centerline. Set display_voronoi=True to view vertices. Can typically be fixed by adding more data to expand range`
![invalid_too_small+png](https://raw.githubusercontent.com/cyschneck/centerline-width/main/data/doc_examples/invalid_too_small.png)
Can be fixed by expanding the data until the polygon is large enough to contain at least two different vertex points

### Invalid Top and Bottom Bank Positions (flipBankDirection = True)
Expand All @@ -651,7 +651,7 @@ If the data for the left and right riverbanks are generated in reverse order, th
If the latitude/longitude of the banks are generated in reverse order, flip the final values so left/right bank are in order

This can be fixed by using the flipBankDirection optional argument `centerline_width.convertColumnsToCSV(text_file="data_example.txt", flipBankDirection=True)`
![example+png](https://raw.githubusercontent.com/cyschneck/centerline-width/main/data/doc_examples/flipDirection_example.png)
![invalid_flipped_banks+png](https://raw.githubusercontent.com/cyschneck/centerline-width/main/data/doc_examples/invalid_flipped_banks.png)

### Invalid Smoothed Centerline
The smoothed centerline (`river_object.centerlineSmoothed`) can end up lying outside the river if the centerline data points are sparse in a narrow river. If more than two points in the smoothed centerline lie outside the river, a warning will be thrown
Expand Down
2 changes: 1 addition & 1 deletion centerline_width/centerline.py
Expand Up @@ -140,7 +140,7 @@ def centerlinePath(river_voronoi=None,

if starting_node is None:
logger.critical(
"\nCRITICAL ERROR, Polygon too short for the Voronoi diagram generated (no starting node found), unable to plot centerline. Set displayVoronoi=True to view vertices. Can typically be fixed by adding more data to expand range."
"\nCRITICAL ERROR, Polygon too short for the Voronoi diagram generated (no starting node found), unable to plot centerline. Set display_voronoi=True to view vertices. Can typically be fixed by adding more data to expand range"
)
shortest_path_points = None
else:
Expand Down
Binary file modified data/doc_examples/algorithm_step7.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified data/doc_examples/algorithm_step8.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed data/doc_examples/flipDirection_example.png
Binary file not shown.
Binary file removed data/doc_examples/invalid_example1.png
Binary file not shown.
Binary file removed data/doc_examples/invalid_example2.png
Binary file not shown.
Binary file removed data/doc_examples/invalid_example3.png
Binary file not shown.
Binary file removed data/doc_examples/invalid_example4.png
Binary file not shown.
Binary file added data/doc_examples/invalid_flipped_banks.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/doc_examples/invalid_major_polygon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/doc_examples/invalid_minor_polygon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/doc_examples/invalid_too_small.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/doc_examples/invalid_too_wide.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified data/doc_examples/smoothed_centerline.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified data/doc_examples/smoothed_centerline_relative.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
42 changes: 40 additions & 2 deletions generate_readme_diagrams.py
Expand Up @@ -125,7 +125,7 @@
centerline_color="blue",
marker_type="scatter",
plot_title=
f"Centerline Formed by {ro_550_interpolate_centerline_200.interpolate_n_centerpoints} Centerline Coordinates",
f"Centerline Formed by {ro_550_interpolate_centerline_200.interpolate_n_centerpoints} Smoothed Centerline Coordinates",
show_plot=is_debug)
ro_550_interpolate_centerline_200.plotCenterline(
save_plot_name="data/doc_examples/smoothed_centerline_relative.png",
Expand All @@ -134,7 +134,7 @@
marker_type="scatter",
coordinate_unit="Relative Distance",
plot_title=
f"Centerline Formed by {ro_550_interpolate_centerline_200.interpolate_n_centerpoints} Centerline Coordinates with Relative Distance",
f"Centerline Formed by {ro_550_interpolate_centerline_200.interpolate_n_centerpoints} Smoothed Centerline Coordinates with Relative Distance",
show_plot=is_debug)

################### Plot Centerline Width Lines in Matplotlib ###############################
Expand Down Expand Up @@ -389,6 +389,7 @@ def plotNetworkXGraph(fig_save_name=None):
plot_polygon=True,
plot_all_possible_paths=True,
plot_top_bottom_banks=True,
plot_start_end_node=True,
plot_point_labels=True)
plotNetworkXGraph(fig_save_name="data/doc_examples/algorithm_step8.png")
plotAlgorithm(fig_save_name="data/doc_examples/algorithm_step9.png",
Expand All @@ -402,3 +403,40 @@ def plotNetworkXGraph(fig_save_name=None):
plot_all_possible_paths=True,
plot_top_bottom_banks=True,
total_number_of_connections=1)

################### Debugging, Error Handling, and Edge Cases ###############################

ro_725 = centerline_width.riverCenterline(csv_data="data/river_coords.csv",
optional_cutoff=725)
ro_725.plotCenterline(
save_plot_name="data/doc_examples/invalid_too_wide.png",
display_all_possible_paths=True,
show_plot=is_debug)

ro_250 = centerline_width.riverCenterline(csv_data="data/river_coords.csv",
optional_cutoff=250)
ro_250.plotCenterline(
save_plot_name="data/doc_examples/invalid_minor_polygon.png",
display_all_possible_paths=True,
show_plot=is_debug)

ro_1000 = centerline_width.riverCenterline(
csv_data="data/river_coords.csv", optional_cutoff=1000)
ro_1000.plotCenterline(
save_plot_name="data/doc_examples/invalid_major_polygon.png",
display_all_possible_paths=True,
show_plot=is_debug)

ro_10 = centerline_width.riverCenterline(csv_data="data/river_coords.csv",
optional_cutoff=5)
ro_10.plotCenterline(
save_plot_name="data/doc_examples/invalid_too_small.png",
display_voronoi=True,
show_plot=is_debug)

centerline_width.convertColumnsToCSV(text_file="data/river_coords.txt",
flipBankDirection=False)
ro_400 = centerline_width.riverCenterline(csv_data="data/river_coords.csv")
ro_400.plotCenterline(
save_plot_name="data/doc_examples/invalid_flipped_banks.png",
show_plot=is_debug)
10 changes: 6 additions & 4 deletions river_centerline_width_example.py
Expand Up @@ -2,10 +2,12 @@
import centerline_width

if __name__ == "__main__":
#centerline_width.extractPointsToTextFile(left_kml="data/leftbank.kml",
# right_kml="data/rightbank.kml",
# text_output_name="data/river_coords.txt")
#centerline_width.convertColumnsToCSV(text_file="data/river_coords.txt", flipBankDirection=True)
centerline_width.extractPointsToTextFile(
left_kml="data/leftbank.kml",
right_kml="data/rightbank.kml",
text_output_name="data/river_coords.txt")
centerline_width.convertColumnsToCSV(text_file="data/river_coords.txt",
flipBankDirection=True)

#centerline_width.extractPointsToTextFile(left_kml="data/59deg48_18dot87_N_69deg46_59dot57_E_lb.kml",
# right_kml="data/59deg48_18dot87_N_69deg46_59dot57_E_rb.kml",
Expand Down

0 comments on commit 7d13907

Please sign in to comment.