-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcanesmLE.py
696 lines (571 loc) · 24.3 KB
/
canesmLE.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
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
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
import cccmautils as cutl
import pandas as pd
import scipy as sp
import scipy.stats
printtofile=False
plt.close('all')
# @@ Look at Southern Ocean and Southern Jet
natorig=False # do not include markers for original nat runs
basepath='/raid/ra40/data/kem/CanSISE/CanESM2/LE/'
sims=('historical-r1','historical-r2','historical-r3','historical-r4','historical-r5')
simsnat=('historicalNat-r1','historicalNat-r2','historicalNat-r3','historicalNat-r4','historicalNat-r5')
ensnum=10
# CMIP variable names
field='sic'; comp='OImon'; cmin=-3e11; cmax=3e11;cmap='red2blue_w20'
#field='tas'; comp='Amon'; cmin=-1; cmax=1; cmap='blue2red_w20'
reg2=True # if sea ice, include southern hem? if other, include regional mean?
region= 'etroppac'
sea='DJF'
siglevel=0.1 #0.05
timesel=None
timesel2 = '2002-01-01,2012-12-31'
superii=0
regstr=''
if reg2:
if field=='sic':
regstr='sh'
else:
regstr=region
years=np.arange(1950,2021)
if sea=='DJF':
years=years[:-1]
simnhdt={}
simshdt={}
simgmdt={}
simrmdt={}
simtrnddt={}
alltrnddt={}
for sim in sims:
ensnhdt={} # northern hem
ensshdt={} # southern hem
ensgmdt={} # global mean
ensrmdt={} # regional mean
ensseldt={}
enstrnddt={}
for eii in np.arange(1,ensnum+1):
fname=basepath + sim + '/' + field + '/' + field + '_' + comp + '_CanESM2_' +\
sim + '_r' + str(eii) + 'i1p1_195001-202012.nc'
if superii==0: # just get once
lat=cnc.getNCvar(fname,'lat')
lon=cnc.getNCvar(fname,'lon')
fld = cnc.getNCvar(fname,field,timesel=timesel,seas=sea)
# select a given time period and keep maps
fldsel = cnc.getNCvar(fname,field,timesel=timesel2,seas=sea)
nt = fldsel.shape[0]
nlon=fldsel.shape[2]
nlat=fldsel.shape[1]
fldre = fldsel.reshape((nt,nlon*nlat))
xx=np.arange(0,nt)
#ensseldt[eii] = fldsel
if field=='sic':
ensnhdt[eii],ensshdt[eii] = cutl.calc_totseaicearea(fld/100.,lat,lon,isarea=False)
fldsel=cutl.calc_seaicearea(fldsel,lat,lon)
fldre=fldsel.reshape((nt,nlon*nlat))
else:
ensgmdt[eii] = cutl.global_mean_areawgted3d(fld,lat,lon)
ensrmdt[eii] = cutl.calc_regmean(fld,lat,lon,region)
#slope[eii], intercept, r_value, p_value, std_err = sp.stats.linregress(xx,dat) # not good for 3d data?
# this is just the second timesel (ie 2002-2012)
slope,intercept = np.polyfit(xx,fldre,1) # supposedly can do w/ higher dims?
enstrnddt[eii] = slope #.reshape((nlat,nlon)) # reshape later @@
# also save all trends into one dictionary (don't differentiate by seed/base run)
alltrnddt[superii] = slope
superii+=1
if field=='sic':
simnhdt[sim] = pd.DataFrame(ensnhdt,index=years)
simshdt[sim] = pd.DataFrame(ensshdt,index=years)
else:
simgmdt[sim] = pd.DataFrame(ensgmdt,index=years)
simrmdt[sim] = pd.DataFrame(ensrmdt,index=years)
# calc time mean and trend of ensseldt. Then each ens member is a map of trends
tmpdf = pd.DataFrame(enstrnddt)#,index=years)
#simseldt[sim] = trenddf
simtrnddt[sim] = tmpdf
alltrnddf = pd.DataFrame(alltrnddt)
# # first, the timeseries
if field=='sic':
plotdt = simnhdt # NH ice
plotdt2 = simshdt # SH ice
else:
plotdt = simgmdt # global mean
plotdt2 = simrmdt # regional mean
col=0.0
fig,axs=plt.subplots(2,1,sharey=True)
ax=axs[0]
for sim in sims:
df=plotdt[sim]
ax.plot(years,df-df.mean(axis=0),color=str(col))
if reg2: #field=='sic':
df=plotdt2[sim]
ax.plot(years,df-df.mean(axis=0),color=str(col),linestyle='--')
col+=0.2
ax.set_title(field + ' ' + str(sea) + ' ' + regstr + ' (dashed)')
col=0.0
ax=axs[1]
for sim in sims:
df=plotdt[sim]
ax.plot(years,df.mean(axis=1)-df.mean(axis=1).mean(axis=0),color=str(col))
if reg2: #field=='sic':
df=plotdt2[sim]
ax.plot(years,df.mean(axis=1)-df.mean(axis=1).mean(axis=0),color=str(col),linestyle='--')
col+=0.2
ax.set_xlabel('mean of groups')
if printtofile:
fig.savefig(field + 'LE_remtm' + str(sea) + regstr + '_timeseries.pdf') # time mean removed
# # Maps
# plot mean trend map for each "group"
for sim in sims:
trnds = simtrnddt[sim]
groupm = trnds.mean(axis=1)
groupm = groupm.reshape((nlat,nlon))
plt.figure()
mh = cplt.kemmap(groupm*nt,lat,lon,cmin=cmin,cmax=cmax,title=sim,cmap=cmap)
# mean of all runs
trndmean = alltrnddf.mean(axis=1).reshape((nlat,nlon))
plt.figure()
mh = cplt.kemmap(trndmean*nt,lat,lon,cmin=cmin,cmax=cmax,title='LE mean trend ' + timesel2,cmap=cmap)
# @@ now combine with cmip5 ensemble, and CESM if possible..
# ==================================================================
# This is the part of the file that I actually care about...for paper..
# Use files that already have SIE or SIA calculated ======= 1/6/2015
# ==================== plot NH sea ice area ========================
field='sianh'; comp='OImon';
season='DJF' #'ND'
dopct=False # make the calculation into a percent change
# if season is set to just September (9), I get an error:
# ValueError: Big-endian buffer not supported on little-endian compiler
# I suspect that the hadisst file is the opposite endian to what my python install is on:
# http://pandas.pydata.org/pandas-docs/dev/gotchas.html#byte-ordering-issues
# This may not come up for 'ND' average because the cnc module already does some
# averaging and stores data in a new structure. Whereas just reading in a month reads
# directly from the file and doesn't do any averaging (??)
# Try the fix in the link if want an individual month.
import cccmacmaps as ccm
subyrs=np.arange(1979,1990)
subyrs2=np.arange(2002,2013)
if sea=='DJF':
subyrs2=np.arange(2002,2012) # because timeseries ends 2012-12
printtofile=False
# ======= CANESM LE (TOT) ===
superii=0
allflddt={}
for sim in sims:
for eii in np.arange(1,ensnum+1):
fname=basepath + sim + '/' + field + '/' + field + '_' + comp + '_CanESM2_' +\
sim + '_r' + str(eii) + 'i1p1_195001-202012.nc'
allflddt[superii] = cnc.getNCvar(fname,field,seas=season)
superii+=1
allflddf=pd.DataFrame(allflddt,index=years)
# ======= CANESM LE (NAT) ===
superii=0
allnatdt={}
for sim in simsnat:
for eii in np.arange(1,ensnum+1):
fname=basepath + sim + '/' + field + '/' + field + '_' + comp + '_CanESM2_' +\
sim + '_r' + str(eii) + 'i1p1_195001-202012.nc'
allnatdt[superii] = cnc.getNCvar(fname,field,seas=season)
superii+=1
allnatdf=pd.DataFrame(allnatdt,index=years)
# =============== OBS:
basedir='/HOME/rkm/work/BCs/'
subdir='HadISST/'
hadfile=basedir + subdir + 'hadisst1.1_bc_128_64_1870_2013m03_' + field + '_1870010100-2013030100.nc'
hadsel='1950-01-01,2012-12-31'
hadyrs=np.arange(1950,2013)
if sea=='DJF':
hadyrs=hadyrs[:-1]
hadfld=cnc.getNCvar(hadfile,field,timesel=hadsel,seas=season)
haddf = pd.Series(hadfld,index=hadyrs)
pasthad = haddf.loc[subyrs]
preshad = haddf.loc[subyrs2]
(hadtstat,hadpv) = cutl.ttest_ind(preshad,pasthad)
if dopct:
diffhad= (preshad.mean(axis=0) - pasthad.mean(axis=0)) / pasthad.mean(axis=0) *100
else:
diffhad=preshad.mean(axis=0) - pasthad.mean(axis=0)
subdir='NSIDC/'
nsidcfile = basedir + subdir + 'nsidc_bt_128x64_1978m11_2011m12_' + field + '_1978111600-2011121612.nc'
nsidcsel='1979-01-01,2011-12-31'
nsidcyrs=np.arange(1979,2012)
if sea=='DJF':
nsidcyrs=nsidcyrs[:-1]
nsidcfld=cnc.getNCvar(nsidcfile,field,timesel=nsidcsel,seas=season)
nsidcdf=pd.Series(nsidcfld,index=nsidcyrs)
pastnsidc = nsidcdf.loc[subyrs]
presnsidc = nsidcdf.loc[subyrs2[:-1]]
(nsidctstat,nsidcpv) = cutl.ttest_ind(presnsidc,pastnsidc)
if dopct:
diffnsidc=(presnsidc.mean(axis=0) - pastnsidc.mean(axis=0)) / pastnsidc.mean(axis=0) *100
else:
diffnsidc=presnsidc.mean(axis=0) - pastnsidc.mean(axis=0)
# =============== original five:
casename='historicalrcp45'
ensnum=5
basedir='/HOME/rkm/work/DATA/CanESM2/' + casename
origsel='1950-01-01,2012-12-31'
origyrs = np.arange(1950,2013)
if sea=='DJF':
origyrs=origyrs[:-1]
origdt={}
for eii in np.arange(1,ensnum+1):
fname=basedir + '/' + field + '/' + field + '_' + comp + '_CanESM2_' +\
casename + '_r' + str(eii) + 'i1p1_185001-201212.nc'
origdt[eii] = cnc.getNCvar(fname,field,timesel=origsel,seas=season)
origdf=pd.DataFrame(origdt,index=origyrs)
pastorig = origdf.loc[subyrs]
presorig = origdf.loc[subyrs2]
(origtstat,origpv) = cutl.ttest_ind(presorig,pastorig,axis=0)
if dopct:
difforig = (presorig.mean(axis=0) - pastorig.mean(axis=0)) / pastorig.mean(axis=0) *100
else:
difforig = presorig.mean(axis=0) - pastorig.mean(axis=0)
# =============== original five: NAT
casename='historicalNat'
basedir='/HOME/rkm/work/DATA/CanESM2/' + casename
orignatdt={}
for eii in np.arange(1,ensnum+1):
fname=basedir + '/' + field + '/' + field + '_' + comp + '_CanESM2_' +\
casename + '_r' + str(eii) + 'i1p1_185001-201212.nc'
orignatdt[eii] = cnc.getNCvar(fname,field,timesel=origsel,seas=season)
orignatdf=pd.DataFrame(orignatdt,index=origyrs)
pastnatorig = orignatdf.loc[subyrs]
presnatorig = orignatdf.loc[subyrs2]
(natorigtstat,natorigpv) = cutl.ttest_ind(presnatorig,pastnatorig,axis=0)
if dopct:
diffnatorig = (presnatorig.mean(axis=0) - pastnatorig.mean(axis=0)) / pastnatorig.mean(axis=0)*100
else:
diffnatorig = presnatorig.mean(axis=0) - pastnatorig.mean(axis=0)
# TIMESERIES
firebrick=ccm.get_linecolor('firebrick')
hcol=ccm.get_linecolor('darkolivegreen3')
hcolline=ccm.get_linecolor('darkolivegreen3')#'darkseagreen4')
natcol=ccm.get_linecolor('steelblue3')
natcolline=ccm.get_linecolor('steelblue3')#4')
fig,axs=plt.subplots(1,1)
axs.plot(years,allnatdf,color=natcol,alpha=.5)
axs.plot(years,allflddf,color='r',alpha=.3)
axs.plot(origyrs,orignatdf,color=natcol,linewidth=2)
axs.plot(origyrs,origdf,color='brown',linewidth=2)
axs.plot(hadyrs,haddf,color='b',linewidth=2)
axs.plot(nsidcyrs,nsidcdf,color='g',linewidth=2)
axs.set_title(field + ' ' + str(season))
# NOW DO DIFF PDFS
# this will work too: allflddf.query('index>=1979 & index<1990')
past=allflddf.loc[subyrs]
pres=allflddf.loc[subyrs2]
pastnat=allnatdf.loc[subyrs]
presnat=allnatdf.loc[subyrs2]
if dopct:
alldiff = (pres.mean(axis=0)- past.mean(axis=0)) / past.mean(axis=0)*100
allnatdiff = (presnat.mean(axis=0)- pastnat.mean(axis=0)) / pastnat.mean(axis=0)*100
pct='pct'
else:
alldiff =pres.mean(axis=0)- past.mean(axis=0)
allnatdiff =presnat.mean(axis=0)- pastnat.mean(axis=0)
pct=''
fig,ax = plt.subplots(1,1)
allnatdiff.hist(color=natcol,alpha=0.5)
alldiff.hist(color='r',alpha=0.5)
for eii in range(1,6):
ax.axvline(difforig[eii],color=ccm.get_linecolor('firebrick'),linewidth=3)
ax.axvline(diffnatorig[eii],color=natcol,linewidth=3)
ax.axvline(diffhad,color='b',linewidth=3)
ax.axvline(diffnsidc,color='g',linewidth=3)
ax.set_title(field + ' anom ' + str(season))
from scipy.stats import norm
# ======== PDFS
anormed=norm.fit(alldiff)
amean=anormed[0]
asd=anormed[1]
#Generate X points
axlims = [-4*asd+amean, 4*asd+amean] # large limits
axx = np.linspace(axlims[0],axlims[1],500)
#Get Y points via Normal PDF with fitted parameters
apdf_fitted = norm.pdf(axx,loc=amean,scale=asd)
# NAT
nnormed=norm.fit(allnatdiff)
nmean=nnormed[0]
nsd=nnormed[1]
#Generate X points
nxlims = [-4*nsd+nmean, 4*nsd+nmean] # large limits
nxx = np.linspace(nxlims[0],nxlims[1],500)
#Get Y points via Normal PDF with fitted parameters
npdf_fitted = norm.pdf(nxx,loc=nmean,scale=nsd)
# normed means: integral of the histogram will sum to 1 @@@ don't think it's right
fig,ax=plt.subplots(1,1)
allnatdiff.hist(normed=True,color=natcol,alpha=0.5)#,histtype='stepfilled')
alldiff.hist(normed=True,color=firebrick,alpha=0.5)#,histtype='stepfilled')
#plt.title(field + ' anom ' + str(season))
ax.plot(axx,apdf_fitted,color=firebrick,linewidth=2)
ax.plot(nxx,npdf_fitted,color=natcol,linewidth=2)
axylims=ax.get_ylim()
ax.axvline(color='k',linestyle='--')
for eii in range(1,6):
ax.plot(difforig[eii],axylims[1],marker='|',markersize=20,color=firebrick)
ax.plot(diffnatorig[eii],axylims[1],marker='|',markersize=20,color=natcol)
ax.axvline(x=difforig[eii],ymin=.97,ymax=1,color=firebrick,linewidth=2)
ax.axvline(x=diffnatorig[eii],ymin=.97,ymax=1,color=natcol,linewidth=2)
hh=ax.axvline(diffhad,color='b',linewidth=3)
nn=ax.axvline(diffnsidc,color='g',linewidth=3)
ax.legend((hh,nn),('HadISST','NSIDC'),loc='upper left')
ax.set_ylabel('Density')
#ax.set_xlabel('$\Delta$ Sea Ice Area (m$^2$)')
if dopct:
ax.set_xlabel('$\Delta$ Sea Ice Area (%)')
#xt=ax.get_xticks()
#ax.set_xticklabels(xt/np.float(1e12))
else:
ax.set_xlabel('$\Delta$ Sea Ice Area (millions of km$^2$)')
xt=ax.get_xticks()
ax.set_xticklabels(xt/np.float(1e12))
ax.grid('off')
if printtofile:
fig.savefig(field + 'diff' + pct + '_PDFHIST_CanESMLE_TOTNAT_' + str(season) + '.pdf')
fig,ax=plt.subplots(1,1)
allnatdiff.hist(normed=True,color=natcol,alpha=0.5)#,histtype='stepfilled')
alldiff.hist(normed=True,color=firebrick,alpha=0.5)#,histtype='stepfilled')
#plt.title(field + ' anom ' + str(season))
ax.plot(axx,apdf_fitted,color=firebrick,linewidth=2)
ax.plot(nxx,npdf_fitted,color=natcol,linewidth=2)
axylims=ax.get_ylim()
ax.set_ylim((axylims[0],axylims[1]+(axylims[1]*.1)))
axylims=ax.get_ylim()
ax.axvline(color='k',linestyle='--')
for eii in range(1,6):
#ax.plot(difforig[eii],axylims[1],marker='|',markersize=20,color=firebrick)
#ax.plot(diffnatorig[eii],axylims[1],marker='|',markersize=20,color='k')
ax.axvline(x=difforig[eii],ymin=.97,ymax=1,color=firebrick,linewidth=2)
ax.axvline(x=diffnatorig[eii],ymin=.97,ymax=1,color=natcol,linewidth=2)
hh=ax.axvline(diffhad,color='b',linewidth=3)
nn=ax.axvline(diffnsidc,color='g',linewidth=3)
#ax.legend((hh,nn),('HadISST','NSIDC'),loc='upper left')
ax.annotate('NSIDC',xy=(diffnsidc-(diffnsidc*.05),axylims[1]-(axylims[1]*.07)),xycoords='data')#,rotation=45)
ax.annotate('HadISST',xy=(diffhad-(diffhad*.05),axylims[1]-(axylims[1]*.07)),xycoords='data')#,rotation=45)
ax.annotate('Historical',xy=(.36,.57),xytext=(.2,.7), xycoords='figure fraction',
arrowprops=dict(facecolor=firebrick, edgecolor='None',shrink=0.05))
ax.annotate('HistoricalNat',xy=(.7,.5),xytext=(.75,.6), xycoords='figure fraction',
arrowprops=dict(facecolor='k', edgecolor='None',shrink=0.05))
ax.annotate('Sea Ice Loss', xy=(0,1.02), xytext=(.53,1.02),xycoords='axes fraction',
arrowprops=dict(facecolor='k', edgecolor='None',shrink=0.05),verticalalignment='center')
ax.annotate('Sea Ice Gain', xy=(1,1.02), xytext=(.74,1.02),xycoords='axes fraction',
arrowprops=dict(facecolor='k', edgecolor='None',shrink=0.05),verticalalignment='center')
ax.set_ylabel('Density')
if dopct:
ax.set_xlabel('$\Delta$ Sea Ice Area (%)')
#xt=ax.get_xticks()
#ax.set_xticklabels(xt/np.float(1e12))
else:
ax.set_xlabel('$\Delta$ Sea Ice Area (m$^2$)')
ax.set_xlabel('$\Delta$ Sea Ice Area (millions of km$^2$)')
xt=ax.get_xticks()
ax.set_xticklabels(xt/np.float(1e12))
ax.grid('off')
if printtofile:
fig.savefig(field + 'diff' + pct + '_PDFHIST_CanESMLE_TOTNAT_' + str(season) + '_annotate.pdf')
import matplotlib.patches as mpatches
import matplotlib.lines as mlines
#http://matplotlib.org/users/legend_guide.html#proxy-legend-handles
# # # PAPER ############
printtofile=False
ms = 7 # markersize
deffs='none' # default fillstyle
mew=1.5
fig,ax=plt.subplots(1,1)
allnatdiff.hist(normed=True,color=natcol,alpha=0.5)#,histtype='stepfilled')
alldiff.hist(normed=True,color=hcol,alpha=0.5)#,histtype='stepfilled')
# use proxy artist for histogram legend entries
#tot = mpatches.Patch(color=firebrick,alpha=0.5)#, label='The red data')
#nat = mpatches.Patch(color='0.5',alpha=0.5)#, label='The red data')
tot=mlines.Line2D([],[],color=hcolline,linewidth=2)
nat=mlines.Line2D([],[],color=natcolline,linewidth=2)
ax.plot(axx,apdf_fitted,color=hcolline,linewidth=2)
ax.plot(nxx,npdf_fitted,color=natcolline,linewidth=2)
axylims=ax.get_ylim()
ax.set_ylim((axylims[0],axylims[1]+(axylims[1]*.1)))
axylims=ax.get_ylim()
ax.axvline(color='k',linestyle='--')
for eii in range(1,6):
#ax.plot(difforig[eii],axylims[1],marker='|',markersize=20,color=firebrick)
#ax.plot(diffnatorig[eii],axylims[1],marker='|',markersize=20,color='k')
# move these to ON the pdf fit.
# search for difforig[eii] nearest to axx, then plot apdf_fitted[axx] as marker, filled or not based on sig.
plotx = difforig[eii]
idx = cutl.find_nearest(axx,plotx)
ploty = apdf_fitted[idx]
print 'Orig hist ' + str(eii) + ' PVAL: ' + str(origpv[eii-1])
if origpv[eii-1]<=siglevel: #significant, fill the marker
fs='full'
else:
fs=deffs # defaultfs
ax.plot(plotx,ploty,marker='o',color=hcolline,mec=hcolline,fillstyle=fs,mew=mew,markersize=ms)
#ax.axvline(x=difforig[eii],ymin=.97,ymax=1,color=firebrick,linewidth=2)
plotx = diffnatorig[eii]
idx = cutl.find_nearest(nxx,plotx)
ploty = npdf_fitted[idx]
if natorigpv[eii-1]<=siglevel: #significant, fill the marker
fs='full'
else:
fs=deffs # defaultfs
if natorig:
natstr=''
ax.plot(plotx,ploty,marker='o',color=natcolline,mec=natcolline,fillstyle=fs,mew=mew,markersize=ms)
else:
natstr='nonatorig'
#ax.axvline(x=diffnatorig[eii],ymin=.97,ymax=1,color='k',lineawidth=2)
#nn=ax.axvline(diffnsidc,color='g',linewidth=3)
plotx=diffnsidc
idx=cutl.find_nearest(axx,plotx)
ploty=apdf_fitted[idx]
if nsidcpv<siglevel: #significant, fill the marker
fs='full'
else:
fs=deffs # defaultfs
nn=mlines.Line2D([],[],color='g',linestyle='none',marker='o',mec='g',mew=mew,markersize=ms,fillstyle=fs)
ax.plot(plotx,ploty,marker='o',color='g',mec='g',fillstyle=fs,mew=mew,markersize=ms)
#nn = ax.axvline(x=diffnsidc,ymin=.97,ymax=1,color='g',linewidth=3)
## do not plot hadisst anymore
## plotx=diffhad
## idx=cutl.find_nearest(axx,plotx)
## ploty=apdf_fitted[idx]
## if hadpv<siglevel: #significant, fill the marker
## fs='full'
## else:
## fs=deffs # defaultfs
## hh=mlines.Line2D([],[],color='b',linestyle='none',marker='o',mec='b',mew=mew,markersize=ms,fillstyle=fs)
## ax.plot(plotx,ploty,marker='o',color='b',mec='b',fillstyle=fs,mew=mew,markersize=ms)
## #hh = ax.axvline(x=diffhad,ymin=.97,ymax=1,color='b',linewidth=3)
## ax.legend((nn,hh,tot,nat),('NSIDC','HadISST','Historical','HistoricalNat'),loc='upper left',frameon=False)
ax.legend((nn,tot,nat),('NSIDC','Historical','HistoricalNat'),loc='upper right',frameon=False)
## ax.annotate('NSIDC',xy=(diffnsidc-(diffnsidc*.05),axylims[1]-(axylims[1]*.07)),xycoords='data')#,rotation=45)
## tlaby = 0.94
## txt = ax.annotate('SIA Loss',xy=(0.3, tlaby), xycoords='axes fraction')#,bbox=txtbox) # just text
## laby=0.98 # 1.03
## ann = ax.annotate('', xy=(0, laby), xycoords='axes fraction',
## xytext=(0.7, laby), textcoords='axes fraction',
## arrowprops=dict(arrowstyle='<->',connectionstyle='arc3',facecolor='k',
## edgecolor='k',patchB=txt,patchA=txt),
## verticalalignment='center')
## ax.annotate('SIA Gain',xy=(.8,tlaby), xycoords='axes fraction')
## ann = ax.annotate('', xy=(0.72, laby), xycoords='axes fraction',
## xytext=(1, laby), textcoords='axes fraction',
## arrowprops=dict(arrowstyle='<->',connectionstyle='arc3',facecolor='k',
## edgecolor='k',patchB=txt,patchA=txt),
## verticalalignment='center')
ax.set_ylabel('Density')
ax.set_yticklabels('')
if dopct:
ax.set_xlabel('$\Delta$ Sea Ice Area (%)')
#xt=ax.get_xticks()
#ax.set_xticklabels(xt/np.float(1e12))
else:
ax.set_xlabel('$\Delta$ Sea Ice Area (millions of km$^2$)')
xt=ax.get_xticks()
ax.set_xticklabels(xt/np.float(1e12))
ax.grid('off')
if season == 'ND':
ax.set_title('Arctic sea-ice area change (Nov-Dec)')
elif season == 'DJF':
ax.set_title('Arctic sea-ice area change (Dec-Jan-Feb)')
else:
ax.set_title('Arctic sea-ice area change (' + season + ')')
if printtofile:
fig.savefig(field + 'diff' + pct + '_PDFHIST_CanESMLE_TOTNAT_' + str(season) + '_paper2f' + natstr + '.pdf')
ax.set_rasterized(True)
fig.savefig(field + 'diff'+ pct + '_PDFHIST_CanESMLE_TOTNAT_' + str(season) + '_paper2f' + natstr + '.eps')
printtofile=False
fig,ax=plt.subplots(1,1)
plt.title(field + ' anom ' + str(season))
tot=ax.plot(axx,apdf_fitted,color=ccm.get_linecolor('firebrick'),linewidth=2)
nat=ax.plot(nxx,npdf_fitted,color='k',linewidth=2)
ax.fill_between(axx,apdf_fitted,color='r',alpha=0.5)
ax.fill_between(nxx,npdf_fitted,color='k',alpha=0.5)
#ax.grid()
axylims=ax.get_ylim()
for eii in range(1,6):
ax.plot(difforig[eii],axylims[1],marker='v',markersize=10,color=firebrick)
#ax.plot(diffnatorig[eii],axylims[1],marker='v',markersize=10,color='k') # want original NAT runs?
hh=ax.axvline(diffhad,color='b',linewidth=3)
nn=ax.axvline(diffnsidc,color='g',linewidth=3)
ax.set_ylabel('frequency')
#ax.legend((tot,nat,hh,nn),('TOT LE','NAT LE','HadISST','NSIDC'))
ax.legend((hh,nn),('HadISST','NSIDC'))
if printtofile:
fig.savefig(field + 'diff'+ pct + '_PDF_CanESMLE_TOTNAT_' + str(season) + '.pdf')
# # # PAPER2 NO NAT ############
printtofile=False
ms = 7 # markersize
deffs='none' # default fillstyle
mew=1.5
fig,ax=plt.subplots(1,1)
#allnatdiff.hist(normed=True,color=natcol,alpha=0.5)#,histtype='stepfilled')
alldiff.hist(normed=True,color=hcol,alpha=0.5)#,histtype='stepfilled')
# use proxy artist for histogram legend entries
#tot = mpatches.Patch(color=firebrick,alpha=0.5)#, label='The red data')
#nat = mpatches.Patch(color='0.5',alpha=0.5)#, label='The red data')
tot=mlines.Line2D([],[],color=hcolline,linewidth=2)
#nat=mlines.Line2D([],[],color=natcolline,linewidth=2)
ax.plot(axx,apdf_fitted,color=hcolline,linewidth=2)
#ax.plot(nxx,npdf_fitted,color=natcolline,linewidth=2)
axylims=ax.get_ylim()
ax.set_ylim((axylims[0],axylims[1]+(axylims[1]*.1)))
axylims=ax.get_ylim()
ax.axvline(color='k',linestyle='--')
for eii in range(1,6):
#ax.plot(difforig[eii],axylims[1],marker='|',markersize=20,color=firebrick)
#ax.plot(diffnatorig[eii],axylims[1],marker='|',markersize=20,color='k')
# move these to ON the pdf fit.
# search for difforig[eii] nearest to axx, then plot apdf_fitted[axx] as marker, filled or not based on sig.
plotx = difforig[eii]
idx = cutl.find_nearest(axx,plotx)
ploty = apdf_fitted[idx]
print 'Orig hist ' + str(eii) + ' PVAL: ' + str(origpv[eii-1])
if origpv[eii-1]<=siglevel: #significant, fill the marker
fs='full'
else:
fs=deffs # defaultfs
ax.plot(plotx,ploty,marker='o',color=hcolline,mec=hcolline,fillstyle=fs,mew=mew,markersize=ms)
#ax.axvline(x=difforig[eii],ymin=.97,ymax=1,color=firebrick,linewidth=2)
#plotx = diffnatorig[eii]
#idx = cutl.find_nearest(nxx,plotx)
#ploty = npdf_fitted[idx]
#if natorigpv[eii-1]<=siglevel: #significant, fill the marker
# fs='full'
#else:
# fs=deffs # defaultfs
#if natorig:
# natstr=''
# ax.plot(plotx,ploty,marker='o',color=natcolline,mec=natcolline,fillstyle=fs,mew=mew,markersize=ms)
#else:
# natstr='nonatorig'
#ax.axvline(x=diffnatorig[eii],ymin=.97,ymax=1,color='k',lineawidth=2)
plotx=diffnsidc
idx=cutl.find_nearest(axx,plotx)
ploty=apdf_fitted[idx]
if nsidcpv<siglevel: #significant, fill the marker
fs='full'
else:
fs=deffs # defaultfs
nn=mlines.Line2D([],[],color='g',linestyle='none',marker='o',mec='g',mew=mew,markersize=ms,fillstyle=fs)
ax.plot(plotx,ploty,marker='o',color='g',mec='g',fillstyle=fs,mew=mew,markersize=ms)
ax.legend((nn,tot),('NSIDC','Historical'),loc='upper right',frameon=False)
ax.set_ylabel('Density')
ax.set_yticklabels('')
if dopct:
ax.set_xlabel('$\Delta$ Sea Ice Area (%)')
#xt=ax.get_xticks()
#ax.set_xticklabels(xt/np.float(1e12))
else:
ax.set_xlabel('$\Delta$ Sea Ice Area (millions of km$^2$)')
xt=ax.get_xticks()
ax.set_xticklabels(xt/np.float(1e12))
ax.grid('off')
if season == 'ND':
ax.set_title('Arctic sea-ice area change (Nov-Dec)')
elif season == 'DJF':
ax.set_title('Arctic sea-ice area change (Dec-Jan-Feb)')
else:
ax.set_title('Arctic sea-ice area change (' + season + ')')
if printtofile:
fig.savefig(field + 'diff' + pct + '_PDFHIST_CanESMLE_TOT_' + str(season) + '_paper2f.pdf')
ax.set_rasterized(True)
fig.savefig(field + 'diff'+ pct + '_PDFHIST_CanESMLE_TOT_' + str(season) + '_paper2f.eps')