Skip to content

Commit 038c048

Browse files
committed
kml_to_csv expand codecov
1 parent 18250d7 commit 038c048

5 files changed

+241
-30
lines changed

centerline_width/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,6 @@
5858
from .error_handling import errorHandlingWidth
5959
from .error_handling import errorHandlingSaveCenterlineCSV
6060
from .error_handling import errorHandlingSaveCenterlineMAT
61-
from .error_handling import errorHandlingExtractPointsToTextFile
61+
from .error_handling import errorHandlingKmlToCSV
6262
from .error_handling import errorHandlingCenterlineWidth
6363
from .error_handling import errorHandlingIncrementalSinuosity

centerline_width/error_handling.py

+16-20
Original file line numberDiff line numberDiff line change
@@ -467,12 +467,12 @@ def errrorHandlingTxtToCSV(txt_input: str = None,
467467
)
468468

469469

470-
def errorHandlingExtractPointsToTextFile(left_kml: str = None,
471-
right_kml: str = None,
472-
flip_direction: bool = None,
473-
csv_output: str = None,
474-
text_output_name: str = None) -> None:
475-
# Error Handling for extractPointsToTextFile()
470+
def errorHandlingKmlToCSV(left_kml: str = None,
471+
right_kml: str = None,
472+
flip_direction: bool = None,
473+
csv_output: str = None,
474+
text_output_name: str = None) -> None:
475+
# Error Handling for kml_to_csv()
476476
if left_kml is None:
477477
raise ValueError("[left_kml]: Requires left_kml file")
478478
else:
@@ -521,22 +521,18 @@ def errorHandlingExtractPointsToTextFile(left_kml: str = None,
521521
raise ValueError(
522522
f"[csv_output]: Extension must be a .csv file, current extension = '{csv_output.split('.')[1]}'"
523523
)
524-
525-
# TEMP: Pending Deprecation
526-
if csv_output is None and text_output_name is None:
527-
raise ValueError(
528-
"[csv_output/text_output_name]: Requires output file name")
529-
else:
530-
if text_output_name is not None:
531-
if type(text_output_name) != str:
532-
raise ValueError(
533-
f"[text_output_name]: Must be a str, current type = '{type(text_output_name)}'"
534-
)
535-
else:
536-
if not text_output_name.lower().endswith(".txt"):
524+
else:
525+
# Pending Deprecation
526+
if text_output_name is not None:
527+
if type(text_output_name) != str:
537528
raise ValueError(
538-
f"[text_output_name]: Extension must be a .txt file, current extension = '{text_output_name.split('.')[1]}'"
529+
f"[text_output_name]: Must be a str, current type = '{type(text_output_name)}'"
539530
)
531+
else:
532+
if not text_output_name.lower().endswith(".txt"):
533+
raise ValueError(
534+
f"[text_output_name]: Extension must be a .txt file, current extension = '{text_output_name.split('.')[1]}'"
535+
)
540536

541537

542538
## Error Handling: riverCenterlineClass.py

centerline_width/getCoordinatesKML.py

+5-8
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,11 @@ def kml_to_csv(left_kml: str = None,
6666

6767
### Pending Deprecated argument "text_output_name" replaced with "csv_output"
6868

69-
centerline_width.errorHandlingExtractPointsToTextFile(
70-
left_kml=left_kml,
71-
right_kml=right_kml,
72-
flip_direction=flip_direction,
73-
csv_output=csv_output,
74-
text_output_name=text_output_name)
69+
centerline_width.errorHandlingKmlToCSV(left_kml=left_kml,
70+
right_kml=right_kml,
71+
flip_direction=flip_direction,
72+
csv_output=csv_output,
73+
text_output_name=text_output_name)
7574

7675
def extractKML(kml_file: str = None) -> (list, list):
7776
# extract points from kml file for the given bank
@@ -170,8 +169,6 @@ def txt_to_csv(txt_input: str = None,
170169
rlon = rlon[::-1]
171170

172171
# account for relative and absolute paths to use txt_input name and location for .csv
173-
if text_file is not None and txt_input is None:
174-
txt_input = text_file # Pending Deprecation
175172
full_path, filename = os.path.split(os.path.abspath(txt_input))
176173
csv_file_name = filename.split(".")[0] + ".csv"
177174

centerline_width/pytests/test_errorGetCoordinatesKML.py

+27-1
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,42 @@ def test_kmlToCSV_rightKMLInvalidExtension():
7777

7878

7979
def test_kmlToCSV_textOutputNameRequired():
80+
# Pending Deprecation
8081
with pytest.raises(
8182
ValueError,
8283
match=re.escape(
8384
"[csv_output/text_output_name]: Requires output file name")):
84-
# Update Pending Deprecation ValueError
8585
centerline_width.kml_to_csv(left_kml="left_kml.kml",
8686
right_kml="right_kml.kml",
8787
text_output_name=None)
8888

8989

90+
@pytest.mark.parametrize("invalid_input, error_output",
91+
invalid_non_str_options)
92+
def test_kmlToCSV_TxtOutputNameInvalidTypes(invalid_input, error_output):
93+
# Pending Deprecation
94+
with pytest.raises(
95+
ValueError,
96+
match=re.escape(
97+
f"[text_output_name]: Must be a str, current type = '{error_output}'"
98+
)):
99+
centerline_width.kml_to_csv(left_kml="left_kml.kml",
100+
right_kml="right_kml.kml",
101+
text_output_name=invalid_input)
102+
103+
104+
def test_kmlToCSV_textOutputNameInvalidExtension():
105+
# Pending Deprecation
106+
with pytest.raises(
107+
ValueError,
108+
match=re.escape(
109+
"[text_output_name]: Extension must be a .txt file, current extension = 'csv"
110+
)):
111+
centerline_width.kml_to_csv(left_kml="left_kml.kml",
112+
right_kml="right_kml.kml",
113+
text_output_name="csv_output.csv")
114+
115+
90116
@pytest.mark.parametrize("invalid_input, error_output",
91117
invalid_non_str_options)
92118
def test_kmlToCSV_CSVOutputNameInvalidTypes(invalid_input, error_output):

centerline_width/pytests/test_verifyRiverCenterlineClass.py

+192
Original file line numberDiff line numberDiff line change
@@ -1057,6 +1057,198 @@ def test_CenterlineWidth_futureWarning_functionName():
10571057
assert river_class_example.sinuosity == pytest.approx(1.0124452966878812)
10581058

10591059

1060+
def test_CenterlineWidth_futureWarning_variableName():
1061+
# Pending Deprecation: TO BE REMOVED
1062+
with pytest.warns(
1063+
FutureWarning,
1064+
match=re.escape(
1065+
"optional_cutoff has been replaced with cutoff and will be removed in the future"
1066+
)):
1067+
river_class_example = centerline_width.CenterlineWidth(
1068+
csv_data=csv_data(), optional_cutoff=10)
1069+
assert river_class_example.interpolate_data is False
1070+
assert river_class_example.interpolate_n == 5
1071+
assert river_class_example.df_len == 10
1072+
assert river_class_example.interpolate_n_centerpoints == 10
1073+
assert river_class_example.df_len == river_class_example.interpolate_n_centerpoints
1074+
assert river_class_example.ellipsoid == "WGS84"
1075+
assert river_class_example.left_bank_coordinates == [
1076+
pytest.approx([-92.86856870164004, 30.03758064742554]),
1077+
pytest.approx([-92.86854932864128, 30.03761289873068]),
1078+
pytest.approx([-92.86854615646304, 30.03764767910492]),
1079+
pytest.approx([-92.86853555132092, 30.03767440933011]),
1080+
pytest.approx([-92.8685329553435, 30.03770236278642]),
1081+
pytest.approx([-92.86852225012414, 30.03772919351539]),
1082+
pytest.approx([-92.86851215967346, 30.0377490549762]),
1083+
pytest.approx([-92.86850070336357, 30.03778301480612]),
1084+
pytest.approx([-92.86848128471485, 30.03781601910584]),
1085+
pytest.approx([-92.86847053431237, 30.03784317873953])
1086+
]
1087+
assert river_class_example.right_bank_coordinates == [
1088+
pytest.approx([-92.867475846432, 30.03744106431763]),
1089+
pytest.approx([-92.86747357248916, 30.03744779451432]),
1090+
pytest.approx([-92.86744912321454, 30.03748158510661]),
1091+
pytest.approx([-92.86743200196584, 30.03750644719021]),
1092+
pytest.approx([-92.86743019872144, 30.03752454918347]),
1093+
pytest.approx([-92.8674152219088, 30.0375426005056]),
1094+
pytest.approx([-92.8674007572212, 30.0375721590616]),
1095+
pytest.approx([-92.86738399853574, 30.03760885519144]),
1096+
pytest.approx([-92.86736152540908, 30.03763647218977]),
1097+
pytest.approx([-92.86733658820408, 30.0376710739572])
1098+
]
1099+
assert river_class_example.left_bank_relative_coordinates == [
1100+
(0.0, 0.0),
1101+
pytest.approx((3.5751565498267706, 1.8685232872800528)),
1102+
pytest.approx((7.430668106736567, 2.1744787187346564)),
1103+
pytest.approx((10.393796078619014, 3.1973421235928603)),
1104+
pytest.approx((13.492522825788607, 3.447722696303108)),
1105+
pytest.approx((16.46679209719587, 4.4802376180320564)),
1106+
pytest.approx((18.668496614410742, 5.4534580897883)),
1107+
pytest.approx((22.433048932416597, 6.5584139868999225)),
1108+
pytest.approx((26.09167847287943, 8.431334212903316)),
1109+
pytest.approx((29.102408368196336, 9.468204479555887))
1110+
]
1111+
assert river_class_example.right_bank_relative_coordinates == [
1112+
pytest.approx((-15.47271352150741, 105.40592884424659)),
1113+
pytest.approx((-14.726648435102671, 105.62524358470733)),
1114+
pytest.approx((-10.980834588706166, 107.98334030850498)),
1115+
pytest.approx((-8.224779903906521, 109.63465739390857)),
1116+
pytest.approx((-6.218116559125793, 109.80856031565474)),
1117+
pytest.approx((-4.2170575255238525, 111.25305312138605)),
1118+
pytest.approx((-0.9403865325118183, 112.64813796581723)),
1119+
pytest.approx((3.1275089584774993, 114.26446962246438)),
1120+
pytest.approx((6.188960842797235, 116.43196765474976)),
1121+
pytest.approx((10.024698871772665, 118.8371160736737))
1122+
]
1123+
assert river_class_example.right_bank_length == pytest.approx(
1124+
0.0291159670403472)
1125+
assert river_class_example.left_bank_length == pytest.approx(
1126+
0.03091855487702919)
1127+
assert river_class_example.area == pytest.approx(3.1320671725985596)
1128+
assert river_class_example.starting_node == pytest.approx(
1129+
(-92.86792843577895, 30.037755468515407))
1130+
assert river_class_example.ending_node == pytest.approx(
1131+
(-92.86801289742837, 30.03752504557166))
1132+
assert river_class_example.x_voronoi_ridge_point == [
1133+
pytest.approx((-92.86792843577895, -92.86797730665528)),
1134+
pytest.approx((-92.86792843577895, -92.86763066313195)),
1135+
pytest.approx((-92.86800558484293, -92.8679831604442)),
1136+
pytest.approx((-92.86800558484293, -92.86800742482134)),
1137+
pytest.approx((-92.86797730665528, -92.8679831604442)),
1138+
pytest.approx((-92.86800742482134, -92.86836579067878)),
1139+
pytest.approx((-92.86801289742837, -92.86800742482134))
1140+
]
1141+
assert river_class_example.y_voronoi_ridge_point == [
1142+
pytest.approx((30.037755468515407, 30.037632240539036)),
1143+
pytest.approx((30.037755468515407, 30.037587198340198)),
1144+
pytest.approx((30.037556089755398, 30.037616220602295)),
1145+
pytest.approx((30.037556089755398, 30.03754989867807)),
1146+
pytest.approx((30.037632240539036, 30.037616220602295)),
1147+
pytest.approx((30.03754989867807, 30.037662199505217)),
1148+
pytest.approx((30.03752504557166, 30.03754989867807))
1149+
]
1150+
assert river_class_example.starting_node_relative == pytest.approx(
1151+
(19.37962855169771, 61.75347314188457))
1152+
assert river_class_example.ending_node_relative == pytest.approx(
1153+
(-6.163506358375243, 53.60729340259522))
1154+
assert river_class_example.x_voronoi_ridge_point_relative == [
1155+
pytest.approx((19.37962855169771, 5.719402714977766)),
1156+
pytest.approx((19.37962855169771, 0.7265597682606407)),
1157+
pytest.approx((-2.722159670063122, 3.943540534289469)),
1158+
pytest.approx((-2.722159670063122, -3.4084605052625445)),
1159+
pytest.approx((5.719402714977766, 3.943540534289469)),
1160+
pytest.approx((-3.4084605052625445, 9.040316297491838)),
1161+
pytest.approx((-6.163506358375243, -3.4084605052625445))
1162+
]
1163+
assert river_class_example.y_voronoi_ridge_point_relative == [
1164+
pytest.approx((61.75347314188457, 57.03996061049505)),
1165+
pytest.approx((61.75347314188457, 90.47371913953327)),
1166+
pytest.approx((54.31257503764738, 56.47537260188891)),
1167+
pytest.approx((54.31257503764738, 54.1351126169003)),
1168+
pytest.approx((57.03996061049505, 56.47537260188891)),
1169+
pytest.approx((54.1351126169003, 19.57072693253479)),
1170+
pytest.approx((53.60729340259522, 54.1351126169003))
1171+
]
1172+
assert river_class_example.centerline_voronoi == [
1173+
pytest.approx((-92.86792843577895, 30.037755468515407)),
1174+
pytest.approx((-92.86797730665528, 30.037632240539036)),
1175+
pytest.approx((-92.8679831604442, 30.037616220602295)),
1176+
pytest.approx((-92.86800558484293, 30.037556089755398)),
1177+
pytest.approx((-92.86800742482134, 30.03754989867807)),
1178+
pytest.approx((-92.86801289742837, 30.03752504557166))
1179+
]
1180+
assert river_class_example.centerline_length == pytest.approx(
1181+
0.0268358436902184)
1182+
assert river_class_example.equal_distance == 10
1183+
assert river_class_example.centerline_equal_distance == [
1184+
pytest.approx((-92.86792843577895, 30.037755468515407)),
1185+
pytest.approx((-92.86796225513369, 30.0376701930044)),
1186+
pytest.approx((-92.8679947819878, 30.03758453771908))
1187+
]
1188+
assert river_class_example.centerline_evenly_spaced == [
1189+
pytest.approx((-92.86792843577895, 30.037755468515407)),
1190+
pytest.approx((-92.86793850025879, 30.037730090916774)),
1191+
pytest.approx((-92.86794856473864, 30.037704713318142)),
1192+
pytest.approx((-92.86795862921848, 30.03767933571951)),
1193+
pytest.approx((-92.86796869369832, 30.037653958120877)),
1194+
pytest.approx((-92.8679786579938, 30.037628542360324)),
1195+
pytest.approx((-92.86798811587208, 30.03760293266184)),
1196+
pytest.approx((-92.86799765519947, 30.03757735303128)),
1197+
pytest.approx((-92.86800689722405, 30.037551673913928)),
1198+
pytest.approx((-92.86801289742837, 30.03752504557166))
1199+
]
1200+
assert river_class_example.centerline_smoothed == [
1201+
pytest.approx((-92.86792864517531, 30.03775552495917)),
1202+
pytest.approx((-92.86793830351385, 30.037730038227725)),
1203+
pytest.approx((-92.86794834164479, 30.037704658553707)),
1204+
pytest.approx((-92.8679585709002, 30.037679328615422)),
1205+
pytest.approx((-92.8679688026121, 30.037653991091172)),
1206+
pytest.approx((-92.86797884811266, 30.037628588659278)),
1207+
pytest.approx((-92.86798851873392, 30.03760306399804)),
1208+
pytest.approx((-92.86799762580799, 30.03757735978578)),
1209+
pytest.approx((-92.86800598066694, 30.037551418700797)),
1210+
pytest.approx((-92.86801339464283, 30.037525183421394))
1211+
]
1212+
assert river_class_example.centerline_voronoi_relative == [
1213+
pytest.approx((19.37962855169771, 61.75347314188457)),
1214+
pytest.approx((5.719402714977766, 57.03996061049505)),
1215+
pytest.approx((3.943540534289469, 56.47537260188891)),
1216+
pytest.approx((-2.722159670063122, 54.31257503764738)),
1217+
pytest.approx((-3.4084605052625445, 54.1351126169003)),
1218+
pytest.approx((-6.163506358375243, 53.60729340259522))
1219+
]
1220+
assert river_class_example.centerline_equal_distance_relative == [
1221+
pytest.approx((19.37962855169771, 61.75347314188457)),
1222+
pytest.approx((9.926557886575461, 58.491655396579134)),
1223+
pytest.approx((0.43138978280792034, 55.35449383456564))
1224+
]
1225+
assert river_class_example.centerline_evenly_spaced_relative == [
1226+
pytest.approx((19.37962855169771, 61.75347314188457)),
1227+
pytest.approx((16.566438223196965, 60.782772210259715)),
1228+
pytest.approx((13.75324799118586, 59.81207078062485)),
1229+
pytest.approx((10.940057853530279, 58.8413688592248)),
1230+
pytest.approx((8.126867813965323, 57.87066644099266)),
1231+
pytest.approx((5.309447553845384, 56.90962631910795)),
1232+
pytest.approx((2.4705290187939486, 55.99742969527903)),
1233+
pytest.approx((-0.36505634661324626, 55.07737682589534)),
1234+
pytest.approx((-3.211669900810025, 54.185998374970055)),
1235+
pytest.approx((-6.163506358375243, 53.60729340259522))
1236+
]
1237+
assert river_class_example.centerline_smoothed_relative == [
1238+
pytest.approx((19.38588540411508, 61.73327688441957)),
1239+
pytest.approx((16.56059758465421, 60.801748243230456)),
1240+
pytest.approx((13.747177300992124, 59.83358816671705)),
1241+
pytest.approx((10.939270373724167, 58.84699365006703)),
1242+
pytest.approx((8.130522617001684, 57.8601617063664)),
1243+
pytest.approx((5.314579839859855, 56.89128935609742)),
1244+
pytest.approx((2.4850878432378534, 55.95857364348811)),
1245+
pytest.approx((-0.3643075754810865, 55.08021162834345)),
1246+
pytest.approx((-3.2399606268696415, 54.27440038709772)),
1247+
pytest.approx((-6.148225524463743, 53.55933701482967))
1248+
]
1249+
assert river_class_example.sinuosity == pytest.approx(1.0008911599991046)
1250+
1251+
10601252
def test_CenterlineWidth_default_incrementalSinuosity():
10611253
river_class_example = centerline_width.CenterlineWidth(csv_data=csv_data())
10621254
assert river_class_example.incremental_sinuosity() == {

0 commit comments

Comments
 (0)