Skip to content

Commit

Permalink
seperate repeated width sections
Browse files Browse the repository at this point in the history
  • Loading branch information
cyschneck committed Mar 26, 2024
1 parent 16db6d9 commit e5ff799
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 44 deletions.
2 changes: 1 addition & 1 deletion centerline_width/pytests/test_errorWidth.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def river_class_object():
river_class_example = river_class_object()


## riverWidthFromCenterlineCoordinates() #####################################################
## riverWidthFromCenterline() #####################################################
def test_riverWidthFromCenterline_riverObjectRequired():
with pytest.raises(
ValueError,
Expand Down
56 changes: 13 additions & 43 deletions centerline_width/pytests/test_verifyWidth.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import centerline_width


def test_riverWidthFromCenterline_transectSlopeAverage():
def generate_testRiver():
csv_example = StringIO()
csv_example.write("llat,llon,rlat,rlon\n")
csv_example.write(
Expand All @@ -32,9 +32,10 @@ def test_riverWidthFromCenterline_transectSlopeAverage():
)
csv_example.seek(0)

test_river = centerline_width.riverCenterline(csv_data=csv_example)
return centerline_width.riverCenterline(csv_data=csv_example)


span_distance = 3
def generate_expectedCenterline(span_distance=None):
# group points inclusive of previous point: [A, B, C, D] = [A, B], [B, C], [C, D]
groups_of_n_points = []
for i in range(0, len(test_river.centerlineEvenlySpaced), span_distance):
Expand All @@ -49,7 +50,16 @@ def test_riverWidthFromCenterline_transectSlopeAverage():
for group_points in groups_of_n_points:
middle_of_list = (len(group_points) + 1) // 2
centerline_slope_expected.append(group_points[middle_of_list])
return centerline_slope_expected


## riverWidthFromCenterline #####################################################
test_river = generate_testRiver()
span_distance = 3
centerline_slope_expected = generate_expectedCenterline(span_distance)


def test_riverWidthFromCenterline_transectSlopeAverage():
river_width_dict = test_river.riverWidthFromCenterline(
transect_slope="Average",
transect_span_distance=span_distance,
Expand All @@ -67,46 +77,6 @@ def test_riverWidthFromCenterline_transectSlopeAverage():


def test_riverWidthFromCenterline_transectSlopeDirect():
csv_example = StringIO()
csv_example.write("llat,llon,rlat,rlon\n")
csv_example.write(
"48.286399957085044,-4.259939230629442,48.28244110043403,-4.255739731090472\n"
)
csv_example.write(
"48.2850027485986,-4.2625639178417885,48.280578002893776,-4.2602891889242755\n"
)
csv_example.write(
"48.283954817150175,-4.265713542496371,48.28011221789134,-4.265888521643745\n"
)
csv_example.write(
"48.283954817160175,-4.26833822970741,48.28011221789134,-4.2711378960671595\n"
)
csv_example.write(
"48.28558492344624,-4.271312875214591,48.28244110043403,-4.276212291343171\n"
)
csv_example.write(
"49.287447838366376,-4.27393756242688,48.28581779152722,-4.278836978555489\n"
)
csv_example.seek(0)

test_river = centerline_width.riverCenterline(csv_data=csv_example)

span_distance = 3
# group points inclusive of previous point: [A, B, C, D] = [A, B], [B, C], [C, D]
groups_of_n_points = []
for i in range(0, len(test_river.centerlineEvenlySpaced), span_distance):
if i == 0:
groups_of_n_points.append(
test_river.centerlineEvenlySpaced[0:span_distance])
else:
groups_of_n_points.append(
test_river.centerlineEvenlySpaced[i - 1:i + span_distance])

centerline_slope_expected = []
for group_points in groups_of_n_points:
middle_of_list = (len(group_points) + 1) // 2
centerline_slope_expected.append(group_points[middle_of_list])

river_width_dict = test_river.riverWidthFromCenterline(
transect_slope="Direct",
transect_span_distance=span_distance,
Expand Down

0 comments on commit e5ff799

Please sign in to comment.