-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_vis_paper.py
308 lines (253 loc) · 12.2 KB
/
data_vis_paper.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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
import scipy
import seaborn as sns
from sklearn.metrics import r2_score
# This is the code used to create visualizations of the data. All file paths below are for my local computer, therefore,
# users who downloaded this from GitHub will not be able to see these.
df = pd.read_csv(r"D:\\Etienne\\fall2022\\agu_data\\results\\AGU_dataset.csv", encoding='unicode_escape')
plt.rcParams.update({'font.size': 16})
tides = np.asarray(df['Tidal Amplitude (cm)'])
flood90 = np.asarray(df['90th Percentile Flood Depth (cm)'])
avgFlood = np.asarray(df['Avg. Flood Depth (cm)'])
all_acc = np.asarray(df['Accretion Rate (mm/yr)'])
bulk = np.asarray(df['Bulk Density (g/cm3)'])
sally = np.asarray(df['Soil Porewater Salinity (ppt)'])
ndvi = np.asarray(df['NDVI'])
VEGE = np.asarray(df['Average Height Dominant (cm)'])
#### Some Plots and relationships for making distinguishing points in paper #####
# Check
slope1, intercept1, pearsons_r_value1, p_value1, std_err1 = scipy.stats.linregress(flood90, avgFlood)
#####
fig4, ax4 = plt.subplots(figsize=(8, 6))
scat4 = ax4.scatter(flood90, avgFlood)
m, b = np.polyfit(flood90, avgFlood, deg=1)
xseq = np.linspace(0, np.max(flood90), num=100)
ax4.plot(xseq, xseq*m + b, "k--", lw=2.5, label="{m}90th Percentile Flood Depth + {b}".format(b=round(b, 2), m=round(m, 2)))
# r-squared
predicted1 = flood90*m + b
score1 = r2_score(avgFlood, predicted1)
print(score1)
ax4.set_ylabel('Avg. Flood Depth (cm)')
ax4.set_xlabel('90th Percentile Flood Depth (cm)')
# plt.legend()
plt.show()
fig4.savefig("D:\\Etienne\\PAPER_2023\\data_vis\\avgFlood_90flood_scatterplot.eps",
dpi=300, format="eps")
#### Some Plots and relationships for making distinguishing points in paper #####
# Check
slope, intercept, pearsons_r_value, p_value, std_err = scipy.stats.linregress(flood90, tides)
#####
fig3, ax3 = plt.subplots(figsize=(8, 6))
scat3 = ax3.scatter(flood90, tides)
m, b = np.polyfit(flood90, tides, deg=1)
xseq = np.linspace(0, np.max(flood90), num=100)
ax3.plot(xseq, xseq*m + b, "k--", lw=2.5, label="{m}90th Percentile Flood Depth + {b}".format(b=round(b, 2), m=round(m, 2)))
# r-squared
from sklearn.metrics import r2_score
predicted = flood90*m + b
score = r2_score(tides, predicted)
print(score)
ax3.set_ylabel('Tidal Amplitude (cm)')
ax3.set_xlabel('90th Percentile Flood Depth (cm)')
# plt.legend()
plt.show()
fig3.savefig("D:\\Etienne\\PAPER_2023\\data_vis\\tide_90flood_scatterplot.eps",
dpi=300, format="eps")
######################################################################################
fig1, ax1 = plt.subplots(figsize=(8, 6))
scat = ax1.scatter(tides, all_acc, c=bulk, cmap="rocket_r", s=50*10**bulk)
cbar = fig1.colorbar(scat, ticks=[np.min(bulk), np.max(bulk)])
cbar.ax.set_yticklabels([round(np.min(bulk), 2), round(np.max(bulk), 2)])# vertically oriented colorbar
cbar.ax.get_yaxis().labelpad = 10
cbar.set_label('Bulk Density (g/cm3)', rotation=270)
m, b = np.polyfit(tides, all_acc, deg=1)
xseq = np.linspace(0, np.max(tides), num=100)
ax1.plot(xseq, xseq*m + b, "k--", lw=2.5, label="{m}Tide Amp + {b}".format(b=round(b, 2), m=round(m, 2)))
ax1.set_ylabel('Accretion Rate (mm/yr)')
ax1.set_xlabel('Tidal Amplitude (cm)')
plt.legend()
plt.show()
fig1.savefig("D:\\Etienne\\PAPER_2023\\data_vis\\tides_accretion_scatterplot.eps",
dpi=300, format="eps")
# NDVI versus salinity
fig2, ax2 = plt.subplots(figsize=(8, 6))
scat = ax2.scatter(ndvi, sally, c=all_acc, cmap="rocket_r", s=5*all_acc)
cbar = fig2.colorbar(scat, ticks=[np.min(all_acc), np.max(all_acc)])
cbar.ax.set_yticklabels([round(np.min(all_acc), 2), round(np.max(all_acc), 2)])# vertically oriented colorbar
cbar.ax.get_yaxis().labelpad = 10
cbar.set_label('Accretion Rate (mm/yr)', rotation=270)
m, b = np.polyfit(ndvi, sally, deg=1)
xseq = np.linspace(0, np.max(ndvi), num=100)
ax2.plot(xseq, xseq*m + b, "k--", lw=2.5, label="{m} Soil Porewater Salinity + {b}".format(b=round(b, 2), m=round(m, 2)))
ax2.set_ylabel('NDVI')
ax2.set_xlabel('Soil Porewater Salinity (ppt)')
plt.legend()
plt.show()
fig2.savefig("D:\\Etienne\\PAPER_2023\\data_vis\\ndvi_salinity_scatterplot.eps",
dpi=300, format="eps")
## NDVI, Salinity, and Average height of the dominant
fig2, ax2 = plt.subplots(figsize=(8, 6))
scat = ax2.scatter(ndvi, sally, c=VEGE, cmap="rocket_r", s=VEGE**2)
cbar = fig2.colorbar(scat, ticks=[np.min(VEGE), np.max(VEGE)])
cbar.ax.set_yticklabels([round(np.min(VEGE), 2), round(np.max(VEGE), 2)])# vertically oriented colorbar
cbar.ax.get_yaxis().labelpad = 10
cbar.set_label('Average Height Dominant (cm)', rotation=270)
m, b = np.polyfit(ndvi, sally, deg=1)
xseq = np.linspace(0, np.max(ndvi), num=100)
ax2.plot(xseq, xseq*m + b, "k--", lw=2.5, label="{m} Soil Porewater Salinity + {b}".format(b=round(b, 2), m=round(m, 2)))
ax2.set_ylabel('NDVI')
ax2.set_xlabel('Soil Porewater Salinity (ppt)')
plt.legend()
plt.show()
fig2.savefig("D:\\Etienne\\PAPER_2023\\data_vis\\ndvi_salinity_VEGE_scatterplot.eps",
dpi=300, format="eps")
# Show that TSS comliments the interpretation that position in tidal frame is related to Suspended Sediment delivery
tss = np.asarray(df['TSS (mg/l)'])
fig2, ax2 = plt.subplots(figsize=(8, 6))
scat2 = ax2.scatter(tss, all_acc, c=bulk, cmap="rocket_r", s=50*10**bulk)
cbar = fig2.colorbar(scat2, ticks=[np.min(bulk), np.max(bulk)])
cbar.ax.set_yticklabels([round(np.min(bulk), 2), round(np.max(bulk), 2)])# vertically oriented colorbar
cbar.ax.get_yaxis().labelpad = 10
cbar.set_label('Bulk Density (g/cm3)', rotation=270)
m, b = np.polyfit(tss, all_acc, deg=1)
xseq = np.linspace(0, np.max(tss), num=100)
ax2.plot(xseq, xseq*m + b, "k--", lw=2.5, label="{m}TSS + {b}".format(b=round(b, 2), m=round(m, 2)))
ax2.set_ylabel('Accretion Rate (mm/yr)')
ax2.set_xlabel('TSS (mg/l)')
plt.legend()
plt.show()
fig2.savefig("D:\\Etienne\\PAPER_2023\\data_vis\\tss_accretion_scatterplot.eps",
dpi=300, format="eps")
# Part 2. NDVI Looking specifically at difference between Freshwater + Intermediate and Saline Marshes
# Say that there is a clear difference between ndvi in saline marsh and fresh-inter marshes
for_part2 = df[(df['Community'] == 'Saline') | (df['Community'] == 'Freshwater') | (df['Community'] == 'Intermediate')]
sns.set_theme(style='white', font_scale=1.4)
f = plt.figure(figsize=(8, 6))
ax = f.add_subplot(1, 1, 1)
sns.histplot(ax=ax, stat="count", multiple="stack", bins=30,
x=for_part2['NDVI'], kde=False,
hue=for_part2["Community"], palette=["Red", "Orange", "Purple"],
element="bars", legend=True)
ax.set_title("Distribution of NDVI")
ax.set_xlabel("NDVI")
ax.set_ylabel("Count")
f.subplots_adjust(bottom=0.2)
plt.show()
f.savefig("D:\\Etienne\\PAPER_2023\\data_vis\\ndvi_histogram.eps",
dpi=300, format="eps")
# say there is a clear difference in the salinity between saline and fresh-inter marshes
sns.set_theme(style='white', font_scale=1.4)
f = plt.figure(figsize=(8, 6))
ax = f.add_subplot(1, 1, 1)
sns.histplot(ax=ax, stat="count", multiple="stack", bins=30,
x=for_part2['Soil Porewater Salinity (ppt)'], kde=False,
hue=for_part2["Community"], palette=["Red", "Orange", "Purple"],
element="bars", legend=True)
ax.set_title("Distribution of Soil Porewater Salinity (ppt)")
ax.set_xlabel('Soil Porewater Salinity (ppt)')
ax.set_ylabel("Count")
f.subplots_adjust(bottom=0.2)
plt.show()
f.savefig("D:\\Etienne\\PAPER_2023\\data_vis\\salinity_histogram.eps",
dpi=300, format="eps")
# Show interesting relationship with NDVI and accretion and say that it is related to difference in flooding regimes
flooding = np.asarray(for_part2['Avg. Flood Depth (cm)'])
ndvi = np.asarray(for_part2['NDVI'])
part2_acc = np.asarray(for_part2['Accretion Rate (mm/yr)'])
fig2, ax2 = plt.subplots(figsize=(8, 6))
scat2 = ax2.scatter(ndvi, part2_acc, c=flooding, cmap="rocket_r", s=5*flooding)
cbar = fig2.colorbar(scat2, ticks=[np.min(flooding), np.max(flooding)])
cbar.ax.set_yticklabels([round(np.min(flooding), 2), round(np.max(flooding), 2)])# vertically oriented colorbar
cbar.ax.get_yaxis().labelpad = 10
cbar.set_label('Avg. Flood Depth (cm)', rotation=270)
ax2.set_ylabel('Accretion Rate (mm/yr)')
ax2.set_xlabel('NDVI')
# plt.legend()
plt.show()
fig2.savefig("D:\\Etienne\\PAPER_2023\\data_vis\\ndvi_accretion_scatterplot.eps",
dpi=300, format="eps")
# Say that this is likely due to the salinity flooding brings
salinity = np.asarray(for_part2['Soil Porewater Salinity (ppt)'])
#### Add a plot so that they are on the same scale
fig2, ax2 = plt.subplots(figsize=(8, 6))
scat2 = ax2.scatter(salinity, part2_acc, c=flooding, cmap="rocket_r", s=5*flooding)
cbar = fig2.colorbar(scat2, ticks=[np.min(flooding), np.max(flooding)])
cbar.ax.set_yticklabels([round(np.min(flooding), 2), round(np.max(flooding), 2)])# vertically oriented colorbar
cbar.ax.get_yaxis().labelpad = 20
cbar.set_label('Avg. Flood Depth (cm)', rotation=270)
ax2.set_ylabel('Distribution of Soil Porewater (ppt)')
ax2.set_xlabel('Soil Porewater Salinity (ppt)')
# plt.legend()
plt.show()
fig2.savefig("D:\\Etienne\\PAPER_2023\\data_vis\\salinity_floodDepth_scatterplot.eps",
dpi=300, format="eps")
##### Showing transitions across marsh gradients
# Tidal: Describes the oceanic influences on the ecosystem and flooding regime (saline versus fresh)
sns.set_theme(style='white', font_scale=1.4)
f = plt.figure(figsize=(8, 6))
ax = f.add_subplot(1, 1, 1)
sns.histplot(ax=ax, stat="count", multiple="stack", bins=30,
x=for_part2['Tidal Amplitude (cm)'], kde=False,
hue=for_part2["Community"], palette=["Red", "Orange", "Purple"],
element="bars", legend=True)
ax.set_title("Distribution of Tidal Amplitude (cm)")
ax.set_xlabel('Tidal Amplitude (cm)')
ax.set_ylabel("Count")
f.subplots_adjust(bottom=0.2)
plt.show()
f.savefig("D:\\Etienne\\PAPER_2023\\data_vis\\tides_histogram.eps",
dpi=300, format="eps")
# Salinity and NDVI: defines the vegetation type and colonization (both are provided above)
#################### MARSH GRADIENTS FOR ALL DATA POINTS
sns.set_theme(style='white', font_scale=1.4)
f = plt.figure(figsize=(8, 6))
ax = f.add_subplot(1, 1, 1)
sns.histplot(ax=ax, stat="count", multiple="stack", bins=30,
x=df['Tidal Amplitude (cm)'], kde=False,
hue=df["Community"], palette=['#ADD8E6', '#032180', '#5DC069', '#006E0D'],
element="bars", legend=True)
ax.set_title("Distribution of Tidal Amplitude (cm)", fontsize=24)
ax.set_xlabel('Tidal Amplitude (cm)', fontsize=21)
ax.set_ylabel("Count", fontsize=21)
ax.tick_params(axis='both', which='major', labelsize=18)
f.legend(fontsize=21)
f.subplots_adjust(bottom=0.2)
plt.show()
f.savefig("D:\\Etienne\\PAPER_2023\\data_vis\\allmarshes_tides_histogram.eps",
dpi=300, format="eps")
## For salinity gradients
sns.set_theme(style='white', font_scale=1.4)
f = plt.figure(figsize=(8, 6))
ax = f.add_subplot(1, 1, 1)
sns.histplot(ax=ax, stat="count", multiple="stack", bins=30,
x=df['Soil Porewater Salinity (ppt)'], kde=False,
hue=df["Community"], palette=['#ADD8E6', '#032180', '#5DC069', '#006E0D'],
element="bars", legend=True)
ax.set_title("Distribution of Soil Porewater Salinity (ppt)", fontsize=24)
ax.set_xlabel('Soil Porewater Salinity (ppt)', fontsize=21)
ax.set_ylabel("Count", fontsize=21)
ax.tick_params(axis='both', which='major', labelsize=18)
f.legend(fontsize=21)
f.subplots_adjust(bottom=0.2)
plt.show()
f.savefig("D:\\Etienne\\PAPER_2023\\data_vis\\allmarshes_salinity_histogram.eps",
dpi=300, format="eps")
# For NDVI gradient
sns.set_theme(style='white', font_scale=1.4)
f = plt.figure(figsize=(8, 6))
ax = f.add_subplot(1, 1, 1)
sns.histplot(ax=ax, stat="count", multiple="stack", bins=30,
x=df['NDVI'], kde=False,
hue=df["Community"], palette=['#ADD8E6', '#032180', '#5DC069', '#006E0D'],
element="bars", legend=True)
ax.set_title("Distribution of NDVI", fontsize=24)
ax.set_xlabel("NDVI", fontsize=21)
ax.set_ylabel("Count", fontsize=21)
ax.tick_params(axis='both', which='major', labelsize=18)
f.legend(fontsize=21)
f.subplots_adjust(bottom=0.2)
plt.show()
f.savefig("D:\\Etienne\\PAPER_2023\\data_vis\\allmarshes_ndvi_histogram.eps",
dpi=300, format="eps")