-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathccsm4_MOC.py
2367 lines (1810 loc) · 77.7 KB
/
ccsm4_MOC.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
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding: utf-8 -*-
# <nbformat>3.0</nbformat>
# <markdowncell>
# Create a plot of streamfunction in southern ocean -- geotimescales project.<br>
# Overlay it on mean and anomalous temperature. Then calculate heat transport of anomalous W working on the mean Temp.<br>
# <br>
# <ul>
# <li>Figure 1: Climatological Eulerian MOC (1970-1999 mean)</li>
# <li>Figure 2: Sulfate engineering anomalous Eulerian MOC (2045-2054 compared to climo)</li>
# <li>Figure 3: GHG removal anomalous Eulerian MOC (2045-2054 compared to climo)</li>
# <li>Figure 4: Climatological TEMP (1970-1999 mean) with sulfate engineering anom eulerian MOC (contours)</li>
# </ul>
# <br>
# For figures 1-4: + MOC has solid lines (cw), - MOC has dashed lines (ccw). no zero contour.
# <br><br>
# <ul>
# <li>Figure 5: Anomalous TEMP (shading) with anomalous eulerian MOC (contours) for sulfate eng (left), ghg removal (right)</li>
# <li>Figure 6: Same as Fig. 5 but anomalous eddy-induced MOC</li>
# <li>Figure 7: Same as Fig. 5 but anomalous total MOC (eulerian + eddy-induced)</li>
# <li>Figure 8: Same as Fig. 7 but zoomed closer in on SH region</li>
# <li>Figure 9: Same as Fig. 5 but anomalous submeso-scale eddy MOC</li>
# </ul>
# <br>
# For figures 5-9: + MOC has thick solid lines (cw), - MOC has thin solid lines (ccw). no zero contour.
# <br><br>
# <ul>
# <li>Figure 10a: components of heat trans calc for sulfates run: climo dT/dz; anomalous WVEL+WISOP; anom WVEL; anom WISOP</li>
# <li>Figure 10b: Heating rate (wprime*dTbar/dz; K/s) at each level for sulfate engineering (left) and GHG removal (right)</li>
# <li>Figure 11: same as Fig. 10 but in K/day and zoomed in</li>
# <li>Figure 12: Same as Fig. 10, but multiply by layer thickness to convert to W/m2 in each grid cell. Overlaid with climo TEMP contours (gray) and anomalous eulerian MOC (green)</li>
# </ul>
# <br>
# For figures 10-12: having trouble removing the spurious data in lower left. It's probably related to the bathymetry and not appropriately handling missing data.
# <br><br>
# <em>Figure headings are below the figures</em>
# <codecell>
#%matplotlib inline
import cccmaplots as cplt
import cccmaNC as cnc
plt.close('all')
printtofile=False
basepath = '/Users/kelly/School/DATA/'
casenamec = 'b40.20th.track1.1deg.006'
casenamep = 'geo2035ensavg' # or 'rcp8_5GHGrem1850'
filenamec = basepath + casenamec + '/' + casenamec + '.pop.ANN.1970-1999.nc'
filenamep = basepath + casenamep + '/' + casenamep + '.pop.ANN.2045-2054.nc'
print filenamec
print filenamep
pig=True # do pine island glacier region # @@@ testing
# From ocean_temps_vert2_SOforthesis.m @@@
# indices in the lon direction for the various SO basins
# probably need to shift by 1 for python (0-based), also I don't think this indexing works in python
#iwed = [294:320 1:30];
#iross = [183:227];
#ipig = [250:276];
# 80W to 120W ? http://www.awi.de/fileadmin/user_upload/News/Press_Releases/2013/3._Quartal/Pine_Island_Glacier/PIG_map_Bodentopograpfie_beschriftet_p.jpg
#if pig:
# gridslicelonw = 80;
# gridslicelone = 120;
# <codecell>
latauxgrid = cnc.getNCvar(filenamec,'lat_aux_grid',sqz=False)
transreg = cnc.getNCvar(filenamec, 'transport_regions',sqz=False)
moccomp = cnc.getNCvar(filenamec, 'moc_components',sqz=False)
mocz = cnc.getNCvar(filenamec,'moc_z',sqz=False)
""" float MOC(time, transport_reg, moc_comp, moc_z, lat_aux_grid) ;
MOC:long_name = "Meridional Overturning Circulation" ;
MOC:units = "Sverdrups" ;
MOC:coordinates = "lat_aux_grid moc_z moc_components transport_region time" ;
MOC:missing_value = 9.96921e+36f ;
transport_regions =
"Global Ocean - Marginal Seas",
"Atlantic Ocean + Mediterranean Sea + Labrador Sea + GIN Sea + Arctic Ocean + Hudson Bay"
moc_components =
"Eulerian Mean",
"Eddy-Induced (bolus)",
"Submeso" ;
float moc_z(moc_z) ;
moc_z:long_name = "depth from surface to top of layer" ;
moc_z:units = "centimeters" ;
moc_z:positive = "down" ;
moc_z:valid_min = 0.f ;
moc_z:valid_max = 549999.1f ;
moc_z = 0, 1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000,
11000, 12000, 13000, 14000, 15000, 16000, 17019.68, 18076.13, 19182.12,
20349.93, 21592.34, 22923.31, 24358.45, 25915.58, 27615.26, 29481.47,
31542.37, 33831.23, 36387.47, 39258.05, 42498.89, 46176.66, 50370.69,
55174.91, 60699.67, 67072.86, 74439.8, 82960.7, 92804.35, 104136.8,
117104, 131809.4, 148290.1, 166499.2, 186301.4, 207487.4, 229803.9,
252990.4, 276809.8, 301067.1, 325613.8, 350344.9, 375189.2, 400101.2,
425052.5, 450026.1, 475012, 500004.7, 525000.9, 549999.1 ;
"""
totmocc = cnc.getNCvar(filenamec,'MOC',sqz=False)
totmocp = cnc.getNCvar(filenamep,'MOC',sqz=False)
print totmocc.shape
mocc=totmocc[0,0,0,...]
print mocc.shape
print totmocp.shape
mocp=totmocp[0,0,0,...]
# <codecell>
lats,levs = np.meshgrid(latauxgrid,mocz/100.)
contsp = np.arange(0,36,3)#[0,2,4,6,8,10,12,14,16,18,20]
contsn = np.arange(-10,-.5,.5)
fig = plt.figure()
ax = fig.add_subplot(111)
CS1 = plt.contour(lats,levs,mocc,contsp,\
colors='k',linestyles='solid')
plt.clabel(CS1,fmt = '%2.1f',inline=1,fontsize=10)
CS1 = plt.contour(lats,levs,mocc,contsn,\
colors='k',linestyles='dashed')
plt.clabel(CS1,fmt = '%2.1f',inline=1,fontsize=10)
ax.set_ylim((0,3000))
ax.invert_yaxis()
ax.set_xlim((-80,-40))
ax.set_title(casenamec + ' Eul MOC')
# <headingcell level=3>
# Fig. 1: Climo Eulerian MOC (1970-1999)
# <codecell>
contspd = np.arange(0,5,.2)
contsnd = np.arange(-5,-.2,.3)
fig = plt.figure()
ax = fig.add_subplot(111)
CS1 = plt.contour(lats,levs,mocp-mocc,contspd,\
colors='k',linestyles='solid')
plt.clabel(CS1,fmt = '%2.1f',inline=1,fontsize=10)
CS1 = plt.contour(lats,levs,mocp-mocc,contsnd,\
colors='k',linestyles='dashed')
plt.clabel(CS1,fmt = '%2.1f',inline=1,fontsize=10)
#CS1 = plt.contour(lats,levs,mocp-mocc,[0,0],\
# colors='r',linestyles='solid')
ax.set_ylim((0,3000))
ax.invert_yaxis()
ax.set_xlim((-80,-40))
ax.set_title(casenamep + ' - ' + casenamec + ' Eul MOC anomaly')
# <headingcell level=3>
# Fig. 2: Sulfate engineering (geo2035ensavg): Anomalous Eulerian MOC
# <codecell>
casenamep2 = 'rcp8_5GHGrem1850' # or 'rcp8_5GHGrem1850'
filenamep2 = basepath + casenamep2 + '/' + casenamep2 + '.pop.ANN.2045-2054.nc'
print filenamep
totmocp2 = cnc.getNCvar(filenamep2,'MOC',sqz=False)
mocp2=totmocp2[0,0,0,...]
contspd = np.arange(.2,5,.2)
contsnd = np.arange(-5,-.2,.3)
fig = plt.figure()
ax = fig.add_subplot(111)
CS1 = plt.contour(lats,levs,mocp2-mocc,contspd,\
colors='k',linestyles='solid')
plt.clabel(CS1,fmt = '%2.1f',inline=1,fontsize=10)
CS1 = plt.contour(lats,levs,mocp2-mocc,contsnd,\
colors='k',linestyles='dashed')
plt.clabel(CS1,fmt = '%2.1f',inline=1,fontsize=10)
#CS1 = plt.contour(lats,levs,mocp-mocc,[0,0],\
# colors='r',linestyles='solid')
ax.set_ylim((0,3000))
ax.invert_yaxis()
ax.set_xlim((-80,-40))
ax.set_title(casenamep2 + ' - ' + casenamec + ' Eul MOC anomaly')
# <headingcell level=3>
# Fig. 3: GHG removal (rcp8_5GHGrem1850): Anomalous Eulerian MOC
# <codecell>
kmt = cnc.getNCvar(filenamec,'KMT')
# Now add TEMP
tempc = np.squeeze(cnc.getNCvar(filenamec,'TEMP'))
tempp = np.squeeze(cnc.getNCvar(filenamep,'TEMP'))
tempp2 = np.squeeze(cnc.getNCvar(filenamep2,'TEMP'))
zt = cnc.getNCvar(filenamec, 'z_t')
tlat = cnc.getNCvar(filenamec,'TLAT')
tlon = cnc.getNCvar(filenamec,'TLONG')
tarea=cnc.getNCvar(filenamec,'TAREA')
tareat = np.tile(tarea,(len(zt),1,1))
import numpy.ma as ma
print tempc.shape
for lii,zz in enumerate(zt):
# first mask out levels below sea floor
tempc[lii,...] = ma.masked_where(kmt <= lii,tempc[lii,...])
tempp[lii,...] = ma.masked_where(kmt <= lii,tempp[lii,...])
tempp2[lii,...] = ma.masked_where(kmt <= lii,tempp2[lii,...])
tareat[lii,...] = ma.masked_where(kmt <= lii,tareat[lii,...]) # @@ not working??
tareat = ma.masked_where(tempp.mask,tareat)
totzonalarea= ma.sum(tareat,axis=2)
totzonalareat=np.tile(totzonalarea,(tareat.shape[2],1,1))
totzonalareat=np.transpose(totzonalareat,(1,2,0))
fullzonalwgts= tareat/totzonalareat
fullzonalwgts=ma.masked_where(tareat.mask,fullzonalwgts) # remember have to use fld.mask !
if pig: # 80W to 120W. Or 280 to 230
printtofile=False
""" @@@@ need to weight the grid cells by area, even for zonal means. @@@@
piglon = range(230,281) # lon indices
piglat = range(0,187) # lat indices
kmtpig=kmt[piglat,:]
kmtpig=kmtpig[:,piglon]
tareapig=tarea[piglat,:]
tareapig=tareapig[:,piglon]
kmtpigt = np.tile(kmtpig,(fld.shape[0],1,1))
tareapigt = np.tile(tareapig,(len(zt),1,1))
tareat = np.tile(tarea,(len(zt),1,1))
"""
lonlims = [230,280]; region = 'PIG'; strlims='80W-120W'
#lonlims = [230,260]; region='PIG2'; strlims='100W-120W'
rmaskout = np.logical_and(tlon>lonlims[0], tlon<lonlims[1]) # region mask! this masks OUT the region itself
rmask = np.logical_or(tlon<=lonlims[0],tlon>=lonlims[1]) # use this one for averaging. keep only the region
testmask = tempc[0,...]
testmask = ma.masked_where(rmask,testmask)
bm = cplt.kemmap(testmask,tlat[:,0],tlon[0,:],title='region mask',type='sh')
if printtofile:
plt.savefig(region + '_' + strlims + '_map.pdf')
# tile the mask
rmask = np.tile(rmask,(len(zt),1,1))
print rmask.shape
tempcreg = ma.masked_where(rmask,tempc)
temppreg = ma.masked_where(rmask,tempp)
tempp2reg = ma.masked_where(rmask,tempp2)
tareatreg = ma.masked_where(rmask,tareat)
# now also mask out cells below ocean floor:
for lii,zz in enumerate(zt):
# mask out levels below sea floor
tempcreg[lii,...] = ma.masked_where(kmt <= lii,tempcreg[lii,...]) # @@@ do the masks combine? hope so.
temppreg[lii,...] = ma.masked_where(kmt <= lii,temppreg[lii,...])
tempp2reg[lii,...] = ma.masked_where(kmt <= lii, tempp2reg[lii,...])
tareatreg[lii,...] = ma.masked_where(kmt <= lii, tareatreg[lii,...])
# @@@ test plot again
#testagain=tareatreg # @@ hopefully doubley-masked. YES works.
#plt.figure()
#ret=cplt.kemmap(testagain[0,...],tlat[:,0],tlon[0,:],title='double masked field?',type='sh')
#plt.figure()
#ret=cplt.kemmap(testagain[50,...],tlat[:,0],tlon[0,:],title='double masked field?',type='sh')
regzonalarea= ma.sum(tareatreg,axis=2) # only want to sum where there isn't land
regzonalareat=np.tile(regzonalarea,(tareatreg.shape[2],1,1))
regzonalareat=np.transpose(regzonalareat,(1,2,0))
regzonalwgts= tareatreg/regzonalareat
regzonalwgts=ma.masked_where(tareatreg.mask,regzonalwgts)
#plt.figure()
#ret=cplt.kemmap(regzonalwgts[0,...],tlat[:,0],tlon[0,:],title='regzonmask: double masked field?',type='sh')
#plt.figure()
#ret=cplt.kemmap(regzonalwgts[50,...],tlat[:,0],tlon[0,:],title='regzonmask: double masked field?',type='sh')
#tempcreg=np.squeeze(np.mean(tempcreg,axis=2))
#temppreg=np.squeeze(np.mean(temppreg,axis=2))
#tempp2reg=np.squeeze(np.mean(tempp2reg,axis=2))
# don't actually need weights in zonal mean, but can't hurt.
# need weights in area average for SLR and vert heat trans
# @@@@ but I still can't figure out what's wrong with vert heat trans calc at depth.
tempcreg=np.squeeze(ma.average(tempcreg,axis=2,weights=regzonalwgts))
temppreg=np.squeeze(ma.average(temppreg,axis=2,weights=regzonalwgts))
tempp2reg=np.squeeze(ma.average(tempp2reg,axis=2,weights=regzonalwgts))
tlats,zlevs = np.meshgrid(np.squeeze(tlat[:,1]),zt/100.)
cmap='jet'
cmin=-2; cmax=8
#cmlen=float( plt.cm.get_cmap(cmap).N) # or: from __future__ import division
cmlen=float(30)
incr = (cmax-cmin) / (cmlen)
conts = np.arange(cmin,cmax+incr,incr)
fig = plt.figure()
ax = fig.add_subplot(111)
CF1 = plt.contourf(tlats,zlevs,tempcreg,cmap=cmap,vmin=cmin,vmax=cmax,levels=conts,extend='both')
ax.set_ylim((0,800))
ax.invert_yaxis()
ax.set_xlim((-75,-50))
ax.set_title(region + ' climo TEMP')
cbar = fig.colorbar(CF1)
# # ====================== paper ====================
# # PIG zonal mean TEMP
#cmap='blue2red_w20'
cmap='blue2red_w20' # @@@
cmin=-.5; cmax=.5
printtofile=True
ylim=800
#cmlen=float( plt.cm.get_cmap(cmap).N) # or: from __future__ import division
cmlen=float(20)
incr = (cmax-cmin) / (cmlen)
conts = np.arange(cmin,cmax+incr,incr)
#fig = plt.figure()
fig,axs=plt.subplots(1,2,sharey=True)
ax=axs[0]
fig.set_size_inches(14,3)
#ax = fig.add_subplot(121)
CF1 = ax.contourf(tlats,zlevs,temppreg-tempcreg,cmap=cmap,vmin=cmin,vmax=cmax,levels=conts,extend='both')
# contours for MOC anomaly
contspd = np.arange(.1,5,.3)
contsnd = np.arange(-5,-.1,.3)
ax.set_ylim((0,ylim))
ax.invert_yaxis()
ax.set_xlim((-75,-50))
ax.set_yticks(np.arange(0,900,100))
ax.set_yticklabels([0,'',200,'',400,'',600,'',800],fontsize=18)
ax.set_xticks(np.arange(-75,-45,5))
ax.set_xticklabels(['75$^\circ$S', '70$^\circ$S', '65$^\circ$S', \
'60$^\circ$S', '55$^\circ$S', '50$^\circ$S'],fontsize=18)
#ax.set_title(casenamep + ' ' + region + ' anom TEMP')
ax.set_title('PIG Sulf',fontsize=18)
ax.set_ylabel('Depth (m)',fontsize=18)
ax.axvline(x=-65,linestyle='--',color='k') # @@@ the vert line is to show the area averaged in the VHT plots
#cbar = fig.colorbar(CF1)
#ax2 = fig.add_subplot(122)
ax2=axs[1]
CF2 = ax2.contourf(tlats,zlevs,tempp2reg-tempcreg,cmap=cmap,vmin=cmin,vmax=cmax,levels=conts,extend='both')
ax2.set_ylim((0,ylim))
ax2.invert_yaxis()
ax2.set_xlim((-75,-50))
ax2.set_yticks(np.arange(0,900,100))
ax2.set_yticklabels([0,'',200,'',400,'',600,'',800],fontsize=18)
ax2.set_xticks(np.arange(-75,-45,5))
ax2.set_xticklabels(['75$^\circ$S', '70$^\circ$S', '65$^\circ$S', \
'60$^\circ$S', '55$^\circ$S', '50$^\circ$S'],fontsize=18)
#ax2.set_title(casenamep2 + ' ' + region + ' anom TEMP')
ax2.set_title('PIG GHGrem',fontsize=18)
ax2.axvline(x=-65,linestyle='--',color='k') # @@@ the vert line is to show the area averaged in the VHT plots
#cbar = fig.colorbar(CF2)
cbar_ax = fig.add_axes([.91,.15, .02,.7])
fig.colorbar(CF2,cax=cbar_ax)
if printtofile:
fig.savefig('TEMPanom_subplotSHzm_' + region + '_c_ylim' + str(ylim) + '.pdf')
# ===== TEST figure showing the difference b/w Sulf and GHGrem differences
printtofile=False
cmin=-1.2; cmax=1.2
cmap='blue2red_20'
cmlen=float(20)
incr = (cmax-cmin) / (cmlen)
conts = np.arange(cmin,cmax+incr,incr)
fig = plt.figure()
fig.set_size_inches(7,3)
ax = fig.add_subplot(111)
CF1 = plt.contourf(tlats,zlevs,(temppreg-tempcreg)-(tempp2reg-tempcreg),
cmap=cmap,vmin=cmin,vmax=cmax,levels=conts,extend='both')
# contours for MOC anomaly
contspd = np.arange(.1,5,.3)
contsnd = np.arange(-5,-.1,.3)
ax.set_ylim((0,ylim))
ax.invert_yaxis()
ax.set_xlim((-75,-50))
ax.set_title(casenamep + '-' + casenamep2 + ' ' + region + ' anom TEMP')
cbar = fig.colorbar(CF1)
if printtofile:
fig.savefig('TEMPanom_Sulf-GHGrem_' + region + '.pdf')
# end if pig region
# #########################
tempc=np.squeeze(ma.mean(tempc,axis=2))
tempp=np.squeeze(ma.mean(tempp,axis=2))
tempp2=np.squeeze(ma.mean(tempp2,axis=2))
print tempc.shape
# <codecell>
tlats,zlevs = np.meshgrid(np.squeeze(tlat[:,1]),zt/100.)
cmap='jet'
cmin=-2; cmax=8
#cmlen=float( plt.cm.get_cmap(cmap).N) # or: from __future__ import division
cmlen=float(30)
incr = (cmax-cmin) / (cmlen)
conts = np.arange(cmin,cmax+incr,incr)
fig = plt.figure()
ax = fig.add_subplot(111)
CF1 = plt.contourf(tlats,zlevs,tempc,cmap=cmap,vmin=cmin,vmax=cmax,levels=conts,extend='both')
contspd = np.arange(.2,5,.2)
contsnd = np.arange(-5,-.2,.3)
CS1 = plt.contour(lats,levs,mocp-mocc,contspd,\
colors='k',linestyles='solid')
plt.clabel(CS1,fmt = '%2.1f',inline=1,fontsize=10)
CS1 = plt.contour(lats,levs,mocp-mocc,contsnd,\
colors='k',linestyles='dashed')
plt.clabel(CS1,fmt = '%2.1f',inline=1,fontsize=10)
ax.set_ylim((0,3000))
ax.invert_yaxis()
ax.set_xlim((-80,-40))
ax.set_title('climo TEMP & ' + casenamep + ' anom Eul MOC')
cbar = fig.colorbar(CF1)
# <headingcell level=3>
# Fig. 4: Climo TEMP (shading) with sulfate enginering anomalous Eulerian MOC (contours)
# <codecell>
# EULERIAN MOC
cmap='blue2red_w20'
cmin=-.5; cmax=.5
printtofile=False
moctype='eul'
#cmlen=float( plt.cm.get_cmap(cmap).N) # or: from __future__ import division
cmlen=float(20)
incr = (cmax-cmin) / (cmlen)
conts = np.arange(cmin,cmax+incr,incr)
fig = plt.figure()
fig.set_size_inches(14,3)
ax = fig.add_subplot(121)
CF1 = plt.contourf(tlats,zlevs,tempp-tempc,cmap=cmap,vmin=cmin,vmax=cmax,levels=conts,extend='both')
# contours for MOC anomaly
contspd = np.arange(.1,5,.3)
contsnd = np.arange(-5,-.1,.3)
CS1 = plt.contour(lats,levs,mocp-mocc,contspd,\
colors='k',linestyles='solid',linewidths=2)
#plt.clabel(CS1,fmt = '%2.1f',inline=1,fontsize=10)
CS1 = plt.contour(lats,levs,mocp-mocc,contsnd,\
colors='k',linestyles='solid')
#plt.clabel(CS1,fmt = '%2.1f',inline=1,fontsize=10)
ax.set_ylim((0,2000))
ax.invert_yaxis()
ax.set_xlim((-80,-40))
ax.set_title(casenamep + ' anom TEMP (shade) & ' + moctype + ' MOC (cont)')
cbar = fig.colorbar(CF1)
ax2 = fig.add_subplot(122)
CF2 = plt.contourf(tlats,zlevs,tempp2-tempc,cmap=cmap,vmin=cmin,vmax=cmax,levels=conts,extend='both')
CS2 = plt.contour(lats,levs,mocp2-mocc,contspd,\
colors='k',linestyles='solid',linewidths=2)
#plt.clabel(CS2,fmt = '%2.1f',inline=1,fontsize=10)
CS2 = plt.contour(lats,levs,mocp2-mocc,contsnd,\
colors='k',linestyles='solid')
#plt.clabel(CS2,fmt = '%2.1f',inline=1,fontsize=10)
ax2.set_ylim((0,2000))
ax2.invert_yaxis()
ax2.set_xlim((-80,-40))
ax2.set_title(casenamep2 + ' anom TEMP (shade) & ' + moctype + ' MOC (cont)')
cbar = fig.colorbar(CF2)
if printtofile:
fig.savefig('MOC' + moctype + 'anom_climoTEMP_subplotSHzm.pdf')
# <headingcell level=3>
# Fig. 5: Anomalous TEMP (shading) with anomalous Eulerian MOC in contours (left: sulfate, right: ghgrem)
# <codecell>
# EDDY-INDUCED MOC
cmap='blue2red_w20'
cmin=-.5; cmax=.5
#cmlen=float( plt.cm.get_cmap(cmap).N) # or: from __future__ import division
cmlen=float(20)
incr = (cmax-cmin) / (cmlen)
conts = np.arange(cmin,cmax+incr,incr)
plotmoc = totmocp[0,0,1,...]-totmocc[0,0,1,...] # eddy-induced
plotmoc2 = totmocp2[0,0,1,...]-totmocc[0,0,1,...] # eddy-induced
moctype='eddy'
fig = plt.figure()
fig.set_size_inches(14,3)
ax = fig.add_subplot(121)
CF1 = plt.contourf(tlats,zlevs,tempp-tempc,cmap=cmap,vmin=cmin,vmax=cmax,levels=conts,extend='both')
# contours for MOC anomaly
contspd = np.arange(.2,5,.3)
contsnd = np.arange(-5,-.2,.3)
CS1 = plt.contour(lats,levs,plotmoc,contspd,\
colors='k',linestyles='solid',linewidths=2)
#plt.clabel(CS1,fmt = '%2.1f',inline=1,fontsize=10)
CS1 = plt.contour(lats,levs,plotmoc,contsnd,\
colors='k',linestyles='solid')
#plt.clabel(CS1,fmt = '%2.1f',inline=1,fontsize=10)
ax.set_ylim((0,2000))
ax.invert_yaxis()
ax.set_xlim((-80,-40))
ax.set_title(casenamep + ' anom TEMP (shade) & ' + moctype + ' MOC (cont)')
cbar = fig.colorbar(CF1)
ax2 = fig.add_subplot(122)
CF2 = plt.contourf(tlats,zlevs,tempp2-tempc,cmap=cmap,vmin=cmin,vmax=cmax,levels=conts,extend='both')
CS2 = plt.contour(lats,levs,plotmoc2,contspd,\
colors='k',linestyles='solid',linewidths=2)
#plt.clabel(CS2,fmt = '%2.1f',inline=1,fontsize=10)
CS2 = plt.contour(lats,levs,plotmoc2,contsnd,\
colors='k',linestyles='solid')
#plt.clabel(CS2,fmt = '%2.1f',inline=1,fontsize=10)
ax2.set_ylim((0,2000))
ax2.invert_yaxis()
ax2.set_xlim((-80,-40))
ax2.set_title(casenamep2 + ' anom TEMP (shade) & ' + moctype + ' MOC (cont)')
cbar = fig.colorbar(CF2)
if printtofile:
fig.savefig('MOC' + moctype + 'anom_climoTEMP_subplotSHzm.pdf')
# <headingcell level=3>
# Fig. 6: Anomalous TEMP (shading) with anomalous Eddy-induced MOC in contours (left: sulfate, right: ghgrem)
# <codecell>
# TOTAL (EULERIAN + EDDY-INDUCED) MOC
cmap='blue2red_w20'
cmin=-.5; cmax=.5
printtofile=False
#cmlen=float( plt.cm.get_cmap(cmap).N) # or: from __future__ import division
cmlen=float(20)
incr = (cmax-cmin) / (cmlen)
conts = np.arange(cmin,cmax+incr,incr)
plotmoc = (totmocp[0,0,1,...]+totmocp[0,0,0,...])-(totmocc[0,0,1,...]+totmocc[0,0,0,...]) # Eulerian+eddy-induced
plotmoc2 = (totmocp2[0,0,1,...]+totmocp2[0,0,0,...])-(totmocc[0,0,1,...]+totmocc[0,0,0,...]) # Eulerian+eddy-induced
moctype='eul+edd'
fig = plt.figure()
fig.set_size_inches(14,3)
ax = fig.add_subplot(121)
CF1 = plt.contourf(tlats,zlevs,tempp-tempc,cmap=cmap,vmin=cmin,vmax=cmax,levels=conts,extend='both')
# contours for MOC anomaly
contspd = np.arange(.1,5,.3)
contsnd = np.arange(-5,-.1,.3)
CS1 = plt.contour(lats,levs,plotmoc,contspd,\
colors='k',linestyles='solid',linewidths=2)
#plt.clabel(CS1,fmt = '%2.1f',inline=1,fontsize=10)
CS1 = plt.contour(lats,levs,plotmoc,contsnd,\
colors='k',linestyles='solid')
#plt.clabel(CS1,fmt = '%2.1f',inline=1,fontsize=10)
ax.set_ylim((0,2000))
ax.invert_yaxis()
ax.set_xlim((-80,-40))
ax.set_title(casenamep + ' anom TEMP (shade) & ' + moctype + ' MOC (cont)')
cbar = fig.colorbar(CF1)
ax2 = fig.add_subplot(122)
CF2 = plt.contourf(tlats,zlevs,tempp2-tempc,cmap=cmap,vmin=cmin,vmax=cmax,levels=conts,extend='both')
CS2 = plt.contour(lats,levs,plotmoc2,contspd,\
colors='k',linestyles='solid',linewidths=2)
#plt.clabel(CS2,fmt = '%2.1f',inline=1,fontsize=10)
CS2 = plt.contour(lats,levs,plotmoc2,contsnd,\
colors='k',linestyles='solid')
#plt.clabel(CS2,fmt = '%2.1f',inline=1,fontsize=10)
ax2.set_ylim((0,2000))
ax2.invert_yaxis()
ax2.set_xlim((-80,-40))
ax2.set_title(casenamep2 + ' anom TEMP (shade) & ' + moctype + ' MOC (cont)')
cbar = fig.colorbar(CF2)
if printtofile:
fig.savefig('MOC' + moctype + 'anom_climoTEMP_subplotSHzm.pdf')
# <headingcell level=3>
# Fig. 7: Same as above, but total anomalous MOC (Eulerian + eddy-induced)
# <codecell>
# ZOOM: TOTAL (EULERIAN + EDDY-INDUCED) MOC
cmap='blue2red_w20'
cmin=-.5; cmax=.5
printtofile=False
#cmlen=float( plt.cm.get_cmap(cmap).N) # or: from __future__ import division
cmlen=float(20)
incr = (cmax-cmin) / (cmlen)
conts = np.arange(cmin,cmax+incr,incr)
plotmoc = (totmocp[0,0,1,...]+totmocp[0,0,0,...])-(totmocc[0,0,1,...]+totmocc[0,0,0,...]) # Eulerian+eddy-induced
plotmoc2 = (totmocp2[0,0,1,...]+totmocp2[0,0,0,...])-(totmocc[0,0,1,...]+totmocc[0,0,0,...]) # Eulerian+eddy-induced
moctype='eul+edd'
fig = plt.figure()
fig.set_size_inches(14,3)
ax = fig.add_subplot(121)
CF1 = plt.contourf(tlats,zlevs,tempp-tempc,cmap=cmap,vmin=cmin,vmax=cmax,levels=conts,extend='both')
# contours for MOC anomaly
#contspd = np.arange(.01,5,.1)
contspd = [.05,.1,.2,.3,.4,.5,1,1.5]
#contsnd = np.arange(-5,-.01,.1)
contsnd = [-1.5,-1,-.5,-.4,-.3,-.2,-.1,-.05]
CS1 = plt.contour(lats,levs,plotmoc,contspd,\
colors='k',linestyles='solid',linewidths=2)
#plt.clabel(CS1,fmt = '%2.1f',inline=1,fontsize=10)
CS1 = plt.contour(lats,levs,plotmoc,contsnd,\
colors='k',linestyles='solid')
#plt.clabel(CS1,fmt = '%2.1f',inline=1,fontsize=10)
ax.set_ylim((0,1000))
ax.invert_yaxis()
ax.set_xlim((-80,-55))
ax.set_title(casenamep + ' anom TEMP (shade) & ' + moctype + ' MOC (cont)')
cbar = fig.colorbar(CF1)
ax2 = fig.add_subplot(122)
CF2 = plt.contourf(tlats,zlevs,tempp2-tempc,cmap=cmap,vmin=cmin,vmax=cmax,levels=conts,extend='both')
CS2 = plt.contour(lats,levs,plotmoc2,contspd,\
colors='k',linestyles='solid',linewidths=2)
#plt.clabel(CS2,fmt = '%2.1f',inline=1,fontsize=10)
CS2 = plt.contour(lats,levs,plotmoc2,contsnd,\
colors='k',linestyles='solid')
#plt.clabel(CS2,fmt = '%2.1f',inline=1,fontsize=10)
ax2.set_ylim((0,1000))
ax2.invert_yaxis()
ax2.set_xlim((-80,-55))
ax2.set_title(casenamep2 + ' anom TEMP (shade) & ' + moctype + ' MOC (cont)')
cbar = fig.colorbar(CF2)
if printtofile:
fig.savefig('MOC' + moctype + 'anom_climoTEMP_subplotSHzmZOOM.pdf')
# <headingcell level=3>
# Fig. 8: Same as Fig. 7 (total MOC) but zoomed in
# <codecell>
# SUBMESO-SCALE EDDY
cmap='blue2red_w20'
cmin=-.5; cmax=.5
printtofile=False
#cmlen=float( plt.cm.get_cmap(cmap).N) # or: from __future__ import division
cmlen=float(20)
incr = (cmax-cmin) / (cmlen)
conts = np.arange(cmin,cmax+incr,incr)
plotmoc = totmocp[0,0,2,...]-totmocc[0,0,2,...] # submeso
plotmoc2 = totmocp2[0,0,2,...]-totmocc[0,0,2,...] # submeso
moctype='submeso'
fig = plt.figure()
fig.set_size_inches(14,3)
ax = fig.add_subplot(121)
CF1 = plt.contourf(tlats,zlevs,tempp-tempc,cmap=cmap,vmin=cmin,vmax=cmax,levels=conts,extend='both')
# contours for MOC anomaly
contspd = np.arange(.1,5,.2)
contsnd = np.arange(-5,-.1,.2)
CS1 = plt.contour(lats,levs,plotmoc,contspd,\
colors='k',linestyles='solid',linewidths=2)
#plt.clabel(CS1,fmt = '%2.1f',inline=1,fontsize=10)
CS1 = plt.contour(lats,levs,plotmoc,contsnd,\
colors='k',linestyles='solid')
#plt.clabel(CS1,fmt = '%2.1f',inline=1,fontsize=10)
ax.set_ylim((0,2000))
ax.invert_yaxis()
ax.set_xlim((-80,-40))
ax.set_title(casenamep + ' anom TEMP (shade) & ' + moctype + ' MOC (cont)')
cbar = fig.colorbar(CF1)
ax2 = fig.add_subplot(122)
CF2 = plt.contourf(tlats,zlevs,tempp2-tempc,cmap=cmap,vmin=cmin,vmax=cmax,levels=conts,extend='both')
CS2 = plt.contour(lats,levs,plotmoc2,contspd,\
colors='k',linestyles='solid',linewidths=2)
#plt.clabel(CS2,fmt = '%2.1f',inline=1,fontsize=10)
CS2 = plt.contour(lats,levs,plotmoc2,contsnd,\
colors='k',linestyles='solid')
#plt.clabel(CS2,fmt = '%2.1f',inline=1,fontsize=10)
ax2.set_ylim((0,2000))
ax2.invert_yaxis()
ax2.set_xlim((-80,-40))
ax2.set_title(casenamep2 + ' anom TEMP (shade) & ' + moctype + ' MOC (cont)')
cbar = fig.colorbar(CF2)
if printtofile:
fig.savefig('MOC' + moctype + 'anom_climoTEMP_subplotSHzm.pdf')
# <headingcell level=3>
# Fig. 9: same as Figs 5,6, etc but submeso-scale eddy MOC
# <headingcell level=3>
# Next, Calculate wprime*dTbar/dz at all levels
# <codecell>
print filenamec
print filenamep
print filenamep2
kmt = cnc.getNCvar(filenamec,'KMT')
wvc = np.squeeze(cnc.getNCvar(filenamec,'WVEL'))/100. # convert to m/s
wic = np.squeeze(cnc.getNCvar(filenamec,'WISOP'))/100.
wvp = np.squeeze(cnc.getNCvar(filenamep,'WVEL'))/100.
wip = np.squeeze(cnc.getNCvar(filenamep,'WISOP'))/100.
wvp2 = np.squeeze(cnc.getNCvar(filenamep2,'WVEL'))/100.
wip2 = np.squeeze(cnc.getNCvar(filenamep2,'WISOP'))/100.
# for each level, calc wprime*dTvar/dz
wprime = (wvp+wip)-(wvc+wic)
wprime2= (wvp2+wip2)-(wvc+wic)
wvelprime = wvp-wvc
wisopprime = wip-wic
wvelprime2 = wvp2-wvc
wisopprime2 = wip2-wic
# also wbar*dTprime/dz
wbar = wvc+wic
wisopbar = wic
wvelbar = wvc
print wprime.shape
# use index-of deepest grid cell to determine if the cell should be included in zonal mean
# for each level:
# if kmt<=level index:
# mask the cell
# aka: for each level, mask where kmt<=level index
import numpy.ma as ma
import scipy.stats
for lii,zz in enumerate(zt):
# first mask out levels below sea floor
wprime[lii,...] = ma.masked_where(kmt <= lii,wprime[lii,...])
wprime2[lii,...] = ma.masked_where(kmt <= lii,wprime2[lii,...])
wvelprime[lii,...] = ma.masked_where(kmt <= lii,wvelprime[lii,...])
wvelprime2[lii,...] = ma.masked_where(kmt <= lii,wvelprime2[lii,...])
wisopprime[lii,...] = ma.masked_where(kmt <= lii,wisopprime[lii,...])
wisopprime2[lii,...] = ma.masked_where(kmt <= lii,wisopprime2[lii,...])
wbar[lii,...] = ma.masked_where(kmt <= lii,wbar[lii,...])
wvelbar[lii,...] = ma.masked_where(kmt <= lii,wvelbar[lii,...])
wisopbar[lii,...] = ma.masked_where(kmt <= lii,wisopbar[lii,...])
#plt.figure()
#plt.pcolor(wprime[10,...],vmin=-2e-6,vmax=2e-6)
#plt.colorbar()
# Now take zonal mean
#wprime = np.squeeze(sp.stats.nanmean(wprime,axis=2)) # give wtrans of Inf and 0 in most spots?
#wprime2 = np.squeeze(sp.stats.nanmean(wprime2,axis=2))
if pig:
wprimereg = ma.masked_where(rmask,wprime)
wprime2reg = ma.masked_where(rmask,wprime2)
wvelprimereg = ma.masked_where(rmask,wvelprime)
wvelprime2reg = ma.masked_where(rmask,wvelprime2)
wisopprimereg = ma.masked_where(rmask,wisopprime)
wisopprime2reg = ma.masked_where(rmask,wisopprime2)
# test masks again @@@@ works fine
#testmaskxx = wprimereg
#plt.figure()
#ret=cplt.kemmap(testmaskxx[0,...],tlat[:,0],tlon[0,:],type='sh',title='wprimereg mask test')
#plt.figure()
#ret=cplt.kemmap(testmaskxx[50,...],tlat[:,0],tlon[0,:],type='sh',title='wprimereg mask test')
wbarreg = ma.masked_where(rmask,wbar)
wvelbarreg = ma.masked_where(rmask,wvelbar)
wisopbarreg = ma.masked_where(rmask,wisopbar)
#zonal mean
# @@@ change to ma.mean
wprimereg = np.squeeze(ma.mean(wprimereg,axis=2))
wprime2reg = np.squeeze(ma.mean(wprime2reg,axis=2))
wvelprimereg = np.squeeze(ma.mean(wvelprimereg,axis=2))
wvelprime2reg = np.squeeze(ma.mean(wvelprime2reg,axis=2))
wisopprimereg = np.squeeze(ma.mean(wisopprimereg,axis=2))
wisopprime2reg = np.squeeze(ma.mean(wisopprime2reg,axis=2))
wbarreg = np.squeeze(ma.mean(wbarreg,axis=2))
wvelbarreg = np.squeeze(ma.mean(wvelbarreg,axis=2))
wisopbarreg = np.squeeze(ma.mean(wisopbarreg,axis=2))
tbarreg = tempcreg# already zonal meaned MEAN T
dtbarreg = ma.diff(tbarreg,axis=0) # delta of MEAN T with height
tprimereg = temppreg-tempcreg
tprime2reg = tempp2reg-tempcreg
dtprimereg = ma.diff(tprimereg, axis=0) # delta of ANOM T with height
dtprime2reg = ma.diff(tprime2reg, axis=0)
# thickness of each layer
dzt = np.diff(zt/100.) # convert to m
# @@@@ switch to ma.zeros
wtransreg = ma.zeros((len(dzt),wprimereg.shape[1]))
wtrans2reg = ma.zeros((len(dzt),wprime2reg.shape[1]))
wtranswvreg = ma.zeros((len(dzt),wprimereg.shape[1]))
wtranswv2reg = ma.zeros((len(dzt),wprime2reg.shape[1]))
wtranswireg = ma.zeros((len(dzt),wprimereg.shape[1]))
wtranswi2reg = ma.zeros((len(dzt),wprime2reg.shape[1]))
wbartransreg = ma.zeros((len(dzt),wbarreg.shape[1])) # mean w time anom dT
wbartrans2reg = ma.zeros((len(dzt),wbarreg.shape[1])) # mean w time anom dT
wbartranswvreg = ma.zeros((len(dzt),wbarreg.shape[1]))
wbartranswv2reg = ma.zeros((len(dzt),wbarreg.shape[1]))
wbartranswireg = ma.zeros((len(dzt),wbarreg.shape[1]))
wbartranswi2reg = ma.zeros((len(dzt),wbarreg.shape[1]))
# calc heat transport (heating rate) for each level
for lii,dz in enumerate(dzt):
#print 'ind: ' + str(lii) + ', dz: ' + str(dz)
# W prime * (dTbar / dz)
wtransreg[lii,...] = wprimereg[lii,...]*(dtbarreg[lii,...]/dz)
wtrans2reg[lii,...] = wprime2reg[lii,...]*(dtbarreg[lii,...]/dz)
wtranswvreg[lii,...] = wvelprimereg[lii,...]*(dtbarreg[lii,...]/dz) # WVEL only
wtranswv2reg[lii,...] = wvelprime2reg[lii,...]*(dtbarreg[lii,...]/dz)
wtranswireg[lii,...] = wisopprimereg[lii,...]*(dtbarreg[lii,...]/dz) # WISOP only
wtranswi2reg[lii,...] = wisopprime2reg[lii,...]*(dtbarreg[lii,...]/dz)
# W bar * (dTprime / dz)
wbartransreg[lii,...] = wbarreg[lii,...]*(dtprimereg[lii,...]/dz)
wbartrans2reg[lii,...] = wbarreg[lii,...]*(dtprime2reg[lii,...]/dz)
wbartranswvreg[lii,...] = wvelbarreg[lii,...]*(dtprimereg[lii,...]/dz)
wbartranswv2reg[lii,...] = wvelbarreg[lii,...]*(dtprime2reg[lii,...]/dz)
wbartranswireg[lii,...] = wisopbarreg[lii,...]*(dtprimereg[lii,...]/dz)
wbartranswi2reg[lii,...] = wisopbarreg[lii,...]*(dtprime2reg[lii,...]/dz)
# #
# # PIG zonal mean vertical heat trans and velocity subplot
printtofile=False
meshlats,meshdz = np.meshgrid(np.squeeze(tlat[:,1]),zt[1:]/100.)
cmlen=float(20)
ylims = (0,500)
xlims = (-77,-40)
fig = plt.figure()
fig.set_size_inches(14,8)
cmax=.8; cmin=-.8
incr = (cmax-cmin) / (cmlen)
conts = np.arange(cmin,cmax+incr,incr)
ax = fig.add_subplot(241)
plt.contourf(meshlats,meshdz,dtbarreg,cmap='blue2red_20',vmin=cmin,vmax=cmax,levels=conts,extend='both')
plt.colorbar()
ax.set_ylim(ylims)
ax.set_xlim(xlims)
ax.invert_yaxis()
ax.set_title(region + ' dTbar/dz')
cmax=1e-6; cmin=-1e-6
incr = (cmax-cmin) / (cmlen)
conts = np.arange(cmin,cmax+incr,incr)
ax = fig.add_subplot(242)
plt.contourf(tlats,zlevs,wprimereg,cmap='blue2red_20',vmin=cmin,vmax=cmax,levels=conts,extend='both')
plt.colorbar()
ax.set_ylim(ylims)
ax.set_xlim(xlims)
ax.invert_yaxis()
ax.set_title('sulfates: ' + region + ' wprime')
cmax=3e-7; cmin=-3e-7
incr = (cmax-cmin) / (cmlen)
conts = np.arange(cmin,cmax+incr,incr)
ax = fig.add_subplot(243)