-
Notifications
You must be signed in to change notification settings - Fork 1
/
basicdiag_genie_toPDF.py
1864 lines (1761 loc) · 110 KB
/
basicdiag_genie_toPDF.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
# Generates basic plots using basic colorscales etc. for a biogem experiment
# ... and gathers the plot in a PDF compiled with LaTeX with one big figure per page
# Also plots the difference if only 2 exps are provided
# The idea is to obtain for each run a summary that can be compared with other runs very quickly
# Very useful to compare results of 2 exps (dev and master) before merging 2 branches on github
# To run the script, adapt the paths and filenames and just 'python basicdiag_genie_toPDF.py'
# For now, all exps must be in the same directory
# The scripts largely relies on 3 functions:
# 1. geniemap.py: plots a 2D map of a genie output
# 2. genielat.py : plots a lat-depth output
# 3. genielev.py: plots a 2D map at every depth level
# Rk: In order to accomodate cgenie experiment names with dots, we create temporary ln -s
# update Jan 19 2021 :: add seice fraction as a map
# update May 13 2020 :: computes the diff if a single run is provided, between 2 different saved time slices
# update Mar 24 2020 :: major change in the way files are read
# ... allowing more flexibility in terms of input files and saved variables
# update Mar 23 2020 :: script should work for grid other than 36 x 36 x 16
# possibility to change the cartopy map projection
# improved format of the user params
# improved communication between python and latex
# update Mar 6 2020 :: includes sedgem/omensed basic output
# update Dec 1 2019 :: plt.step corrected: using 'post', and appending the last value to each array plotted
# update Dec 1 2019 :: plots requested year (e.g., 9999.5) instead of the last time step
# ... also used to make sure that the run reached the expected duration
# update Nov 21 2019 :: if only 2 exps provided, also plots the difference and generates a 3rd PDF
# TODO
# avoid doing diff if grids are different and...
# allow diff for different grids except that does not plot diff of different vertical levels
import matplotlib as mpl
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
from matplotlib.colors import LinearSegmentedColormap
import matplotlib.ticker as mticker
import netCDF4
from netCDF4 import Dataset
import numpy as np
import matplotlib.colors as colors
import os
import string
import warnings
import netCDF4
from netCDF4 import Dataset
from matplotlib.colors import BoundaryNorm
from sklearn.linear_model import LinearRegression
from cartopy.mpl.gridliner import LONGITUDE_FORMATTER, LATITUDE_FORMATTER
########################## USER_DEFINED OPTIONS ##########################
indir ='EXAMPLE.input'
exps = ['wardetal.2018.ECOGEM.SPIN']
times2plot = [9999.5]
# MAP PROJECTIONS [https://scitools.org.uk/cartopy/docs/latest/crs/projections.html]
projdata = ccrs.LambertCylindrical() # Andy's style
#projdata = ccrs.EqualEarth() # The trendy one
#projdata = ccrs.RotatedPole() # The funny one
#projdata = ccrs.EckertIV() # Chris' style
#projdata = ccrs.PlateCarree() # Basic and boring
# MUFFIN CONFIG
do_biogem = 'y'
do_sedgem = 'n' # are we plotting sedgem outputs?
##########################################################################
# additional options (should not be changed in general)
do_diff = 'y'
save_fig = 'y'
create_pdf_summary = 'y'
plot_stepped_outline = 'y'
# nothing to change below this line
if len(exps) > 2 or len(times2plot) > 2 or (len(exps) > 2 and len(times2plot) > 2):
do_diff = 'n'
# using standard python frontend instead of the web browser
mpl.use('TkAgg')
# ignore futurewarnings
warnings.filterwarnings("ignore", category=FutureWarning)
# graphical options
plot_font_size = 13
label_size = plot_font_size/2.
plot_label_size = plot_font_size+3
mpl.rc('font', size=plot_font_size+7)
# for the figure
figXsize = 6
figYsize = 4.5
# for the annotations on the maps
xlabel = 0
ylabel = 1.05
# data projection system
data_crs = ccrs.PlateCarree()
# functions
functionstoload = ['stepped_coastline_cGENIE','stepped_outline_cGENIE','light_grid','geniemap','genielat','fakealpha','custom_colormaps', 'custom_chars','genielev', 'dopdf']
for function2load in functionstoload:
string2execute = 'source/' + function2load + '.py'
exec(open(string2execute).read()) # python 3
diffcmap = light_centered
difflower = 'darkblue'
diffupper = 'darkred'
# Here we provide the list of variables to read
# right column = name of the variable in the ncfile
# left column = name that you want to give to this variable in the workspace
# typically, I add 'sed' to sedgem variables to avoid redundance with the oceanic component
# If a field is not present in the nc file, it will just be skipped, no worries
dict_biogem3d = {
'time':'time',
'grid_topo':'grid_topo',
'grid_mask_3d':'grid_mask_3d',
'lon':'lon',
'lat':'lat',
'lon_edges':'lon_edges',
'lat_edges':'lat_edges',
'grid_area_ocn':'grid_area',
'ocn_temp':'ocn_temp',
'ocn_sal':'ocn_sal',
'phys_ocn_rho':'phys_ocn_rho',
'ocn_O2':'ocn_O2',
'ocn_H2S':'ocn_H2S',
'ocn_PO4':'ocn_PO4',
'ocn_DIC_13C':'ocn_DIC_13C',
'misc_col_Dage':'misc_col_Dage',
}
dict_biogem2d = {
'atm_temp':'atm_temp', # basic ocean state
'phys_wspeed':'phys_wspeed',
'phys_opsi':'phys_opsi',
'phys_psi':'phys_psi',
'phys_seaice':'phys_seaice',
'phys_cost':'phys_cost',
'grid_area_atm':'grid_area',
'bio_export_POC':'bio_export_POC', # export PROD
'bio_export_POC':'bio_export_POC',
'bio_diag_k_temp':'bio_diag_k_temp',
'bio_diag_k_light':'bio_diag_k_light',
'bio_diag_k_PO4':'bio_diag_k_PO4',
'lon_psi':'lon_psi', # grids
'lon_psi_edges':'lon_psi_edges',
'lat_psi':'lat_psi',
'lat_psi_edges':'lat_psi_edges',
'lat_moc':'lat_moc',
'lat_moc_edges':'lat_moc_edges',
'zt_moc':'zt_moc',
'zt':'zt',
'zt_moc_edges':'zt_moc_edges',
'zt_edges':'zt_edges',
}
dict_sedgem2d = {
'sed_lon':'lon',
'sed_lat':'lat',
'sed_lon_edges':'lon_edges',
'sed_lat_edges':'lat_edges',
'sed_grid_topo':'sed_grid_topo',
'sed_grid_mask':'sed_grid_mask',
'sed_ocn_temp':'ocn_temp', # overlying ocean properties
'sed_ocn_sal':'ocn_sal',
'sed_ocn_DIC':'ocn_DIC',
'sed_ocn_DIC_13C':'ocn_DIC_13C',
'sed_ocn_PO4':'ocn_PO4',
'sed_ocn_O2':'ocn_O2',
'sed_ocn_ALK':'ocn_ALK',
'sed_ocn_H2S':'ocn_H2S',
'sedocn_fnet_DIC_13C':'sedocn_fnet_DIC_13C', # benthic interface exchange
'sedocn_fnet_PO4':'sedocn_fnet_PO4',
'fsed_POC':'fsed_POC', # sedimentary fluxes
'fsed_POC_frac2':'fsed_POC_frac2',
'fsed_POC_13C':'fsed_POC_13C',
'fburial_det':'fburial_det', # sediment burial flux
'fburial_POC':'fburial_POC',
'fburial_POC_13C':'fburial_POC_13C',
'OMEN_wtpct_top':'OMEN_wtpct_top', # OMENSED
'OMEN_wtpct_bot':'OMEN_wtpct_bot'
}
# function to read nc fields only if they are present in the nc file
def readncfile(inpath, indic, mydata):
my_data=mydata
f = Dataset(inpath)
for x in indic:
varname = x
var2read = indic[x]
if var2read in f.variables:
my_data[varname] = f.variables[var2read][:]
f.close()
return(my_data)
def dovar(varname): # checking that var exists
truefalse = varname in globals()
return(truefalse)
globalcount = 0
expcount = 0
for exp in exps:
timecount = 0
for time2plot in times2plot:
plottedT = 'yr' + str(time2plot)
savedfiles = []
diffsavedfiles = []
filecount = 0
difffilecount = 0
if do_diff == 'y':
if globalcount ==0:
exp0 = exp
plottedT0 = plottedT
elif globalcount ==1:
exp1 = exp
plottedT1 = plottedT
########################################################################
# READING DATA #
########################################################################
# Here we loop over ncfiles, loading existing variables and skipping missing ones
# And gathering the data into a python ensemble called 'my_data'
my_data={}
if do_biogem == 'y':
my_data = readncfile(indir + '/' + exp + '/biogem/fields_biogem_3d.nc', dict_biogem3d, my_data)
my_data = readncfile(indir + '/' + exp + '/biogem/fields_biogem_2d.nc', dict_biogem2d, my_data)
if do_sedgem == 'y':
my_data = readncfile(indir + '/' + exp + '/sedgem/fields_sedgem_2d.nc', dict_sedgem2d, my_data)
# Here we read every field in 'my_data' and send them to the workspace
for varname in my_data:
exec(varname + " = my_data['" + varname + "']")
########################################################################
# BIOGEM #
########################################################################
if do_biogem == 'y':
# ===================== LOADING DATA =====================
# checking grids: no difference if grids are not the same (nor now...)
#if do_diff == 'y':
# if globalcount ==0:
# zt_0 = zt
# lon_0 = lon
# lat_0 = lat
# elif globalcount ==1:
# zt_1 = zt
# lon_1 = lon
# lat_1 = lat
# if (zt_1 != zt_0).all or (lon_1 != lon_0).all or (lat_1 != lat_0).all:
# do_diff = 'n'
# print('Grids are different, disabling do_diff')
# extracting the grid
nz = np.shape(ocn_temp)[1]
nlon = np.shape(ocn_temp)[2]
nlat = np.shape(ocn_temp)[3]
# extracting time slice of interest
T = np.argwhere(time == time2plot)[0][0] # index of the time slice to plot, as a float (not an array)
# ===================== CALCULATIONS =====================
# zonal temp
lat_ocn_temp = np.ma.mean(np.squeeze(ocn_temp[T,:,:,:]),axis=2)
# zonal salt
lat_ocn_sal = np.ma.mean(np.squeeze(ocn_sal[T,:,:,:]),axis=2)
# SST
SST = ocn_temp[T,0,:,:] # (36, 36)
latSST = np.ma.mean(np.squeeze(SST),axis=1)
ilat_tropics = np.where(abs(lat)<=30)
SST_tropics = np.squeeze(SST[ilat_tropics,:]) # checked: extracts the tropics
grid_area_ocn_tropics = np.squeeze(grid_area_ocn[ilat_tropics,:]) # checked: grid_area_ocn mashed over land
SST_tropics_avg = np.round(np.sum(np.multiply(SST_tropics,grid_area_ocn_tropics))/np.sum(grid_area_ocn_tropics),1)
# SSS
SSS = ocn_sal[T,0,:,:] # (36, 36)
if dovar('phys_ocn_rho'):
phys_ocn_rho_surface = phys_ocn_rho[T,0,:,:]
# building fake land-sea mask - required by stepped_coastline
if np.shape(np.argwhere((grid_topo.mask==True)))[0] > 0: # if some land points
landsea_mask = np.where(grid_topo.mask==True,-1,1)
land = np.ma.masked_where(landsea_mask==1,landsea_mask)
landflag = 1
else: # if waterworld, needed to avoid script to crash
landsea_mask = np.full(np.shape(grid_topo),-1)
land = np.full(np.shape(grid_topo), np.nan)
landflag = 0
plot_stepped_outline = 'n'
# ocean area
oceanareatot = np.sum(grid_area_ocn)
# SAT
SAT = atm_temp[T,:,:]
SAT_avg = np.round(np.sum(np.multiply(SAT,grid_area_atm))/np.sum(grid_area_atm),3)
if do_diff == 'y':
if globalcount ==0:
sat_0 = SAT_avg
elif globalcount ==1:
sat_1 = SAT_avg
SAT_avg_diff = sat_1 - sat_0
# phys_seaice
lat_phys_seaice = np.ma.mean(phys_seaice[T,:,:],axis=1)
# SI fraction
SIfrac = phys_seaice[T,:,:]
SIfrac50 = np.ma.masked_where(SIfrac < 50, SIfrac)
SATstr = 'Global SAT = ' + str(SAT_avg) + ' ' + degree_sign + 'C'
# deep O2
O2 = ocn_O2[T,:,:,:]*1E6 # (16, 36, 36); umol L-1)
deepO2 = np.full(np.array([36, 36]),np.nan)
# deepest level?
for i in np.arange(0,36):
for j in np.arange(0,36):
ix = np.squeeze(np.ma.where(grid_mask_3d[:,i,j].mask == False))
if ix.any(): # if land point, leave np.nan in the array
ideepest = ix[-1]
#print(ideepest)
deepO2[i,j] = O2[ideepest,i,j]
else:
deepO2[i,j] = O2[-1,i,j]
deepO2 = np.ma.masked_where(grid_topo.mask==True,deepO2)
# deepO2 on shelves
shallow_threshold = 400 # m
deepO2_shallowpfonly = np.ma.masked_where(grid_topo > shallow_threshold,deepO2)
pfmask = np.full(np.array([nlon, nlat]),1)
pfmask[grid_topo > shallow_threshold] = -1
# area of seafloor anoxia?
anoxia_threshold = 0
seafloor_anoxic_area = np.ma.masked_where(deepO2 > anoxia_threshold,grid_area_ocn)
seafloor_anoxia_abs = np.ma.sum(seafloor_anoxic_area)
seafloor_anoxia_per = seafloor_anoxia_abs / np.ma.sum(grid_area_ocn)
if do_diff == 'y':
if globalcount ==0:
seafloor_anoxia_abs_0 = seafloor_anoxia_abs
seafloor_anoxia_per_0 = seafloor_anoxia_per
elif globalcount ==1:
seafloor_anoxia_abs_1 = seafloor_anoxia_abs
seafloor_anoxia_per_1 = seafloor_anoxia_per
seafloor_anoxia_abs_diff = seafloor_anoxia_abs_1 - seafloor_anoxia_abs_0
seafloor_anoxia_per_diff = seafloor_anoxia_per_1 - seafloor_anoxia_per_0
# ocn_O2
lat_ocn_O2 = np.ma.mean(O2,axis=2)
# ocn_H2S
H2S = ocn_H2S[T,:,:,:]*1E6 # (16, 36, 36); umol L-1)
ma_H2S = np.ma.masked_where(np.squeeze(H2S) == 0, np.squeeze(H2S))
lat_ocn_H2S = np.ma.mean(H2S,axis=2)
ma_lat_ocn_H2S = np.ma.masked_where(lat_ocn_H2S == 0,lat_ocn_H2S)
if dovar('misc_col_Dage'):
lat_misc_col_Dage = np.ma.mean(misc_col_Dage[T,:,:,:], axis=2)
lat_ocn_DIC_13C = np.ma.mean(ocn_DIC_13C[T,:,:,:], axis=2)
# ===================== PLOTTING =====================
if dovar('grid_topo'):
# %%%%%%%%%%%% grid_topo %%%%%%%%%%%%
# --- parameters ---
levs = np.arange(0,5.5+1E-6,0.5)
ticklevs = levs
lower = fakealpha(mpl.colors.to_rgba('darkblue')[0:3],0.65)
upper = fakealpha(mpl.colors.to_rgba('darkred')[0:3],0.90)
cmap = fzcmap_alpha065
norm = BoundaryNorm(levs, ncolors=cmap.N, clip=False)
cbartitle = 'Bathymetry (km. b.s.l.)'
filename = exp + '_' + plottedT + '_grid_topo.png'
# --- figure ---
geniemap(lon_edges, lat_edges, grid_topo*1E-3, cmap, levs, ticklevs, 'max', lower, upper, projdata ,cbartitle, filename, 'n', 'none', 'none', 'none', 0, 'n', 'none', 'none','png')
filecount += 1; lnfile = 'file' + str(filecount) + '.png'
os.system('ln -s ' + filename + ' ' + lnfile)
savedfiles.append(filename)
# --- diff ---
if do_diff == 'y':
if globalcount ==0:
grid_topo_0 = grid_topo*1E-3
elif globalcount ==1:
grid_topo_1 = grid_topo*1E-3
diff = grid_topo_1 - grid_topo_0
difflevs = np.arange(-5.,5.+1E-3,0.5)
diffticklevs = np.arange(-5.,5.+1E-3,1)
diffextend = 'both'
difffilename = exp1 + '_' + plottedT1 + '_minus_' + exp0 + '_' + plottedT0 + '_grid_topo.png'
geniemap(lon_edges, lat_edges, diff, diffcmap, difflevs, diffticklevs, diffextend, difflower, diffupper, projdata ,cbartitle, difffilename, 'n', 'none', 'none', 'none', 0, 'n', 'none', 'none','png')
difffilecount += 1; difflnfile = 'difffile' + str(difffilecount) + '.png'
os.system('ln -s ' + difffilename + ' ' + difflnfile)
diffsavedfiles.append(difffilename)
if dovar('phys_wspeed'):
# %%%%%%%%%%%% phys_wspeed %%%%%%%%%%%%
# --- parameters ---
levs = np.arange(0,8+1E-6,0.5)
clevs = np.arange(0,8+1E-6,1)
ticklevs = np.arange(0,8+1E-6,2)
lower = fakealpha(mpl.colors.to_rgba('darkblue')[0:3],0.65)
upper = fakealpha(mpl.colors.to_rgba('darkred')[0:3],0.90)
cmap = fzcmap_alpha065
norm = BoundaryNorm(levs, ncolors=cmap.N, clip=False)
cbartitle = 'Wind speed (m s$^{-1}$)'
filename = exp + '_' + plottedT + '_phys_wspeed.png'
# --- figure ---
geniemap(lon_edges, lat_edges, phys_wspeed[T,:,:], cmap, levs, ticklevs, 'max', lower, upper, projdata ,cbartitle, filename, 'y', lon, lat, clevs, 0.75, 'n', 'none', 'none','png')
filecount += 1; lnfile = 'file' + str(filecount) + '.png'
os.system('ln -s ' + filename + ' ' + lnfile)
savedfiles.append(filename)
# --- diff ---
if do_diff == 'y':
if globalcount ==0:
phys_wspeed_0 = phys_wspeed[T,:,:]
elif globalcount ==1:
phys_wspeed_1 = phys_wspeed[T,:,:]
diff = phys_wspeed_1 - phys_wspeed_0
difflevs = np.arange(-3,3+1E-3,0.25)
diffclevs = np.arange(-3,3+1E-3,0.5)
diffticklevs = np.arange(-3,3+1E-3,1)
diffextend = 'both'
difffilename = exp1 + '_' + plottedT1 + '_minus_' + exp0 + '_' + plottedT0 + '_phys_wspeed.png'
geniemap(lon_edges, lat_edges, diff, diffcmap, difflevs, diffticklevs, diffextend, difflower, diffupper, projdata ,cbartitle, difffilename, 'y', lon, lat, diffclevs, 0.75, 'n', 'none', 'none','png')
difffilecount += 1; difflnfile = 'difffile' + str(difffilecount) + '.png'
os.system('ln -s ' + difffilename + ' ' + difflnfile)
diffsavedfiles.append(difffilename)
if dovar('phys_ocn_rho'):
# %%%%%%%%%%%% SSS %%%%%%%%%%%%
# --- parameters ---
levs = np.arange(1020,1030+1E-9,0.5) # 1E-3 is just to include the upper bound
ticklevs = np.arange(1020,1030+1E-9,2)
clevs = np.arange(1020,1030+1E-9,0.5)
extend = 'both'
lower = fakealpha(mpl.colors.to_rgba('darkblue')[0:3],0.65)
upper = fakealpha(mpl.colors.to_rgba('darkred')[0:3],0.75)
cmap = fzcmap2
cbartitle = 'rho'
filename = exp + '_' + plottedT + '_rho.png'
# --- figure ---
geniemap(lon_edges, lat_edges, phys_ocn_rho_surface, cmap, levs, ticklevs, extend, lower, upper, projdata ,cbartitle, filename, 'y', lon, lat, clevs, 0.5, 'n', 'none', 'none','png')
filecount += 1; lnfile = 'file' + str(filecount) + '.png'
os.system('ln -s ' + filename + ' ' + lnfile)
savedfiles.append(filename)
# --- diff ---
if do_diff == 'y':
if globalcount ==0:
phys_ocn_rho_surface_0 = phys_ocn_rho_surface
elif globalcount ==1:
phys_ocn_rho_surface_1 = phys_ocn_rho_surface
diff = phys_ocn_rho_surface_1 - phys_ocn_rho_surface_0
difflevs = np.arange(-2.,2.+1E-9,0.25)
diffclevs = np.arange(-2.,2.+1E-9,0.25)
diffticklevs = np.arange(-2.,2.+1E-9,0.5)
diffextend = 'both'
difffilename = exp1 + '_' + plottedT1 + '_minus_' + exp0 + '_' + plottedT0 + '_rho.png'
geniemap(lon_edges, lat_edges, diff, diffcmap, difflevs, diffticklevs, diffextend, difflower, diffupper, projdata ,cbartitle, difffilename, 'n', lon, lat, diffclevs, 0.5, 'n', 'none', 'none','png')
difffilecount += 1; difflnfile = 'difffile' + str(difffilecount) + '.png'
os.system('ln -s ' + difffilename + ' ' + difflnfile)
diffsavedfiles.append(difffilename)
if dovar('SSS'):
# %%%%%%%%%%%% SSS %%%%%%%%%%%%
# --- parameters ---
levs = np.arange(31,37+1E-9,0.25) # 1E-3 is just to include the upper bound
ticklevs = np.arange(31,37+1E-9,1)
clevs = np.arange(31,37+1E-9,1)
extend = 'both'
lower = fakealpha(mpl.colors.to_rgba('darkblue')[0:3],0.65)
upper = fakealpha(mpl.colors.to_rgba('darkred')[0:3],0.75)
cmap = fzcmap2
cbartitle = 'SSS (PSU)'
filename = exp + '_' + plottedT + '_SSS.png'
# --- figure ---
geniemap(lon_edges, lat_edges, SSS, cmap, levs, ticklevs, extend, lower, upper, projdata ,cbartitle, filename, 'y', lon, lat, clevs, 0.75, 'n', 'none', 'none','png')
filecount += 1; lnfile = 'file' + str(filecount) + '.png'
os.system('ln -s ' + filename + ' ' + lnfile)
savedfiles.append(filename)
# --- diff ---
if do_diff == 'y':
if globalcount ==0:
SSS_0 = SSS
elif globalcount ==1:
SSS_1 = SSS
diff = SSS_1 - SSS_0
difflevs = np.arange(-1.,1.+1E-6,0.1)
diffclevs = np.arange(-1.,1.+1E-6,0.1)
diffticklevs = np.arange(-1.,1.+1E-6,0.5)
diffextend = 'both'
difffilename = exp1 + '_' + plottedT1 + '_minus_' + exp0 + '_' + plottedT0 + '_SSS.png'
geniemap(lon_edges, lat_edges, diff, diffcmap, difflevs, diffticklevs, diffextend, difflower, diffupper, projdata ,cbartitle, difffilename, 'y', lon, lat, diffclevs, 1, 'n', 'none', 'none','png')
difffilecount += 1; difflnfile = 'difffile' + str(difffilecount) + '.png'
os.system('ln -s ' + difffilename + ' ' + difflnfile)
diffsavedfiles.append(difffilename)
if dovar('lat_ocn_sal'):
# %%%%%%%%%%% lat-depth sal profile %%%%%%%%%%%%
# --- parameters ---
levs = np.arange(34.6,35.2+1E-9,0.025)
ticklevs = np.arange(34.6,35.2+1E-9,0.1)
clevs = np.arange(34.6,35.2+1E-9,0.025)
lower = fakealpha(mpl.colors.to_rgba('darkblue')[0:3],0.65)
upper = fakealpha(mpl.colors.to_rgba('darkred')[0:3],0.90)
cmap = fzcmap_alpha065
norm = BoundaryNorm(levs, ncolors=cmap.N, clip=False)
extend = 'both'
cbartitle = 'Salinity (psu)'
filename = exp + '_' + plottedT + '_lat_ocn_sal.png'
# --- figure ---
genielat(lat_edges,-1*zt_edges/1000.,lat_ocn_sal, cmap, levs, ticklevs, 'both', lower, upper, cbartitle, filename, 'y', lat, -1*zt/1000., levs, 0.5)
filecount += 1; lnfile = 'file' + str(filecount) + '.png'
os.system('ln -s ' + filename + ' ' + lnfile)
savedfiles.append(filename)
# --- diff ---
if do_diff == 'y':
if globalcount ==0:
lat_ocn_sal_0 = lat_ocn_sal
elif globalcount ==1:
lat_ocn_sal_1 = lat_ocn_sal
diff = lat_ocn_sal_1 - lat_ocn_sal_0
difflevs = np.arange(-0.4,0.4+1E-3,0.02)
diffticklevs = np.arange(-0.4,0.4+1E-3,0.1)
diffextend = 'both'
difffilename = exp1 + '_' + plottedT1 + '_minus_' + exp0 + '_' + plottedT0 + '_lat_ocn_sal.png'
genielat(lat_edges,-1*zt_edges/1000.,diff, diffcmap, difflevs, diffticklevs, diffextend, difflower, diffupper, cbartitle, difffilename, 'y', lat, -1*zt/1000., difflevs, 0.5)
difffilecount += 1; difflnfile = 'difffile' + str(difffilecount) + '.png'
os.system('ln -s ' + difffilename + ' ' + difflnfile)
diffsavedfiles.append(difffilename)
if dovar('SST'):
# %%%%%%%%%%%% SST with sea ice %%%%%%%%%%%%
# not using standard functions because contour labels
# --- parameters ---
levs = np.arange(-2,36+1E-9,2) # 1E-3 is just to include the upper bound
clevsneg = np.array([-2])
clevspos = np.arange(2,50+1E-9,2)
clevszero = np.array([0])
ticklevs = levs
extend = 'max'
lower = fakealpha(mpl.colors.to_rgba('darkblue')[0:3],0.65)
upper = fakealpha(mpl.colors.to_rgba('darkred')[0:3],0.75)
cmap = fzcmap2
cbartitle = 'SST' + degree_sign + ' C'
filename = exp + '_' + plottedT + '_SST_SIfrac50perc.png'
# --- figure ---
norm = BoundaryNorm(levs, ncolors=cmap.N, clip=False)
fig = plt.figure(figsize=(figXsize, figYsize))
ax = fig.add_subplot(111,projection=projdata)
ax = fig.gca(); ax.set(aspect=2); ax.set_aspect('auto')
cf = plt.pcolormesh(lon_edges, lat_edges, SST, transform=data_crs, cmap=cmap, norm=norm)
cneg = plt.contour(lon, lat, SST, clevsneg, cmap = None, colors='k',linewidths=0.5, linestyles='dashed',transform=data_crs)
cpos = plt.contour(lon, lat, SST, clevspos, cmap = None, colors='k',linewidths=0.5,transform=data_crs)
czero = plt.contour(lon, lat,SST, clevszero, cmap = None, colors='k',linewidths=0.75,transform=data_crs)
plt.clabel(cneg,inline=1,inline_spacing=5, fontsize=label_size,fmt='%1.0f',colors='k')
plt.clabel(cpos,inline=1,inline_spacing=5,fontsize=label_size,fmt='%1.0f',colors='k')
plt.clabel(czero,inline=1,inline_spacing=5,fontsize=label_size,fmt='%1.0f',colors='k')
cf2 = plt.pcolormesh(lon_edges, lat_edges, SIfrac50, cmap=lightgreycmap, transform=ccrs.PlateCarree())
plt.pcolormesh(lon_edges, lat_edges, land, cmap=whitecmap, transform=ccrs.PlateCarree())
if landflag == 1:
stepped_coastline_cGENIE(lon_edges,lat_edges, data_crs, grid_area_ocn,1.25)
gl = ax.gridlines(crs=data_crs, draw_labels=False,
linewidth=0.5, color='k', alpha=0.2, linestyle='-', zorder=999)
gl.xlabels_top = False; gl.ylabels_left = False; gl.xlines = True
gl.xlocator = mticker.FixedLocator([-180, -120, -60, 0, 60, 120, 180]); gl.xformatter = LONGITUDE_FORMATTER
gl.ylocator = mticker.FixedLocator([-90, -60, -30, 0, 30, 60, 90]); gl.yformatter = LATITUDE_FORMATTER
gl.xlabel_style = {'size': plot_font_size, 'color': 'gray'}; gl.xlabel_style = {'color': 'red', 'weight': 'bold'}
cb = fig.colorbar(cf, orientation='horizontal',extend=extend,ticks=ticklevs)
cf.cmap.set_under(lower); cf.cmap.set_over(upper)
cb.ax.tick_params(labelsize=plot_font_size)
cb.ax.set_title(cbartitle, weight='normal', fontsize=plot_font_size)
plt.tight_layout()
filename = exp + '_' + plottedT + '_SST_SIfrac50perc.png'
if save_fig == 'y':
plt.savefig(filename,format='png', dpi=450)
filecount += 1; lnfile = 'file' + str(filecount) + '.png'
os.system('ln -s ' + filename + ' ' + lnfile)
savedfiles.append(filename)
# --- diff ---
if do_diff == 'y':
if globalcount ==0:
SST_0 = SST
elif globalcount ==1:
SST_1 = SST
diff = SST_1 - SST_0
difflevs = np.arange(-7.5,7.5+1E-3,0.5)
diffclevs = np.arange(-7.5,7.5+1E-3,0.5)
diffticklevs = np.arange(-7.5,7.5+1E-3,2.5)
diffextend = 'both'
difffilename = exp1 + '_' + plottedT1 + '_minus_' + exp0 + '_' + plottedT0 + '_SST.png'
geniemap(lon_edges, lat_edges, diff, diffcmap, difflevs, diffticklevs, diffextend, difflower, diffupper, projdata ,cbartitle, difffilename, 'y', lon, lat, diffclevs, 1., 'n', 'none', 'none','png')
difffilecount += 1; difflnfile = 'difffile' + str(difffilecount) + '.png'
os.system('ln -s ' + difffilename + ' ' + difflnfile)
diffsavedfiles.append(difffilename)
if dovar('lat_ocn_temp'):
# %%%%%%%%%%% lat-depth temp profile %%%%%%%%%%%%
# --- parameters ---
levs = np.arange(0,30+1E-9,1)
ticklevs = np.arange(0,30+1E-9,4)
clevs = np.arange(0,30+1E-9,1)
lower = fakealpha(mpl.colors.to_rgba('darkblue')[0:3],0.65)
upper = fakealpha(mpl.colors.to_rgba('darkred')[0:3],0.90)
cmap = fzcmap_alpha065
norm = BoundaryNorm(levs, ncolors=cmap.N, clip=False)
extend = 'max'
cbartitle = 'Temperature (' + degree_sign + 'C)'
filename = exp + '_' + plottedT + '_lat_ocn_temp.png'
# --- figure ---
genielat(lat_edges,-1*zt_edges/1000.,lat_ocn_temp, cmap, levs, ticklevs, 'both', lower, upper, cbartitle, filename, 'y', lat, -1*zt/1000., levs, 0.5)
filecount += 1; lnfile = 'file' + str(filecount) + '.png'
os.system('ln -s ' + filename + ' ' + lnfile)
savedfiles.append(filename)
# --- diff ---
if do_diff == 'y':
if globalcount ==0:
lat_ocn_temp_0 = lat_ocn_temp
elif globalcount ==1:
lat_ocn_temp_1 = lat_ocn_temp
diff = lat_ocn_temp_1 - lat_ocn_temp_0
difflevs = np.arange(-5,5+1E-3,0.5)
diffticklevs = np.arange(-5,5+1E-3,2.5)
diffextend = 'both'
difffilename = exp1 + '_' + plottedT1 + '_minus_' + exp0 + '_' + plottedT0 + '_lat_ocn_temp.png'
genielat(lat_edges,-1*zt_edges/1000.,diff, diffcmap, difflevs, diffticklevs, diffextend, difflower, diffupper, cbartitle, difffilename, 'y', lat, -1*zt/1000., difflevs, 0.5)
difffilecount += 1; difflnfile = 'difffile' + str(difffilecount) + '.png'
os.system('ln -s ' + difffilename + ' ' + difflnfile)
diffsavedfiles.append(difffilename)
if dovar('latSST'):
# %%%%%%%%%%%% zonal SST profile %%%%%%%%%%%%
# --- figure ---
fig = plt.figure(figsize=(figXsize, figYsize))
ax = fig.add_subplot(111)
ax = fig.gca()
cf = plt.step(lat_edges, np.append(latSST,latSST[-1]), '-k', where='post')
plt.ylim(-90, 90)
plt.ylim(-3,38)
major_yticks = np.arange(0, 35+1E-9, 5)
major_xticks = np.arange(-90, 90+1E-9, 30)
ax.set_xticks(major_xticks)
ax.set_yticks(major_yticks)
ax.tick_params(labelsize = plot_font_size)
ax.grid(which='both')
if save_fig == 'y':
filename = exp + '_' + plottedT + '_latSST.png'
plt.savefig(filename,format='png')
filecount += 1; lnfile = 'file' + str(filecount) + '.png'
os.system('ln -s ' + filename + ' ' + lnfile)
savedfiles.append(filename)
# --- diff ---
if do_diff == 'y':
if globalcount ==0:
latSST_0 = latSST
elif globalcount ==1:
latSST_1 = latSST
diff = latSST_1 - latSST_0
fig = plt.figure(figsize=(figXsize, figYsize))
ax = fig.add_subplot(111)
ax = fig.gca()
plt.step(lat_edges, np.append(latSST_0,latSST_0[-1]), '-r', where='post')
plt.step(lat_edges, np.append(latSST_1,latSST_1[-1]), '-b', where='post')
plt.ylim(-90, 90)
plt.ylim(-5,40)
major_yticks = np.arange(-5, 40+1E-9, 5)
major_xticks = np.arange(-90, 90+1E-9, 30)
ax.set_xticks(major_xticks)
ax.set_yticks(major_yticks)
ax.tick_params(labelsize = plot_font_size)
ax.grid(which='both')
if save_fig == 'y':
difffilename = exp1 + '_' + plottedT1 + '_minus_' + exp0 + '_' + plottedT0 + '_latSST.png'
plt.savefig(difffilename,format='png')
difffilecount += 1; difflnfile = 'difffile' + str(difffilecount) + '.png'
os.system('ln -s ' + difffilename + ' ' + difflnfile)
diffsavedfiles.append(difffilename)
if dovar('lat_phys_seaice'):
# %%%%%%%%%%%% phys_seaice %%%%%%%%%%%%
# --- figure ---
fig = plt.figure(figsize=(figXsize, figYsize))
ax = fig.add_subplot(111)
ax = fig.gca(); ax.set(aspect=0.5)
cf = plt.step(lat_edges, np.append(lat_phys_seaice,lat_phys_seaice[-1]), '-k', where='post')
plt.ylim(-90, 90)
plt.ylim(-0,110)
major_yticks = np.arange(0, 100+1E-9, 20)
major_xticks = np.arange(-90, 90+1E-9, 30)
ax.set_xticks(major_xticks)
ax.set_yticks(major_yticks)
ax.tick_params(labelsize = plot_font_size)
ax.grid(which='both')
if save_fig == 'y':
filename = exp + '_' + plottedT + '_phys_seaice_fraction.png'
plt.savefig(filename,format='png')
filecount += 1; lnfile = 'file' + str(filecount) + '.png'
os.system('ln -s ' + filename + ' ' + lnfile)
savedfiles.append(filename)
# --- diff ---
if do_diff == 'y':
if globalcount ==0:
lat_phys_seaice_0 = lat_phys_seaice
elif globalcount ==1:
lat_phys_seaice_1 = lat_phys_seaice
diff = lat_phys_seaice_1 - lat_phys_seaice_0
fig = plt.figure(figsize=(figXsize, figYsize))
ax = fig.add_subplot(111)
ax = fig.gca(); ax.set(aspect=0.5)
plt.step(lat_edges, np.append(lat_phys_seaice_0,lat_phys_seaice_0[-1]), '-r', where='post')
plt.step(lat_edges, np.append(lat_phys_seaice_1,lat_phys_seaice_1[-1]), '-b', where='post')
plt.ylim(-90, 90)
plt.ylim(0,110)
major_yticks = np.arange(0, 100+1E-9, 20)
major_xticks = np.arange(-90, 90+1E-9, 30)
ax.set_xticks(major_xticks)
ax.set_yticks(major_yticks)
ax.tick_params(labelsize = plot_font_size)
ax.grid(which='both')
if save_fig == 'y':
difffilename = exp1 + '_' + plottedT1 + '_minus_' + exp0 + '_' + plottedT0 + '_phys_seaice_fraction.png'
plt.savefig(difffilename,format='png', dpi=450)
difffilecount += 1; difflnfile = 'difffile' + str(difffilecount) + '.png'
os.system('ln -s ' + difffilename + ' ' + difflnfile)
diffsavedfiles.append(difffilename)
if dovar('phys_opsi'):
# %%%%%%%%%%%% MOC %%%%%%%%%%%%
# --- parameters ---
levs = np.array([-30, -25, -20, -15, -10, -5, 0, 5, 10, 15, 20, 25, 30])
lower = fakealpha(mpl.colors.to_rgba('darkblue')[0:3],0.65)
upper = fakealpha(mpl.colors.to_rgba('darkred')[0:3],0.90)
cmap = fzcmap_alpha065
norm = BoundaryNorm(levs, ncolors=cmap.N, clip=False)
extend = 'both'
cbartitle = 'Overturning streamfunction'
filename = exp + '_' + plottedT + '_phys_opsi.png'
clevs = np.arange(-35,35+1E-9,5)
# --- figure ---
genielat(lat_moc_edges,-1*zt_moc_edges/1000.,phys_opsi[T,:,:], cmap, levs, clevs, 'both', lower, upper, cbartitle, filename, 'y', lat_moc, -1*zt_moc/1000., levs, 0.75)
filecount += 1; lnfile = 'file' + str(filecount) + '.png'
os.system('ln -s ' + filename + ' ' + lnfile)
savedfiles.append(filename)
# --- diff ---
if do_diff == 'y':
if globalcount ==0:
phys_opsi_0 = phys_opsi[T,:,:]
elif globalcount ==1:
phys_opsi_1 = phys_opsi[T,:,:]
diff = phys_opsi_1 - phys_opsi_0
difflevs = np.arange(-30,30+1E-3,2.5)
#difflevs = np.arange(-10,10+1E-3,1)
diffticklevs = np.arange(-30,30+1E-3,5)
#diffticklevs = np.arange(-10,10+1E-3,5)
diffextend = 'both'
difffilename = exp1 + '_' + plottedT1 + '_minus_' + exp0 + '_' + plottedT0 + '_phys_opsi.png'
genielat(lat_moc_edges,-1*zt_moc_edges/1000.,diff, diffcmap, difflevs, diffticklevs, diffextend, difflower, diffupper, cbartitle, difffilename, 'y', lat_moc, -1*zt_moc/1000., difflevs, 0.5)
difffilecount += 1; difflnfile = 'difffile' + str(difffilecount) + '.png'
os.system('ln -s ' + difffilename + ' ' + difflnfile)
diffsavedfiles.append(difffilename)
if dovar('phys_seaice'):
# %%%%%%%%%%%% sea-ice cover percent %%%%%%%%%%%%
# --- parameters ---
levs = np.arange(0,100+1E-9,5.)
ticklevs = np.arange(0,100+1E-9,10)
lower = fakealpha(mpl.colors.to_rgba('darkblue')[0:3],0.65)
upper = fakealpha(mpl.colors.to_rgba('darkred')[0:3],0.90)
cmap = fzcmap_alpha065
norm = BoundaryNorm(levs, ncolors=cmap.N, clip=False)
extend = 'neither'
cbartitle = 'Sea-ice cover (%)'
filename = exp + '_' + plottedT + '_phys_seaice.png'
# --- figure ---
geniemap(lon_edges, lat_edges, phys_seaice[T,:,:], cmap, levs, ticklevs, 'both', lower, upper, projdata ,cbartitle, filename, 'n', 'none', 'none', 'none', 0., 'n', 'none', 'none','png')
filecount += 1; lnfile = 'file' + str(filecount) + '.png'
os.system('ln -s ' + filename + ' ' + lnfile)
savedfiles.append(filename)
# --- diff ---
if do_diff == 'y':
if globalcount ==0:
phys_seaice_0 = phys_seaice[T,:,:]
elif globalcount ==1:
phys_seaice_1 = phys_seaice[T,:,:]
diff = phys_seaice_1 - phys_seaice_0
difflevs = np.arange(-100,100+1E-9,10)
diffticklevs = np.arange(-100,100+1E-9,20)
diffextend = 'both'
difffilename = exp1 + '_' + plottedT1 + '_minus_' + exp0 + '_' + plottedT0 + '_phys_seaice.png'
geniemap(lon_edges, lat_edges, diff, diffcmap, difflevs, diffticklevs, diffextend, difflower, diffupper, projdata ,cbartitle, difffilename, 'n', 'none', 'none', 'none', 1.25, 'n', 'none', 'none','png')
difffilecount += 1; difflnfile = 'difffile' + str(difffilecount) + '.png'
os.system('ln -s ' + difffilename + ' ' + difflnfile)
diffsavedfiles.append(difffilename)
if dovar('phys_cost'):
# %%%%%%%%%%%% convective adjustments %%%%%%%%%%%%
conv_threshold = 500
# --- parameters ---
levs = np.arange(0,600+1E-6,50)
if np.max(phys_cost[T,:,:]) > conv_threshold: # if new diag in nb/yr (48 biogem timesteps in 1 year)
timestep_factor = 1.
else: # still old diag in nb/timestep
timestep_factor = 48.
lower = fakealpha(mpl.colors.to_rgba('darkblue')[0:3],0.65)
upper = fakealpha(mpl.colors.to_rgba('darkred')[0:3],0.90)
cmap = fzcmap_alpha065
norm = BoundaryNorm(levs, ncolors=cmap.N, clip=False)
extend = 'max'
cbartitle = 'Ocean convection'
filename = exp + '_' + plottedT + '_phys_cost.png'
# --- figure ---
geniemap(lon_edges, lat_edges, phys_cost[T,:,:]*timestep_factor, cmap, levs, levs, 'both', lower, upper, projdata ,cbartitle, filename, 'n', 'none', 'none', 'none', 0., 'n', 'none', 'none','png')
filecount += 1; lnfile = 'file' + str(filecount) + '.png'
os.system('ln -s ' + filename + ' ' + lnfile)
savedfiles.append(filename)
# --- diff ---
if do_diff == 'y':
if globalcount ==0:
phys_cost_0 = phys_cost[T,:,:]*timestep_factor
elif globalcount ==1:
phys_cost_1 = phys_cost[T,:,:]*timestep_factor
diff = phys_cost_1 - phys_cost_0
difflevs = np.arange(-400,400+1E-3,20)
diffticklevs = np.arange(-400,400+1E-3,100)
diffextend = 'both'
difffilename = exp1 + '_' + plottedT1 + '_minus_' + exp0 + '_' + plottedT0 + '_phys_cost.png'
geniemap(lon_edges, lat_edges, diff, diffcmap, difflevs, diffticklevs, diffextend, difflower, diffupper, projdata ,cbartitle, difffilename, 'n', 'none', 'none', 'none', 1.25, 'n', 'none', 'none','png')
difffilecount += 1; difflnfile = 'difffile' + str(difffilecount) + '.png'
os.system('ln -s ' + difffilename + ' ' + difflnfile)
diffsavedfiles.append(difffilename)
if dovar('phys_psi'):
# %%%%%%%%%%%% phys_psi %%%%%%%%%%%%
# not using standard functions because possibility to highlight anormal values
# --- parameters ---
lookfor_issues = 'n' # 'y' if you want to check runs, 'n' if you want a publication-ready figure
thres = 50 # threshold in Sv for anormal values
levs = np.arange(-60,60+1E-6,2.5)
clevs = np.arange(-1000,100+1E-6,5)
clevs2 = np.arange(-100,100+1E-6,10)
lower = fakealpha(mpl.colors.to_rgba('darkblue')[0:3],0.65)
upper = fakealpha(mpl.colors.to_rgba('darkred')[0:3],0.90)
cmap = light_centered
norm = BoundaryNorm(levs, ncolors=cmap.N, clip=False)
extend = 'both'
cbartitle = 'Barotropic streamfunction (Sv)'
# highlight anormaly high values
if lookfor_issues == 'y':
ix = np.array([])
sqval = np.squeeze(phys_psi[T,:,:])
ix = np.argwhere(abs(sqval) > thres)
nbanomalies = np.shape(ix)[0]
if nbanomalies > 0:
print(' Value > ' + str(thres) + ' Sv detected in ' + str(nbanomalies) + ' location(s) -- DANGER')
anomalflag = 'y'
else:
anomalflag = 'f'
# --- figure ---
fig = plt.figure(figsize=(figXsize, figYsize))
ax = fig.add_subplot(111,projection=projdata)
ax = fig.gca(); ax.set(aspect=2); ax.set_aspect('auto')
cf = plt.pcolormesh(lon_psi_edges, lat_psi_edges, phys_psi[T,:,:], transform=ccrs.PlateCarree(),cmap=cmap, norm=norm)
ct = plt.contour(lon_psi, lat_psi, np.squeeze(phys_psi[T,:,:]), clevs, transform=ccrs.PlateCarree(), colors='k', linewidths = 0.45)
ct2 = plt.contour(lon_psi, lat_psi, np.squeeze(phys_psi[T,:,:]), clevs2, transform=ccrs.PlateCarree(), colors='k', linewidths = 0.75)
plt.pcolormesh(lon_edges, lat_edges, land, cmap=whitecmap, transform=ccrs.PlateCarree())
if landflag == 1:
stepped_coastline_cGENIE(lon_edges,lat_edges, data_crs, grid_area_ocn,1.25)
if ((lookfor_issues == 'y') and (anomalflag == 'y')):
for anom in np.arange(nbanomalies):
anom_lon = lon_psi[ix[anom][1]]
anom_lat = lat_psi[ix[anom][0]]
r = 35
plt.plot(anom_lon,anom_lat, marker='o', markersize=r, markeredgecolor = 'orange', markeredgewidth = 1.5, markerfacecolor = 'none', transform=ccrs.PlateCarree(), zorder=1000)
print(' lon = ' + str(anom_lon) + ', lat = ' + str(anom_lat) + ', psi = ' + str(sqval[ix[anom][0], ix[anom][1]]) + ' Sv')
gl = ax.gridlines(crs=data_crs, draw_labels=False,
linewidth=0.5, color='k', alpha=0.2, linestyle='-', zorder=999)
gl.xlabels_top = False; gl.ylabels_left = False; gl.xlines = True
gl.xlocator = mticker.FixedLocator([-180, -120, -60, 0, 60, 120, 180]); gl.xformatter = LONGITUDE_FORMATTER
gl.ylocator = mticker.FixedLocator([-90, -60, -30, 0, 30, 60, 90]); gl.yformatter = LATITUDE_FORMATTER
gl.xlabel_style = {'size': plot_font_size, 'color': 'gray'}; gl.xlabel_style = {'color': 'red', 'weight': 'bold'}
cb = fig.colorbar(cf, orientation='horizontal',extend=extend)
cf.cmap.set_under(lower); cf.cmap.set_over(upper)
cb.ax.tick_params(labelsize=plot_font_size)
cb.ax.set_title(cbartitle, weight='normal', fontsize=plot_font_size)
plt.tight_layout()
filename = exp + '_' + plottedT + '_phys_psi.png'
if save_fig == 'y':
plt.savefig(filename,format='png')
filecount += 1; lnfile = 'file' + str(filecount) + '.png'
os.system('ln -s ' + filename + ' ' + lnfile)
savedfiles.append(filename)
# --- diff ---
if do_diff == 'y':
if globalcount ==0:
phys_psi_0 = phys_psi[T,:,:]
elif globalcount ==1:
phys_psi_1 = phys_psi[T,:,:]
diff = abs(phys_psi_1) - abs(phys_psi_0)
difflevs = np.arange(-15,15+1E-3,1)
diffclevs = np.arange(-15,15+1E-3,5)
diffclevs2 = np.arange(-15,15+1E-3,1)
diffticklevs = np.arange(-15,15+1E-3,5)
diffextend = 'both'
difffilename = exp1 + '_' + plottedT1 + '_minus_' + exp0 + '_' + plottedT0 + '_phys_psi.png'
diffnorm = BoundaryNorm(difflevs, ncolors=diffcmap.N, clip=False)
fig = plt.figure(figsize=(figXsize, figYsize))
ax = fig.add_subplot(111,projection=projdata)
ax = fig.gca(); ax.set(aspect=2); ax.set_aspect('auto')
cf = plt.pcolormesh(lon_psi_edges, lat_psi_edges, diff, transform=ccrs.PlateCarree(),cmap=diffcmap, norm=diffnorm)
ct = plt.contour(lon_psi, lat_psi, np.squeeze(diff), diffclevs, transform=ccrs.PlateCarree(), colors='k', linewidths = 0.45)
ct2 = plt.contour(lon_psi, lat_psi, np.squeeze(diff), diffclevs2, transform=ccrs.PlateCarree(), colors='k', linewidths = 0.75)
plt.pcolormesh(lon_edges, lat_edges, land, cmap=whitecmap, transform=ccrs.PlateCarree())
if landflag == 1:
stepped_coastline_cGENIE(lon_edges,lat_edges, data_crs, grid_area_ocn,1.25)
gl = ax.gridlines(crs=data_crs, draw_labels=False,
linewidth=0.5, color='k', alpha=0.2, linestyle='-', zorder=999)
gl.xlabels_top = False; gl.ylabels_left = False; gl.xlines = True
gl.xlocator = mticker.FixedLocator([-180, -120, -60, 0, 60, 120, 180]); gl.xformatter = LONGITUDE_FORMATTER
gl.ylocator = mticker.FixedLocator([-90, -60, -30, 0, 30, 60, 90]); gl.yformatter = LATITUDE_FORMATTER
gl.xlabel_style = {'size': plot_font_size, 'color': 'gray'}; gl.xlabel_style = {'color': 'red', 'weight': 'bold'}
cb = fig.colorbar(cf, orientation='horizontal',extend=extend)
cf.cmap.set_under(difflower); cf.cmap.set_over(diffupper)
cb.ax.tick_params(labelsize=plot_font_size)
cb.ax.set_title(cbartitle, weight='normal', fontsize=plot_font_size)
plt.tight_layout()
if save_fig == 'y':
plt.savefig(difffilename,format='png', dpi=450)
difffilecount += 1; difflnfile = 'difffile' + str(difffilecount) + '.png'
os.system('ln -s ' + difffilename + ' ' + difflnfile)
diffsavedfiles.append(difffilename)
if dovar('bio_export_POC'):
# %%%%%%%%%%%% bio export POC %%%%%%%%%%%%
# --- parameters ---
levs = np.arange(0,7.5+1E-9,0.5)
ticklevs = np.arange(0,7+1E-9,1)
clevs = np.arange(0,7.5+1E-9,2)
lower = fakealpha(mpl.colors.to_rgba('darkblue')[0:3],0.65)
upper = fakealpha(mpl.colors.to_rgba('darkred')[0:3],0.90)
cmap = fzcmap_alpha065
norm = BoundaryNorm(levs, ncolors=cmap.N, clip=False)
extend = 'max'
cbartitle = 'Biological export -- POC (mol m$^{-2}$ yr$^{-1}$)'
filename = exp + '_' + plottedT + '_bio_export_POC.png'
# --- figure ---
geniemap(lon_edges, lat_edges, bio_export_POC[T,:,:], cmap, levs, ticklevs, 'both', lower, upper, projdata ,cbartitle, filename, 'y', lon, lat, clevs, 0.75, 'n', 'none', 'none','png')
filecount += 1; lnfile = 'file' + str(filecount) + '.png'
os.system('ln -s ' + filename + ' ' + lnfile)
savedfiles.append(filename)
# --- diff ---
if do_diff == 'y':
if globalcount ==0:
bio_export_POC_0 = bio_export_POC[T,:,:]
elif globalcount ==1:
bio_export_POC_1 = bio_export_POC[T,:,:]
diff = bio_export_POC_1 - bio_export_POC_0
difflevs = np.arange(-2.,2.+1E-3,0.2)
diffclevs = np.arange(-2.,2.+1E-3,0.5)
diffticklevs = np.arange(-2.,2.+1E-3,0.5)
diffextend = 'both'
difffilename = exp1 + '_' + plottedT1 + '_minus_' + exp0 + '_' + plottedT0 + '_bio_export_POC.png'
geniemap(lon_edges, lat_edges, diff, diffcmap, difflevs, diffticklevs, diffextend, difflower, diffupper, projdata ,cbartitle, difffilename, 'y', lon, lat, difflevs, 0.75, 'n', 'none', 'none','png')
difffilecount += 1; difflnfile = 'difffile' + str(difffilecount) + '.png'
os.system('ln -s ' + difffilename + ' ' + difflnfile)
diffsavedfiles.append(difffilename)
if dovar('bio_diag_k_PO4'):
# %%%%%%%%%%%% biological productivity control - k_PO4 %%%%%%%%%%%%
# --- parameters ---
levs = np.arange(0,1+1E-9,0.1)
ticklevs = np.arange(0,1+1E-9,0.5)
clevs = np.arange(0,1+1E-9,0.5)
lower = fakealpha(mpl.colors.to_rgba('darkblue')[0:3],0.65)
upper = fakealpha(mpl.colors.to_rgba('darkred')[0:3],0.90)
cmap = fzcmap_alpha065
norm = BoundaryNorm(levs, ncolors=cmap.N, clip=False)
extend = 'max'
cbartitle = 'Biological productivity control - k_PO4'
filename = exp + '_' + plottedT + '_bio_diag_k_PO4.png'
# --- figure ---
geniemap(lon_edges, lat_edges, bio_diag_k_PO4[T,:,:], cmap, levs, ticklevs, 'both', lower, upper, projdata ,cbartitle, filename, 'y', lon, lat, clevs, 0.75, 'n', 'none', 'none','png')
filecount += 1; lnfile = 'file' + str(filecount) + '.png'
os.system('ln -s ' + filename + ' ' + lnfile)
savedfiles.append(filename)
# --- diff ---
if do_diff == 'y':
if globalcount ==0:
bio_diag_k_PO4_0 = bio_diag_k_PO4[T,:,:]