-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGPIdecomp_barCharts_Bootstrapped.m
513 lines (464 loc) · 26.3 KB
/
GPIdecomp_barCharts_Bootstrapped.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
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
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
% Create bar chart for GPI term contributions to full GPI, as plotted in
% map form on the AMS poster and most of my talks.
%
% 2019-03-05
%% Read in lat/lon from extra file
% testFile = '/Users/meganfowler/gp_fuse/TC/GPI_daily/Bootstrap_testResults/GPI_DailyGPIvars_MJOphase_1-OMI_iBoot1.nc';
%
% lon = ncread(testFile,'lon');
% lat = ncread(testFile,'lat');
%
% iJune = 152; %Day of year that June starts
% iNov = 334; %Day of year that November ends
% %
% %
% % %% Read in GPI variables and carry out decomposition
% % %GPIdir = '/Volumes/MyPassport/Data/TCs/GPI/ERA-I/';
% % %GPIdir = '/Users/meganfowler/gp_fuse/TC/GPI_daily/Bootstrap_testResults/';
% GPIdir = '/Users/meganfowler/gp_fuse/TC/GPI_daily/Bootstrap_testResults/';
% %
% % %% Test section
% % % GPIdir = '/Volumes/MyPassport/Data/TCs/GPI/ERA-I/GPI_DailyGPIvars_MJOphase1.nc'; %Old file
% % % %newDir = '/Users/meganfowler/gp_fuse/TC/GPI_daily/Bootstrap_testResults/GPI_DailyGPIvars_MJOphase_1-OMI_iBoot1.nc'; %Bootstrapped file
% % % newDir = '~/Desktop/GPI_DailyGPIvars_MJOphase_1-OMI_iBoot1.nc'; %Bootstrapped file
% % %
% % %
% % % oldLon = ncread(GPIdir,'lon');
% % % oldLat = ncread(GPIdir,'lat');
% % % ilon = find(oldLon>=60 & oldLon<=200);
% % % ilat = find(oldLat>-5 & oldLat<40);
% % %
% % % var_old = ncread(GPIdir,'GPI'); %[lon lat time]
% % % var_new = ncread(newDir,'GPI'); %[lon lat time]
% % % var_old(var_old<=-32767) = NaN;
% % % var_new(var_new<=-32767) = NaN;
% % %
% % % diffVars = squeeze((var_new(:,:,iJune)-var_old(ilon,ilat,iJune)));
% % % diffPct = diffVars./squeeze(var_old(ilon,ilat,iJune));
% % %
% % % figure;
% % % contourf(lon,lat,isfinite(diffPct)','linecolor','none')
% % % hold on;
% % % plot(coast.long, coast.lat, 'k', coast.long+360, coast.lat, 'k');
% % % axis([50 210 0 45]);
% % % colorbar()
% % % title('Diff (%) GPI')
% % %
% % %
% % %
% % %
% % % % Big differences showing up in potential intensity, which uses SST, SLP,
% % % % and P,T,R profiles.
% % % newFile = '/Users/meganfowler/gp_fuse/TC/GPI_daily/Bootstrap_DailyGPIvariables/DailyGPIvars_MJOphase_1-OMI_iBoot1.nc';
% % % newFile2 = '/Users/meganfowler/gp_fuse/TC/GPI_daily/Bootstrap_DailyGPIvariables/DailyGPIvars_MJOphase_1-OMI_iBoot2.nc';
% % % oldFile = '/Users/meganfowler/gp_fuse/TC/GPI_daily/DailyGPIvars_MJOphase1.nc';
% % %
% % % var_old = ncread(oldFile,'SST'); %[lon lat time]
% % % var_new = ncread(newFile,'SST'); %[lon lat time]
% % % var_new2 = ncread(newFile2,'SST');
% % %
% % % diffVars = squeeze((var_new(iJune,:,:,1)-var_old(iJune,ilon,ilat,1)));
% % % diffPct = diffVars./squeeze(var_old(iJune,ilon,ilat,1));
% % %
% % % figure;
% % % contourf(lon,lat,diffPct','linecolor','none')
% % % hold on;
% % % plot(coast.long, coast.lat, 'k', coast.long+360, coast.lat, 'k');
% % % axis([50 210 0 45]);
% % % colorbar()
% % % title('Diff (%) in V (level=1)')
% %
% %
% %% Define GPI "climatology" as average of all 8 phases
% nBoot = 2;
%
% GPI_mjo = NaN(nBoot,numel(lon),numel(lat),iNov-iJune+1,8); %Original GPI for mjo phases
% termsMJO = NaN(nBoot,numel(lon),numel(lat),iNov-iJune+1,4,8);
%
% for iBoot=1:nBoot
% tic
% for iPhase=1:8
% MJOfile = [GPIdir,'GPI_DailyGPIvars_MJOphase_',num2str(iPhase),'-OMI_iBoot',num2str(iBoot),'.nc']; %OMI index
% %MJOfile = [GPIdir,'GPI_DailyGPIvars_MJOphase',num2str(iPhase),'.nc']; %OMI index
%
% absVort_mjo = ncread(MJOfile,'ABSVORT'); %[lon lat time]
% RH700_mjo = ncread(MJOfile,'RELHUM');
% Vmax_mjo = ncread(MJOfile,'VMAX');
% Vshear_mjo = ncread(MJOfile,'VSHEAR');
% tempGPI_mjo = ncread(MJOfile,'GPI');
% GPI_mjo(iBoot,:,:,:,iPhase) = tempGPI_mjo(:,:,iJune:iNov);
%
% absVort_mjo(absVort_mjo<=-32767) = NaN;
% RH700_mjo(RH700_mjo<=-32767) = NaN;
% Vmax_mjo(Vmax_mjo<=-32767) = NaN;
% Vshear_mjo(Vshear_mjo<=-32767) = NaN;
% GPI_mjo(GPI_mjo<=-32767) = NaN;
%
% term1_mjo = abs((10^5) * absVort_mjo).^(3/2);
% term2_mjo = (RH700_mjo / 50).^3;
% term3_mjo = (Vmax_mjo / 70).^3;
% term4_mjo = (1 + (0.1*Vshear_mjo)).^-2;
%
%
% %Make land mask using term 3 (potential intensity term)
% mask = double(isfinite(term3_mjo));
% mask(mask==0) = NaN;
%
% term1_mjo = term1_mjo.*mask;
% term2_mjo = term2_mjo.*mask;
% term3_mjo = term3_mjo.*mask; %Unnecessary but consistent
% term4_mjo = term4_mjo.*mask;
%
% termsMJO(iBoot,:,:,:,1,iPhase) = term1_mjo(:,:,iJune:iNov);
% termsMJO(iBoot,:,:,:,2,iPhase) = term2_mjo(:,:,iJune:iNov);
% termsMJO(iBoot,:,:,:,3,iPhase) = term3_mjo(:,:,iJune:iNov);
% termsMJO(iBoot,:,:,:,4,iPhase) = term4_mjo(:,:,iJune:iNov);
% end
% fprintf('Done with bootstrap %i \n',iBoot);
% toc
% end
%
%
% %Take average of all the terms, and then use that average to compute GPI
% termsClim = squeeze(nanmean(termsMJO,6)); %Average over phases
%
% % GPI_clim = termsClim(:,:,:,1).*termsClim(:,:,:,2).*termsClim(:,:,:,3).*termsClim(:,:,:,4);
% % GPIratio = (termsMJO(:,:,:,1,1)./termsClim(:,:,:,1)).*...
% % (termsMJO(:,:,iJune:iNov,2,1)./termsClim(:,:,iJune:iNov,2)).*...
% % (termsMJO(:,:,iJune:iNov,3,1)./termsClim(:,:,iJune:iNov,3)).*...
% % (termsMJO(:,:,iJune:iNov,4,1)./termsClim(:,:,iJune:iNov,4));
% %
% %% Start testing out log-ifying
%
% %Get difference for each phase from climo average
% climSeasonal = squeeze(nanmean(termsClim(:,:,:,:,:),4));
%
% for iPhase=1:8
% iCount=1;
% for iDay=1:(iNov-iJune+1)
% diffTerm(:,:,:,iCount,:,iPhase) = squeeze(termsMJO(:,:,:,iDay,:,iPhase))-climSeasonal(:,:,:,:);
% iCount = iCount+1;
% end
% end
%
% %As in eq. 5 of Zhao and Li (2018), define coefficients as product of mean
% % terms not being changed in a given equation
% alpha1 = termsClim(:,:,:,:,2).*termsClim(:,:,:,:,3).*termsClim(:,:,:,:,4);
% alpha2 = termsClim(:,:,:,:,1).*termsClim(:,:,:,:,3).*termsClim(:,:,:,:,4);
% alpha3 = termsClim(:,:,:,:,1).*termsClim(:,:,:,:,2).*termsClim(:,:,:,:,4);
% alpha4 = termsClim(:,:,:,:,1).*termsClim(:,:,:,:,2).*termsClim(:,:,:,:,3);
%
% %Use sum to get at full GPI in each phase of the MJO
% for iPhase=1:8
% dGPI_phs(:,:,:,:,iPhase) = (alpha1.*squeeze(diffTerm(:,:,:,:,1,iPhase))) + (alpha2.*squeeze(diffTerm(:,:,:,:,2,iPhase))) + ...
% (alpha3.*squeeze(diffTerm(:,:,:,:,3,iPhase))) + (alpha4.*squeeze(diffTerm(:,:,:,:,4,iPhase)));
% end
%
% %Get regional averages of each term
% lonsLeft = [100,120,130,140,160];
% lonsRight = [120,130,140,160,180];
% ilats = find(lat>=5 & lat<=20);
%
% fprintf('Now at line 153 - getting averages for each term/bootstrap/region/phase');
%
% for iBoot=1:nBoot
% for iPhase=1:8
% for iReg=1:5
% ilons = find(lon>=lonsLeft(iReg) & lon<lonsRight(iReg));
%
% dGPI_avg(iBoot,iPhase,iReg) = nanmean(nanmean(nanmean(dGPI_phs(iBoot,ilons,ilats,:,iPhase))));
% term1_avg(iBoot,iPhase,iReg) = nanmean(nanmean(nanmean((squeeze(alpha1(iBoot,ilons,ilats,:)).*squeeze(diffTerm(iBoot,ilons,ilats,:,1,iPhase))))));
% term2_avg(iBoot,iPhase,iReg) = nanmean(nanmean(nanmean((squeeze(alpha2(iBoot,ilons,ilats,:)).*squeeze(diffTerm(iBoot,ilons,ilats,:,2,iPhase))))));
% term3_avg(iBoot,iPhase,iReg) = nanmean(nanmean(nanmean((squeeze(alpha3(iBoot,ilons,ilats,:)).*squeeze(diffTerm(iBoot,ilons,ilats,:,3,iPhase))))));
% term4_avg(iBoot,iPhase,iReg) = nanmean(nanmean(nanmean((squeeze(alpha4(iBoot,ilons,ilats,:)).*squeeze(diffTerm(iBoot,ilons,ilats,:,4,iPhase))))));
%
% clearvars ilons
% end
% end
% end
%Quick check that the map still looks reasonable for fullGPI phase 1:
% contourf(lon,lat,nanmean(dGPI_phs(:,:,:,1),3)',-4:0.04:4,'linecolor','none');
%% Try plotting
%
% iGPI = 1;
% c = categorical({'100?-120?','120?-130?','130?-140?','140?-160?','160?-180?'});
%
% phs1 = [term1_avg(iGPI,1),term2_avg(iGPI,1),term3_avg(iGPI,1),term4_avg(iGPI,1),dGPI_avg(iGPI,1);...
% term1_avg(iGPI,2),term2_avg(iGPI,2),term3_avg(iGPI,2),term4_avg(iGPI,2),dGPI_avg(iGPI,2);...
% term1_avg(iGPI,3),term2_avg(iGPI,3),term3_avg(iGPI,3),term4_avg(iGPI,3),dGPI_avg(iGPI,3);...
% term1_avg(iGPI,4),term2_avg(iGPI,4),term3_avg(iGPI,4),term4_avg(iGPI,4),dGPI_avg(iGPI,4);...
% term1_avg(iGPI,5),term2_avg(iGPI,5),term3_avg(iGPI,5),term4_avg(iGPI,5),dGPI_avg(iGPI,5)];
%
% figure;
% bar(c,phs1);
% legend({'Vorticity','Humidity','Potential Intensity','Shear','fullGPI'},'location','northwest');
% xlabel('Region','fontsize',20)
% title('Phase 1','fontsize',20);
% ax = gca;
% ax.FontSize = 16;
%
% % MOVE INTO FOR LOOP %
% figure;
% c = categorical({'100?-120?','120?-130?','130?-140?','140?-160?','160?-180?'});
%
% for iGPI=1:8
% phsRegions = [term1_avg(iGPI,1),term2_avg(iGPI,1),term3_avg(iGPI,1),term4_avg(iGPI,1),dGPI_avg(iGPI,1);...
% term1_avg(iGPI,2),term2_avg(iGPI,2),term3_avg(iGPI,2),term4_avg(iGPI,2),dGPI_avg(iGPI,2);...
% term1_avg(iGPI,3),term2_avg(iGPI,3),term3_avg(iGPI,3),term4_avg(iGPI,3),dGPI_avg(iGPI,3);...
% term1_avg(iGPI,4),term2_avg(iGPI,4),term3_avg(iGPI,4),term4_avg(iGPI,4),dGPI_avg(iGPI,4);...
% term1_avg(iGPI,5),term2_avg(iGPI,5),term3_avg(iGPI,5),term4_avg(iGPI,5),dGPI_avg(iGPI,5)];
%
% figure;
% %Only add x-axis regions if bottom plot
% if iGPI<8
% bar(phsRegions);
% ax = gca;
% ax.FontSize = 14;
% title(['Phase ',num2str(iGPI)],'fontsize',16);
% elseif iGPI==8
% bar(c,phsRegions);
% xlabel('Region','FontSize',16)
% title(['Phase ',num2str(iGPI)],'fontsize',16);
% ax = gca;
% ax.FontSize = 14;
% end
%
% %Only add legend to top plot
% if iGPI==1
% legend({'Vorticity','Humidity','Potential Intensity','Shear','fullGPI'},'location','northwest');
% end
%
%
% clearvars phsRegions
% %print(['~/Desktop/TestBarChart_Phs',num2str(iGPI),'.pdf'],'-dpdf','-bestfit')
% end
%% Try plotting the mean based on the bootsrap with error bars
%Took too long to bus between pritchnode and local, so copied over this
% code to /fast/mdfowler and ran it on the group node - super fast. Saved
% out termX_avg and dGPI_avg and nBoot.
load('/Users/meganfowler/gp_fuse/TC/GPI_daily/bootstrap_scripts/BootstrappedGPIterms_100_5to20lat.mat');
term1_avgBootstraps = squeeze(nanmean(term1_avg,1));
term2_avgBootstraps = squeeze(nanmean(term2_avg,1));
term3_avgBootstraps = squeeze(nanmean(term3_avg,1));
term4_avgBootstraps = squeeze(nanmean(term4_avg,1));
dGPI_avgBootstraps = squeeze(nanmean(dGPI_avg,1));
% stdErr_term1 = squeeze(nanstd(term1_avg))/sqrt(nBoot-1);
% stdErr_term2 = squeeze(nanstd(term2_avg))/sqrt(nBoot-1);
% stdErr_term3 = squeeze(nanstd(term3_avg))/sqrt(nBoot-1);
% stdErr_term4 = squeeze(nanstd(term4_avg))/sqrt(nBoot-1);
% stdErr_dGPI = squeeze(nanstd(dGPI_avg))/sqrt(nBoot-1);
term1_pctile = prctile(term1_avg,[25,75],1);
term2_pctile = prctile(term2_avg,[25,75],1);
term3_pctile = prctile(term3_avg,[25,75],1);
term4_pctile = prctile(term4_avg,[25,75],1);
dGPI_pctile = prctile(dGPI_avg,[25,75],1);
%% Line plot?
% figure;
% errorbar(1:8,dGPI_avgBootstraps(:,1),dGPI_pctile(1,:,1), dGPI_pctile(2,:,1),'red','LineWidth',.75)
% hold on
% errorbar(1:8,dGPI_avgBootstraps(:,2),dGPI_pctile(1,:,2), dGPI_pctile(2,:,2),'Color',[0.9290 0.6940 0.1250],'LineWidth',.75)
% errorbar(1:8,dGPI_avgBootstraps(:,3),dGPI_pctile(1,:,3), dGPI_pctile(2,:,3),'Color',[0.4660 0.6740 0.1880],'LineWidth',.75)
% errorbar(1:8,dGPI_avgBootstraps(:,4),dGPI_pctile(1,:,4), dGPI_pctile(2,:,4),'Color',[0 0.4470 0.7410],'LineWidth',.75)
% errorbar(1:8,dGPI_avgBootstraps(:,5),dGPI_pctile(1,:,5), dGPI_pctile(2,:,5),'Color',[0.4940 0.1840 0.5560],'LineWidth',.75)
% legend('100?-120?','120?-130?','130?-140?','140?-160?','160?-180?')
% %Plot thicker main line
% plot(1:8, dGPI_avgBootstraps(:,1), 'red','LineWidth',2,'HandleVisibility','off');
% plot(1:8, dGPI_avgBootstraps(:,2), 'Color',[0.9290 0.6940 0.1250],'LineWidth',2,'HandleVisibility','off');
% plot(1:8, dGPI_avgBootstraps(:,3), 'Color',[0.4660 0.6740 0.1880],'LineWidth',2,'HandleVisibility','off');
% plot(1:8, dGPI_avgBootstraps(:,4), 'Color',[0 0.4470 0.7410],'LineWidth',2,'HandleVisibility','off');
% plot(1:8, dGPI_avgBootstraps(:,5), 'Color',[0.4940 0.1840 0.5560],'LineWidth',2,'HandleVisibility','off');
% %Plot options
% plot([0.5,8.5],[0 0],'k-','HandleVisibility','off') %Plot solid black line at 0
% title('GPI progression','FontSize',20)
% xlabel('MJO Phase','FontSize',16);
% ylabel('GPI anomaly','FontSize',16);
% xlim([0.5 8.5])
%% Bar chart with just GPI?
figure;
regionLabels = {'100?-120?','120?-130?','130?-140?','140?-160?','160?-180?'};
%Plot bars and change colors
hBar = bar(1:8,dGPI_avgBootstraps,'FaceColor','flat');
legend(regionLabels,'fontsize',16)
hBar(1).CData = [1 0 0];
hBar(2).CData = [0.9290 0.6940 0.1250];
hBar(3).CData = [0.4660 0.6740 0.1880];
hBar(4).CData = [0 0.4470 0.7410];
hBar(5).CData = [0.4940 0.1840 0.5560];
%Add error bars
for k1=1:5
ctr(k1,:) = bsxfun(@plus, hBar(1).XData, [hBar(k1).XOffset]');
ydt(k1,:) = hBar(k1).YData;
%hBar(k1).CData = k1;
end
hold on;
errorbar(ctr',ydt',squeeze(dGPI_pctile(1,:,:)),squeeze(dGPI_pctile(2,:,:)),'Color',[0.4,0.4,0.4],'linestyle','none','LineWidth',.75,'HandleVisibility','off')
%Plot options
title('GPI progression', 'fontsize',24);
ylabel('GPI anomaly', 'fontsize',20);
xlabel('MJO Phase (OMI)', 'fontsize',20);
ax=gca;
ax.FontSize=16;
%Add lines to separate phases
plot([1.5 1.5], ylim,'Color',0.5*ones(1,3),'HandleVisibility','off')
plot([2.5 2.5], ylim,'Color',0.5*ones(1,3),'HandleVisibility','off')
plot([3.5 3.5], ylim,'Color',0.5*ones(1,3),'HandleVisibility','off')
plot([4.5 4.5], ylim,'Color',0.5*ones(1,3),'HandleVisibility','off')
plot([5.5 5.5], ylim,'Color',0.5*ones(1,3),'HandleVisibility','off')
plot([6.5 6.5], ylim,'Color',0.5*ones(1,3),'HandleVisibility','off')
plot([7.5 7.5], ylim,'Color',0.5*ones(1,3),'HandleVisibility','off')
%Add smooth curves for regions 1 and 5
cs = spline(ctr(1,:),[0 ydt(1,:) 0]); %Region 1
xx = linspace(0,8.5,101);
plot(xx,ppval(cs,xx),'r-','linewidth',2,'HandleVisibility','off');
cs = spline(ctr(5,:),[0 ydt(5,:) 0]); %Region 1
xx = linspace(0,8.5,101);
plot(xx,ppval(cs,xx),'Color',[0.4940 0.1840 0.5560],'linewidth',2,'HandleVisibility','off');
xlim([0.5 8.5])
fig = gcf;
fig.PaperPositionMode = 'auto';
%print('~/Desktop/TestBarChart_withInterquartileErrBar','-depsc')
print('/Users/meganfowler/Documents/Irvine/TCs/Figures/GPI-BarChart_WithRegionalCurves','-depsc');
%% Figure with rows as regions instead of phases (more readable?)
figure;
c = categorical({'Phase 1', 'Phase 2', 'Phase 3', 'Phase 4', 'Phase 5', 'Phase 6', 'Phase 7', 'Phase 8'});
regionLabels = {'100?-120?','120?-130?','130?-140?','140?-160?','160?-180?'};
for iGPI=1:5
phsRegions = [term1_avgBootstraps(1,iGPI),term2_avgBootstraps(1,iGPI),term3_avgBootstraps(1,iGPI),term4_avgBootstraps(1,iGPI),dGPI_avgBootstraps(1,iGPI);...
term1_avgBootstraps(2,iGPI),term2_avgBootstraps(2,iGPI),term3_avgBootstraps(2,iGPI),term4_avgBootstraps(2,iGPI),dGPI_avgBootstraps(2,iGPI);...
term1_avgBootstraps(3,iGPI),term2_avgBootstraps(3,iGPI),term3_avgBootstraps(3,iGPI),term4_avgBootstraps(3,iGPI),dGPI_avgBootstraps(3,iGPI);...
term1_avgBootstraps(4,iGPI),term2_avgBootstraps(4,iGPI),term3_avgBootstraps(4,iGPI),term4_avgBootstraps(4,iGPI),dGPI_avgBootstraps(4,iGPI);...
term1_avgBootstraps(5,iGPI),term2_avgBootstraps(5,iGPI),term3_avgBootstraps(5,iGPI),term4_avgBootstraps(5,iGPI),dGPI_avgBootstraps(5,iGPI);...
term1_avgBootstraps(6,iGPI),term2_avgBootstraps(6,iGPI),term3_avgBootstraps(6,iGPI),term4_avgBootstraps(6,iGPI),dGPI_avgBootstraps(6,iGPI);...
term1_avgBootstraps(7,iGPI),term2_avgBootstraps(7,iGPI),term3_avgBootstraps(7,iGPI),term4_avgBootstraps(7,iGPI),dGPI_avgBootstraps(7,iGPI);...
term1_avgBootstraps(8,iGPI),term2_avgBootstraps(8,iGPI),term3_avgBootstraps(8,iGPI),term4_avgBootstraps(8,iGPI),dGPI_avgBootstraps(8,iGPI)];
errHigh = [term1_pctile(2,1,iGPI),term2_pctile(2,1,iGPI),term3_pctile(2,1,iGPI),term4_pctile(2,1,iGPI),dGPI_pctile(2,1,iGPI);...
term1_pctile(2,2,iGPI),term2_pctile(2,2,iGPI),term3_pctile(2,2,iGPI),term4_pctile(2,2,iGPI),dGPI_pctile(2,2,iGPI);...
term1_pctile(2,3,iGPI),term2_pctile(2,3,iGPI),term3_pctile(2,3,iGPI),term4_pctile(2,3,iGPI),dGPI_pctile(2,3,iGPI);...
term1_pctile(2,4,iGPI),term2_pctile(2,4,iGPI),term3_pctile(2,4,iGPI),term4_pctile(2,4,iGPI),dGPI_pctile(2,4,iGPI);...
term1_pctile(2,5,iGPI),term2_pctile(2,5,iGPI),term3_pctile(2,5,iGPI),term4_pctile(2,5,iGPI),dGPI_pctile(2,5,iGPI);...
term1_pctile(2,6,iGPI),term2_pctile(2,6,iGPI),term3_pctile(2,6,iGPI),term4_pctile(2,6,iGPI),dGPI_pctile(2,6,iGPI);...
term1_pctile(2,7,iGPI),term2_pctile(2,7,iGPI),term3_pctile(2,7,iGPI),term4_pctile(2,7,iGPI),dGPI_pctile(2,7,iGPI);...
term1_pctile(2,8,iGPI),term2_pctile(2,8,iGPI),term3_pctile(2,8,iGPI),term4_pctile(2,8,iGPI),dGPI_pctile(2,8,iGPI)];
errLow = [term1_pctile(1,1,iGPI),term2_pctile(1,1,iGPI),term3_pctile(1,1,iGPI),term4_pctile(1,1,iGPI),dGPI_pctile(1,1,iGPI);...
term1_pctile(1,2,iGPI),term2_pctile(1,2,iGPI),term3_pctile(1,2,iGPI),term4_pctile(1,2,iGPI),dGPI_pctile(1,2,iGPI);...
term1_pctile(1,3,iGPI),term2_pctile(1,3,iGPI),term3_pctile(1,3,iGPI),term4_pctile(1,3,iGPI),dGPI_pctile(1,3,iGPI);...
term1_pctile(1,4,iGPI),term2_pctile(1,4,iGPI),term3_pctile(1,4,iGPI),term4_pctile(1,4,iGPI),dGPI_pctile(1,4,iGPI);...
term1_pctile(1,5,iGPI),term2_pctile(1,5,iGPI),term3_pctile(1,5,iGPI),term4_pctile(1,5,iGPI),dGPI_pctile(1,5,iGPI);...
term1_pctile(1,6,iGPI),term2_pctile(1,6,iGPI),term3_pctile(1,6,iGPI),term4_pctile(1,6,iGPI),dGPI_pctile(1,6,iGPI);...
term1_pctile(1,7,iGPI),term2_pctile(1,7,iGPI),term3_pctile(1,7,iGPI),term4_pctile(1,7,iGPI),dGPI_pctile(1,7,iGPI);...
term1_pctile(1,8,iGPI),term2_pctile(1,8,iGPI),term3_pctile(1,8,iGPI),term4_pctile(1,8,iGPI),dGPI_pctile(1,8,iGPI)];
% errRegions = [stdErr_term1(1,iGPI),stdErr_term2(1,iGPI),stdErr_term3(1,iGPI),stdErr_term4(1,iGPI),stdErr_dGPI(1,iGPI);...
% stdErr_term1(2,iGPI),stdErr_term2(2,iGPI),stdErr_term3(2,iGPI),stdErr_term4(2,iGPI),stdErr_dGPI(2,iGPI);...
% stdErr_term1(3,iGPI),stdErr_term2(3,iGPI),stdErr_term3(3,iGPI),stdErr_term4(3,iGPI),stdErr_dGPI(3,iGPI);...
% stdErr_term1(4,iGPI),stdErr_term2(4,iGPI),stdErr_term3(4,iGPI),stdErr_term4(4,iGPI),stdErr_dGPI(4,iGPI);...
% stdErr_term1(5,iGPI),stdErr_term2(5,iGPI),stdErr_term3(5,iGPI),stdErr_term4(5,iGPI),stdErr_dGPI(5,iGPI);...
% stdErr_term1(6,iGPI),stdErr_term2(6,iGPI),stdErr_term3(6,iGPI),stdErr_term4(6,iGPI),stdErr_dGPI(6,iGPI);...
% stdErr_term1(7,iGPI),stdErr_term2(7,iGPI),stdErr_term3(7,iGPI),stdErr_term4(7,iGPI),stdErr_dGPI(7,iGPI);...
% stdErr_term1(8,iGPI),stdErr_term2(8,iGPI),stdErr_term3(8,iGPI),stdErr_term4(8,iGPI),stdErr_dGPI(8,iGPI)];
%Only add x-axis regions if bottom plot
subplot(3,2,iGPI)
ctrs = 1:8;
hBar = bar(ctrs,phsRegions,1);
for k1=1:size(phsRegions,2)
ctr(k1,:) = bsxfun(@plus, hBar(1).XData, [hBar(k1).XOffset]');
ydt(k1,:) = hBar(k1).YData;
end
hold on
%errorbar(ctr',ydt',2.*errRegions,'k','linestyle','none','LineWidth',1)
errorbar(ctr',ydt',errLow,errHigh,'Color',[0.4,0.4,0.4],'linestyle','none','LineWidth',.75)
ylim([-3, 3]);
xlabel('MJO Phase [OMI]','FontSize',16)
title(['Region: ',regionLabels{iGPI}],'fontsize',16);
ax = gca;
ax.FontSize = 14;
%Add lines to separate phases
plot([1.5 1.5], ylim,'Color',0.5*ones(1,3),'HandleVisibility','off')
plot([2.5 2.5], ylim,'Color',0.5*ones(1,3),'HandleVisibility','off')
plot([3.5 3.5], ylim,'Color',0.5*ones(1,3),'HandleVisibility','off')
plot([4.5 4.5], ylim,'Color',0.5*ones(1,3),'HandleVisibility','off')
plot([5.5 5.5], ylim,'Color',0.5*ones(1,3),'HandleVisibility','off')
plot([6.5 6.5], ylim,'Color',0.5*ones(1,3),'HandleVisibility','off')
plot([7.5 7.5], ylim,'Color',0.5*ones(1,3),'HandleVisibility','off')
%Only add legend to top plot
if iGPI==5
legend({'Vorticity','Humidity','Potential Intensity','Shear','fullGPI'},'location','southeast','fontsize',10);
end
clearvars phsRegions
%print(['~/Desktop/TestBarChart_Phs',num2str(iGPI),'.pdf'],'-dpdf','-bestfit')
end
fig = gcf;
fig.PaperPositionMode = 'auto';
%print('~/Desktop/TestBarChart_withInterquartileErrBar','-depsc')
print('/Users/meganfowler/Documents/Irvine/TCs/Figures/GPI-BarChart_noMap_5to20lat&landMask','-depsc');
%
% % % fig.PaperUnits = 'inches';
% % % fig.PaperPosition=[0 0 8 12];
% % % print('5by3DimensionsFigure','-dpng','-r0')
%% Plot regions 1 and 5 in separate figures and add curves for terms
figure;
c = categorical({'Phase 1', 'Phase 2', 'Phase 3', 'Phase 4', 'Phase 5', 'Phase 6', 'Phase 7', 'Phase 8'});
regionLabels = {'100?-120?','120?-130?','130?-140?','140?-160?','160?-180?'};
iGPI = 5; %Set region to region 1
%Extract region and phase specific data
phsRegions = [term1_avgBootstraps(1,iGPI),term2_avgBootstraps(1,iGPI),term3_avgBootstraps(1,iGPI),term4_avgBootstraps(1,iGPI),dGPI_avgBootstraps(1,iGPI);...
term1_avgBootstraps(2,iGPI),term2_avgBootstraps(2,iGPI),term3_avgBootstraps(2,iGPI),term4_avgBootstraps(2,iGPI),dGPI_avgBootstraps(2,iGPI);...
term1_avgBootstraps(3,iGPI),term2_avgBootstraps(3,iGPI),term3_avgBootstraps(3,iGPI),term4_avgBootstraps(3,iGPI),dGPI_avgBootstraps(3,iGPI);...
term1_avgBootstraps(4,iGPI),term2_avgBootstraps(4,iGPI),term3_avgBootstraps(4,iGPI),term4_avgBootstraps(4,iGPI),dGPI_avgBootstraps(4,iGPI);...
term1_avgBootstraps(5,iGPI),term2_avgBootstraps(5,iGPI),term3_avgBootstraps(5,iGPI),term4_avgBootstraps(5,iGPI),dGPI_avgBootstraps(5,iGPI);...
term1_avgBootstraps(6,iGPI),term2_avgBootstraps(6,iGPI),term3_avgBootstraps(6,iGPI),term4_avgBootstraps(6,iGPI),dGPI_avgBootstraps(6,iGPI);...
term1_avgBootstraps(7,iGPI),term2_avgBootstraps(7,iGPI),term3_avgBootstraps(7,iGPI),term4_avgBootstraps(7,iGPI),dGPI_avgBootstraps(7,iGPI);...
term1_avgBootstraps(8,iGPI),term2_avgBootstraps(8,iGPI),term3_avgBootstraps(8,iGPI),term4_avgBootstraps(8,iGPI),dGPI_avgBootstraps(8,iGPI)];
errHigh = [term1_pctile(2,1,iGPI),term2_pctile(2,1,iGPI),term3_pctile(2,1,iGPI),term4_pctile(2,1,iGPI),dGPI_pctile(2,1,iGPI);...
term1_pctile(2,2,iGPI),term2_pctile(2,2,iGPI),term3_pctile(2,2,iGPI),term4_pctile(2,2,iGPI),dGPI_pctile(2,2,iGPI);...
term1_pctile(2,3,iGPI),term2_pctile(2,3,iGPI),term3_pctile(2,3,iGPI),term4_pctile(2,3,iGPI),dGPI_pctile(2,3,iGPI);...
term1_pctile(2,4,iGPI),term2_pctile(2,4,iGPI),term3_pctile(2,4,iGPI),term4_pctile(2,4,iGPI),dGPI_pctile(2,4,iGPI);...
term1_pctile(2,5,iGPI),term2_pctile(2,5,iGPI),term3_pctile(2,5,iGPI),term4_pctile(2,5,iGPI),dGPI_pctile(2,5,iGPI);...
term1_pctile(2,6,iGPI),term2_pctile(2,6,iGPI),term3_pctile(2,6,iGPI),term4_pctile(2,6,iGPI),dGPI_pctile(2,6,iGPI);...
term1_pctile(2,7,iGPI),term2_pctile(2,7,iGPI),term3_pctile(2,7,iGPI),term4_pctile(2,7,iGPI),dGPI_pctile(2,7,iGPI);...
term1_pctile(2,8,iGPI),term2_pctile(2,8,iGPI),term3_pctile(2,8,iGPI),term4_pctile(2,8,iGPI),dGPI_pctile(2,8,iGPI)];
errLow = [term1_pctile(1,1,iGPI),term2_pctile(1,1,iGPI),term3_pctile(1,1,iGPI),term4_pctile(1,1,iGPI),dGPI_pctile(1,1,iGPI);...
term1_pctile(1,2,iGPI),term2_pctile(1,2,iGPI),term3_pctile(1,2,iGPI),term4_pctile(1,2,iGPI),dGPI_pctile(1,2,iGPI);...
term1_pctile(1,3,iGPI),term2_pctile(1,3,iGPI),term3_pctile(1,3,iGPI),term4_pctile(1,3,iGPI),dGPI_pctile(1,3,iGPI);...
term1_pctile(1,4,iGPI),term2_pctile(1,4,iGPI),term3_pctile(1,4,iGPI),term4_pctile(1,4,iGPI),dGPI_pctile(1,4,iGPI);...
term1_pctile(1,5,iGPI),term2_pctile(1,5,iGPI),term3_pctile(1,5,iGPI),term4_pctile(1,5,iGPI),dGPI_pctile(1,5,iGPI);...
term1_pctile(1,6,iGPI),term2_pctile(1,6,iGPI),term3_pctile(1,6,iGPI),term4_pctile(1,6,iGPI),dGPI_pctile(1,6,iGPI);...
term1_pctile(1,7,iGPI),term2_pctile(1,7,iGPI),term3_pctile(1,7,iGPI),term4_pctile(1,7,iGPI),dGPI_pctile(1,7,iGPI);...
term1_pctile(1,8,iGPI),term2_pctile(1,8,iGPI),term3_pctile(1,8,iGPI),term4_pctile(1,8,iGPI),dGPI_pctile(1,8,iGPI)];
ctrs = 1:8;
%Make bar plot
hBar = bar(ctrs,phsRegions,1);
for k1=1:size(phsRegions,2)
ctr(k1,:) = bsxfun(@plus, hBar(1).XData, [hBar(k1).XOffset]');
ydt(k1,:) = hBar(k1).YData;
end
hold on
%errorbar(ctr',ydt',2.*errRegions,'k','linestyle','none','LineWidth',1)
errorbar(ctr',ydt',errLow,errHigh,'Color',[0.4,0.4,0.4],'linestyle','none','LineWidth',.75)
ylim([-3, 3]);
xlabel('MJO Phase [OMI]','FontSize',16)
title(['Region: ',regionLabels{iGPI}],'fontsize',16);
ax = gca;
ax.FontSize = 14;
%Add lines to separate phases
plot([1.5 1.5], ylim,'Color',0.5*ones(1,3),'HandleVisibility','off')
plot([2.5 2.5], ylim,'Color',0.5*ones(1,3),'HandleVisibility','off')
plot([3.5 3.5], ylim,'Color',0.5*ones(1,3),'HandleVisibility','off')
plot([4.5 4.5], ylim,'Color',0.5*ones(1,3),'HandleVisibility','off')
plot([5.5 5.5], ylim,'Color',0.5*ones(1,3),'HandleVisibility','off')
plot([6.5 6.5], ylim,'Color',0.5*ones(1,3),'HandleVisibility','off')
plot([7.5 7.5], ylim,'Color',0.5*ones(1,3),'HandleVisibility','off')
legend({'Vorticity','Humidity','Potential Intensity','Shear','fullGPI'},'location','southeast','fontsize',12);
%Add smooth curve for shear
xx = linspace(0,8.5,101);
cs_shr = spline(ctr(4,:),[0 ydt(4,:) 0]); %Shear term
plot(xx,ppval(cs_shr,xx),'Color',[0.4940, 0.1840, 0.5560],'linewidth',1,'HandleVisibility','off');
%Add smooth curve for potential intensity
cs_pi = spline(ctr(3,:),[0 ydt(3,:) 0]); %Shear term
plot(xx,ppval(cs_pi,xx),'Color',[0.9290, 0.6940, 0.1250],'linewidth',1,'HandleVisibility','off');
%Add smooth curve for RH
cs_rh = spline(ctr(2,:),[0 ydt(2,:) 0]); %Shear term
plot(xx,ppval(cs_rh,xx),'Color',[0.8500, 0.3250, 0.0980],'linewidth',1,'HandleVisibility','off');
xlim([0.5 8.5])
fig = gcf;
fig.PaperPositionMode = 'auto';
print('/Users/meganfowler/Documents/Irvine/TCs/Figures/GPI-Region5only_WithCurves','-depsc');