Skip to content

Commit

Permalink
update the csv files to no save the index
Browse files Browse the repository at this point in the history
  • Loading branch information
2320sharon committed Apr 19, 2024
1 parent 3391239 commit 0f4859d
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
8 changes: 4 additions & 4 deletions scripts/apply_tidal_correction.py
Original file line number Diff line number Diff line change
Expand Up @@ -1166,7 +1166,7 @@ def main():
# Reset index if you want 'dates' back as a column
pivot_df.reset_index(inplace=True)

pivot_df.to_csv(TIDE_PREDICTIONS_FILE_NAME)
pivot_df.to_csv(TIDE_PREDICTIONS_FILE_NAME,index=False)

print(f"Applying tide corrections to {RAW_TIMESERIES_FILE_PATH}")
tide_corrected_timeseries_df = tidally_correct_timeseries(
Expand All @@ -1188,12 +1188,12 @@ def main():
only_keep_points_on_transects=DROP_INTERSECTIONS,extension='tidally_corrected')
# optionally save to session location in ROI the tide_corrected_timeseries_df to csv
tide_corrected_timeseries_df.to_csv(
os.path.join(os.getcwd(), "tidally_corrected_transect_time_series_merged.csv")
os.path.join(os.getcwd(), "tidally_corrected_transect_time_series_merged.csv"),index=False
)
# Tidally correct the raw time series
print(f"Tidally corrected data saved to {os.path.abspath(TIDALLY_CORRECTED_FILE_NAME)}")
# Save the Tidally corrected time series
tide_corrected_timeseries_df.to_csv(TIDALLY_CORRECTED_FILE_NAME)
tide_corrected_timeseries_df.to_csv(TIDALLY_CORRECTED_FILE_NAME,index=False)

# save the time series as a matrix of date vs transect id with the cross_distance as the values
pivot_df = tide_corrected_timeseries_df.pivot_table(index='dates', columns='transect_id', values='cross_distance', aggfunc='first')
Expand All @@ -1203,7 +1203,7 @@ def main():
# Tidally correct the raw time series
print(f"Tidally corrected data saved to {os.path.abspath(TIDALLY_CORRECTED_MATRIX_FILE_NAME)}")
# Save the Tidally corrected time series
pivot_df.to_csv(TIDALLY_CORRECTED_MATRIX_FILE_NAME)
pivot_df.to_csv(TIDALLY_CORRECTED_MATRIX_FILE_NAME,index=False)

if __name__ == "__main__":
main()
2 changes: 1 addition & 1 deletion scripts/gen_csv_per_transect_tide_corrected.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def save_csv_per_id(
for uid in unique_ids:
new_filename = f"{uid}_{filename}"
new_df = df[df[id_column_name] == uid]
new_df.to_csv(os.path.join(save_location, new_filename))
new_df.to_csv(os.path.join(save_location, new_filename),index=False)

# 1. Enter the path to the csv file that contains the tide corrected time series
# - replace the path below with the path to the csv file
Expand Down
4 changes: 2 additions & 2 deletions src/coastseg/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -1915,10 +1915,10 @@ def save_transects(
"raw")
# save the raw transect time series which contains the columns ['dates', 'x', 'y', 'transect_id', 'cross_distance','shore_x','shore_y'] to file
filepath = os.path.join(save_location, f"raw_transect_time_series_merged.csv")
merged_timeseries_df.to_csv(filepath, sep=",")
merged_timeseries_df.to_csv(filepath, sep=",",index=False)

filepath = os.path.join(save_location, f"raw_transect_time_series.csv")
timeseries_df.to_csv(filepath, sep=",")
timeseries_df.to_csv(filepath, sep=",",index=False)
# save transect settings to file
transect_settings = get_transect_settings(settings)
transect_settings_path = os.path.join(save_location, "transects_settings.json")
Expand Down
6 changes: 3 additions & 3 deletions src/coastseg/tide_correction.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def correct_tides(
pivot_df = predicted_tides_df.pivot_table(index='dates', columns='transect_id', values='tide', aggfunc='first')
# Reset index if you want 'dates' back as a column
pivot_df.reset_index(inplace=True)
pivot_df.to_csv(os.path.join(session_path, "predicted_tides.csv"))
pivot_df.to_csv(os.path.join(session_path, "predicted_tides.csv"),index=False)

tide_corrected_timeseries_df = tidally_correct_timeseries(
raw_timeseries_df,
Expand All @@ -237,12 +237,12 @@ def correct_tides(
'tidally_corrected')

# Save the Tidally corrected time series
timeseries_df.to_csv(os.path.join(session_path, 'tidally_corrected_transect_time_series.csv'))
timeseries_df.to_csv(os.path.join(session_path, 'tidally_corrected_transect_time_series.csv'),index=False)


# optionally save to session location in ROI the tide_corrected_timeseries_df to csv
tide_corrected_timeseries_merged_df.to_csv(
os.path.join(session_path, "tidally_corrected_transect_time_series_merged.csv")
os.path.join(session_path, "tidally_corrected_transect_time_series_merged.csv"),index=False
)

update(f"{roi_id} was tidally corrected")
Expand Down

0 comments on commit 0f4859d

Please sign in to comment.