-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathall_nzame_conc_plots.py
1129 lines (793 loc) · 43.6 KB
/
all_nzame_conc_plots.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
#!/usr/bin/env python
# coding: utf-8
import numpy as np
import netCDF4 as nc
import pylab as plt
import matplotlib
import numpy.ma as ma
from matplotlib import rcParams
import datetime
import cartopy.crs as ccrs
from cartopy.util import add_cyclic_point
import matplotlib.dates as mdates
import pandas as pd
from scipy.optimize import curve_fit
import cftime
import nc_time_axis
import xarray as xr
rcParams['font.size'] = 7
# In[2]:
var_lab = 'CH$_4$'
#output for plots
output_write = '/home/users/zosiast/jasmin_plots/no_anthro_ensemble_ssp370/output_plots_jan/'
#constants
mr_ch4 = 16.
mr_co = 28.
mr_o3 = 48.
per_sec_to_per_yr = 60*60*24*360
g_to_Tg = 1e12
n_a = 6.022e23
#stash codes
stash_ch4 = 'mass_fraction_of_methane_in_air'
stash_co = 'mass_fraction_of_carbon_monoxide_in_air'
stash_ch4_oh = 'm01s50i041'
stash_oh = 'mass_fraction_of_hydroxyl_radical_in_air'
stash_o3 = 'mass_fraction_of_ozone_in_air'
stash_trop = 'm01s50i062'
stash_mass = 'm01s50i063'
stash_temp = 'surface_temperature'
# # 2015-2050: net zero anthro
# ### u-by186
suite_id = 'u-by186'
suite_lab = 'uby186'
dates = '2015_2050'
data_1 = nc.Dataset(f'/gws/nopw/j04/ukca_vol1/znjs2/{suite_id}/netcdf/{suite_lab}_ch4_{dates}.nc')
#extract variables to arrays
ch4_1 = data_1.variables[stash_ch4][:]*28.97/mr_ch4*1e9
lat_1 = data_1.variables['latitude'][:]
lon_1 = data_1.variables['longitude'][:]
time_1 = data_1.variables['time']
cf_dtime_1 = cftime.num2date(time_1[:],time_1.units, time_1.calendar)
dtime_1 = np.array([nc_time_axis.CalendarDateTime(item, "360_day") for item in cf_dtime_1])
#tropospheric mask
data_trop_1 = nc.Dataset(f'/gws/nopw/j04/ukca_vol1/znjs2/{suite_id}/netcdf/{suite_lab}_trop_mask_{dates}.nc')
trop_1 = data_trop_1.variables[stash_trop][:]
#air mass
data_mass_1 = nc.Dataset(f'/gws/nopw/j04/ukca_vol1/znjs2/{suite_id}/netcdf/{suite_lab}_airmass_{dates}.nc')
mass_1 = data_mass_1.variables[stash_mass][:]
#temperature starts in 2014
data_temp_1 = nc.Dataset(f'/gws/nopw/j04/ukca_vol1/znjs2/{suite_id}/netcdf/{suite_lab}_surf_temp_2015_2050.nc')
temp_1 = data_temp_1.variables[stash_temp][:]
#ch4_oh data
data_ch4_oh = nc.Dataset(f'/gws/nopw/j04/ukca_vol1/znjs2/{suite_id}/netcdf/{suite_lab}_ch4_oh_flux_{dates}.nc')
ch4_oh_1 = data_ch4_oh.variables[stash_ch4_oh][:]
#o3_conc
data_o3 = nc.Dataset(f'/gws/nopw/j04/ukca_vol1/znjs2/{suite_id}/netcdf/{suite_lab}_o3_{dates}.nc')
o3_1 = data_o3.variables[stash_o3][:]
#oh_conc
data_oh = nc.Dataset(f'/gws/nopw/j04/ukca_vol1/znjs2/{suite_id}/netcdf/{suite_lab}_oh_{dates}.nc')
oh_1 = data_oh.variables[stash_oh][:]
# ### u-bz146
suite_id = 'u-bz146'
suite_lab = 'ubz146'
dates = '2015_2050'
data_146 = nc.Dataset(f'/gws/nopw/j04/ukca_vol1/znjs2/{suite_id}/netcdf/{suite_lab}_ch4_{dates}.nc')
#extract variables to arrays
ch4_146 = data_146.variables[stash_ch4][:]*28.97/mr_ch4*1e9
lat_146 = data_146.variables['latitude'][:]
lon_146 = data_146.variables['longitude'][:]
time_146 = data_146.variables['time']
cf_dtime_146 = cftime.num2date(time_146[:],time_146.units, time_146.calendar)
dtime_146 = np.array([nc_time_axis.CalendarDateTime(item, "360_day") for item in cf_dtime_146])
#tropospheric mask
data_trop_146 = nc.Dataset(f'/gws/nopw/j04/ukca_vol1/znjs2/{suite_id}/netcdf/{suite_lab}_trop_mask_{dates}.nc')
trop_146 = data_trop_146.variables[stash_trop][:]
#air mass
data_mass_146 = nc.Dataset(f'/gws/nopw/j04/ukca_vol1/znjs2/{suite_id}/netcdf/{suite_lab}_airmass_{dates}.nc')
mass_146 = data_mass_146.variables[stash_mass][:]
#temperature starts in 2014
data_temp_146 = nc.Dataset(f'/gws/nopw/j04/ukca_vol1/znjs2/{suite_id}/netcdf/{suite_lab}_surf_temp_{dates}.nc')
temp_146 = data_temp_146.variables[stash_temp][:]
#ch4_oh
data_ch4_oh_146 = nc.Dataset(f'/gws/nopw/j04/ukca_vol1/znjs2/{suite_id}/netcdf/{suite_lab}_ch4_oh_flux_{dates}.nc')
ch4_oh_146 = data_ch4_oh_146.variables[stash_ch4_oh][:]
#o3 conc
data_o3_146 = nc.Dataset(f'/gws/nopw/j04/ukca_vol1/znjs2/{suite_id}/netcdf/{suite_lab}_o3_{dates}.nc')
o3_146 = data_o3_146.variables[stash_o3][:]
#oh_conc
data_oh_146 = nc.Dataset(f'/gws/nopw/j04/ukca_vol1/znjs2/{suite_id}/netcdf/{suite_lab}_oh_{dates}.nc')
oh_146 = data_oh_146.variables[stash_oh][:]
#### u-bz473
suite_id = 'u-bz473'
suite_lab = 'ubz473'
dates = '2015_2050'
data_473 = nc.Dataset(f'/gws/nopw/j04/ukca_vol1/znjs2/{suite_id}/netcdf/{suite_lab}_ch4_{dates}.nc')
#extract variables to arrays
ch4_473 = data_473.variables[stash_ch4][:]*28.97/mr_ch4*1e9
lat_473 = data_473.variables['latitude'][:]
lon_473 = data_473.variables['longitude'][:]
time_473 = data_473.variables['time']
cf_dtime_473 = cftime.num2date(time_473[:],time_473.units, time_473.calendar)
dtime_473 = np.array([nc_time_axis.CalendarDateTime(item, "360_day") for item in cf_dtime_473])
#tropospheric mask
data_trop_473 = nc.Dataset(f'/gws/nopw/j04/ukca_vol1/znjs2/{suite_id}/netcdf/{suite_lab}_trop_mask_{dates}.nc')
trop_473 = data_trop_473.variables[stash_trop][:]
#air mass
data_mass_473 = nc.Dataset(f'/gws/nopw/j04/ukca_vol1/znjs2/{suite_id}/netcdf/{suite_lab}_airmass_{dates}.nc')
mass_473 = data_mass_473.variables[stash_mass][:]
#temperature starts in 2014
data_temp_473 = nc.Dataset(f'/gws/nopw/j04/ukca_vol1/znjs2/{suite_id}/netcdf/{suite_lab}_surf_temp_{dates}.nc')
temp_473 = data_temp_473.variables[stash_temp][:]
#ch4_oh
data_ch4_oh_473 = nc.Dataset(f'/gws/nopw/j04/ukca_vol1/znjs2/{suite_id}/netcdf/{suite_lab}_ch4_oh_flux_{dates}.nc')
ch4_oh_473 = data_ch4_oh_473.variables[stash_ch4_oh][:]
#o3_conc
data_o3_473 = nc.Dataset(f'/gws/nopw/j04/ukca_vol1/znjs2/{suite_id}/netcdf/{suite_lab}_o3_{dates}.nc')
o3_473 = data_o3_473.variables[stash_o3][:]
#oh_conc
data_oh_473 = nc.Dataset(f'/gws/nopw/j04/ukca_vol1/znjs2/{suite_id}/netcdf/{suite_lab}_oh_{dates}.nc')
oh_473 = data_oh_473.variables[stash_oh][:]
# ## SSP370 counterfactual: u-bo797
suite_id = 'u-bo797'
suite_lab = 'ubo797'
dates = '2015_2050'
#ssp370 u-bo797
data_3 = nc.Dataset(f'/gws/nopw/j04/ukca_vol1/znjs2/{suite_id}/netcdf/{suite_lab}_ch4_{dates}.nc')
#extract variables to arrays
ch4_3 = data_3.variables['mass_fraction_of_methane_in_air'][:-1,:,:,:]*28.97/mr_ch4*1e9
lat_3 = data_3.variables['latitude'][:]
lon_3 = data_3.variables['longitude'][:]
time_3 = data_3.variables['time']
cf_dtime_3 = cftime.num2date(time_3[:-1],time_3.units, time_3.calendar)
dtime_3 = np.array([nc_time_axis.CalendarDateTime(item, "360_day") for item in cf_dtime_3])
#surface temperature
data_temp_3 = nc.Dataset(f'/gws/nopw/j04/ukca_vol1/znjs2/{suite_id}/netcdf/{suite_lab}_ann_temp_2015_2050.nc')
temp_3 = data_temp_3.variables[stash_temp][:]
#tropospheric mask
data_trop_3 = nc.Dataset(f'/gws/nopw/j04/ukca_vol1/znjs2/{suite_id}/netcdf/{suite_lab}_trop_mask_{dates}.nc')
trop_3 = data_trop_3.variables[stash_trop][:-1,:,:,:]
#air mass
data_mass_3 = nc.Dataset(f'/gws/nopw/j04/ukca_vol1/znjs2/{suite_id}/netcdf/{suite_lab}_airmass_{dates}.nc')
mass_3 = data_mass_3.variables[stash_mass][:-1,:,:,:]
#ch4_oh
data_ch4_oh_3 = nc.Dataset(f'/gws/nopw/j04/ukca_vol1/znjs2/{suite_id}/netcdf/{suite_lab}_ch4_oh_flux_{dates}.nc')
ch4_oh_3 = data_ch4_oh_3.variables[stash_ch4_oh][:-1,:,:,:]
#o3_conc
data_o3_3 = nc.Dataset(f'/gws/nopw/j04/ukca_vol1/znjs2/{suite_id}/netcdf/{suite_lab}_o3_{dates}.nc')
o3_3 = data_o3_3.variables[stash_o3][:-1,:,:,:]
#oh_conc
data_oh_3 = nc.Dataset(f'/gws/nopw/j04/ukca_vol1/znjs2/{suite_id}/netcdf/{suite_lab}_oh_{dates}.nc')
oh_3 = data_oh_3.variables[stash_oh][:-1,:,:,:]
# for some reason some of them are up to 2051 so the last year is removed
# ### u-ca723 SSP370
suite_id = 'u-ca723'
suite_lab = 'uca723'
dates = '2015_2050'
#ssp370 u-bo797
data_4 = nc.Dataset(f'/gws/nopw/j04/ukca_vol1/znjs2/{suite_id}/netcdf/{suite_lab}_ch4_{dates}.nc')
#extract variables to arrays
ch4_4 = data_4.variables['mass_fraction_of_methane_in_air'][:,:,:,:]*28.97/mr_ch4*1e9
lat_4 = data_4.variables['latitude'][:]
lon_4 = data_4.variables['longitude'][:]
time_4 = data_4.variables['time']
cf_dtime_4 = cftime.num2date(time_4[:],time_4.units, time_4.calendar)
dtime_4 = np.array([nc_time_axis.CalendarDateTime(item, "360_day") for item in cf_dtime_4])
#surface temperature
data_temp_4 = nc.Dataset(f'/gws/nopw/j04/ukca_vol1/znjs2/{suite_id}/netcdf/{suite_lab}_surf_temp_2015_2050.nc')
temp_4 = data_temp_4.variables[stash_temp][:]
#tropospheric mask
data_trop_4 = nc.Dataset(f'/gws/nopw/j04/ukca_vol1/znjs2/{suite_id}/netcdf/{suite_lab}_trop_mask_{dates}.nc')
trop_4 = data_trop_4.variables[stash_trop][:,:,:,:]
#air mass
data_mass_4 = nc.Dataset(f'/gws/nopw/j04/ukca_vol1/znjs2/{suite_id}/netcdf/{suite_lab}_airmass_{dates}.nc')
mass_4 = data_mass_4.variables[stash_mass][:,:,:,:]
#ch4_oh
data_ch4_oh_4 = nc.Dataset(f'/gws/nopw/j04/ukca_vol1/znjs2/{suite_id}/netcdf/{suite_lab}_ch4_oh_flux_{dates}.nc')
ch4_oh_4 = data_ch4_oh_4.variables[stash_ch4_oh][:,:,:,:]
#o3_conc
data_o3_4 = nc.Dataset(f'/gws/nopw/j04/ukca_vol1/znjs2/{suite_id}/netcdf/{suite_lab}_o3_{dates}.nc')
o3_4 = data_o3_4.variables[stash_o3][:]
#oh_conc
data_oh_4 = nc.Dataset(f'/gws/nopw/j04/ukca_vol1/znjs2/{suite_id}/netcdf/{suite_lab}_oh_{dates}.nc')
oh_4 = data_oh_4.variables[stash_oh][:]
# ### u-cb039 SSP370
suite_id = 'u-cb039'
suite_lab = 'ucb039'
dates = '2015_2050'
#ssp370
data_5 = nc.Dataset(f'/gws/nopw/j04/ukca_vol1/znjs2/{suite_id}/netcdf/{suite_lab}_ch4_{dates}.nc')
#extract variables to arrays
ch4_5 = data_5.variables['mass_fraction_of_methane_in_air'][:,:,:,:]*28.97/mr_ch4*1e9
lat_5 = data_5.variables['latitude'][:]
lon_5 = data_5.variables['longitude'][:]
time_5 = data_5.variables['time']
cf_dtime_5 = cftime.num2date(time_5[:],time_5.units, time_5.calendar)
dtime_5 = np.array([nc_time_axis.CalendarDateTime(item, "360_day") for item in cf_dtime_5])
#surface temperature
data_temp_5 = nc.Dataset(f'/gws/nopw/j04/ukca_vol1/znjs2/{suite_id}/netcdf/{suite_lab}_surf_temp_2015_2050.nc')
temp_5 = data_temp_5.variables[stash_temp][:]
#tropospheric mask
data_trop_5 = nc.Dataset(f'/gws/nopw/j04/ukca_vol1/znjs2/{suite_id}/netcdf/{suite_lab}_trop_mask_{dates}.nc')
trop_5 = data_trop_5.variables[stash_trop][:,:,:,:]
#air mass
data_mass_5 = nc.Dataset(f'/gws/nopw/j04/ukca_vol1/znjs2/{suite_id}/netcdf/{suite_lab}_airmass_{dates}.nc')
mass_5 = data_mass_5.variables[stash_mass][:,:,:,:]
#ch4_oh
data_ch4_oh_5 = nc.Dataset(f'/gws/nopw/j04/ukca_vol1/znjs2/{suite_id}/netcdf/{suite_lab}_ch4_oh_flux_{dates}.nc')
ch4_oh_5 = data_ch4_oh_5.variables[stash_ch4_oh][:,:,:,:]
#o3_conc
data_o3_5 = nc.Dataset(f'/gws/nopw/j04/ukca_vol1/znjs2/{suite_id}/netcdf/{suite_lab}_o3_{dates}.nc')
o3_5 = data_o3_5.variables[stash_o3][:]
#oh_conc
data_oh_5 = nc.Dataset(f'/gws/nopw/j04/ukca_vol1/znjs2/{suite_id}/netcdf/{suite_lab}_oh_{dates}.nc')
oh_5 = data_oh_5.variables[stash_oh][:]
#SSP126: u-bo812
suite_id = 'u-bo812'
suite_lab = 'ubo812'
dates = '2015_2050'
data_6 = nc.Dataset(f'/gws/nopw/j04/ukca_vol1/znjs2/{suite_id}/netcdf/{suite_lab}_ch4_{dates}.nc')
#extract variables to arrays
ch4_6 = data_6.variables['mass_fraction_of_methane_in_air'][:-1,:,:,:]*28.97/mr_ch4*1e9
lat_6 = data_6.variables['latitude'][:]
lon_6 = data_6.variables['longitude'][:]
time_6 = data_6.variables['time']
cf_dtime_6 = cftime.num2date(time_6[:-1],time_6.units, time_6.calendar)
dtime_6 = np.array([nc_time_axis.CalendarDateTime(item, "360_day") for item in cf_dtime_6])
#surface temperature
data_temp_6 = nc.Dataset(f'/gws/nopw/j04/ukca_vol1/znjs2/{suite_id}/netcdf/{suite_lab}_surf_temp_{dates}.nc')
temp_6 = data_temp_6.variables[stash_temp][:-1,:,:]
#tropospheric mask
data_trop_6 = nc.Dataset(f'/gws/nopw/j04/ukca_vol1/znjs2/{suite_id}/netcdf/{suite_lab}_trop_mask_{dates}.nc')
trop_6 = data_trop_6.variables[stash_trop][:-1,:,:,:]
#air mass
data_mass_6 = nc.Dataset(f'/gws/nopw/j04/ukca_vol1/znjs2/{suite_id}/netcdf/{suite_lab}_airmass_{dates}.nc')
mass_6 = data_mass_6.variables[stash_mass][:-1,:,:,:]
#ch4_oh
data_ch4_oh_6 = nc.Dataset(f'/gws/nopw/j04/ukca_vol1/znjs2/{suite_id}/netcdf/{suite_lab}_ch4_oh_flux_{dates}.nc')
ch4_oh_6 = data_ch4_oh_6.variables[stash_ch4_oh][:-1,:,:,:]
#o3_conc
data_o3_6 = nc.Dataset(f'/gws/nopw/j04/ukca_vol1/znjs2/{suite_id}/netcdf/{suite_lab}_o3_{dates}.nc')
o3_6 = data_o3_6.variables[stash_o3][:-1,:,:,:]
#oh_conc
data_oh_6 = nc.Dataset(f'/gws/nopw/j04/ukca_vol1/znjs2/{suite_id}/netcdf/{suite_lab}_oh_{dates}.nc')
oh_6 = data_oh_6.variables[stash_oh][:-1,:,:,:]
# bl593 data
ch4_dataset_int = xr.open_dataset(f'/gws/nopw/j04/ukca_vol1/znjs2/u-bl593/netcdf/ubl593_ch4_1850_2014.nc')
nc_ch4_data_int = nc.Dataset(f'/gws/nopw/j04/ukca_vol1/znjs2/u-bl593/netcdf/ubl593_ch4_1850_2014.nc')
data_hist_bl593 = ch4_dataset_int.sel(time=slice('1984-01-01', '2015-12-30'))
stash_name_bl = 'UM_m01s34i009_vn1102'
ch4_hist_bl593 = data_hist_bl593.variables[stash_name_bl]*28.97/mr_ch4*1e9
time_bl593 = nc_ch4_data_int.variables['time']
cf_dtime_bl593 = cftime.num2date(time_bl593[-32:],time_bl593.units, time_bl593.calendar)
dtime_bl593 = np.array([nc_time_axis.CalendarDateTime(item, "360_day") for item in cf_dtime_bl593])
# bn213 dataset
ch4_dataset_bn213 = xr.open_dataset(f'/gws/nopw/j04/ukca_vol1/znjs2/u-bn213/netcdf/ubn213_ch4_ann_1985_2013.nc')
nc_ch4_data_bn213 = nc.Dataset(f'/gws/nopw/j04/ukca_vol1/znjs2/u-bn213/netcdf/ubn213_ch4_ann_1985_2013.nc')
data_hist_bn213 = ch4_dataset_bn213.sel(time=slice('1984-01-01', '2015-12-30'))
ch4_hist_bn213 = data_hist_bn213.variables[stash_ch4]*28.97/mr_ch4*1e9
time_bn213 = nc_ch4_data_int.variables['time']
cf_dtime_bn213 = cftime.num2date(time_bn213[-30:],time_bn213.units, time_bn213.calendar)
dtime_bn213 = np.array([nc_time_axis.CalendarDateTime(item, "360_day") for item in cf_dtime_bn213])
# bl998 dataset
ch4_dataset_bl998 = xr.open_dataset(f'/gws/nopw/j04/ukca_vol1/znjs2/u-bl998/netcdf/ubl998_ch4_ann_1985_2013.nc')
nc_ch4_data_bl998 = nc.Dataset(f'/gws/nopw/j04/ukca_vol1/znjs2/u-bl998/netcdf/ubl998_ch4_ann_1985_2013.nc')
data_hist_bl998 = ch4_dataset_bl998.sel(time=slice('1984-01-01', '2015-12-30'))
ch4_hist_bl998 = data_hist_bl998.variables[stash_ch4]*28.97/mr_ch4*1e9
time_bl998 = nc_ch4_data_int.variables['time']
cf_dtime_bl998 = cftime.num2date(time_bl998[-30:],time_bl998.units, time_bl998.calendar)
dtime_bl998 = np.array([nc_time_axis.CalendarDateTime(item, "360_day") for item in cf_dtime_bl998])
# ## Area and volume datasets
area = nc.Dataset(f'/gws/nopw/j04/ukca_vol1/jmw240/covid_crunch/area/areacella_fx_UKESM1-0-LL_piControl_r1i1p1f2_gn.nc')
box_area = area.variables['areacella'][:]
total_area = np.sum(box_area)
area_scaled = box_area/total_area
lat_area_scaled = area_scaled[:,0]#1D array of latitude scaling values
# Altitude data
alt_data = nc.Dataset(f'/home/users/zosiast/vol_n96.nc')
alt = alt_data.variables['level_height'][:]
vol = alt_data.variables['grid_cell_volume'][:]
# Population data
pop_data = nc.Dataset(f'/home/users/zosiast/ssp_population/pop_ssp3_n96_2006_2100.nc')
pop_2006_2100 = pop_data.variables['population'][:]
pop_xr = xr.open_dataset(f'/home/users/zosiast/ssp_population/pop_ssp3_n96_2006_2100.nc', decode_times=False)
pop_xr_time = pop_xr.variables['time']
year = np.array(pop_xr_time + 1661,dtype='int')
#select relevant years for population data
pop_data_2015_2050 = pop_2006_2100[9:45,:,:]
#ssp126 population data
pop_data_ssp1 = nc.Dataset(f'/home/users/zosiast/ssp_population/pop_ssp1_n96_2006_2100.nc')
pop_2006_2100_ssp1 = pop_data_ssp1.variables['population'][:]
pop_xr_1 = xr.open_dataset(f'/home/users/zosiast/ssp_population/pop_ssp1_n96_2006_2100.nc', decode_times=False)
#test = xr.decode_cf(pop_xr)
pop_xr_time_1 = pop_xr.variables['time']
year_1 = np.array(pop_xr_time + 1661,dtype='int')
pop_data_2015_2050_ssp1 = pop_2006_2100_ssp1[9:45,:,:]
print('All data read in')
#define functions
def molec_cm3(conc_kg_kg, mass, vol, mr):
molec_box = conc_kg_kg*mass/mr*1000*n_a #molecules per box
molec_cm3 = molec_box/(vol*1e6) #molec per cm3
return molec_cm3
# ## CH4 burden
#sum of all CH4 including stratosphere
#ens 1
ch4_bl593_kg = np.multiply(mass_1,ch4_1/28*mr_ch4/1e9) #ch4 in kg
ch4_bur_bl593 = ch4_bl593_kg.sum(axis=(1,2,3))/1e9 # sum over lat, lon, alt, in Tg
#ens 2
ch4_bz146_kg = np.multiply(mass_146,ch4_146/28*mr_ch4/1e9) #ch4 in kg
ch4_bur_bz146 = ch4_bz146_kg.sum(axis=(1,2,3))/1e9 # sum over lat, lon, alt, in Tg
#ens 3
ch4_bz473_kg = np.multiply(mass_473,ch4_473/28*mr_ch4/1e9) #ch4 in kg
ch4_bur_bz473 = ch4_bz473_kg.sum(axis=(1,2,3))/1e9 # sum over lat, lon, alt, in Tg
ch4_bur_ens_mean = np.mean([ch4_bur_bz473,ch4_bur_bz146,ch4_bur_bl593],axis = 0)
#ssp370
ch4_bo797_kg = np.multiply(mass_3,ch4_3/28*mr_ch4/1e9) #ch4 in kg
ch4_bur_bo797 = ch4_bo797_kg.sum(axis=(1,2,3))/1e9 # sum over lat, lon, alt, in Tg
ch4_ca723_kg = np.multiply(mass_4,ch4_4/28*mr_ch4/1e9) #ch4 in kg
ch4_bur_ca723 = ch4_ca723_kg.sum(axis=(1,2,3))/1e9 # sum over lat, lon, alt, in Tg
ch4_cb039_kg = np.multiply(mass_5,ch4_5/28*mr_ch4/1e9) #ch4 in kg
ch4_bur_cb039 = ch4_cb039_kg.sum(axis=(1,2,3))/1e9 # sum over lat, lon, alt, in Tg
ch4_bur_ssp_mean = np.mean([ch4_bur_bo797,ch4_bur_ca723,ch4_bur_cb039],axis = 0)
ch4_bo812_kg = np.multiply(mass_6,ch4_6/28*mr_ch4/1e9) #ch4 in kg
ch4_bur_bo812 = ch4_bo812_kg.sum(axis=(1,2,3))/1e9 # sum over lat, lon, alt, in Tg
#methane lifetime calc
def ch4_lifetime_calc(ch4_bur, oh_ch4_flux, trop_nc):#ch4 in kg #oh in ppb
#make trop mask
trop_mask = ma.masked_where(trop_nc < 0.9999999, trop_nc)
#flux calcs
ch4_oh_tg_yr = oh_ch4_flux*mr_ch4*per_sec_to_per_yr/g_to_Tg
ch4_oh_trop = ma.masked_where(trop_mask.mask,ch4_oh_tg_yr)
#sum over lat lon alt
flux_sum = np.sum(ch4_oh_trop, axis=(1,2,3))
#flux_sum_all = np.sum(ch4_oh_tg_yr, axis=(1,2,3))
#sum of only tropospheric methane
#ch4_kg_trop = ma.masked_where(trop_mask.mask, ch4_kg)
#bur_trop = ch4_kg_trop.sum(axis=(1,2,3))/1e9 # sum over lat, lon, alt, in Tg
#lifetime calc
t_ch4_strat_trop = ch4_bur/flux_sum
return t_ch4_strat_trop, flux_sum
# calculate methane lifetime
t_ch4_by186, flux_by186 = ch4_lifetime_calc(ch4_bur_bl593,ch4_oh_1, trop_1)
t_ch4_bz146, flux_bz146 = ch4_lifetime_calc(ch4_bur_bz146,ch4_oh_146, trop_146)
t_ch4_bz473, flux_bz473 = ch4_lifetime_calc(ch4_bur_bz473,ch4_oh_473, trop_473)
t_ch4_bo797, flux_bo797 = ch4_lifetime_calc(ch4_bur_bo797,ch4_oh_3, trop_3)
t_ch4_ca723, flux_ca723 = ch4_lifetime_calc(ch4_bur_ca723,ch4_oh_4, trop_4)
t_ch4_cb039, flux_cb039 = ch4_lifetime_calc(ch4_bur_cb039,ch4_oh_5, trop_5)
t_ch4_bo812, flux_bo812 = ch4_lifetime_calc(ch4_bur_bo812,ch4_oh_6, trop_6)
# methane lifetime ens mean
t_ch4_ens_mean = np.mean([t_ch4_by186,t_ch4_bz146,t_ch4_bz473],axis=0)
t_ch4_ssp_mean = np.mean([t_ch4_bo797,t_ch4_ca723,t_ch4_cb039],axis=0)
#Fig: methane lifetime
fig = plt.figure(figsize=(3.5,2.625), dpi=300)
ax = plt.axes()
ax.plot(dtime_1, t_ch4_by186, c='skyblue',linewidth=1)
ax.plot(dtime_146, t_ch4_bz146, c='skyblue',linewidth=1)
ax.plot(dtime_473, t_ch4_bz473, c='skyblue',linewidth=1)
ax.plot(dtime_473, t_ch4_ens_mean, label = 'ZAME',c='C0')
ax.plot(dtime_6, t_ch4_bo812, c='orange',linewidth=1, label = 'SSP1-2.6')
ax.plot(dtime_3, t_ch4_bo797, c='pink')
ax.plot(dtime_4, t_ch4_ca723, c='pink')
ax.plot(dtime_5, t_ch4_cb039, c='pink')
ax.plot(dtime_3, t_ch4_ssp_mean, label = 'SSP370', c='#f11111')
ax.plot([dtime_1[0],dtime_1[-1]], [9.823, 9.823], 'grey',linestyle=':', label = 'PI level')
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
plt.text(dtime_1[2], 9.4 , 'b', weight='bold', fontsize=8)
plt.legend(loc=3)
plt.xlabel('Time')
plt.ylabel('CH$_4$ lifetime (years)')
#plt.title('CH$_4$ lifetime 2015-2050')
plt.savefig(f'{output_write}ch4_lifetime_2015_2050.eps', format = 'eps', bbox_inches='tight')
print('Lifetime calcs and plots done')
# ## NOAA obs data
#1984-2019 obs data
noaa_ch4 = pd.read_csv(f'/home/users/zosiast/scripts/noaa_annual_average_methane.csv',header=0,skiprows=1,usecols=[1,2,3],index_col=0)
noaa_years = np.array(noaa_ch4.index, dtype='str')
noaa_mean_conc = np.array(noaa_ch4['mean'])
# ## 2014 data points, from historical runs
# in ppb
ch4_2014_bl593 = 1633.55
ch4_2014_bl998 = 1617.53
ch4_2014_bn213 = 1620.09
ch4_2014_ens_mean = np.mean([ch4_2014_bl593,ch4_2014_bl998,ch4_2014_bn213])
# In[29]:
d_time_2014 = cftime.datetime(year=2014, month=6, day=1)
nc_dtime_2014 = nc_time_axis.CalendarDateTime(d_time_2014, "360_day")
dtime_2014_2050 = np.insert(dtime_1,0, nc_dtime_2014)
d_time_2015 = cftime.datetime(year=2015, month=6, day=1)
nc_dtime_2015 = nc_time_axis.CalendarDateTime(d_time_2015, "360_day")
noaa_time_1985_2015 = np.append(dtime_bn213,nc_dtime_2015)
noaa_dtime_1985_2020 = np.concatenate((noaa_time_1985_2015,dtime_2014_2050[2:7]),axis=0)
# ## CH4 surface conc
# mean surface conc
#area weighted by latitude and mean over lon
ch4_lat_weighted_by186 = np.mean(np.average(ch4_1[:,0,:,:],axis=(1),weights = lat_area_scaled), axis = 1)
ch4_lat_weighted_bz146 = np.mean(np.average(ch4_146[:,0,:,:],axis=(1),weights = lat_area_scaled), axis = 1)
ch4_lat_weighted_bz473 = np.mean(np.average(ch4_473[:,0,:,:],axis=(1),weights = lat_area_scaled), axis = 1)
ch4_lat_weighted_ens = np.mean([ch4_lat_weighted_by186,ch4_lat_weighted_bz146,ch4_lat_weighted_bz473],axis=0)
ch4_lat_weighted_bo797 = np.mean(np.average(ch4_3[:,0,:,:],axis=(1),weights = lat_area_scaled), axis = 1)
ch4_lat_weighted_ca723 = np.mean(np.average(ch4_4[:,0,:,:],axis=(1),weights = lat_area_scaled), axis = 1)
ch4_lat_weighted_cb039 = np.mean(np.average(ch4_5[:,0,:,:],axis=(1),weights = lat_area_scaled), axis = 1)
ch4_lat_weighted_ssp = np.mean([ch4_lat_weighted_bo797,ch4_lat_weighted_ca723,ch4_lat_weighted_cb039],axis=0)
ch4_lat_weighted_bo812 = np.mean(np.average(ch4_6[:,0,:,:],axis=(1),weights = lat_area_scaled), axis = 1)
# surface conc for hist ensemble members
ch4_lat_weighted_bl593 = np.mean(np.average(ch4_hist_bl593[:,0,:,:],axis=(1),weights = lat_area_scaled), axis = 1)
ch4_lat_weighted_bn213 = np.mean(np.average(ch4_hist_bn213[:,0,:,:],axis=(1),weights = lat_area_scaled), axis = 1)
ch4_lat_weighted_bl998 = np.mean(np.average(ch4_hist_bl998[:,0,:,:],axis=(1),weights = lat_area_scaled), axis = 1)
# hist ensemble mean
hist_mean_ch4 = np.mean([ch4_lat_weighted_bl998,ch4_lat_weighted_bn213,ch4_lat_weighted_bl593[-30:]],axis=0)
# 2014-2050 area weighted CH4 surface conc with obs
fig = plt.figure(figsize=(3.5,2.625), dpi=300)
ax = plt.axes()
ax.plot(dtime_2014_2050, np.insert(ch4_lat_weighted_by186,0, ch4_2014_bl593), c='skyblue',linewidth=1)
ax.plot(dtime_2014_2050, np.insert(ch4_lat_weighted_bz146,0,ch4_2014_bn213), c='skyblue',linewidth=1)
ax.plot(dtime_2014_2050, np.insert(ch4_lat_weighted_bz473,0, ch4_2014_bl998), c='skyblue',linewidth=1)
ax.plot(dtime_2014_2050, np.insert(ch4_lat_weighted_ens,0,ch4_2014_ens_mean), label = 'ZAME', c='C0',linewidth=1)
ax.plot(dtime_2014_2050, np.insert(ch4_lat_weighted_bo797,0, ch4_2014_bl593), c='pink')
ax.plot(dtime_2014_2050, np.insert(ch4_lat_weighted_ca723,0, ch4_2014_bl998), c='pink')
ax.plot(dtime_2014_2050, np.insert(ch4_lat_weighted_cb039,0,ch4_2014_bn213), c='pink')
ax.plot(dtime_2014_2050, np.insert(ch4_lat_weighted_ssp,0,ch4_2014_ens_mean), label = 'SSP3-7.0', c='#f11111')
ax.scatter(dtime_2014_2050[:6], noaa_mean_conc[-6:], c='darkslategray', label = 'NOAA obs', marker='+')
ax.plot([dtime_2014_2050[0],dtime_2014_2050[-1]], [776, 776], 'grey',linestyle=':', label = 'PI level')
ax.spines['top'].set_visible(False)
#ax2.spines['top'].set_visible(False)
plt.legend()
plt.xlabel('Time')
plt.ylabel(f'Mean surface [{var_lab}] (ppb)')
#plt.title(f'Mean surface {var_lab} 2015-2050')
#plt.savefig(f'{output_write}ch4_surface_conc_obs_2015_2050.eps', format = 'eps', bbox_inches='tight')
# Normalise to year 2000 values
# year 2000 conc from bl593 hist run
ch4_2000_bl593 = 1537.89
ch4_2000_noaa = noaa_mean_conc[-20]
pi_ratio_2000 = 776./ch4_2000_bl593
# Normalised surface conc
fig = plt.figure(figsize=(3.5,2.625), dpi=300)
ax = plt.axes()
ax.plot(dtime_2014_2050, np.insert(ch4_lat_weighted_by186,0, ch4_2014_bl593)/ch4_2000_bl593, c='skyblue',linewidth=1)
ax.plot(dtime_2014_2050, np.insert(ch4_lat_weighted_bz146,0,ch4_2014_bn213)/ch4_2000_bl593, c='skyblue',linewidth=1)
ax.plot(dtime_2014_2050, np.insert(ch4_lat_weighted_bz473,0, ch4_2014_bl998)/ch4_2000_bl593, c='skyblue',linewidth=1)
ax.plot(dtime_2014_2050, np.insert(ch4_lat_weighted_ens,0,ch4_2014_ens_mean)/ch4_2000_bl593, label = 'NZAME', c='C0',linewidth=1)
ax.plot(dtime_2014_2050, np.insert(ch4_lat_weighted_bo797,0, ch4_2014_bl593)/ch4_2000_bl593, c='pink')
ax.plot(dtime_2014_2050, np.insert(ch4_lat_weighted_ca723,0, ch4_2014_bl998)/ch4_2000_bl593, c='pink')
ax.plot(dtime_2014_2050, np.insert(ch4_lat_weighted_cb039,0,ch4_2014_bn213)/ch4_2000_bl593, c='pink')
ax.plot(dtime_2014_2050, np.insert(ch4_lat_weighted_ssp,0,ch4_2014_ens_mean)/ch4_2000_bl593, label = 'SSP3-7.0', c='#f11111')
ax.plot([dtime_bl593[0],dtime_2014_2050[-1]], [pi_ratio_2000, pi_ratio_2000], 'grey',linestyle=':', label = 'PI level')
ax.plot(dtime_2014_2050, np.insert(ch4_lat_weighted_bo812,0, ch4_2014_bl998)/ch4_2000_bl593, label='SSP1-2.6', c='orange',linewidth=1)
ax.plot(dtime_bl593, ch4_lat_weighted_bl593/ch4_2000_bl593, c='lightgrey', linewidth=1,zorder=1)
ax.plot(dtime_bn213, ch4_lat_weighted_bn213/ch4_2000_bl593, c='lightgrey',linewidth=1,zorder=1)
ax.plot(dtime_bl998, ch4_lat_weighted_bl998/ch4_2000_bl593, c='lightgrey',linewidth=1,zorder=1)
ax.plot(dtime_bl998, hist_mean_ch4/ch4_2000_bl593, c='grey',label='historical',zorder=2)
ax.plot(noaa_dtime_1985_2020, noaa_mean_conc[1:]/ch4_2000_noaa, c='k', label = 'NOAA obs', marker='+',zorder=3, ms=3, alpha = 0.7, ls="none")
ax.text(dtime_1[-15], 1.4 , 'b', weight='bold', fontsize=8)
ax2=ax.twinx()
#ax2.plot(dtime_2014_2050, np.insert(ch4_lat_weighted_ens,0,ch4_2014_ens_mean), c='black',linewidth=1, linestyle='--')
#ax2.plot(dtime_2014_2050, np.insert(ch4_lat_weighted_ssp,0,ch4_2014_ens_mean), c='black',linestyle='--')
ax2.set_ylim(545, 2260)
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax2.spines['top'].set_visible(False)
ax.legend(fontsize = 7,ncol=2, loc=2)
plt.xlabel('Time')
ax.set_ylabel(f'Mean surface [{var_lab}] / year 2000 [CH$_4$]')
ax2.set_ylabel(f'Mean surface model [{var_lab}] (ppb)')
#plt.title(f'Mean surface {var_lab} 2015-2050 relative to year 2000')
plt.savefig(f'{output_write}ch4_relative_surface_conc_2015_2050.eps', format = 'eps', bbox_inches='tight')
# GMST plots
# ## GMST calculation
#by186 temp meaning
temp_1_lon_mean = np.mean(temp_1, axis = 2)
mean_sur_temp_186 = np.average(temp_1_lon_mean,weights = lat_area_scaled, axis = (1))
temp_146_lon_mean = np.mean(temp_146, axis = 2)
mean_sur_temp_146 = np.average(temp_146_lon_mean,weights = lat_area_scaled, axis = (1))
temp_473_lon_mean = np.mean(temp_473, axis = 2)
mean_sur_temp_473 = np.average(temp_473_lon_mean,weights = lat_area_scaled, axis = (1))
gmst_ens_mean = np.mean([mean_sur_temp_473,mean_sur_temp_146,mean_sur_temp_186],axis = 0)
# In[13]:
#bo797 global mean, area weighted
temp_3_lon_mean = np.mean(temp_3, axis = 2)
mean_sur_temp_bo797 = np.average(temp_3_lon_mean,weights = lat_area_scaled, axis = (1))
#ca723 global mean, area weighted
temp_4_lon_mean = np.mean(temp_4, axis = 2)
mean_sur_temp_ca723 = np.average(temp_4_lon_mean,weights = lat_area_scaled, axis = (1))
temp_5_lon_mean = np.mean(temp_5, axis = 2)
mean_sur_temp_cb039 = np.average(temp_5_lon_mean,weights = lat_area_scaled, axis = (1))
gmst_ens_mean_ssp = np.mean([mean_sur_temp_bo797,mean_sur_temp_ca723,mean_sur_temp_cb039],axis = 0)
#bo812
temp_6_lon_mean = np.mean(temp_6, axis = 2)
mean_sur_temp_bo812 = np.average(temp_6_lon_mean,weights = lat_area_scaled, axis = (1))
# GMST vs time
fig = plt.figure(figsize=(3.5,2.625), dpi=300)
ax = plt.axes()
ax.plot(dtime_1, mean_sur_temp_186, c='skyblue',linewidth=1) #temp for by186 is from 2014(?)
ax.plot(dtime_146, mean_sur_temp_146, c='skyblue',linewidth=1)
ax.plot(dtime_473, mean_sur_temp_473, c='skyblue',linewidth=1)
ax.plot(dtime_473, gmst_ens_mean, label = 'ZAME',c='C0')
ax.plot(dtime_3, mean_sur_temp_bo797, c='pink')
ax.plot(dtime_4, mean_sur_temp_ca723, c='pink')
ax.plot(dtime_5, mean_sur_temp_cb039, c='pink')
#ax.plot(dtime_3, gmst_ens_mean_ssp, label = 'SSP3-7.0',c='#f11111')
ax.plot(dtime_6, mean_sur_temp_bo812, c='orange')
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
plt.legend()
plt.xlabel('Time')
plt.ylabel(f'GMST (K)')
#plt.title('GMST 2015-2050')
plt.savefig(f'{output_write}gmst_2015_2050.eps', format = 'eps', bbox_inches='tight')
# GMST anomaly wrt 2015
fig = plt.figure(figsize=(3.5,2.625), dpi=300)
ax = plt.axes()
ax.plot(dtime_1, mean_sur_temp_186 - mean_sur_temp_186[0], c='skyblue',linewidth=1) #temp for by186 is from 2014(?)
ax.plot(dtime_146, mean_sur_temp_146 - mean_sur_temp_146[0], c='skyblue',linewidth=1)
ax.plot(dtime_473, mean_sur_temp_473 - mean_sur_temp_473[0], c='skyblue',linewidth=1)
ax.plot(dtime_473, gmst_ens_mean - gmst_ens_mean[0], label = 'ZAME',c='C0')
ax.plot(dtime_3, mean_sur_temp_bo797 - mean_sur_temp_bo797[0], c='pink')
ax.plot(dtime_4, mean_sur_temp_ca723 - mean_sur_temp_ca723[0], c='pink')
ax.plot(dtime_5, mean_sur_temp_cb039 - mean_sur_temp_cb039[0], c='pink')
ax.plot(dtime_6, mean_sur_temp_bo812 - mean_sur_temp_bo812[0], c='orange', label = 'SSP1-2.6')
ax.plot(dtime_3, gmst_ens_mean_ssp - gmst_ens_mean_ssp[0], label = 'SSP3-7.0',c='#f11111')
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
plt.text(dtime_1[2], 1.9 , 'a', weight='bold', fontsize=8)
plt.legend(bbox_to_anchor=(0.5,0.75))
plt.xlabel('Time')
plt.ylabel(f'GMST anomaly wrt 2015 (K)')
#plt.title('GMST anomaly 2015-2050')
plt.savefig(f'{output_write}gmst_anomaly_2015_2050_ssp126.eps', format = 'eps', bbox_inches='tight')
#gmst map plot
gmst_mean_map_nzame = np.mean([temp_1,temp_146,temp_473],axis = 0)
gmst_mean_map_ssp = np.mean([temp_3,temp_4,temp_5],axis = 0)
from matplotlib.colors import LinearSegmentedColormap,ListedColormap
from matplotlib import cm
top = cm.get_cmap('Blues_r', 128)
bottom = cm.get_cmap('Reds', 128)
newcolors = np.vstack((top(np.linspace(0, 1, 90)),
bottom(np.linspace(0, 0.1, 10))))
newcmp = ListedColormap(newcolors, name='Red_blue')
fig = plt.figure(figsize=(3.5,2.625), dpi=300)
ax = plt.axes()
ax = plt.axes(projection=ccrs.Robinson(central_longitude=0, globe=None))
ax.set_global()
ax.coastlines(linewidth=0.5)
var_name = 'Surface Temperature$_{ZAME - SSP37.0}$'
ch4_diff_cyclic, lon_plot = add_cyclic_point(np.mean(gmst_mean_map_nzame[-10:,:,:] - gmst_mean_map_ssp[-10:,:,:],
axis=0), coord=lon_473)
plt.pcolormesh(lon_plot,lat_473,ch4_diff_cyclic, cmap=newcmp,transform=ccrs.PlateCarree(central_longitude=0), vmin=-9, vmax=1)
plt.annotate('b', (0.1,0.85), xycoords='figure fraction',weight='bold', fontsize=8)
plt.colorbar(label = f'{var_name} / K',orientation='horizontal',pad=0.05)
#plt.title(f'Surface temperature 2040-2050: ZAME - SSP3-7.0')
plt.savefig(f'{output_write}gmst_surf_map_2040_2050.eps', format = 'eps', bbox_inches='tight')
#Trop mask based on trop mask variable
#tropospheric mask
trop_mask_186 = ma.masked_where(trop_1 < 1, trop_1)
trop_mask_146 = ma.masked_where(trop_146 < 1, trop_146)
trop_mask_473 = ma.masked_where(trop_473 < 1, trop_473)
trop_mask_3 = ma.masked_where(trop_3 < 1, trop_3)
#ozone in ppb
o3_186_ppb = o3_1*28.97/mr_o3*1e9
o3_146_ppb = o3_146*28.97/mr_o3*1e9
o3_473_ppb = o3_473*28.97/mr_o3*1e9
o3_bo797 = o3_3*28.97/mr_o3*1e9
o3_ca723 = o3_4*28.97/mr_o3*1e9
o3_cb039 = o3_5*28.97/mr_o3*1e9
o3_bo812 = o3_6*28.97/mr_o3*1e9
#surface selected
surf_o3_186 = o3_186_ppb[:,0,:,:]
surf_o3_146 = o3_146_ppb[:,0,:,:]
surf_o3_473 = o3_473_ppb[:,0,:,:]
surf_o3_ens_mean = np.mean([surf_o3_186,surf_o3_146,surf_o3_473],axis=0)
surf_o3_bo797 = o3_bo797[:,0,:,:]
surf_o3_ca723 = o3_ca723[:,0,:,:]
surf_o3_cb039 = o3_cb039[:,0,:,:]
surf_o3_ens_mean_ssp = np.mean([surf_o3_bo797[:36,:,:],surf_o3_ca723,surf_o3_cb039],axis=0)
surf_o3_ssp126 = o3_bo812[:,0,:,:]
#area weighted by latitude and mean over lon
o3_lat_weighted_186 = np.mean(np.average(surf_o3_186,axis=(1),weights = lat_area_scaled), axis = 1)
o3_lat_weighted_146 = np.mean(np.average(surf_o3_146,axis=(1),weights = lat_area_scaled), axis = 1)
o3_lat_weighted_473 = np.mean(np.average(surf_o3_473,axis=(1),weights = lat_area_scaled), axis = 1)
o3_lat_weighted_ens_mean = np.mean([o3_lat_weighted_186,o3_lat_weighted_146,o3_lat_weighted_473],axis=0)
o3_lat_weighted_bo797 = np.mean(np.average(surf_o3_bo797,axis=(1),weights = lat_area_scaled), axis = 1)
o3_lat_weighted_ca723 = np.mean(np.average(surf_o3_ca723,axis=(1),weights = lat_area_scaled), axis = 1)
o3_lat_weighted_cb039 = np.mean(np.average(surf_o3_ca723,axis=(1),weights = lat_area_scaled), axis = 1)
o3_lat_weighted_ens_mean_ssp = np.mean([o3_lat_weighted_bo797[:36],o3_lat_weighted_ca723,o3_lat_weighted_cb039],axis=0)
# o3 surface conc
fig = plt.figure(figsize=(3.5,2.625), dpi=300)
ax = plt.axes()
ax.plot(dtime_1, o3_lat_weighted_186, c='skyblue',linewidth=1)
ax.plot(dtime_146, o3_lat_weighted_146, c='skyblue',linewidth=1)
ax.plot(dtime_473, o3_lat_weighted_473, c='skyblue',linewidth=1)
ax.plot(dtime_473, o3_lat_weighted_ens_mean, label = 'ZAME', c='C0')
ax.plot(dtime_3, o3_lat_weighted_bo797[:36], c='pink')
ax.plot(dtime_4, o3_lat_weighted_ca723, c='pink')
ax.plot(dtime_5, o3_lat_weighted_cb039, c='pink')
ax.plot(dtime_4, o3_lat_weighted_ens_mean_ssp, label = 'SSP370', c='#f11111')
ax.plot([dtime_1[0],dtime_1[-1]], [20, 20], 'grey',linestyle=':', label = 'PI level')
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
plt.legend()
plt.xlabel('Time')
plt.ylabel(f'O$_3$ (ppb)')
#plt.title('O$_3$ mean surface conc 2015-2050')
plt.savefig(f'{output_write}o3_surface_area_weighted_2015_2050.eps', format = 'eps', bbox_inches='tight')
#population weighting
#area weighted by population
o3_pop_weighted_186 = np.average(surf_o3_186,axis=(1,2),weights = pop_data_2015_2050)
o3_pop_weighted_146 = np.average(surf_o3_146,axis=(1,2),weights = pop_data_2015_2050)
o3_pop_weighted_473 = np.average(surf_o3_473,axis=(1,2),weights = pop_data_2015_2050)
o3_pop_weighted_ens_mean = np.mean([o3_pop_weighted_186,o3_pop_weighted_146,o3_pop_weighted_473],axis=0)
o3_pop_weighted_bo797 = np.average(surf_o3_bo797[:36,:,:],axis=(1,2),weights = pop_data_2015_2050)
o3_pop_weighted_ca723 = np.average(surf_o3_ca723,axis=(1,2),weights = pop_data_2015_2050)
o3_pop_weighted_cb039 = np.average(surf_o3_cb039,axis=(1,2),weights = pop_data_2015_2050)
o3_pop_weighted_ens_mean_ssp = np.mean([o3_pop_weighted_bo797,o3_pop_weighted_ca723,o3_pop_weighted_cb039],axis=0)
o3_pop_weighted_bo812 = np.average(surf_o3_ssp126,axis=(1,2),weights = pop_data_2015_2050_ssp1)
#ozone surface population weighted
fig = plt.figure(figsize=(3.5,2.625), dpi=300)
ax = plt.axes()
ax.plot(dtime_1, o3_pop_weighted_186, c='skyblue',linewidth=1)
ax.plot(dtime_146, o3_pop_weighted_146, c='skyblue',linewidth=1)
ax.plot(dtime_473, o3_pop_weighted_473, c='skyblue',linewidth=1)
ax.plot(dtime_473, o3_pop_weighted_ens_mean, label = 'ZAME', c='C0')
ax.plot(dtime_3, o3_pop_weighted_bo797, c='pink')
ax.plot(dtime_3, o3_pop_weighted_ca723, c='pink')
ax.plot(dtime_3, o3_pop_weighted_cb039, c='pink')
ax.plot(dtime_3, o3_pop_weighted_bo812, label = 'SSP1-2.6', c='orange')
plt.text(dtime_1[2], 34.5 , 'd', weight='bold', fontsize=8)
ax.plot(dtime_3, o3_pop_weighted_ens_mean_ssp, label = 'SSP3-7.0', c='#f11111')
#ax.plot([dtime_1[0],dtime_1[-1]], [20, 20], 'grey',linestyle=':', label = 'PI level')
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
plt.legend(loc=3)
plt.xlabel('Time')
plt.ylabel(f'Pop. wt. O$_3$ (ppb)')
#plt.title('O$_3$ mean surface conc 2015-2050: population weighted')
plt.savefig(f'{output_write}o3_surface_pop_weighted_2015_2050.eps', format = 'eps', bbox_inches='tight')
# ozone surface concentration plot
fig = plt.figure(figsize=(3.5,2.625), dpi=300)
ax = plt.axes()
ax = plt.axes(projection=ccrs.Robinson(central_longitude=0.0))
ax.coastlines(linewidth=0.3)
var_name = 'Surface [O$_3$]$_{ZAME - SSP37.0}$'
ch4_diff_cyclic, lon_plot = add_cyclic_point(np.mean(surf_o3_ens_mean[-10:,:,:] - surf_o3_ens_mean_ssp[-10:,:,:],axis=0),
coord=lon_473)
plt.pcolormesh(lon_plot,lat_473,ch4_diff_cyclic, cmap='Oranges_r',vmin = -18, vmax = 0,
transform=ccrs.PlateCarree(central_longitude=0))#, cmap='bwr', vmin = -8, vmax = 8)
plt.annotate('c', (0.1,0.85), xycoords='figure fraction',weight='bold', fontsize=8)
plt.colorbar(label = f'{var_name} (ppb)',orientation='horizontal',pad=0.05)
#plt.title(f'Surface ozone 2040-2050: ZAME - SSP3-7.0')
plt.savefig(f'{output_write}o3_surf_map_2040_2050.eps', format = 'eps', bbox_inches='tight')
#OH concentration
# convert to molec cm -3
oh_molec_cm3_186 = molec_cm3(oh_1, mass_1, vol, 17)
oh_molec_cm3_146 = molec_cm3(oh_146, mass_146, vol, 17)
oh_molec_cm3_473 = molec_cm3(oh_473, mass_473, vol, 17)
oh_molec_cm3_bo797 = molec_cm3(oh_3[:36,:,:,:], mass_3, vol, 17)
oh_molec_cm3_ca723 = molec_cm3(oh_4, mass_4, vol, 17)
oh_molec_cm3_cb039 = molec_cm3(oh_5, mass_5, vol, 17)
oh_molec_cm3_bo812 = molec_cm3(oh_6, mass_6, vol, 17)
#by186 oh
oh_trop_186 = ma.masked_where(o3_186_ppb > 125,oh_molec_cm3_186)
oh_trop_mean_186 = np.average(oh_trop_186, weights=mass_1, axis = (1,2,3))
#by146 oh
oh_trop_146 = ma.masked_where(o3_146_ppb > 125,oh_molec_cm3_146)
oh_trop_mean_146 = np.average(oh_trop_146, weights=mass_146, axis = (1,2,3))
#by473 oh
oh_trop_473 = ma.masked_where(o3_473_ppb > 125,oh_molec_cm3_473)
oh_trop_mean_473 = np.average(oh_trop_473, weights=mass_473, axis = (1,2,3))
#bo797 oh
oh_trop_bo797 = ma.masked_where(o3_bo797 > 125,oh_molec_cm3_bo797)
oh_trop_mean_bo797 = np.average(oh_trop_bo797, weights=mass_3, axis = (1,2,3))
#ca723 oh
oh_trop_ca723 = ma.masked_where(o3_ca723 > 125,oh_molec_cm3_ca723)
oh_trop_mean_ca723 = np.average(oh_trop_ca723, weights=mass_4, axis = (1,2,3))
#cb039 oh
oh_trop_cb039 = ma.masked_where(o3_cb039 > 125,oh_molec_cm3_cb039)
oh_trop_mean_cb039 = np.average(oh_trop_cb039, weights=mass_5, axis = (1,2,3))
#bo812 oh
oh_trop_bo812 = ma.masked_where(o3_bo812 > 125,oh_molec_cm3_bo812)
oh_trop_mean_bo812 = np.average(oh_trop_bo812, weights=mass_5, axis = (1,2,3))
#ensemble mean
oh_trop_ens_mean = np.mean([oh_trop_mean_186,oh_trop_mean_146,oh_trop_mean_473], axis = 0)
oh_trop_ens_mean_ssp = np.mean([oh_trop_mean_bo797,oh_trop_mean_ca723,oh_trop_mean_cb039], axis = 0)