Skip to content

Commit 1074aae

Browse files
committed
Merge remote-tracking branch 'origin/benton-cascade' into benton-cascade
2 parents 8086e7f + e21f196 commit 1074aae

File tree

4 files changed

+387
-8
lines changed

4 files changed

+387
-8
lines changed

scripts/marsh_ms/Alter_Elevations.py

Lines changed: 0 additions & 8 deletions
This file was deleted.
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
import copy
2+
3+
import matplotlib.pyplot as plt
4+
import numpy as np
5+
import os
6+
import copy
7+
8+
import pandas as pd
9+
10+
os.chdir("E:\\Chapter 2\\")
11+
#save_path = 'C:\\Users\\frank\\OneDrive - University of North Carolina at Chapel Hill\\Chapter 2\\Cascade_CSV_Outputs\\Hindcasts\\'
12+
13+
14+
15+
16+
Base_Name_List = ['Geom_1',
17+
'Geom_3',
18+
'Geom_4',
19+
'Geom_5']
20+
21+
Base_Name = Base_Name_List[0]
22+
23+
if Base_Name == 'Geom_1':
24+
Cascade_Offset = 90
25+
if Base_Name == 'Geom_3':
26+
Cascade_Offset = 490
27+
if Base_Name == 'Geom_4':
28+
Cascade_Offset = 170
29+
if Base_Name == 'Geom_5':
30+
Cascade_Offset = 160
31+
32+
run_name = 'Geom_1_IH_10_S1.npz' #'Geom_4_IL_10_S49_New_Sink.npz'
33+
#for geos in range(len(Base_Name_List)):
34+
# temp_run_name = copy.deepcopy(Base_Name_List[geos]+'_Calibrated_Hindcast_2.npz')
35+
# run_name.append(copy.deepcopy(temp_run_name))
36+
37+
output = np.load(run_name, allow_pickle=True)
38+
cascade = output["cascade"]
39+
cascade = cascade[0]
40+
41+
bmft = cascade._bmft_coupler
42+
bmftc = bmft._bmftc[0]
43+
O_flux = bmftc.fluxes
44+
Forest_e = bmftc.Forest_edge
45+
Marsh_e = bmftc.Marsh_edge
46+
47+
initial_C = bmftc._marshOM_initial # kg's C accross entire platfrom
48+
initial_marsh_C_g = initial_C*1000
49+
50+
# Create initial C layer
51+
Initial_Marsh_Width = Forest_e[49] - Marsh_e[49]
52+
Per_m_Marsh_C_g = initial_marsh_C_g/Initial_Marsh_Width
53+
Initial_Transect_C_Value = np.zeros(len(bmftc.elevation[0]))
54+
55+
# Add initial C to marsh cells
56+
Initial_Transect_C_Value[int(Marsh_e[49]):int(Forest_e[49])] = Per_m_Marsh_C_g
57+
Total_C_Deposited_TS = [Initial_Transect_C_Value]
58+
59+
#Bmftc._BayOM[yr]
60+
61+
Shoreline_location_TS = cascade.brie.x_s_save
62+
All_Reletive_Shoreline = ((-Shoreline_location_TS+1624+90)+Forest_e[49])[0]
63+
64+
65+
# Start Year = [50]
66+
Start_Year = 49
67+
End_Year = Start_Year+125
68+
69+
C_autoch = bmftc._organic_dep_autoch# Subtract eroded mass from depositional record
70+
C_alloch = bmftc._organic_dep_alloch
71+
72+
Total_Annual_C_Change = np.sum((C_alloch,C_autoch),axis=0)
73+
74+
for years in range(Start_Year,End_Year):
75+
temp_sum = np.sum(Total_Annual_C_Change[Start_Year:years],axis=0)
76+
marsh_accumulation = temp_sum[int(Marsh_e[years]):]
77+
temp_total_marsh_C_Change = np.zeros(len(temp_sum))
78+
temp_total_marsh_C_Change[int(Marsh_e[years]):] = marsh_accumulation
79+
new_C_deposition_plus_C0 = np.sum((temp_total_marsh_C_Change,Initial_Transect_C_Value),axis=0)
80+
new_C_deposition_plus_C0[new_C_deposition_plus_C0 < 0] = 0
81+
Total_C_Deposited_TS.append(copy.deepcopy(new_C_deposition_plus_C0))
82+
83+
plt.plot(Total_C_Deposited_TS[0][0:])
84+
#plt.plot(Total_C_Deposited_TS[10][0:])
85+
plt.plot(Total_C_Deposited_TS[24][0:],alpha=0.8)
86+
#plt.plot(Total_C_Deposited_TS[30][0:])
87+
plt.plot(Total_C_Deposited_TS[49][0:], alpha=0.8)
88+
plt.plot(Total_C_Deposited_TS[74][0:], alpha=0.8)
89+
plt.plot(Total_C_Deposited_TS[99][0:], alpha=0.8)
90+
plt.plot(Total_C_Deposited_TS[124][0:],alpha=0.8)
91+
92+
# plt.axvline(x=All_Reletive_Shoreline[0])
93+
# plt.axvline(x=Marsh_e[49])
94+
# #plt.axvline(x=All_Reletive_Shoreline[24])
95+
# plt.axvline(x=Marsh_e[74])
96+
# #plt.axvline(x=All_Reletive_Shoreline[49])
97+
# plt.axvline(x=Marsh_e[99])
98+
# plt.axvline(x=All_Reletive_Shoreline[74])
99+
# #plt.axvline(x=Marsh_e[124])
100+
# plt.axvline(x=All_Reletive_Shoreline[99])
101+
# #plt.axvline(x=Marsh_e[144],color = 'grey')
102+
# plt.axvline(x=All_Reletive_Shoreline[124])
103+
# #plt.axvline(x=Marsh_e[172],color='black')
104+
105+
plt.xlim(4500,7500)
106+
#plt.ylim(0,3000)
107+
plt.show()
108+
109+
plt.plot(Total_Annual_C_Change[25][0:])
110+
plt.plot(Total_Annual_C_Change[50][0:])
111+
plt.plot(Total_Annual_C_Change[75][0:])
112+
plt.plot(Total_Annual_C_Change[100][0:])
113+
plt.plot(Total_Annual_C_Change[124][0:])
114+
plt.xlim(4000,7000)
115+
plt.ylim(0,3000)
116+
plt.show()
117+
118+
plt.plot(bmftc.elevation[50])
119+
plt.plot(bmftc.elevation[55])
120+
plt.plot(bmftc.elevation[60])
121+
plt.plot(bmftc.elevation[70])
122+
plt.plot(bmftc.elevation[80])
123+
124+
plt.show()
125+
126+
elev = bmftc.elevation
127+
128+
plt.plot(elev[50][4500:])
129+
plt.axvline(x=Forest_e[50]-4500,linestyle ='dashed',color='blue')
130+
plt.axvline(x=Marsh_e[50]-4500,linestyle ='dashed', color='blue')
131+
#plt.show()
132+
133+
plt.plot(elev[70][4500:],color = 'orange')
134+
plt.axvline(x=Forest_e[70]-4500,linestyle ='dashed',color='orange')
135+
plt.axvline(x=Marsh_e[70]-4500,linestyle ='dashed', color='orange')
136+
#plt.show()
137+
138+
plt.plot(elev[90][4500:],color = 'red')
139+
plt.axvline(x=Forest_e[90]-4500,linestyle ='dashed',color='red')
140+
plt.axvline(x=Marsh_e[90]-4500,linestyle ='dashed', color='red')
141+
#plt.show()
142+
143+
plt.plot(elev[110][4500:],color = 'green')
144+
plt.axvline(x=Forest_e[110]-4500,linestyle ='dashed',color='green')
145+
plt.axvline(x=Marsh_e[110]-4500,linestyle ='dashed', color='green')
146+
147+
plt.plot(elev[130][4500:],color = 'black')
148+
plt.axvline(x=Forest_e[130]-4500,linestyle ='dashed',color='black')
149+
plt.axvline(x=Marsh_e[130]-4500,linestyle ='dashed', color='black')
150+
#plt.show()
151+
152+
plt.plot(elev[150][4500:],color = 'grey')
153+
plt.axvline(x=Forest_e[150]-4500,linestyle ='dashed',color='grey')
154+
plt.axvline(x=Marsh_e[150]-4500,linestyle ='dashed', color='grey')
155+
plt.show()
156+
157+
158+
plt.plot(elev[51][4500:])
159+
plt.plot(elev[101][4500:])
160+
plt.plot(elev[151][4500:])
161+
plt.show()
162+
163+
b3d = cascade._barrier3d[0]
164+
165+
166+
z = 20
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
import copy
2+
3+
import matplotlib.pyplot as plt
4+
import numpy as np
5+
import os
6+
import copy
7+
8+
import pandas as pd
9+
10+
os.chdir("E:\\Chapter 2\\")
11+
Base_Save_Path = 'C:\\Users\\frank\\OneDrive - University of North Carolina at Chapel Hill\\Chapter 2\\Updated_Marsh_Accretion_C_Release\\'
12+
#save_path = 'C:\\Users\\frank\\OneDrive - University of North Carolina at Chapel Hill\\Chapter 2\\Cascade_CSV_Outputs\\Hindcasts\\'
13+
14+
#run_name = 'Geom_1_IL_Baseline_S20.npz' #'Geom_4_IL_10_S49_New_Sink.npz'
15+
#for geos in range(len(Base_Name_List)):
16+
# temp_run_name = copy.deepcopy(Base_Name_List[geos]+'_Calibrated_Hindcast_2.npz')
17+
# run_name.append(copy.deepcopy(temp_run_name))
18+
19+
Storm_List = ['Baseline',
20+
'5',
21+
'10']
22+
23+
RSLR = ['IL',
24+
'I',#,
25+
'IH']
26+
27+
Base_Name_List = ['Geom_1',
28+
'Geom_3',
29+
'Geom_4',
30+
'Geom_5']
31+
32+
#Base_Name_List = ['Geom_1']
33+
34+
for Geometries in range(len(Base_Name_List)):
35+
Base_Name = Base_Name_List[Geometries]
36+
37+
if Base_Name == 'Geom_1':
38+
Cascade_Offset = 110
39+
if Base_Name == 'Geom_3':
40+
Cascade_Offset = 490
41+
if Base_Name == 'Geom_4':
42+
Cascade_Offset = 170
43+
if Base_Name == 'Geom_5':
44+
Cascade_Offset = 160
45+
for RSLR_Rates in range(len(RSLR)):
46+
for Storm_Mean_Intensities in range(len(Storm_List)):
47+
Save_Name = Base_Name+'_'+RSLR[RSLR_Rates]+'_'+Storm_List[Storm_Mean_Intensities]
48+
All_Runs_Shoreline_Location = []
49+
All_C_Values = []
50+
for S_Nums in range(0,50):
51+
# Load a specific Model Run
52+
if Base_Name == 'Geom_4':
53+
Load_Name = Base_Name+'_'+RSLR[RSLR_Rates]+'_'+Storm_List[Storm_Mean_Intensities]+'_S'+str(S_Nums)+'_New_Sink.npz'
54+
else:
55+
Load_Name = Base_Name+'_'+RSLR[RSLR_Rates]+'_'+Storm_List[Storm_Mean_Intensities]+'_S'+str(S_Nums)+'.npz'
56+
57+
58+
output = np.load(Load_Name, allow_pickle=True)
59+
cascade = output["cascade"]
60+
cascade = cascade[0]
61+
62+
bmft = cascade._bmft_coupler
63+
bmftc = bmft._bmftc[0]
64+
O_flux = bmftc.fluxes
65+
Forest_e = bmftc.Forest_edge
66+
Marsh_e = bmftc.Marsh_edge
67+
68+
initial_C = bmftc._marshOM_initial # kg's C accross entire platfrom
69+
initial_marsh_C_g = initial_C*1000
70+
71+
# Create initial C layer
72+
Initial_Marsh_Width = Forest_e[49] - Marsh_e[49]
73+
Per_m_Marsh_C_g = initial_marsh_C_g/Initial_Marsh_Width
74+
Initial_Transect_C_Value = np.zeros(len(bmftc.elevation[0]))
75+
76+
# Add initial C to marsh cells
77+
Initial_Transect_C_Value[int(Marsh_e[49]):int(Forest_e[49])] = Per_m_Marsh_C_g
78+
Total_C_Deposited_TS = [Initial_Transect_C_Value]
79+
80+
#Bmftc._BayOM[yr]
81+
82+
Shoreline_location_TS = cascade.brie.x_s_save
83+
All_Reletive_Shoreline = ((-Shoreline_location_TS+1624+Cascade_Offset)+Forest_e[49])[0]
84+
85+
86+
# Start Year = [50]
87+
Start_Year = 50
88+
End_Year = Start_Year+125
89+
90+
C_autoch = bmftc._organic_dep_autoch# Subtract eroded mass from depositional record
91+
C_alloch = bmftc._organic_dep_alloch
92+
93+
Total_Annual_C_Change = np.sum((C_alloch,C_autoch),axis=0)
94+
95+
for years in range(Start_Year,End_Year):
96+
# temp_sum = np.sum(Total_Annual_C_Change[Start_Year:years],axis=0)
97+
# marsh_accumulation = temp_sum[int(Marsh_e[years]):int(Forest_e[years])]
98+
# new_C_deposition_plus_C0 = np.sum((temp_sum,Initial_Transect_C_Value),axis=0)
99+
# new_C_deposition_plus_C0[new_C_deposition_plus_C0 < 0] = 0
100+
# Total_C_Deposited_TS.append(copy.deepcopy(new_C_deposition_plus_C0))
101+
temp_sum = np.sum(Total_Annual_C_Change[Start_Year:years], axis=0)
102+
marsh_accumulation = temp_sum[int(Marsh_e[years]):]
103+
temp_total_marsh_C_Change = np.zeros(len(temp_sum))
104+
temp_total_marsh_C_Change[int(Marsh_e[years]):] = marsh_accumulation
105+
new_C_deposition_plus_C0 = np.sum((temp_total_marsh_C_Change, Initial_Transect_C_Value), axis=0)
106+
new_C_deposition_plus_C0[new_C_deposition_plus_C0 < 0] = 0
107+
Total_C_Deposited_TS.append(copy.deepcopy(new_C_deposition_plus_C0))
108+
109+
All_Runs_Shoreline_Location.append(copy.deepcopy(All_Reletive_Shoreline))
110+
All_C_Values.append(copy.deepcopy(Total_C_Deposited_TS))
111+
print(Save_Name+'_S'+str(S_Nums)+' loaded')
112+
113+
Mean_Shoreline_Location = np.nanmean(All_Runs_Shoreline_Location, axis=0)
114+
Mean_C_Values = np.nanmean(All_C_Values, axis=0)
115+
116+
Full_Save_Path = Base_Save_Path+Save_Name
117+
# Save each of the arrays including mean and full values
118+
np.save(Full_Save_Path+'_Mean_C_Added_Marsh.npy',Mean_C_Values)
119+
np.save(Full_Save_Path+'_Mean_Shoreline_Location_Marsh.npy',Mean_Shoreline_Location)
120+
np.save(Full_Save_Path+'_All_Shoreline_Location_Marsh.npy',All_Runs_Shoreline_Location)
121+
np.save(Full_Save_Path+'_All_C_Added_Marsh.npy',All_C_Values)
122+
123+
x = 20

0 commit comments

Comments
 (0)