-
Notifications
You must be signed in to change notification settings - Fork 0
/
explore_NDVI_Biomass.py
263 lines (236 loc) · 11.5 KB
/
explore_NDVI_Biomass.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
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import funcs
fall2021 = pd.read_csv(r"D:\Etienne\PAPER_2023\explore_NDVI_biomass\DeltaX_Aboveground_Biomass_Necromass_Fall2021.csv",
encoding="unicode_escape")
spring2021 = pd.read_csv(r"D:\Etienne\PAPER_2023\explore_NDVI_biomass\DeltaX_Aboveground_Biomass_Necromass_Spring2021.csv",
encoding="unicode_escape")
df = pd.read_csv(r"D:\Etienne\fall2022\agu_data\results\AGU_dataset.csv", encoding="unicode_escape")
print("NDVI CRMS0399: ", df[df['Unnamed: 0'] == 'CRMS0399']['NDVI'])
print("NDVI CRMS0322: ", df[df['Unnamed: 0'] == 'CRMS0322']['NDVI'])
print("NDVI CRMS0399: ", df[df['Unnamed: 0'] == 'CRMS0294']['NDVI'])
print("NDVI CRMS0399: ", df[df['Unnamed: 0'] == 'CRMS0396']['NDVI'])
print("NDVI CRMS0399: ", df[df['Unnamed: 0'] == 'CRMS0421']['NDVI'])
# ndvi_df = {'NDVI': [df[df['Unnamed: 0'] == 'CRMS0399']['NDVI'],
# df[df['Unnamed: 0'] == 'CRMS0322']['NDVI'],
# df[df['Unnamed: 0'] == 'CRMS0294']['NDVI'],
# df[df['Unnamed: 0'] == 'CRMS0396']['NDVI'],
# df[df['Unnamed: 0'] == 'CRMS0421']['NDVI']]}
# ndvi_df = pd.DataFrame(ndvi_df)
# plt.plot(ndvi_df['NDVI'])
# plt.show()
#
# # test plots for fall2021 site CRMS0399 (Brackish to saline (from GEE map))
# sns.boxplot(data=fall2021[fall2021['site_id'] == 'CRMS0399'],
# x='species',
# y='total_dry_mass', hue='vegetation_class')
# plt.title('CRMS0399')
# plt.show()
# print("Total Mass:", fall2021[fall2021['site_id'] == 'CRMS0399']['total_dry_mass'].sum())
#
# # test plots for fall2021 site CRMS0322 (saline (from GEE map))
# sns.boxplot(data=fall2021[fall2021['site_id'] == 'CRMS0322'],
# x='species',
# y='total_dry_mass', hue='vegetation_class')
# plt.title('CRMS0322')
# plt.show()
# print("Total Mass:", fall2021[fall2021['site_id'] == 'CRMS0322']['total_dry_mass'].sum())
#
# # test plots for fall2021 site CRMS0322 (fresh (from GEE map))
# sns.boxplot(data=fall2021[fall2021['site_id'] == 'CRMS0294'],
# x='species',
# y='total_dry_mass', hue='vegetation_class')
# plt.title('CRMS0294')
# plt.show()
# print("Total Mass:", fall2021[fall2021['site_id'] == 'CRMS0294']['total_dry_mass'].sum())
#
# # test plots for fall2021 site CRMS0322 (intermediate (from GEE map))
# sns.boxplot(data=fall2021[fall2021['site_id'] == 'CRMS0396'],
# x='species',
# y='total_dry_mass', hue='vegetation_class')
# plt.title('CRMS0396')
# plt.show()
# print("Total Mass:", fall2021[fall2021['site_id'] == 'CRMS0396']['total_dry_mass'].sum())
#
# # test plots for fall2021 site CRMS0322 (strong saline (from GEE map))
# sns.boxplot(data=fall2021[fall2021['site_id'] == 'CRMS0421'],
# x='species',
# y='total_dry_mass', hue='vegetation_class')
# plt.title('CRMS0421')
# plt.show()
# print("Total Mass:", fall2021[fall2021['site_id'] == 'CRMS0421']['total_dry_mass'].sum())
#
#
# NEXT: Use the CRMS aboveground biomass dataset instead, ( easier to work with and more data etc )
# Then do an analysis to correlate teh NDVI to aboveground biomass of specific species...
agb = pd.read_csv(r"D:\Etienne\PAPER_2023\explore_NDVI_biomass\CRMS_Biomass\CRMS_Biomass.csv",
encoding="unicode_escape")
# fig, ax = plt.subplots(figsize=(20, 8))
# sns.boxplot(data=agb, x='Common Name as Currently Recognized',
# y='Total Plot Aboveground Live Biomass (g/m2)', showfliers=False)
# funcs.wrap_labels(ax, 5)
# plt.show()
#
# fig, ax = plt.subplots(figsize=(20, 8))
# sns.boxplot(data=agb, x='Common Name as Currently Recognized',
# y='Total Plot Aboveground Dead Biomass (g/m2)', showfliers=False)
# funcs.wrap_labels(ax, 5)
# plt.show()
#
# fig, ax = plt.subplots(figsize=(20, 8))
# sns.boxplot(data=agb, x='Common Name as Currently Recognized',
# y='Aboveground Live Biomass (g/m2)', showfliers=False)
# funcs.wrap_labels(ax, 5)
# plt.show()
#
# fig, ax = plt.subplots(figsize=(20, 8))
# sns.boxplot(data=agb, x='Common Name as Currently Recognized',
# y='Live stems (N)', showfliers=False)
# funcs.wrap_labels(ax, 5)
# plt.show()
#
# fig, ax = plt.subplots(figsize=(20, 8))
# sns.boxplot(data=agb, x='Common Name as Currently Recognized',
# y='Average Live Stem Diameter (mm)', showfliers=False)
# funcs.wrap_labels(ax, 5)
# plt.show()
## Combine the agb dataset with accretion to see how it relates
agb['Simple site'] = [i[:8] for i in agb['Station ID']]
agb_gb = agb.groupby("Simple site").agg({'Aboveground Live Biomass (g/m2)': 'mean',
'Common Name as Currently Recognized': lambda x: x.mode()})
agb_gb = agb_gb.dropna()
agb_gb['Common Name as Currently Recognized'] = [x[0] if type(x) != str else x for x in
agb_gb['Common Name as Currently Recognized']]
new = pd.concat([agb_gb, df.set_index("Unnamed: 0")], axis=1)
#
# # With new lets do some exploring
# fig, ax = plt.subplots(figsize=(10, 10))
# sns.scatterplot(data=new, x='NDVI', y='Accretion Rate (mm/yr)', hue='Common Name as Currently Recognized')
# plt.show()
#
# # fig, ax = plt.subplots(figsize=(20, 8))
# sns.scatterplot(data=new, x='NDVI', y='Aboveground Live Biomass (g/m2)', hue='Accretion Rate (mm/yr)')
# plt.show()
#
# fig, ax = plt.subplots(figsize=(8, 8))
# sns.scatterplot(data=new, x='NDVI', y='Aboveground Live Biomass (g/m2)', hue='Common Name as Currently Recognized')
# plt.show()
#
#
# fig, ax = plt.subplots(figsize=(8, 8))
# sns.scatterplot(data=new, x='NDVI', y='Aboveground Live Biomass (g/m2)', hue='Community')
# plt.show()
#
# fig, ax = plt.subplots(figsize=(8, 8))
# sns.scatterplot(data=new, hue='NDVI', y='Aboveground Live Biomass (g/m2)', x='Soil Porewater Salinity (ppt)')
# plt.show()
#
# # fig, ax = plt.subplots(figsize=(8, 8))
# plt.title("Saline Marsh: NDVI vs Above ground Biomass")
# sns.scatterplot(data=new[new['Community'] == 'Saline'], x='NDVI', y='Aboveground Live Biomass (g/m2)',
# hue='Common Name as Currently Recognized')
# plt.show()
#
# fig, ax = plt.subplots(figsize=(8, 8))
# sns.scatterplot(data=new[new['Community'] == 'Brackish'], x='NDVI', y='Aboveground Live Biomass (g/m2)',
# hue='Common Name as Currently Recognized')
# plt.show()
#
# fig, ax = plt.subplots(figsize=(8, 8))
# sns.scatterplot(data=new[new['Community'] == 'Intermediate'], x='NDVI', y='Aboveground Live Biomass (g/m2)',
# hue='Common Name as Currently Recognized')
# plt.show()
#
# fig, ax = plt.subplots(figsize=(8, 8))
# sns.scatterplot(data=new[new['Community'] == 'Freshwater'], x='NDVI', y='Aboveground Live Biomass (g/m2)',
# hue='Common Name as Currently Recognized')
# plt.show()
#
#
# fig, ax = plt.subplots(figsize=(8, 8))
# sns.scatterplot(data=new, y='NDVI', hue='Aboveground Live Biomass (g/m2)', x='Organic Matter (%)')
# plt.show()
# 1. There is no relationship between NDVI and Organic Matter in the soil
fig, ax = plt.subplots(figsize=(8, 6))
sns.scatterplot(ax=ax, data=new, y='NDVI', hue='Aboveground Live Biomass (g/m2)', x='Organic Matter (%)',
size='Aboveground Live Biomass (g/m2)')
ax.set_xlabel('Organic Matter (%)', fontsize=21)
ax.set_ylabel("NDVI", fontsize=21)
ax.tick_params(axis='both', which='major', labelsize=18)
plt.legend(fontsize=14, title='Aboveground Live Biomass (g/m2)', title_fontsize=18)
plt.show()
fig.savefig("D:\\Etienne\\PAPER_2023\\data_vis\\ndvi_org_scatterplot.eps",
dpi=300, format="eps")
# 2. Aboveground biomass seems to have a slight negative trend with NDVI for some reason
fig1, ax1 = plt.subplots(figsize=(8, 6))
sns.scatterplot(ax=ax1, data=new, y='NDVI', x='Aboveground Live Biomass (g/m2)', hue='Organic Matter (%)',
size='Organic Matter (%)')
ax1.set_xlabel('Aboveground Live Biomass (g/m2)', fontsize=21)
ax1.set_ylabel("NDVI", fontsize=21)
ax1.tick_params(axis='both', which='major', labelsize=18)
plt.legend(fontsize=14, title='Organic Matter (%)', title_fontsize=18)
plt.show()
fig1.savefig("D:\\Etienne\\PAPER_2023\\data_vis\\ndvi_biomass_scatterplot.eps",
dpi=300, format="eps")
# 3. Flooding influences the NDVI signiture / recording
# State that three might be a tidal range dependece of vegetation species that effects the NDVI signiture
fig2, ax2 = plt.subplots(figsize=(8, 6))
sns.scatterplot(data=new, x='90th Percentile Flood Depth (cm)', y='NDVI', hue='Tidal Amplitude (cm)',
size='Tidal Amplitude (cm)')
ax2.set_xlabel("90th Percentile Flood Depth (cm)", fontsize=21)
ax2.set_ylabel("NDVI", fontsize=21)
ax2.tick_params(axis='both', which='major', labelsize=18)
plt.legend(fontsize=14, title='Tidal Amplitude (cm)', title_fontsize=18)
plt.show()
fig2.savefig("D:\\Etienne\\PAPER_2023\\data_vis\\ndvi_flooddepth_tides_scatterplot.eps",
dpi=300, format="eps")
# State that this is not related to different flood inundation times because the highest inundations are on the
# shallower NDVI slope
fig3, ax3 = plt.subplots(figsize=(8, 6))
sns.scatterplot(data=df, x='90th Percentile Flood Depth (cm)', y='NDVI', hue='Avg. Time Flooded (%)',
size='Avg. Time Flooded (%)')
ax3.set_xlabel("90th Percentile Flood Depth (cm)", fontsize=21)
ax3.set_ylabel("NDVI", fontsize=21)
ax3.tick_params(axis='both', which='major', labelsize=18)
plt.legend(fontsize=14, title='Avg. Time Flooded (%)', title_fontsize=18)
plt.show()
fig3.savefig("D:\\Etienne\\PAPER_2023\\data_vis\\ndvi_flooddepth_floodtime_scatterplot.eps",
dpi=300, format="eps")
# State there are transitions across marsh communities (supporting vegetation species arg) in the stteper negative
# relationship
palette = {'Brackish': '#ADD8E6', 'Saline': '#032180', 'Intermediate': '#5DC069', 'Freshwater': '#006E0D'}
fig4, ax4 = plt.subplots(figsize=(8, 6))
sns.scatterplot(data=df, x='90th Percentile Flood Depth (cm)', y='NDVI', hue='Community',
palette=palette)
ax4.set_xlabel("90th Percentile Flood Depth (cm)", fontsize=21)
ax4.set_ylabel("NDVI", fontsize=21)
ax4.tick_params(axis='both', which='major', labelsize=18)
plt.legend(fontsize=14, title='Community', title_fontsize=18)
plt.show()
fig4.savefig("D:\\Etienne\\PAPER_2023\\data_vis\\ndvi_flooddepth_community_scatterplot.eps",
dpi=300, format="eps")
# State that accretion rate is highest where NDVI is highest and lowest
fig5, ax5 = plt.subplots(figsize=(8, 6))
sns.scatterplot(data=new, x='90th Percentile Flood Depth (cm)', y='NDVI', hue='Accretion Rate (mm/yr)',
size='Accretion Rate (mm/yr)')
ax5.set_xlabel("90th Percentile Flood Depth (cm)", fontsize=21)
ax5.set_ylabel("NDVI", fontsize=21)
ax5.tick_params(axis='both', which='major', labelsize=18)
plt.legend(fontsize=14, title='Accretion Rate (mm/yr)', title_fontsize=18)
plt.show()
fig5.savefig("D:\\Etienne\\PAPER_2023\\data_vis\\ndvi_flooddepth_accretion_scatterplot.eps",
dpi=300, format="eps")
# # State that maybe it is related to salinity gradient
fig2, ax2 = plt.subplots(figsize=(8, 6))
sns.scatterplot(data=new, x='90th Percentile Flood Depth (cm)', y='NDVI', hue='Soil Porewater Salinity (ppt)',
size='Soil Porewater Salinity (ppt)')
ax2.set_xlabel("90th Percentile Flood Depth (cm)", fontsize=21)
ax2.set_ylabel("NDVI", fontsize=21)
ax2.tick_params(axis='both', which='major', labelsize=18)
plt.legend(fontsize=14, title='Soil Porewater Salinity (ppt)', title_fontsize=18)
plt.show()
fig2.savefig("D:\\Etienne\\PAPER_2023\\data_vis\\ndvi_flooddepth_salinity_scatterplot.eps",
dpi=300, format="eps")
#