From 601ea9bf807e77845f45a4c9cadf0fab23187e61 Mon Sep 17 00:00:00 2001 From: franklin1895 Date: Tue, 12 Nov 2024 17:37:54 -0500 Subject: [PATCH] Updated Future_Runs_Test.py script for faster plotting --- .../Ocracoke-CASCADE-parameters.yaml | 12 ++--- scripts/ocracoke_ms/Future_Runs_Test.py | 54 ++++++++++++++----- scripts/ocracoke_ms/MISC_Future_Test_Runs.py | 2 +- scripts/ocracoke_ms/Test_Changes.py | 18 +++---- .../run_forward_batch_forward_simulations.py | 6 +-- 5 files changed, 59 insertions(+), 33 deletions(-) diff --git a/data/Ocracoke_init_data/Ocracoke-CASCADE-parameters.yaml b/data/Ocracoke_init_data/Ocracoke-CASCADE-parameters.yaml index 2f593df..183a55a 100644 --- a/data/Ocracoke_init_data/Ocracoke-CASCADE-parameters.yaml +++ b/data/Ocracoke_init_data/Ocracoke-CASCADE-parameters.yaml @@ -20,7 +20,7 @@ GrowthParamStart: false HdDiffu: 0.75 Ki: 7.5e-06 Kr: 7.5e-05 -LShoreface: 524.8348346135758 +LShoreface: 523.9734307609483 MHW: 0.46 MaxShrubHeight: 5.3 MaxUpSlope: 0.25 @@ -31,7 +31,7 @@ Qs_min: 1.0 Qshrub_max: 0.15 RSLR_Constant: true RSLR_const: 0.0056 -Rat: -2.0 +Rat: 0 Rin_i: 0.1 Rin_r: 2.0 SalineLimit: 5 @@ -39,7 +39,7 @@ Sandbag_elevation: 1.9 SeededRNG: true Seedmax: 1000.0 Seedmin: 100.0 -ShorefaceToe: 2099.9999999999995 +ShorefaceToe: 1560.3448275999995 ShrubEl_max: 2.3 ShrubEl_min: 1.2 Shrub_ON: 0 @@ -53,8 +53,8 @@ UprootLimit: -0.2 beta: 0.04 disp_mu: -0.721891 disp_sigma: 1.5 -dune_file: C:\Users\frank\PycharmProjects\CASCADE\data\Ocracoke_init_data\dunes\Dunes_2019\Domain_41_dune_2019.npy -elevation_file: C:\Users\frank\PycharmProjects\CASCADE\data\Ocracoke_init_data\elevations\Topography_2019\Domain_41_topography_2019.npy +dune_file: C:\Users\frank\PycharmProjects\CASCADE\data\Ocracoke_init_data\dunes\Sample_1_dune.npy +elevation_file: C:\Users\frank\PycharmProjects\CASCADE\data\Ocracoke_init_data\elevations\Topography_2019\Domain_49_topography_2019.npy enable_sandbags: false growth_param_file: growthparam_1000dam.npy k_sf: 19324.753176079226 @@ -65,4 +65,4 @@ rmin: 0.55 s_sf_eq: 0.01698590034494604 sandbag_elevation: 1.8 sandbag_need: false -storm_file: C:\Users\frank\PycharmProjects\CASCADE\data\Ocracoke_init_data\storms\Synthetic_Storms\OCR_Future_StormList_2_baseline.npy +storm_file: C:\Users\frank\PycharmProjects\CASCADE\data\Ocracoke_init_data\storms\Synthetic_Storms\Ten_Percent_Storms\OCR_Future_StormList_99_10.npy diff --git a/scripts/ocracoke_ms/Future_Runs_Test.py b/scripts/ocracoke_ms/Future_Runs_Test.py index 4cbbab6..aca75a7 100644 --- a/scripts/ocracoke_ms/Future_Runs_Test.py +++ b/scripts/ocracoke_ms/Future_Runs_Test.py @@ -1,18 +1,16 @@ import copy import numpy as np -import time -import matplotlib.pyplot as plt import pandas as pd from scipy import stats as st import os -import imageio -# Set color palette Change_Rates = np.loadtxt('C:\\Users\\frank\\OneDrive - University of North Carolina at Chapel Hill\\Chapter 3\\Revised_Offshore_Datum\\All_Shoreline_Change_Rates.csv',skiprows=1,delimiter=',') Subset_Change_Rates = np.loadtxt('C:\\Users\\frank\\OneDrive - University of North Carolina at Chapel Hill\\Chapter 3\\Revised_Offshore_Datum\\All_Annual_Change_Rates.csv',skiprows=1,delimiter=',') -os.chdir('C:\\Users\\frank\\OneDrive - University of North Carolina at Chapel Hill\\Chapter 3\\Model Runs\\Future Runs') +#os.chdir('C:\\Users\\frank\\OneDrive - University of North Carolina at Chapel Hill\\Chapter 3\\Model Runs\\Future Runs') +os.chdir('E:\\Model_Runs') + Save_Path = 'C:\\Users\\frank\\OneDrive - University of North Carolina at Chapel Hill\\Chapter 3\\Model Runs\\Summary_Values\\' @@ -37,7 +35,7 @@ def Process_Batch(Base_Name, name_list = [] # IL - for runs in range(0,5): + for runs in range(0,100): name_list.append(str(Base_Name)+'_S'+str(runs)+'_'+str(Sink_Name)) nt_run = 126 @@ -100,10 +98,25 @@ def Process_Batch(Base_Name, Mean_Island_Interior_Change = np.mean(island_width_change_TS, axis=0) - Break_Section,Break_Domain_Location = Find_Most_Common_Drowning_Area(Drowned_Domains=Drowning_Domain_Locations) + Break_Section,Break_Domain_Location, Section_Nums = Find_Most_Common_Drowning_Area(Drowned_Domains=Drowning_Domain_Locations) Avg_Break_Year = np.mean(Model_Run_Years) + # Collate all data from 100 model runs + All_Values_Dict = {'All_EP_Change':All_EP_Change, + 'All_Roadway_Abandonment':All_Roadway_Abandonment, + 'Relocation_TS':Relocation_TS, + 'Frequency_TS':Frequency_TS, + 'Sandbag_Duration_TS':sandbag_duration_TS, + 'Number_Sandbags_TS':number_sandbags_TS, + 'Island_Width_Change_TS':island_width_change_TS, + 'Model_Run_Years':Model_Run_Years, + #'Break_Domain_Locations':Section_Nums + } + + All_Values_Data_Frame = pd.DataFrame(All_Values_Dict) + + Export_Values_Dict = { 'Mean_Shoreline_Change_Rate':Mean_Shoreline_Change_Rate, 'Mean_Roadway_Abandonment':Mean_Roadway_Abandonment, @@ -121,7 +134,12 @@ def Process_Batch(Base_Name, Full_Save_Path = Save_Path+Base_Name+'_'+Sink_Name+'.csv' - Export_DF.to_csv(Full_Save_Path) + #Export_DF.to_csv(Full_Save_Path) + + # Save yearly data as .pkl + Full_Save_Path_PKL = Save_Path+Base_Name+'_'+Sink_Name+'.pkl' + All_Values_Data_Frame.to_pickle(Full_Save_Path_PKL) + return(Export_DF) @@ -129,6 +147,14 @@ def Find_Most_Common_Drowning_Area(Drowned_Domains): # Set the numbers that comprise the 6 groups Greatest_Len = -50 Most_Common_Break = -50 + + All_Len = [0, + 0, + 0, + 0, + 0, + 0] + if len(Drowned_Domains) > 0: Section_1 = range(11,20) Section_2 = range(20,30) @@ -189,7 +215,7 @@ def Find_Most_Common_Drowning_Area(Drowned_Domains): Long_Len = copy.deepcopy(All_Len[most]) Most_Common_Break = st.mode(All_Breaks[Greatest_Len-1])[0][0] - return(Greatest_Len,Most_Common_Break) + return(Greatest_Len,Most_Common_Break, All_Len) def Process_Data(run_name_batch): cascade_list = [] @@ -197,9 +223,9 @@ def Process_Data(run_name_batch): Years_Modeled_List = [] for k in range(0,len(run_name_batch)): # --------- plot --------- - output = np.load(run_name_batch[k] + ".npz", allow_pickle=True) - cascade = output["cascade"] - cascade = cascade[0] + output = np.load(run_name_batch[k] + ".npz", allow_pickle=True)["cascade"] + cascade = output[0] + #cascade = cascade[0] cascade_list.append(copy.deepcopy(cascade)) b3d = cascade.barrier3d ny = np.size(b3d) @@ -215,7 +241,7 @@ def Process_Data(run_name_batch): Island_Drowning_Location_List.append(copy.deepcopy(drown - 4)) #Island_Drowning[run_name_batch[k]] = drowned_cells else: - years_modeled = nt_run + years_modeled = cascade._nt final_year_index = years_modeled-1 #Island_Drowning[run_name_batch[k]] = False Years_Modeled_List.append(copy.deepcopy(years_modeled)) @@ -326,7 +352,7 @@ def Calculate_Sandbag_Years(cascade, years_modeled,buffer_length, number_barrier Mean_Sandbag_Length_List.append(copy.deepcopy(Mean_Sandbag_Length)) return (Number_Sandbag_Emplacements_List,Mean_Sandbag_Length_List,Sandbag_Emplacement_Domains) -Output_DF = Process_Batch(Base_Name = Base_Name_List[1],Sink_Name =Sink_Name[0],Save_Path = Save_Path) +Output_DF = Process_Batch(Base_Name = Base_Name_List[3],Sink_Name =Sink_Name[1],Save_Path = Save_Path) print('Hello') diff --git a/scripts/ocracoke_ms/MISC_Future_Test_Runs.py b/scripts/ocracoke_ms/MISC_Future_Test_Runs.py index 8cbdd6c..eb1abc4 100644 --- a/scripts/ocracoke_ms/MISC_Future_Test_Runs.py +++ b/scripts/ocracoke_ms/MISC_Future_Test_Runs.py @@ -51,7 +51,7 @@ nourishment_volume = 100 # RSLR Data -RSLR_Type = 'I' +RSLR_Type = 'IH' if RSLR_Type == 'IL': RSLR_Data = np.load('C:\\Users\\frank\\PycharmProjects\\CASCADE\\data\\Ocracoke_init_data\\RSLR\\Int_Low_SLR.npy') diff --git a/scripts/ocracoke_ms/Test_Changes.py b/scripts/ocracoke_ms/Test_Changes.py index e6036bc..5ffe091 100644 --- a/scripts/ocracoke_ms/Test_Changes.py +++ b/scripts/ocracoke_ms/Test_Changes.py @@ -20,15 +20,15 @@ run_name_batch = [] run_name_batch.append('OCR_IL_Nourishment_S0_Accretional_Sink_Test_N5_Fixed_Beach_T6') -run_name_batch.append('OCR_IL_Nourishment_S0_Erosional_Sink_Test_N5_Fixed_Beach_T6') -run_name_batch.append('OCR_IL_Nourishment_S1_Accretional_Sink_Test_N5_Fixed_Beach_T6') -run_name_batch.append('OCR_IL_Nourishment_S1_Erosional_Sink_Test_N5_Fixed_Beach_T6') -run_name_batch.append('OCR_IL_Nourishment_S2_Accretional_Sink_Test_N5_Fixed_Beach_T6') -run_name_batch.append('OCR_IL_Nourishment_S2_Erosional_Sink_Test_N5_Fixed_Beach_T6') -run_name_batch.append('OCR_IL_Nourishment_S3_Accretional_Sink_Test_N5_Fixed_Beach_T6') -run_name_batch.append('OCR_IL_Nourishment_S3_Erosional_Sink_Test_N5_Fixed_Beach_T6') -run_name_batch.append('OCR_IL_Nourishment_S4_Accretional_Sink_Test_N5_Fixed_Beach_T6') -run_name_batch.append('OCR_IL_Nourishment_S4_Erosional_Sink_Test_N5_Fixed_Beach_T6') +#run_name_batch.append('OCR_IL_Nourishment_S0_Erosional_Sink_Test_N5_Fixed_Beach_T6') +#run_name_batch.append('OCR_IL_Nourishment_S1_Accretional_Sink_Test_N5_Fixed_Beach_T6') +#run_name_batch.append('OCR_IL_Nourishment_S1_Erosional_Sink_Test_N5_Fixed_Beach_T6') +#run_name_batch.append('OCR_IL_Nourishment_S2_Accretional_Sink_Test_N5_Fixed_Beach_T6') +#run_name_batch.append('OCR_IL_Nourishment_S2_Erosional_Sink_Test_N5_Fixed_Beach_T6') +#run_name_batch.append('OCR_IL_Nourishment_S3_Accretional_Sink_Test_N5_Fixed_Beach_T6') +#run_name_batch.append('OCR_IL_Nourishment_S3_Erosional_Sink_Test_N5_Fixed_Beach_T6') +#run_name_batch.append('OCR_IL_Nourishment_S4_Accretional_Sink_Test_N5_Fixed_Beach_T6') +#run_name_batch.append('OCR_IL_Nourishment_S4_Erosional_Sink_Test_N5_Fixed_Beach_T6') #run_name_batch.append('OCR_IH_Nourishment_S0_Accretional_Sink_Test_N5') #run_name_batch.append('OCR_IH_Status_Quo_S0_Accretional_Sink_Test_N1') diff --git a/scripts/ocracoke_ms/run_forward_batch_forward_simulations.py b/scripts/ocracoke_ms/run_forward_batch_forward_simulations.py index 7cea6d4..76cb6c8 100644 --- a/scripts/ocracoke_ms/run_forward_batch_forward_simulations.py +++ b/scripts/ocracoke_ms/run_forward_batch_forward_simulations.py @@ -53,7 +53,7 @@ Sink_Options = ['Accretional_Sink','Erosional_Sink'] run_name = [] -for snames in range(0,100): +for snames in range(4,100): if Storms == 'Baseline': name_base = 'OCR_'+str(RSLR_Type)+str(Management_name)+'S'+str(snames) else: @@ -66,10 +66,10 @@ s_file = [] if Storms == 'Baseline': - for storm_num in range(0,100): + for storm_num in range(4,100): s_file.append(copy.deepcopy('C:\\Users\\frank\\PycharmProjects\\CASCADE\\data\\Ocracoke_init_data\\storms\\Synthetic_Storms\\OCR_Future_StormList_'+str(storm_num)+'_baseline.npy')) else: - for storm_num in range(0, 100): + for storm_num in range(4, 100): s_file.append(copy.deepcopy( 'C:\\Users\\frank\\PycharmProjects\\CASCADE\\data\\Ocracoke_init_data\\storms\\Synthetic_Storms\\Ten_Percent_Storms\\OCR_Future_StormList_' + str( storm_num) + '_10.npy'))