diff --git a/README.md b/README.md index 8f05256..f8ae3e6 100644 --- a/README.md +++ b/README.md @@ -672,6 +672,10 @@ Once the environment has been built, activate the environment: ``` conda activate centerline_width ``` +To run existing and new tests from the root directory: +``` +python -m pytest +``` ## Citations Originally a Python implementation of [R-Code CMGO](https://github.com/AntoniusGolly/cmgo) (Golly et al. 2017) but has been extensively expanded: diff --git a/centerline_width/preprocessing.py b/centerline_width/preprocessing.py index 6076f1c..92c2de1 100644 --- a/centerline_width/preprocessing.py +++ b/centerline_width/preprocessing.py @@ -2,6 +2,7 @@ import csv import logging import math +import os # External Python libraries (installed via pip install) from collections import Counter @@ -43,7 +44,11 @@ def convertColumnsToCSV(text_file=None, flipBankDirection=False): for i, row in enumerate(left_rows): total_rows.append(row + right_rows[i]) - write_file_name = text_file.split(".")[0] + ".csv" + # account for relative and absolute paths to use text_file name and location for .csv + full_path, filename = os.path.split(os.path.abspath(text_file)) + csv_file_name = filename.split(".")[0] + ".csv" + write_file_name = os.path.join(full_path, csv_file_name) + with open(write_file_name, "w") as f: write = csv.writer(f) write.writerow(header_fields) diff --git a/river_centerline_width_example.py b/river_centerline_width_example.py index 0e082a6..047dc42 100644 --- a/river_centerline_width_example.py +++ b/river_centerline_width_example.py @@ -2,15 +2,15 @@ import centerline_width if __name__ == "__main__": + #centerline_width.extractPointsToTextFile(left_kml="data/leftbank.kml", + # right_kml="data/rightbank.kml", + # text_output_name="data/river_coords.txt") #centerline_width.convertColumnsToCSV(text_file="data/river_coords.txt", flipBankDirection=True) - centerline_width.extractPointsToTextFile(left_kml="data/leftbank.kml", - right_kml="data/rightbank.kml", - text_output_name="data/river_coords.txt") #centerline_width.extractPointsToTextFile(left_kml="data/59deg48_18dot87_N_69deg46_59dot57_E_lb.kml", # right_kml="data/59deg48_18dot87_N_69deg46_59dot57_E_rb.kml", # text_output_name="data/N_output.txt") - centerline_width.convertColumnsToCSV(text_file="data/river_coords.txt", flipBankDirection=True) + #centerline_width.convertColumnsToCSV(text_file="data/river_coords.txt", flipBankDirection=True) # Valid Examples cutoff = None @@ -93,7 +93,7 @@ transect_slope=slope_type, apply_smoothing=False, remove_intersections=False, - save_to_csv="testing_new.csv", + save_to_csv=None, coordinate_reference="banks", coordinate_unit=coord_type)