-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot_Obs_forecast_BA_1984_2020_SWEImod_PCA_HigherPeakSWE.m
236 lines (208 loc) · 8.94 KB
/
plot_Obs_forecast_BA_1984_2020_SWEImod_PCA_HigherPeakSWE.m
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
clc;clear all;close all
%% Plot data from the best GAMs (BurnArea_GAM_NLDAS_Forecasting_Ziter_validation.R)
%from BurnArea_GAM_NLDAS_Forecasting_Ziter_bestmod_select2.R we determined
%that GAMs with 10 predictors outperform those with less (in general)
%% load in data:
Good_mods = readtable('/Volumes/Pruina_External_Elements/DroughtFireSnow/Data/AnlysisData/Best_Obs_Forecast_outputs/BAs_1984_2020_Obs_Good_Mods_SWEImod_PCA_higherPeakSWE.csv');
Good_mods = table2array(Good_mods);
nmods = length(Good_mods);
years = 1984:2020;
nbins = 3; %3 Z bins x 4 regions:
WYs = repmat(1984:2020,1,nbins);
%% fit
%initialize annual prediction and standard error data:
store_predictions=[];
store_se =[];
for i=1:nmods
mod_id = Good_mods(i);
%get current prediction
infilename=sprintf('/Volumes/Pruina_External_Elements/DroughtFireSnow/Data/AnlysisData/Best_Obs_Forecast_outputs/BAs_1984_2020_Obs_Forecast_GAM_Zbins_mod%d_SWEImod_PCA_higherPeakSWE.csv',mod_id);
current_mod_data = readtable(infilename);
current_mod_data = table2array(current_mod_data);
%aggregate to annual_data:
[u,~,j] = unique(WYs);
Annual_BA_predict = accumarray(j,current_mod_data(:,3),[],@sum);
Annual_BA_obs = accumarray(j,current_mod_data(:,1),[],@sum);
%constrain predicted BA to 0
idx = find(Annual_BA_predict<0);
Annual_BA_predict(idx)=0;
store_predictions = [store_predictions,Annual_BA_predict];
%record the standard error along with predition
infilename=sprintf('/Volumes/Pruina_External_Elements/DroughtFireSnow/Data/AnlysisData/Best_Obs_Forecast_outputs/BAs_1984_2020_Obs_Forecast_SE_Zbins_mod%d_SWEImod_PCA_higherPeakSWE.csv',mod_id);
se = readtable(infilename);
se = table2array(se);
store_se = [store_se,se];
end
Annual_BA_obs = [Annual_BA_obs];
ensemble_mean = median(store_predictions')';
ensemble_mean_bestfit = ensemble_mean;
%ensemble_mean = store_predictions;
se = max(store_se')';
%record ensemble upper and lower bounds based on se from gam predictions:
ensemble_upr = prctile(store_predictions',97.5)';
ensemble_lwr = prctile(store_predictions',2.5)';
%% plot data:
lb=ensemble_mean-ensemble_lwr;
ub=ensemble_upr-ensemble_mean;
idx = find(ensemble_mean - lb < 0);
lb(idx) = ensemble_mean(idx);
f=figure;
hold on
shadedErrorBar(years, ensemble_mean, [ub';lb'], 'k-',1);
p1=plot(years, ensemble_mean,'-k','linewidth',3);
%include trend line:
p=polyfit(years,ensemble_mean,1);
y = @(x) p(1)*x + p(2);
plot(years,y(years),'--k','linewidth',2)
p2 = plot(years,Annual_BA_obs,'-r','linewidth',3);
%include trend line:
p=polyfit(years,Annual_BA_obs,1);
y = @(x) p(1)*x + p(2);
plot(years,y(years),'--r','linewidth',2)
legend([p1 p2],{'Predicted','Observed'},'fontsize',25,'location','northwest')
ylabel('Burned area (millions of acres)','fontsize',25)
set(gca,'fontsize',25)
xlim([min(years) max(years)])
f.Position =[1 313 1440 492];
grid on
xticks([1984:2:2020])
xtickangle(45)
box on
ylim([0 4])
saveas(f,'/Users/abolafia/Drought_Fire_Snow/Plots/BA_predict_1984_2020_Obs_GAM_timeseries_SWEImod_PCA_higherPeakSWE_fit.eps','epsc')
%scatter plot:
f=figure;
hold on
cmap = flipud(hot(37));
colormap(cmap)
sz = 250;
c=1984:2020;
p1=scatter(Annual_BA_obs,ensemble_mean,sz,c,'filled',...
'MarkerFaceAlpha',1,'MarkerEdgeAlpha',1,'MarkerEdgeColor','k');
%include 1:1 line
plot(linspace(0,6,10),linspace(0,6,10),'--k','linewidth',4)
%format:
set(gca,'fontsize',25)
xlabel('Observed Burned Area (millions of acres)','fontsize',25)
ylabel('Predicted Burned Area (millions of acres)','fontsize',25)
% title('1984 - 2020 Fire Season Burned Area','fontsize',25)
set(gca,'fontsize',25)
%R and RMSE
R = corr(Annual_BA_obs,ensemble_mean,'rows','complete')
RMSE = sqrt( mean((Annual_BA_obs-ensemble_mean).^2) )
%percent of time +/- anomalies are correctly predicted:
Annual_BA_obs_anom = Annual_BA_obs - mean(Annual_BA_obs);
ensemble_mean_anom = ensemble_mean - mean(ensemble_mean);
idx=find( (Annual_BA_obs_anom>0 & ensemble_mean_anom>0) | (Annual_BA_obs_anom<0 & ensemble_mean_anom<0) | (Annual_BA_obs_anom==0 & ensemble_mean_anom==0));
sprintf('correct anomaly sign predicted %.2f percent of the time',length(idx)/length(ensemble_mean_anom)*100)
xlim([0 4])
ylim([0 4])
c = colorbar;
c.Ticks = 1984:2:2020;
grid on
f.Position = [139 58 887 746];
saveas(f,'/Users/abolafia/Drought_Fire_Snow/Plots/BA_predict_1984_2020_Obs_GAM_scatter_SWEImod_PCA_higherPeakSWE_fit.eps','epsc')
%% Drop1 results
%initialize annual prediction and standard error data:
store_predictions=[];
store_se =[];
for i=1:nmods
mod_id = Good_mods(i);
%get current prediction
infilename=sprintf('/Volumes/Pruina_External_Elements/DroughtFireSnow/Data/AnlysisData/Best_Obs_Forecast_outputs/BAs_1984_2020_Obs_Forecast_GAM_Zbins_mod%d_SWEImod_PCA_higherPeakSWE.csv',mod_id);
current_mod_data = readtable(infilename);
current_mod_data = table2array(current_mod_data);
%aggregate to annual_data:
[u,~,j] = unique(WYs);
Annual_BA_predict = accumarray(j,current_mod_data(:,2),[],@sum);
Annual_BA_obs = accumarray(j,current_mod_data(:,1),[],@sum);
%constrain predicted BA to 0
idx = find(Annual_BA_predict<0);
Annual_BA_predict(idx)=0;
store_predictions = [store_predictions,Annual_BA_predict];
%record the standard error along with predition
infilename=sprintf('/Volumes/Pruina_External_Elements/DroughtFireSnow/Data/AnlysisData/Best_Obs_Forecast_outputs/BAs_1984_2020_Obs_Forecast_SE_Zbins_mod%d_SWEImod_PCA_higherPeakSWE.csv',mod_id);
se = readtable(infilename);
se = table2array(se);
store_se = [store_se,se];
end
Annual_BA_obs = [Annual_BA_obs];
ensemble_mean = median(store_predictions')';
ensemble_mean_drop1 = ensemble_mean;
%ensemble_mean = store_predictions;
se = max(store_se')';
%record ensemble upper and lower bounds based on se from gam predictions:
ensemble_upr = prctile(store_predictions',97.5)';
ensemble_lwr = prctile(store_predictions',2.5)';
%% plot data:
lb=ensemble_mean-ensemble_lwr;
ub=ensemble_upr-ensemble_mean;
idx = find(ensemble_mean - lb < 0);
lb(idx) = ensemble_mean(idx);
f=figure;
hold on
shadedErrorBar(years, ensemble_mean, [ub';lb'], 'k-',1);
p1=plot(years, ensemble_mean,'-k','linewidth',3);
%compute trend line (including 2020):
p=polyfit(years(1:end),ensemble_mean(1:end),1);
y = @(x) p(1)*x + p(2);
sprintf('drop1 prediction increasing trend (including 2020): %.2f/year',p(1)/mean(ensemble_mean(1:end))*100)
%include trend line (excluding 2020):
p=polyfit(years(1:end-1),ensemble_mean(1:end-1),1);
y = @(x) p(1)*x + p(2);
plot(years(1:end-1),y(years(1:end-1)),'--k','linewidth',2)
sprintf('drop1 prediction increasing trend (excluding 2020): %.2f/year',p(1)/mean(ensemble_mean(1:end-1))*100)
p2 = plot(years,Annual_BA_obs,'-r','linewidth',3);
%compute trend line (including 2020):
p=polyfit(years(1:end),Annual_BA_obs(1:end),1);
y = @(x) p(1)*x + p(2);
sprintf('obs increasing trend: %.2f/year (including 2020)',p(1)/mean(Annual_BA_obs)*100)
%include trend line (excluding 2020):
p=polyfit(years(1:end-1),Annual_BA_obs(1:end-1),1);
y = @(x) p(1)*x + p(2);
plot(years(1:end-1),y(years(1:end-1)),'--r','linewidth',2)
sprintf('obs increasing trend: %.2f/year (excluding 2020)',p(1)/mean(Annual_BA_obs(1:end-1))*100)
legend([p1 p2],{'Predicted','Observed'},'fontsize',25,'location','northwest')
ylabel('Burned area (millions of acres)','fontsize',25)
set(gca,'fontsize',25)
xlim([min(years) max(years)])
f.Position =[1 313 1440 492];
grid on
xticks([1984:2:2020])
xtickangle(45)
box on
ylim([0 4])
saveas(f,'/Users/abolafia/Drought_Fire_Snow/Plots/BA_predict_1984_2020_Obs_GAM_timeseries_SWEImod_PCA_higherPeakSWE_drop1.eps','epsc')
%scatter plot:
f=figure;
hold on
cmap = flipud(hot(37));
colormap(cmap)
sz = 250;
c=1984:2020;
p1=scatter(Annual_BA_obs,ensemble_mean,sz,c,'filled',...
'MarkerFaceAlpha',1,'MarkerEdgeAlpha',1,'MarkerEdgeColor','k');
%include 1:1 line
plot(linspace(0,6,10),linspace(0,6,10),'--k','linewidth',4)
%format:
set(gca,'fontsize',25)
xlabel('Observed Burned Area (millions of acres)','fontsize',25)
ylabel('Predicted Burned Area (millions of acres)','fontsize',25)
% title('1984 - 2020 Fire Season Burned Area','fontsize',25)
set(gca,'fontsize',25)
%R and RMSE
R = corr(Annual_BA_obs,ensemble_mean,'rows','complete')
RMSE = sqrt( mean((Annual_BA_obs-ensemble_mean).^2) )
PBIAS = mean( ((ensemble_mean-Annual_BA_obs)./mean(Annual_BA_obs)) ) * 100;
%percent of time +/- anomalies are correctly predicted:
Annual_BA_obs_anom = Annual_BA_obs - mean(Annual_BA_obs);
ensemble_mean_anom = ensemble_mean - mean(ensemble_mean);
idx=find( (Annual_BA_obs_anom>0 & ensemble_mean_anom>0) | (Annual_BA_obs_anom<0 & ensemble_mean_anom<0) | (Annual_BA_obs_anom==0 & ensemble_mean_anom==0));
sprintf('correct anomaly sign predicted %.2f percent of the time',length(idx)/length(ensemble_mean_anom)*100)
xlim([0 4])
ylim([0 4])
c = colorbar;
c.Ticks = 1984:2:2020;
grid on
f.Position = [139 58 887 746];
saveas(f,'/Users/abolafia/Drought_Fire_Snow/Plots/BA_predict_1984_2020_Obs_GAM_scatter_SWEImod_PCA_higherPeakSWE_drop1.eps','epsc')