Skip to content

Commit

Permalink
Added script to calculate dune offset for CASCADE
Browse files Browse the repository at this point in the history
  • Loading branch information
franklin1895 committed Dec 3, 2024
1 parent bec2a78 commit a03db33
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 2 deletions.
88 changes: 88 additions & 0 deletions cascade/tools/Calculate_Dune_Offset.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# Benton Franklin
# Last modified 8/26/2024
# Used to generate shoreline offset for Ocracoke Cascade model runs
# Script designed to import .csv file generated from ArcGis that shows the intersection
# between the dune toe line and some baseline offshore transect
# Important to note you will need your ARCGIS data to have tracked the B3D model domain, transect #, and distance from
# datum. You will likely need to edit lines 28 - 31 as appropriate based on your ARCGIS naming convention

import pandas as pd
import numpy as np
import copy

# Specify location of the wanted data

#Raw_Data_Path = 'C:\\Users\\frank\\OneDrive - University of North Carolina at Chapel Hill\\Chapter 3\\Dune Offsets\\Raw_1976_Offsets.csv'
Raw_Data_Path = 'C:\\Users\\frank\\OneDrive - University of North Carolina at Chapel Hill\\Chapter 3\\Dune Offsets\\Dune_Raw_Points_2019.csv'


Save_Base_Path = 'C:\\Users\\frank\\OneDrive - University of North Carolina at Chapel Hill\\Chapter 3\\Dune Offsets\\

def calculate_Dune_Offset(Raw_Data_Path,
B3D_Domain_Start,
B3D_Domain_End,
Save_Base_Path,
Save_Name):
Raw_Data = pd.read_csv(Raw_Data_Path)

Data_Dict = {'B3D_Grid':Raw_Data['B3D_Grid'],
'Distance':Raw_Data['ORIG_LEN'],
'Transect':Raw_Data['LineID']}
Data_DF = pd.DataFrame(Data_Dict)

Mean_Distance = []

# Seperate out by grid
B3D_Grids = range(B3D_Domain_Start,B3D_Domain_End)
Grid_Values = []

for i in (B3D_Grids):
Subset = Data_DF[Data_DF['B3D_Grid']==int(i)]
Grid_Values.append(copy.deepcopy(Subset))

# Filter data to remove repeated transects
Filtered_Data = []

for h in range(len(Grid_Values)):
Min_Transect_Num =int(min(Grid_Values[h]['Transect']))
Max_Transect_Num = int(max(Grid_Values[h]['Transect']))
Transects = range(Min_Transect_Num,(Max_Transect_Num+1))
Temp_Array = []
for ll in Transects:
transect_vals = Grid_Values[h][Grid_Values[h]['Transect'] == ll]
Temp_Array.append(copy.deepcopy(transect_vals.iloc[0]))
Filtered_Data.append(copy.deepcopy(Temp_Array))

# Calculate distance between the dune and the dataum
Avg_Dune_Toe_Distance = [] # Save array
Avg_Dune_Toe_Distance_Dict = {} # Save in a dict

for j in range(len(Grid_Values)):
focus_data = Filtered_Data[j]
Temp_Distance_Array = []
for k in range(len(focus_data)):
Distance = focus_data[k][1]
Temp_Distance_Array.append(copy.deepcopy(Distance))
Mean_Distance = int(np.mean(Temp_Distance_Array))
Avg_Dune_Toe_Distance.append(copy.deepcopy(Mean_Distance))
Avg_Dune_Toe_Distance_Dict[str(B3D_Grids[j])] = copy.deepcopy(Mean_Distance)

# Calculate the relative distance
baseline_distance = min(Avg_Dune_Toe_Distance)
Relative_dune_offset = np.subtract(Avg_Dune_Toe_Distance,baseline_distance)

Relative_dune_offset_df = pd.DataFrame(Relative_dune_offset)
Datum_dune_offset_df = pd.DataFrame(Avg_Dune_Toe_Distance_Dict, index=[0])

Datum_dune_offset_df.to_csv(path_or_buf=Save_Base_Path+'Datum_'+Save_Name+'_Offset.csv')
Relative_dune_offset_df.to_csv(path_or_buf=Save_Base_Path+'Relative_Dune_'+Save_Name+'_Offset.csv')

# Convert and save relative distance in DM for use in CASCADE model runs
Relative_dune_offset_DM = np.round(np.divide(Relative_dune_offset_df,10))
Relative_dune_offset_DM.to_csv(path_or_buf=Save_Base_Path+'Relative_Dune_'+Save_Name+'_Offset_DM.csv')

calculate_Dune_Offset(Raw_Data_Path = Raw_Data_Path,
B3D_Domain_Start = 9,
B3D_Domain_End = 91,
Save_Base_Path = ,
Save_Name = 'Test_save')
5 changes: 3 additions & 2 deletions cascade/tools/Process_Raw_LIDAR_Elevation_Data.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,9 @@ def Process_Raw_Topo_Data(raw_data_path,

topo_save_name = topo_save_path+base_name+'_topography_2019.npy'
dune_save_name = dune_save_path+base_name+'_dune_2019.npy'
np.save(arr=ProccesedIslandElevationMatrix, file=topo_save_name)
np.save(arr=DuneHeightsVector, file=dune_save_name)
#np.save(arr=ProccesedIslandElevationMatrix, file=topo_save_name)
#np.save(arr=DuneHeightsVector, file=dune_save_name)
print(str(j)+' is processed')

Process_Raw_Topo_Data(raw_data_path = load_path_name,
dune_save_path = dune_save_path_name,
Expand Down

0 comments on commit a03db33

Please sign in to comment.