From e5ff7990a27f1216386eb1a61515723cd4644a48 Mon Sep 17 00:00:00 2001 From: cyschneck <22159116+cyschneck@users.noreply.github.com> Date: Tue, 26 Mar 2024 00:50:05 -0600 Subject: [PATCH] seperate repeated width sections --- centerline_width/pytests/test_errorWidth.py | 2 +- centerline_width/pytests/test_verifyWidth.py | 56 +++++--------------- 2 files changed, 14 insertions(+), 44 deletions(-) diff --git a/centerline_width/pytests/test_errorWidth.py b/centerline_width/pytests/test_errorWidth.py index 8e0b436..a87371b 100644 --- a/centerline_width/pytests/test_errorWidth.py +++ b/centerline_width/pytests/test_errorWidth.py @@ -42,7 +42,7 @@ def river_class_object(): river_class_example = river_class_object() -## riverWidthFromCenterlineCoordinates() ##################################################### +## riverWidthFromCenterline() ##################################################### def test_riverWidthFromCenterline_riverObjectRequired(): with pytest.raises( ValueError, diff --git a/centerline_width/pytests/test_verifyWidth.py b/centerline_width/pytests/test_verifyWidth.py index 668de15..aa5a41c 100644 --- a/centerline_width/pytests/test_verifyWidth.py +++ b/centerline_width/pytests/test_verifyWidth.py @@ -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( @@ -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): @@ -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, @@ -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,