Skip to content

Commit

Permalink
Merge pull request #6 from cyschneck/pep8
Browse files Browse the repository at this point in the history
PEP 8 Deprecation Warnings
  • Loading branch information
cyschneck authored Sep 6, 2024
2 parents e64626c + 67ad5f0 commit 49374cf
Show file tree
Hide file tree
Showing 143 changed files with 14,059 additions and 13,319 deletions.
211 changes: 108 additions & 103 deletions README.md

Large diffs are not rendered by default.

99 changes: 51 additions & 48 deletions centerline_width/__init__.py
Original file line number Diff line number Diff line change
@@ -1,60 +1,63 @@
# get_coordinates_kml.py function calls
from .getCoordinatesKML import extractPointsToTextFile
# centerline.py function calls
from .centerline import _generate_nx_graph
from .centerline import _networkx_graph_shortest_path
from .centerline import _centerline_path
from .centerline import _equal_distance_centerline
from .centerline import _evenly_spaced_centerline
from .centerline import _smoothed_centerline

# channelMigration.py function calls
from .channelMigration import _centerline_migration_rate

# error_handling.py function calls
from .error_handling import _error_handling_plot_centerline
from .error_handling import _error_handling_plot_centerline_width
from .error_handling import _error_handling_width
from .error_handling import _error_handling_save_centerline_csv
from .error_handling import _error_handling_save_centerline_mat
from .error_handling import _errror_handling_txt_to_csv
from .error_handling import _error_handling_kml_to_csv
from .error_handling import _error_handling_centerline_width
from .error_handling import _error_handling_incremental_sinuosity

# getCoordinatesKML.py function calls
from .getCoordinatesKML import kml_to_csv
from .getCoordinatesKML import txt_to_csv
from .getCoordinatesKML import extractPointsToTextFile # pending deprecation
from .getCoordinatesKML import convertColumnsToCSV # pending deprecation

# plotDiagrams.py function calls
from .plotDiagrams import plot_centerline
from .plotDiagrams import plot_centerline_width

# preprocessing.py function calls
from .preprocessing import convertColumnsToCSV
from .preprocessing import leftRightCoordinates
from .preprocessing import generatePolygon
from .preprocessing import generateVoronoi
from .preprocessing import pointsFromVoronoi
from .preprocessing import interpolateBetweenPoints
from .preprocessing import _left_right_coordinates
from .preprocessing import _generate_polygon
from .preprocessing import _generate_voronoi
from .preprocessing import _points_from_voronoi
from .preprocessing import _interpolate_between_points

# riverObject.py function calls
from .riverCenterlineClass import riverCenterline
# riverCenterlineClass.py function calls
from .riverCenterlineClass import riverCenterline # pending deprecation
from .riverCenterlineClass import CenterlineWidth

# relativeDistance.py function calls
from .relativeDistance import relativeSingleCoordinate
from .relativeDistance import relativeBankCoordinates
from .relativeDistance import relativeCenterlineCoordinates
from .relativeDistance import relativeRidgeCoordinates
from .relativeDistance import relativeWidthCoordinates

# centerline.py function calls
from .centerline import centerlinePath
from .centerline import generateNXGraph
from .centerline import networkXGraphShortestPath
from .centerline import equalDistanceCenterline
from .centerline import evenlySpacedCenterline
from .centerline import smoothedCoordinates
from .relativeDistance import _relative_single_coordinate
from .relativeDistance import _relative_bank_coordinates
from .relativeDistance import _relative_centerline_coordinates
from .relativeDistance import _relative_ridge_coordinates
from .relativeDistance import _relative_width_coordinates

# riverFeatures.py function calls
from .riverFeatures import centerlineLength
from .riverFeatures import calculateRiverArea
from .riverFeatures import calculateSinuosity
from .riverFeatures import _calculate_river_area
from .riverFeatures import _centerline_length
from .riverFeatures import _calculate_sinuosity
from .riverFeatures import incremental_sinuosity

# width.py function calls
from .width import riverWidthFromCenterlineCoordinates
from .width import riverWidthFromCenterline
from .width import _width_from_centerline_coordinates
from .width import width

# saveOutput.py function calls
from .saveOutput import saveCenterlineCSV
from .saveOutput import saveCenterlineMAT

# plotDiagrams.py function calls
from .plotDiagrams import plotCenterline
from .plotDiagrams import plotCenterlineWidth

# channelMigration.py function calls
from .channelMigration import centerlineMigrationRate

