Skip to content

Commit

Permalink
update verbose output for coordinate type
Browse files Browse the repository at this point in the history
  • Loading branch information
cyschneck committed Jan 24, 2024
1 parent 114b659 commit 11fe659
Show file tree
Hide file tree
Showing 9 changed files with 3,840 additions and 3,841 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -665,8 +665,8 @@ river_object = centerline_width.riverCenterline(csv_data="data/river_coords.csv"

The number of additional points added by interpolating can be adjusted with `interpolate_n`, but defaults to add 5 additional points between values

## Development
To run or test against `centerline-width` github repo, a development environment can be created via conda/miniconda
## Development Environment
To run or test against `centerline-width` github repo/fork, a development environment can be created via conda/miniconda

First, [install Miniconda](https://docs.conda.io/projects/miniconda/en/latest/miniconda-install.html)

Expand All @@ -675,7 +675,7 @@ Then, using the existing `environment.yml`, a new conda environment can be creat
```
conda env create --file environment.yml
```

Once the environment has been built, activate the environment:
```
conda activate centerline_width
```
Expand Down
16 changes: 10 additions & 6 deletions centerline_width/preprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def leftRightCoordinates(dataframe):
left_bank_coordinates.append([row.llon, row.llat])
return left_bank_coordinates, right_bank_coordinates

def generatePolygon(left_bank_lst, right_bank_lst, recursion_check=False):
def generatePolygon(left_bank_lst, right_bank_lst, coord_type=None, recursion_check=False):
# Return a shapely polygon based on the position of the river bank points
if len(right_bank_lst) == 0:
logger.critical("\nCRITICAL ERROR, right bank data is empty (or NaN)")
Expand All @@ -74,22 +74,26 @@ def generatePolygon(left_bank_lst, right_bank_lst, recursion_check=False):
bottom_river = LineString([Point(right_bank_lst[0][0], right_bank_lst[0][1]), Point(left_bank_lst[0][0], left_bank_lst[0][1])])

if not river_polygon.is_valid and not recursion_check:
logger.critical("[FAILED] Invalid Polygon may need to be corrected")
polygon_check, _, _ = generatePolygon(left_bank_lst, right_bank_lst[::-1], recursion_check=True) # only run once with recursion_check set (just to check if reverse banks fixes issue)
logger.critical(f"[FAILED] Invalid Polygon may need to be corrected - {coord_type}")
# only run once with recursion_check set (just to check if reverse banks fixes issue)
polygon_check, _, _ = generatePolygon(left_bank_lst=left_bank_lst,
right_bank_lst=right_bank_lst[::-1],
coord_type=coord_type,
recursion_check=True)
if polygon_check.is_valid:
logger.critical("\nWARNING: Invalid Polygon Due to Flipped Banks, fix recommendation: rerun convertColumnsToCSV() and set flipBankDirection=True (or reset to default 'False' if currently set to flipBankDirection=True)\n")
if river_polygon.is_valid and not recursion_check:
logger.info("[SUCCESS] Valid polygon generated")
logger.info(f"[SUCCESS] Valid polygon generated - {coord_type}")

return river_polygon, top_river, bottom_river

def generateVoronoi(left_bank_lst, right_bank_lst):
def generateVoronoi(left_bank_lst, right_bank_lst, coord_type=None):
# Generate a Voronoi shape based on the left/right bank points
all_banks_points = left_bank_lst + right_bank_lst
all_banks_points = np.array(all_banks_points)

river_voronoi = Voronoi(all_banks_points)
logger.info("[SUCCESS] Voronoi diagram generated")
logger.info(f"[SUCCESS] Voronoi diagram generated - {coord_type}")
return river_voronoi

def pointsFromVoronoi(river_voronoi, river_polygon):
Expand Down
8 changes: 4 additions & 4 deletions centerline_width/riverCenterlineClass.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,23 @@ def __init__(self,
self.leftBankLength = centerline_width.centerlineLength(centerline_coordinates=left_bank_coordinates, ellipsoid=self.ellipsoid)

# Decimal Degrees: River polygon, position of the top/bottom polygon
river_bank_polygon, top_bank, bottom_bank = centerline_width.generatePolygon(self.left_bank_coordinates, self.right_bank_coordinates)
river_bank_polygon, top_bank, bottom_bank = centerline_width.generatePolygon(self.left_bank_coordinates, self.right_bank_coordinates, coord_type="Decimal Degrees")
self.bank_polygon = river_bank_polygon
self.top_bank = top_bank
self.bottom_bank = bottom_bank

# Relative Coordinates: River polygon, position of the top/bottom polygon
river_bank_polygon, top_bank, bottom_bank = centerline_width.generatePolygon(self.left_bank_relative_coordinates, self.right_bank_relative_coordinates)
river_bank_polygon, top_bank, bottom_bank = centerline_width.generatePolygon(self.left_bank_relative_coordinates, self.right_bank_relative_coordinates, coord_type="Relative Distance")
self.bank_polygon_relative = river_bank_polygon
self.top_bank_relative = top_bank
self.bottom_bank_relative = bottom_bank

# Decimal Degrees; Voronoi generated by left/right bank coordinates
river_bank_voronoi = centerline_width.generateVoronoi(self.left_bank_coordinates, self.right_bank_coordinates)
river_bank_voronoi = centerline_width.generateVoronoi(self.left_bank_coordinates, self.right_bank_coordinates, coord_type="Decimal Degrees")
self.bank_voronoi = river_bank_voronoi

# Relative Distance; Voronoi generated by left/right bank coordinates
river_bank_voronoi = centerline_width.generateVoronoi(self.left_bank_relative_coordinates, self.right_bank_relative_coordinates)
river_bank_voronoi = centerline_width.generateVoronoi(self.left_bank_relative_coordinates, self.right_bank_relative_coordinates, coord_type="Relative Distance")
self.bank_voronoi_relative = river_bank_voronoi

# Decimal Degrees all possible paths: starting/ending node, all possible paths (ridges), paths dictionary
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 11fe659

Please sign in to comment.