Skip to content

Commit

Permalink
Merge branch 'issue_280' into release_1_2_16
Browse files Browse the repository at this point in the history
  • Loading branch information
2320sharon committed Nov 15, 2024
2 parents 5291684 + 929fceb commit 24a6d69
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
8 changes: 6 additions & 2 deletions scripts/apply_tidal_correction.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def add_shore_points_to_timeseries(timeseries_data: pd.DataFrame,
transect = transects_utm.iloc[i]
transect_id = transect['id']
first = transect.geometry.coords[0]
last = transect.geometry.coords[1]
last = transect.geometry.coords[-1]

idx = timeseries_data['transect_id'].str.contains(transect_id)
##in case there is a transect in the config_gdf that doesn't have any intersections
Expand Down Expand Up @@ -377,7 +377,11 @@ def add_lat_lon_to_timeseries(merged_timeseries_df, transects_gdf,timeseries_df,
merged_timeseries_gdf,dropped_points_df = filter_points_outside_transects(merged_timeseries_gdf,transects_gdf,save_location,ext)
if not dropped_points_df.empty:
timeseries_df = filter_dropped_points_out_of_timeseries(timeseries_df, dropped_points_df)

merged_timeseries_df = merged_timeseries_df[~merged_timeseries_df.set_index(['dates', 'transect_id']).index.isin(dropped_points_df.set_index(['dates', 'transect_id']).index)]
if len(merged_timeseries_df) == 0:
print("All points were dropped from the timeseries. This means all of the detected shoreline points were not on the transects. Turn off the only_keep_points_on_transects parameter to keep all points.")


# save the time series of along shore points as points to a geojson (saves shore_x and shore_y as x and y coordinates in the geojson)
cross_shore_pts = convert_date_gdf(merged_timeseries_gdf.drop(columns=['x','y','shore_x','shore_y','cross_distance']).to_crs('epsg:4326'))
# rename the dates column to date
Expand Down
13 changes: 11 additions & 2 deletions src/coastseg/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -1713,7 +1713,7 @@ def add_shore_points_to_timeseries(timeseries_data: pd.DataFrame,
for i, transect in transects_utm.iterrows():
transect_id = transect['id']
first = transect.geometry.coords[0]
last = transect.geometry.coords[1]
last = transect.geometry.coords[-1]

# Filter timeseries data for the current transect_id
idx = timeseries_data['transect_id'] == transect_id
Expand Down Expand Up @@ -1781,7 +1781,11 @@ def add_lat_lon_to_timeseries(merged_timeseries_df, transects_gdf,timeseries_df,
merged_timeseries_gdf,dropped_points_df = filter_points_outside_transects(merged_timeseries_gdf,transects_gdf,save_location,ext)
if not dropped_points_df.empty:
timeseries_df = filter_dropped_points_out_of_timeseries(timeseries_df, dropped_points_df)

merged_timeseries_df = merged_timeseries_df[~merged_timeseries_df.set_index(['dates', 'transect_id']).index.isin(dropped_points_df.set_index(['dates', 'transect_id']).index)]
if len(merged_timeseries_df) == 0:
logger.warning("All points were dropped from the timeseries. This means all of the detected shoreline points were not on the transects. Turn off the only_keep_points_on_transects parameter to keep all points.")
print("All points were dropped from the timeseries. This means all of the detected shoreline points were not on the transects. Turn off the only_keep_points_on_transects parameter to keep all points.")

# save the time series of along shore points as points to a geojson (saves shore_x and shore_y as x and y coordinates in the geojson)
cross_shore_pts = convert_date_gdf(merged_timeseries_gdf.drop(columns=['x','y','shore_x','shore_y','cross_distance']).to_crs('epsg:4326'))
# rename the dates column to date
Expand Down Expand Up @@ -1926,8 +1930,13 @@ def save_transects(
filepath = os.path.join(save_location, "raw_transect_time_series_merged.csv")
merged_timeseries_df.to_csv(filepath, sep=",",index=False)

# sort the columns
sorted_columns = [timeseries_df.columns[0]] + sorted(timeseries_df.columns[1:], key=lambda x: int(''.join(filter(str.isdigit, x))))
timeseries_df = timeseries_df[sorted_columns]

filepath = os.path.join(save_location, "raw_transect_time_series.csv")
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
2 changes: 2 additions & 0 deletions src/coastseg/tide_correction.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,8 @@ def correct_tides(
'tidally_corrected')

# Save the Tidally corrected time series
sorted_columns = [timeseries_df.columns[0]] + sorted(timeseries_df.columns[1:], key=lambda x: int(''.join(filter(str.isdigit, x))))
timeseries_df = timeseries_df[sorted_columns]
timeseries_df.to_csv(os.path.join(session_path, 'tidally_corrected_transect_time_series.csv'),index=False)


Expand Down

0 comments on commit 24a6d69

Please sign in to comment.