# error_handling.py function calls
from .error_handling import errrorHandlingConvertColumnsToCSV
from .error_handling import errorHandlingPlotCenterline
from .error_handling import errorHandlingPlotCenterlineWidth
from .error_handling import errorHandlingRiverWidthFromCenterline
from .error_handling import errorHandlingSaveCenterlineCSV
from .error_handling import errorHandlingSaveCenterlineMAT
from .error_handling import errorHandlingExtractPointsToTextFile
from .error_handling import errorHandlingRiverCenterlineClass
from .error_handling import errorHandlingIncrementalSinuosity
from .saveOutput import save_centerline_csv
from .saveOutput import save_centerline_mat
91 changes: 47 additions & 44 deletions centerline_width/centerline.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,54 +5,56 @@
# the centerline #
# #
# This includes the functions for: #
# - generateNXGraph: generates NetworkX graph #
# from the Voronoi points #
# - _generate_nx_graph: backend to generate a #
# NetworkX graph from the Voronoi points #
# #
# - networkXGraphShortestPath: calculates the #
# shortest path through the Voronoi #
# points to generate centerline #
# - _networkx_graph_shortest_path: backend to #
# calculate the shortest path through #
# the Voronoi points to generate centerline #
# #
# - centerlinePath: determines all possible #
# - _centerline_path: backend to find all possible #
# paths generated by the Voronoi points #
# #
# - equalDistanceCenterline: interpolate the #
# centerline at an equal physical distance #
# - _equal_distance_centerline: backend to #
# interpolate the centerline at an equal #
# physical distance #
# #
# - evenlySpacedCenterline: interpolate the #
# centerline at an evenly spaced distance #
# - _evenly_spaced_centerline: backend to #
# interpolate the centerline at an evenly #
# spaced distance #
# #
# - smoothedCoordinates: b-spline smooth the #
# centerline #
# - _smoothed_centerline: backend to implement a #
# b-spline smooth the centerline #
# #
# #
# #

# Built-in Python functions
import math
# Standard Library Imports
import logging
import math

# External Python libraries
import numpy as np
# Related Third Party Imports
import geopy.distance
import networkx as nx
import numpy as np
from pyproj import Geod
from scipy import interpolate
from shapely.geometry import Point, LineString
from pyproj import Geod
import geopy.distance

# Internal centerline_width reference to access functions, global variables, and error handling
# Internal Local Imports
import centerline_width

## Logging set up for .INFO
## Logging setup for .INFO
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
stream_handler = logging.StreamHandler()
logger.addHandler(stream_handler)


def generateNXGraph(all_points_dict: dict = None) -> (dict, list):
def _generate_nx_graph(all_points_dict: dict = None) -> (dict, list):
# Generate a NetworkX graph to find the largest graph

