-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun_bmftc.py
235 lines (191 loc) · 8.01 KB
/
run_bmftc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
"""----------------------------------------------------------------------
PyBMFT-C: Bay-Marsh-Forest Transect Carbon Model (Python version)
Last updated _25 April 2022_ by _IRB Reeves_
----------------------------------------------------------------------"""
import time
import numpy as np
import matplotlib.pyplot as plt
import warnings
from bmftc import Bmftc
warnings.filterwarnings("ignore")
# ==================================================================================================================================================================================
# Create an instance of the BMI class
bmftc = Bmftc(
name="PyBMFT-C",
time_step_count=125,
relative_sea_level_rise=8,
reference_concentration=50,
slope_upland=0.005,
bay_fetch_initial=5000,
wind_speed=6,
seagrass_on=False,
forest_on=True,
# filename_equilbaydepth="Input/PyBMFT-C/EquilibriumBayDepth_f3000_w5.mat",
filename_equilbaydepth="Input/PyBMFT-C/Equilibrium Bay Depth.mat",
# filename_marshspinup="Input/PyBMFT-C/MarshStrat_all_RSLR1_CO50_width500.mat",
filename_marshspinup="Input/PyBMFT-C/MarshStrat_all_RSLR1_CO50.mat",
marsh_width_initial=1000
)
# ==================================================================================================================================================================================
# Run the PyBMFT-C model
# Initialize in-run figure plotting
fig1 = plt.figure()
ax1 = fig1.add_subplot(2, 2, 1)
plt.xlabel("Distance [m]")
plt.ylabel("Organic Deposition Autoch [g]")
ax2 = fig1.add_subplot(2, 2, 3)
plt.xlabel("Distance [m]")
plt.ylabel("Mineral Deposition [g]")
ax3 = fig1.add_subplot(2, 2, 4)
plt.xlabel("Distance [m]")
plt.ylabel("Elevation [m]")
ax4 = fig1.add_subplot(2, 2, 2)
plt.xlabel("Distance [m]")
plt.ylabel("Organic Deposition Alloch [g]")
# Record start time
Time = time.time()
print(bmftc.name)
# Loop through time
for time_step in range(int(bmftc.dur)):
# Print time step to screen
print("\r", "Time Step: ", time_step, end="")
# Run time step
bmftc.update()
# Plot each time step
if time_step % 5 == 0:
ax1.plot(bmftc.organic_dep_autoch[bmftc.startyear + time_step, bmftc.x_m: bmftc.x_f + 1], label=str(time_step))
ax2.plot(bmftc.mineral_dep[bmftc.startyear + time_step, bmftc.x_m: bmftc.x_f + 1], label=str(time_step))
ax3.plot(bmftc.elevation[bmftc.startyear + time_step, bmftc.x_m: bmftc.x_f + 1], label=str(time_step))
ax4.plot(bmftc.organic_dep_alloch[bmftc.startyear + time_step, bmftc.x_m: bmftc.x_f + 1], label=str(time_step))
# Print elapsed time of simulation
print()
SimDuration = time.time() - Time
print()
print("Elapsed Time: ", SimDuration, "sec")
# ==================================================================================================================================================================================
# Sum Major Fluxes and Output Variables for Analysis
# Organic matter deposited in the marsh over the past 30 years [g]
organic_dep_last30yrs = bmftc.organic_dep_autoch[bmftc.endyear - 31: bmftc.endyear, bmftc.x_m: bmftc.x_f + 1] + bmftc.organic_dep_alloch[bmftc.endyear - 31: bmftc.endyear, bmftc.x_m: bmftc.x_f + 1]
# Mineral matter deposited in the marsh over the past 30 years [g]
mineral_dep_last30yrs = bmftc.mineral_dep[bmftc.endyear - 31: bmftc.endyear, bmftc.x_m: bmftc.x_f + 1]
# # Percent organic matter [%]
loi_last30yrs = organic_dep_last30yrs / (organic_dep_last30yrs + mineral_dep_last30yrs) * 100
# Organic carbon content (%) from Craft et al (1991)
OCP_last30yrs = 0.4 * loi_last30yrs + 0.0025 * loi_last30yrs ** 2
# Organic Carbon deposited in the marsh over the past 30 years [g]
OC_last30yrs = OCP_last30yrs / 100 * (organic_dep_last30yrs + mineral_dep_last30yrs)
# Average Organic Carbon accumulation rate over the last 30 years [g C / m2 / yr]
OC_avg_last30yrs = np.mean(OC_last30yrs, axis=1)
# Total mass of organic matter in the marsh at the end of the simulation [kg]
marshOM_final = np.sum(np.sum(bmftc.organic_dep_autoch[:, bmftc.x_m: bmftc.x_f + 1]) + np.sum(np.sum(bmftc.organic_dep_alloch[:, bmftc.x_m: bmftc.x_f + 1]))) / 1000
# Total mass of mineral matter in the marsh at the end of the simulation [kg]
marshMM_final = np.sum(np.sum(bmftc.mineral_dep[:, bmftc.x_m: bmftc.x_f + 1])) / 1000
# Average loi of the marsh across the marsh platform at the end of the simulation [%]
marshLOI_final = marshOM_final / (marshOM_final + marshMM_final) * 100
# Organic carbon content (%) from Craft et al (1991)
marshOCP_final = 0.4 * marshLOI_final + 0.0025 * marshLOI_final ** 2
# Mass of organic carbon stored in the marsh at the end of the simulation [kg]
marshOC_final = marshOCP_final / 100 * (marshOM_final + marshMM_final)
# ==================================================================================================================================================================================
# Plot
# plt.figure()
# plt.plot(organic_dep_last30yrs)
# plt.xlabel("Year (previous 30)")
# plt.ylabel("Organic Deposition [g]")
# plt.figure()
# plt.plot(mineral_dep_last30yrs)
# plt.xlabel("Year (previous 30)")
# plt.ylabel("Mineral Deposition [g]")
# plt.figure()
# plt.plot(bmftc.organic_dep_autoch[bmftc.endyear - 30: bmftc.endyear + 1, bmftc.x_m: bmftc.x_f + 1])
# plt.xlabel("Distance")
# plt.ylabel("Organic Deposition Autoch [g]")
# plt.figure()
# plt.plot(bmftc.organic_dep_alloch[bmftc.endyear - 30: bmftc.endyear + 1, bmftc.x_m: bmftc.x_f + 1])
# plt.xlabel("Distance")
# plt.ylabel("Organic Deposition Alloch [g]")
plt.figure()
for t in range(bmftc.startyear, bmftc.endyear, 10):
plt.plot(bmftc.elevation[t, :])
plt.xlabel("Distance")
plt.ylabel("Elevation [m MSL]")
plt.title(bmftc.name)
# # Seagrass: bay depth and shoot density
# plt.figure()
# fig = plt.gcf()
# fig.set_size_inches(12, 14)
# plt.rcParams.update({"font.size": 8})
#
# plt.subplot(3,1,1)
# plt.plot(bmftc.Bay_depth[bmftc.startyear:] * -1)
# plt.xlabel("Year")
# plt.ylabel("Bay Depth [m MSL]")
#
# plt.subplot(3,1,2)
# plt.plot(bmftc.seagrass[bmftc.startyear: , 1])
# plt.xlabel("Year")
# plt.ylabel("Shoot Density [shoots/m^2]")
#
# plt.subplot(3,1,3)
# plt.plot(bmftc.Marsh_edge[bmftc.startyear:])
# plt.xlabel("Year")
# plt.ylabel("Marsh Edge Location [m cross-shore]")
# ===========
plt.figure()
fig = plt.gcf()
fig.set_size_inches(7, 15)
plt.subplot(4, 1, 1)
plt.plot(bmftc.OCb[bmftc.startyear: bmftc.endyear + 1])
plt.xlabel("Time [yr]")
plt.ylabel("Bay Org Cont")
plt.subplot(4, 1, 2)
plt.plot(bmftc.BaySedDensity[:bmftc.endyear + 1])
plt.xlabel("Time [yr]")
plt.ylabel("Bay Sed Dens (rhob)")
plt.subplot(4, 1, 3)
plt.plot(bmftc.rhomt[:bmftc.endyear + 1])
plt.xlabel("Time [yr]")
plt.ylabel("Mar Edg Dens (rhom)")
plt.subplot(4, 1, 4)
plt.plot(bmftc.Bay_depth[bmftc.startyear: bmftc.endyear + 1])
plt.xlabel("Time [yr]")
plt.ylabel("Bay Depth")
# ===========
plt.figure()
fig = plt.gcf()
fig.set_size_inches(12, 8)
plt.rcParams.update({"font.size": 8})
# Fe_min
plt.subplot(2, 4, 1)
plt.plot(bmftc.fluxes[0, bmftc.startyear: bmftc.endyear + 1])
plt.ylabel("Fe_min: marsh to bay")
# Fe_org
plt.subplot(2, 4, 2)
plt.plot(bmftc.fluxes[1, bmftc.startyear: bmftc.endyear + 1])
plt.ylabel("Fe_org: marsh to bay")
# Fm_min
plt.subplot(2, 4, 3)
plt.plot(bmftc.fluxes[2, bmftc.startyear: bmftc.endyear + 1])
plt.ylabel("Fm_min: bay to marsh")
# Fm_org
plt.subplot(2, 4, 4)
plt.plot(bmftc.fluxes[3, bmftc.startyear: bmftc.endyear + 1])
plt.ylabel("Fm_org: bay to marsh")
# Fc_min
plt.subplot(2, 4, 5)
plt.plot(bmftc.fluxes[4, bmftc.startyear: bmftc.endyear + 1])
plt.ylabel("Fc_min: external to bay")
# Fc_org
plt.subplot(2, 4, 6)
plt.plot(bmftc.fluxes[5, bmftc.startyear: bmftc.endyear + 1])
plt.ylabel("Fc_org: external to bay")
# Fb_min
plt.subplot(2, 4, 7)
plt.plot(bmftc.fluxes[6, bmftc.startyear: bmftc.endyear + 1])
plt.ylabel("Fb_min: net flux into bay")
# Fb_org
plt.subplot(2, 4, 8)
plt.plot(bmftc.fluxes[7, bmftc.startyear: bmftc.endyear + 1])
plt.ylabel("Fb_org: net flux into bay")
plt.tight_layout()
plt.show()