Skip to content

Commit

Permalink
account for relative paths in convertColumnsToCSV()
Browse files Browse the repository at this point in the history
  • Loading branch information
cyschneck committed Feb 24, 2024
1 parent cf2d1aa commit 056c1fd
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 6 additions & 1 deletion centerline_width/preprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import csv
import logging
import math
import os

# External Python libraries (installed via pip install)
from collections import Counter
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions river_centerline_width_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 056c1fd

Please sign in to comment.