def distanceBetween(start: tuple = None, end: tuple = None) -> float:
def _distance_between(start: tuple = None, end: tuple = None) -> float:
# return the distance between two points on a graph
lat1 = start[0]
lat2 = end[0]
Expand All @@ -78,7 +80,7 @@ def distanceBetween(start: tuple = None, end: tuple = None) -> float:
node_as_keys_pos_values[end_point] = (end_point[0], end_point[1])
all_connections_in_graph.add_edge(start_point,
end_point,
weight=distanceBetween(
weight=_distance_between(
start_point, end_point))

components_of_subgraphs = [
Expand All @@ -94,9 +96,9 @@ def distanceBetween(start: tuple = None, end: tuple = None) -> float:
return all_connections_in_graph, nodes_of_largest_subgraph


def networkXGraphShortestPath(nx_graph=None,
starting_node=None,
ending_node=None):
def _networkx_graph_shortest_path(nx_graph=None,
starting_node=None,
ending_node=None):
# Find the shortest path if it exists
if starting_node is not None:
try:
Expand All @@ -106,7 +108,7 @@ def networkXGraphShortestPath(nx_graph=None,
logger.info("[SUCCESS] Valid centerline path found")
except nx.NetworkXNoPath: # no direct path found
logger.info(
"[FAILED] No direct path found from starting node to ending node. To view gaps, plotCenterline(display_all_possible_paths=True). Recommended fix, rerun riverCenterline: set interpolate_data=True or (if interpolate_data=True) increase interpolate_n"
"[FAILED] No direct path found from starting node to ending node. To view gaps, plot_centerline(display_all_possible_paths=True). Recommended fix, rerun CenterlineWidth: set interpolate_data=True or (if interpolate_data=True) increase interpolate_n"
)
return None
#nx.draw(nx_graph, with_labels=True, font_size=10)
Expand All @@ -115,16 +117,17 @@ def networkXGraphShortestPath(nx_graph=None,
return None


def centerlinePath(river_voronoi=None,
river_polygon=None,
top_polygon_line: LineString = None,
bottom_polygon_line: LineString = None,
multiple_connections: int = 0):
def _centerline_path(river_voronoi=None,
river_polygon=None,
top_polygon_line: LineString = None,
bottom_polygon_line: LineString = None,
multiple_connections: int = 0):
# Return the starting node, ending node, all possible paths positions, and all paths starting/end position as a dictionary
start_end_points_dict = centerline_width.pointsFromVoronoi(
start_end_points_dict = centerline_width._points_from_voronoi(
river_voronoi,
river_polygon) # All possible path connections from Voronoi
nx_graphs, largest_subgraph_nodes = generateNXGraph(start_end_points_dict)
nx_graphs, largest_subgraph_nodes = _generate_nx_graph(
start_end_points_dict)

x_ridge_point = [] # X position on path
y_ridge_point = [] # Y position on path
Expand Down Expand Up @@ -174,15 +177,15 @@ def centerlinePath(river_voronoi=None,
)
shortest_path_points = None
else:
shortest_path_points = networkXGraphShortestPath(
shortest_path_points = _networkx_graph_shortest_path(
nx_graphs, starting_node, ending_node)

return starting_node, ending_node, x_ridge_point, y_ridge_point, shortest_path_points


def equalDistanceCenterline(centerline_coordinates: list = None,
equal_distance: int = None,
ellipsoid="WGS84") -> list:
def _equal_distance_centerline(centerline_coordinates: list = None,
equal_distance: int = None,
ellipsoid="WGS84") -> list:
# Interpolate centerline to space out coordinates an equal physical distance from the next (in meters)
if centerline_coordinates is None:
return None
Expand Down Expand Up @@ -223,8 +226,8 @@ def equalDistanceCenterline(centerline_coordinates: list = None,
return equal_distance_between_centerline_coordinates


def evenlySpacedCenterline(centerline_coordinates: list = None,
number_of_fixed_points: int = None) -> list:
def _evenly_spaced_centerline(centerline_coordinates: list = None,
number_of_fixed_points: int = None) -> list:
# Interpolate to evenly space points along the centerline coordinates (effectively smoothing with fewer points)
if centerline_coordinates is None:
return None
Expand All @@ -247,9 +250,9 @@ def evenlySpacedCenterline(centerline_coordinates: list = None,
return interpolated_centerline_coordinates


def smoothedCoordinates(river_object: centerline_width.riverCenterline = None,
centerline_coordinates: list = None,
interprolate_num: int = None) -> list:
def _smoothed_centerline(river_object=None,
centerline_coordinates: list = None,
interprolate_num: int = None) -> list:
# return a list coordinates after applying b-spline (smoothing)
if centerline_coordinates is None:
return None
Expand Down Expand Up @@ -284,7 +287,7 @@ def smoothedCoordinates(river_object: centerline_width.riverCenterline = None,
points_outside_polygon += 1
if points_outside_polygon > 2:
logger.critical(
f"\nWARNING: Partially invalid smoothed centerline due to sparse centerline data ({points_outside_polygon} points lie outside the polygon), fix recommendation: rerun riverCenterline to create river object with interpolate_n_centerpoints set to {round(len(centerline_coordinates)*2.5)}+\n"
f"\nWARNING: Partially invalid smoothed centerline due to sparse centerline data ({points_outside_polygon} points lie outside the polygon), fix recommendation: rerun CenterlineWidth to create river object with interpolate_n_centerpoints set to {round(len(centerline_coordinates)*2.5)}+\n"
)

return smoothed_coordinates
7 changes: 3 additions & 4 deletions centerline_width/channelMigration.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@
# #
# #

# External Python libraries
# Related Third Party Imports
from pyproj import Geod

# Internal centerline_width reference to access functions, global variables, and error handling
# Internal Local Imports
import centerline_width


def centerlineMigrationRate(start: centerline_width.riverCenterline = None,
end: centerline_width.riverCenterline = None):
def _centerline_migration_rate(start=None, end=None):
# Calculate the river channel migration through the lateral migration of the centerline
pass
Loading

0 comments on commit 49374cf

Please sign in to comment.