Skip to content

Commit

Permalink
error handling when left_kml==right_kml, update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
cyschneck committed May 24, 2023
1 parent 059c21a commit dc4fc49
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,27 +188,27 @@ river_object = centerline_width.riverCenterline(csv_data="data/river_coords.csv"
### Return Latitude/Longitude Coordinates of Centerline
Return the latitude/longtiude coordinates of the centerline based on the left and right banks
```
river_object.centerline_latitude_longtiude
river_object.centerlineLatitudeLongtiude
```
Centerline coordinates are formed from Voronoi vertices

```python
import centerline_width
river_object = centerline_width.riverCenterline(csv_data="data/river_coords.csv", optional_cutoff=15)
river_centerline_coordinates = river_object.centerline_latitude_longtiude
river_centerline_coordinates = river_object.centerlineLatitudeLongtiude
```
Output is a list of tuples: (example) `[(-92.86788596499872, 30.03786596717931), (-92.86789573751797, 30.037834641974108), (-92.8679141386283, 30.037789636848878), (-92.8679251193248, 30.037756853899904), (-92.86796903819089, 30.03765423778148), (-92.86797335733262, 30.037643336049054), (-92.8679920356456, 30.037592224469797), (-92.86800576063828, 30.037555441489403), (-92.86800841510367, 30.037546512833107), (-92.8680119498663, 30.03753043193875)]`

### Return Length of Centerline
Return the length of the centerline found between the left and right bank
```
river_object.centerline_length
river_object.centerlineLength
```
Length returned in kilometers
```python
import centerline_width
river_object = centerline_width.riverCenterline(csv_data="data/river_coords.csv", optional_cutoff=550)
river_centerline_length = river_object.centerline_length
river_centerline_length = river_object.centerlineLength
```
The length of the river centerline returns `215.34700589636674` km

Expand Down Expand Up @@ -416,9 +416,9 @@ river_object = centerline_width.riverCenterline(csv_data="data/river_coords.csv"
The amount of additional points added by interpolating can be adjusted with `interpolate_n`, but defaults to add 5 additional points between values

## Developer Notes: Tech Debt and Bug Fixes
* Verify that smoothing filter option does not produce a line that goes outside of the polygon
* Return the knickpoints (occurrences of knickpoints)
* conversion of centerline lat-lon to meters
* Fix legend overlapping on graph, replace doc_examples that have an overlapping
* Verify that smoothing filter option does not produce a line that goes outside of the polygon

## Citations
Based on work written in R (Golly et al. 2017):
Expand Down
4 changes: 4 additions & 0 deletions centerline_width/error_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,10 @@ def errorHandlingExtractPointsToTextFile(left_kml=None, right_kml=None, text_out
logger.critical("\nCRITICAL ERROR, [right_kml]: Extension must be a .kml file, current extension = '{0}'".format(right_kml.split(".")[1]))
exit()

if right_kml == left_kml:
logger.critical("\nCRITICAL ERROR, right_kml and left_kml are set to the same file (needs a seperate left and right bank): right_kml='{0}' and left_kml='{1}'".format(right_kml, left_kml))
exit()

if text_output_name is None:
logger.critical("\nCRITICAL ERROR, [text_output_name]: Requires output file name")
exit()
Expand Down
7 changes: 7 additions & 0 deletions centerline_width/pytests/test_getCoordinatesKML.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,10 @@ def test_plotCenterline_textOutputNameInvalidTypes(caplog, text_output_name_inva
log_record = caplog.records[0]
assert log_record.levelno == logging.CRITICAL
assert log_record.message == "\nCRITICAL ERROR, [text_output_name]: Must be a str, current type = '{0}'".format(text_output_name_error_output)

def test_extractPointsToTextFile_rightAndLeftKMLMatchInvalid(caplog):
with pytest.raises(SystemExit):
centerline_width.extractPointsToTextFile(left_kml="same_kml.kml", right_kml="same_kml.kml", text_output_name=None)
log_record = caplog.records[0]
assert log_record.levelno == logging.CRITICAL
assert log_record.message == "\nCRITICAL ERROR, right_kml and left_kml are set to the same file (needs a seperate left and right bank): right_kml='same_kml.kml' and left_kml='same_kml.kml'"
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Python Package Setup
from setuptools import setup, find_namespace_packages

VERSION="0.2.0"
VERSION="0.2.1"
DESCRIPTION="A Python package to find the centerline and width of rivers based on the latitude and longitude of the right and left bank"

with open("README.md", "r") as f:
Expand Down

0 comments on commit dc4fc49

Please sign in to comment.