forked from niklasboers/AMOC_EWS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsalinity.py
More file actions
2217 lines (2095 loc) · 112 KB
/
salinity.py
File metadata and controls
2217 lines (2095 loc) · 112 KB
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
import numpy as np
import scipy.stats as st
from netCDF4 import Dataset
import matplotlib.pyplot as plt
from EWS_functions import *
import matplotlib.ticker as mticker
import cartopy.crs as ccrs
import cartopy
from cartopy.util import add_cyclic_point
data_crs = ccrs.PlateCarree()
def funcfit3(x, a, b, c):
if b <= 0 or c <= 0:
return 1e8
else:
return a + np.power(-b * (x - c), 1 / 3)
def funcfit3_jac(x, a, b, c):
return np.array([np.ones(x.shape[0]), -(x-c) * np.power(-b * (x - c), -2/3) / 3, b * np.power(-b * (x - c), -2/3) / 3]).T
def trmm_indices_for_area(area_coords, trmm_lat, trmm_lon):
la = len(trmm_lat)
lo = len(trmm_lon)
n = la * lo
indices = np.arange(n).reshape((la, lo))
trmm_coords = np.transpose([np.repeat(trmm_lat, len(trmm_lon)), np.tile(trmm_lon, len(trmm_lat))])
lat_max = trmm_lat[np.argmin(np.abs(trmm_lat - np.max(area_coords[:, 0])))]
lat_min = trmm_lat[np.argmin(np.abs(trmm_lat - np.min(area_coords[:, 0])))]
lon_max = trmm_lon[np.argmin(np.abs(trmm_lon - np.max(area_coords[:, 1])))]
lon_min = trmm_lon[np.argmin(np.abs(trmm_lon - np.min(area_coords[:, 1])))]
ra_indices = indices[np.where(trmm_lat == lat_min)[0][0] : np.where(trmm_lat == lat_max)[0][0] + 1 , np.where(trmm_lon == lon_min)[0][0] : np.where(trmm_lon == lon_max)[0][0] + 1 ]
ra_indices = ra_indices.flatten()
trmm_ra_coords = trmm_coords[ra_indices]
d = np.zeros((len(area_coords), len(ra_indices)))
for i in range(len(area_coords)):
for j in range(len(ra_indices)):
d[i, j] = np.sum(np.abs(area_coords[i] - trmm_ra_coords[j]))
trmm_indices_area = ra_indices[np.argmin(d, axis = 1)]
return trmm_indices_area
def trmm_indices_for_area2(area_coords, trmm_lat, trmm_lon):
la = len(trmm_lat)
lo = len(trmm_lon)
n = la * lo
indices = np.arange(n).reshape((la, lo))
trmm_coords = np.transpose([np.repeat(trmm_lat, len(trmm_lon)), np.tile(trmm_lon, len(trmm_lat))])
lat_max = trmm_lat[np.argmin(np.abs(trmm_lat - np.max(area_coords[:, 0])))]
lat_min = trmm_lat[np.argmin(np.abs(trmm_lat - np.min(area_coords[:, 0])))]
lon_max = trmm_lon[np.argmin(np.abs(trmm_lon - np.max(area_coords[:, 1])))]
lon_min = trmm_lon[np.argmin(np.abs(trmm_lon - np.min(area_coords[:, 1])))]
ra_indices = indices[np.where(trmm_lat == lat_max)[0][0] : np.where(trmm_lat == lat_min)[0][0] + 1 , np.where(trmm_lon == lon_min)[0][0] : np.where(trmm_lon == lon_max)[0][0] + 1 ]
ra_indices = ra_indices.flatten()
trmm_ra_coords = trmm_coords[ra_indices]
d = np.zeros((len(area_coords), len(ra_indices)))
for i in range(len(area_coords)):
for j in range(len(ra_indices)):
d[i, j] = np.sum(np.abs(area_coords[i] - trmm_ra_coords[j]))
trmm_indices_area = ra_indices[np.argmin(d, axis = 1)]
return trmm_indices_area
def coordinate_indices_from_ra(lat, lon, lat_max, lat_min, lon_max, lon_min):
la = len(lat)
lo = len(lon)
n = la * lo
indices = np.arange(n).reshape((la, lo))
lat_max = lat[np.argmin(np.abs(lat - lat_max))]
lat_min = lat[np.argmin(np.abs(lat - lat_min))]
lon_max = lon[np.argmin(np.abs(lon - lon_max))]
lon_min = lon[np.argmin(np.abs(lon - lon_min))]
ra_indices = indices[np.where(lat == lat_max)[0][0] : np.where(lat == lat_min)[0][0] + 1 , np.where(lon == lon_min)[0][0] : np.where(lon == lon_max)[0][0] + 1 ]
return np.unique(ra_indices.flatten())
def coordinate_indices_from_ra2(lat, lon, lat_max, lat_min, lon_max, lon_min):
la = len(lat)
lo = len(lon)
n = la * lo
indices = np.arange(n).reshape((la, lo))
lat_max = lat[np.argmin(np.abs(lat - lat_max))]
lat_min = lat[np.argmin(np.abs(lat - lat_min))]
lon_max = lon[np.argmin(np.abs(lon - lon_max))]
lon_min = lon[np.argmin(np.abs(lon - lon_min))]
ra_indices = indices[np.where(lat == lat_max)[0][0] : np.where(lat == lat_min)[0][0] + 1 , np.where(lon == lon_min)[0][0] : np.where(lon == lon_max)[0][0] + 1 ]
return np.unique(ra_indices.flatten())
years = np.arange(1900, 2020)
months = ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12']
tlen = int(years.shape[0] * 12)
lat = Dataset('data/EN421/EN.4.2.1.f.analysis.g10.201811.nc').variables['lat'][:]
lon = Dataset('data/EN421/EN.4.2.1.f.analysis.g10.201811.nc').variables['lon'][:]
depth = Dataset('data/EN421/EN.4.2.1.f.analysis.g10.201811.nc').variables['depth'][:]
la = len(lat)
lo = len(lon)
n = la * lo
area = np.ones((la, lo))
area[np.ix_(np.logical_and(lat > 44, lat < 66), np.logical_or(lon > 289, lon < 11))] = -1
salt = Dataset('data/EN421/EN.4.2.1.f.analysis.g10.201811.nc').variables['salinity'][0, 0, :,:]
sal = np.zeros((tlen))
sal_s = np.zeros((tlen))
sal_n = np.zeros((tlen))
sal_sg = np.zeros((tlen))
sal_klus = np.zeros((tlen))
sal_global = np.zeros((tlen, la, lo))
dth = 300
weights = np.cos(lat * 2 * np.pi / 360)
dlen = np.where(depth < dth)[0].shape[0]
area_ceaser_coords = np.loadtxt('data/area_ceaser.txt')
area_ceaser_indices_sal = trmm_indices_for_area(area_ceaser_coords, lat, lon)
# i = 0
# for y in years:
# if y < 2020:
# for m in range(12):
# dat = Dataset('data/EN421/EN.4.2.1.f.analysis.g10.%s%s.nc'%(y, months[m]))
# # print(dat.variables)
# # sal[i] = np.nanmean(dat.variables['salinity'][0, depth < dth, np.logical_and(lat > 44, lat < 66), np.logical_or(lon > 289, lon < 11)])
# # sal_temp = np.nanmean(dat.variables['salinity'][0, depth < dth, np.logical_and(lat > 44, lat < 66), np.logical_or(lon > 289, lon < 11)], axis = 2)
# sal_temp = np.nanmean(dat.variables['salinity'][0, depth < dth, np.logical_and(lat > 44, lat < 66), np.logical_or(lon > 289, lon < 30)], axis = 2)
# sal_temp = np.average(sal_temp, weights = weights[np.logical_and(lat > 44, lat < 66)], axis = 1)
# # sal_temp = np.nanmean(dat.variables['salinity'][0, depth < dth, np.logical_and(lat > 50, lat < 60), np.logical_and(lon > 310, lon < 330)], axis = 2)
# # sal_temp = np.average(sal_temp, weights = weights[np.logical_and(lat > 50, lat < 60)], axis = 1)
# sal[i] = sal_temp.mean()
#
# ## sal_n_temp = np.nanmean(dat.variables['salinity'][0, depth < dth, np.logical_and(lat > 10, lat < 40), np.logical_or(lon > 280, lon < 11)], axis = 2)
# # sal_n_temp = np.nanmean(dat.variables['salinity'][0, depth < dth, np.logical_and(lat > 10, lat < 40), np.logical_or(lon > 289, lon < 30)], axis = 2)
# # sal_n_temp = np.nanmean(dat.variables['salinity'][0, depth < dth, np.logical_and(lat > 10, lat < 40), np.logical_or(lon > 280, lon < 30)], axis = 2)
# # sal_n_temp = np.average(sal_n_temp, weights = weights[np.logical_and(lat > 10, lat < 40)], axis = 1)
# # sal_n[i] = sal_n_temp.mean()
#
#
# ## sal_s_temp = np.nanmean(dat.variables['salinity'][0, depth < dth, np.logical_and(lat > -34, lat < -10), np.logical_or(lon > 280, lon < 11)], axis = 2)
# # sal_s_temp = np.nanmean(dat.variables['salinity'][0, depth < dth, np.logical_and(lat > -34, lat < -10), np.logical_or(lon > 289, lon < 30)], axis = 2)
# # sal_s_temp = np.average(sal_s_temp, weights = weights[np.logical_and(lat > -34, lat < -10)], axis = 1)
# # sal_s[i] = sal_s_temp.mean()
#
#
# sal_klus_temp = np.nanmean(dat.variables['salinity'][0, depth < dth, np.logical_and(lat > 55, lat < 62), np.logical_and(lon > 298, lon < 334)], axis = 2)
# sal_klus_temp = np.average(sal_klus_temp, weights = weights[np.logical_and(lat > 55, lat < 62)], axis = 1)
# sal_klus[i] = sal_klus_temp.mean()
#
#
# # sal_sg[i] = np.nanmean(dat.variables['salinity'][0, depth < dth, :, :].reshape(dlen, la * lo)[:, area_ceaser_indices_sal])
#
#
#
# # sal_global[i] = np.nanmean(dat.variables['salinity'][0, depth < dth], axis = 0)
#
# i += 1
# np.save('data/EN421_NA_salinity_d%d.npy'%dth, sal)
# np.save('data/EN421_SSS_N_d%d.npy'%dth, sal_n)
# np.save('data/EN421_SSS_S_d%d.npy'%dth, sal_s)
# np.save('data/EN421_SG_d%d.npy'%dth, sal_sg)
# np.save('data/EN421_KLUS_d%d.npy'%dth, sal_klus)
#
# np.save('data/EN421_GLOBAL_salinity_d%d.npy'%dth, sal_global)
sal_global = np.load('data/EN421_GLOBAL_salinity_d%d.npy'%dth)
sal_global_temp = np.reshape(sal_global, (sal_global.shape[0], sal_global.shape[1] * sal_global.shape[2]))
norm_sal_global = np.nanmean(sal_global_temp, axis = 1)
m_sal_global = np.mean(sal_global, axis = 0)
tt_samples = 100000
sm_w = 50
rmw = 70
ws = rmw
bound = rmw // 2
am_sal_global = np.zeros((years.shape[0], la, lo))
for i in range(years.shape[0]):
am_sal_global[i] = np.mean(sal_global[i * 12 : (i + 1) * 12], axis = 0)
np.save('data/EN421_GLOBAL_salinity_am_d%d.npy'%dth, am_sal_global)
sst_data = 'HadISST'
if sst_data == 'HadISST':
sst_dat = Dataset('data/HadISST_sst.nc')
sst_time = sst_dat.variables['time'][:]
sst_lat = sst_dat.variables['latitude'][:]
sst_lon = sst_dat.variables['longitude'][:]
sst = sst_dat.variables['sst'][:,:,:]
elif data == 'ERSST':
sst_dat = Dataset('data/sst.mnmean.nc')
sst_time = sst_dat.variables['time'][15*12:-4]
sst_lat = sst_dat.variables['lat'][:]
sst_lon = sst_dat.variables['lon'][:]
sst_sst = sst_dat.variables['sst'][15*12:-4,:,:]
sst, lon = shiftgrid(180., sst, sst_dat, start=False)
sst[sst == -1000] = np.nan
sst_la = sst_lat.shape[0]
sst_lo = sst_lon.shape[0]
sst_n = sst_la * sst_lo
sst_ny = int(sst.shape[0] / 12)
sst_years = np.arange(1870, 1870 + sst_ny)
ssty = np.zeros((sst_ny, sst_la, sst_lo))
sstay = np.zeros((sst_ny, sst_la, sst_lo))
for i in range(sst_ny):
tidx = np.array([10, 11, 12, 13, 14, 15, 16]) + i * 12
tidx = np.array(tidx, dtype = 'int')
ssty[i] = np.nanmean(sst[tidx], axis = 0)
sstay[i] = np.nanmean(sst[i * 12 : (i + 1) * 12], axis = 0)
# # am_sal_global_runstd = np.ones((years.shape[0], la, lo)) * np.nan
# # am_sal_global_runac = np.ones((years.shape[0], la, lo)) * np.nan
# # am_sal_global_runlambda_cor = np.ones((years.shape[0], la, lo)) * np.nan
# #
# # var_en4 = np.ones((la, lo)) * np.nan
# # ar_en4 = np.ones((la, lo)) * np.nan
# # lambda_cor_en4 = np.ones((la, lo)) * np.nan
#
# var_en4_p = np.ones((la, lo)) * np.nan
# ar_en4_p = np.ones((la, lo)) * np.nan
# # lambda_cor_en4_p = np.ones((la, lo)) * np.nan
#
#
# am_sal_global_runstd = np.load('data/am_sal_global_runstd_d%d_sm%d_rmw%d.npy'%(dth, sm_w, rmw))
# am_sal_global_runac = np.load('data/am_sal_global_runac_d%d_sm%d_rmw%d.npy'%(dth, sm_w, rmw))
# am_sal_global_runlambda_cor = np.load('data/am_sal_global_runlambda_cor_d%d_sm%d_rmw%d.npy'%(dth, sm_w, rmw))
#
# var_en4 = np.load('data/trend_am_sal_global_runstd_d%d_sm%d_rmw%d.npy'%(dth, sm_w, rmw))
# ar_en4 = np.load('data/trend_am_sal_global_runac_d%d_sm%d_rmw%d.npy'%(dth, sm_w, rmw))
# lambda_cor_en4 = np.load('data/trend_am_sal_global_runlambda_cor_d%d_sm%d_rmw%d.npy'%(dth, sm_w, rmw))
#
# count = 0
# for i in range(la):
# for j in range(lo):
# if np.sum(np.isnan(am_sal_global[:, i, j])) == 0:
# ts_temp = am_sal_global[:, i, j] - runmean(am_sal_global[:, i, j], sm_w)
#
# # am_sal_global_runstd[:, i, j] = runstd(ts_temp, rmw)**2
# # var_en4[i, j] = st.linregress(years[bound : - bound], am_sal_global_runstd[:, i, j][bound : - bound])[0]
# var_en4_p[i, j] = kendall_tau_test(am_sal_global_runstd[:, i, j][bound : - bound], 1000, var_en4[i, j])
#
# # am_sal_global_runac[:, i, j] = runac(ts_temp, rmw)
# # ar_en4[i, j] = st.linregress(years[bound : - bound], am_sal_global_runac[:, i, j][bound : - bound])[0]
# ar_en4_p[i, j] = kendall_tau_test(am_sal_global_runac[:, i, j][bound : - bound], 1000, ar_en4[i, j])
#
# # am_sal_global_runlambda_cor[:, i, j] = run_fit_a_ar1(ts_temp, rmw)
# # lambda_cor_en4[i, j] = st.linregress(years[bound : - bound], am_sal_global_runlambda_cor[:, i, j][bound : - bound])[0]
# # lambda_cor_en4_p[i, j] = kendall_tau_test(am_sal_global_runlambda_cor[:, i, j][bound : - bound], 1000, lambda_cor_en4[i, j])
# count += 1
# print(count)
#
# # np.save('data/am_sal_global_runstd_d%d_sm%d_rmw%d.npy'%(dth, sm_w, rmw), am_sal_global_runstd)
# # np.save('data/am_sal_global_runac_d%d_sm%d_rmw%d.npy'%(dth, sm_w, rmw), am_sal_global_runac)
# # np.save('data/am_sal_global_runlambda_cor_d%d_sm%d_rmw%d.npy'%(dth, sm_w, rmw), am_sal_global_runlambda_cor)
# #
# # np.save('data/trend_am_sal_global_runstd_d%d_sm%d_rmw%d.npy'%(dth, sm_w, rmw), var_en4)
# # np.save('data/trend_am_sal_global_runac_d%d_sm%d_rmw%d.npy'%(dth, sm_w, rmw), ar_en4)
# # np.save('data/trend_am_sal_global_runlambda_cor_d%d_sm%d_rmw%d.npy'%(dth, sm_w, rmw), lambda_cor_en4)
#
# np.save('data/trend_p_am_sal_global_runstd_d%d_sm%d_rmw%d.npy'%(dth, sm_w, rmw), var_en4_p)
# np.save('data/trend_p_am_sal_global_runac_d%d_sm%d_rmw%d.npy'%(dth, sm_w, rmw), ar_en4_p)
# np.save('data/trend_p_am_sal_global_runlambda_cor_d%d_sm%d_rmw%d.npy'%(dth, sm_w, rmw), lambda_cor_en4_p)
#
#
#
#
# am_sst_global_runstd = np.ones((sst_ny, sst_la, sst_lo)) * np.nan
# am_sst_global_runac = np.ones((sst_ny, sst_la, sst_lo)) * np.nan
# am_sst_global_runlambda_cor = np.ones((sst_ny, sst_la, sst_lo)) * np.nan
#
# var_sst = np.ones((sst_la, sst_lo)) * np.nan
# ar_sst = np.ones((sst_la, sst_lo)) * np.nan
# lambda_cor_sst = np.ones((sst_la, sst_lo)) * np.nan
#
#
# ar_sst_p = np.ones((sst_la, sst_lo)) * np.nan
# var_sst_p = np.ones((sst_la, sst_lo)) * np.nan
# lambda_cor_sst_p = np.ones((sst_la, sst_lo)) * np.nan
#
#
# am_sst_global_runstd = np.load('data/am_sst_global_runstd_d%d_sm%d_rmw%d.npy'%(dth, sm_w, rmw))
# am_sst_global_runac = np.load('data/am_sst_global_runac_d%d_sm%d_rmw%d.npy'%(dth, sm_w, rmw))
# am_sst_global_runlambda_cor = np.load('data/am_sst_global_runlambda_cor_d%d_sm%d_rmw%d.npy'%(dth, sm_w, rmw))
#
# var_sst = np.load('data/trend_am_sst_global_runstd_d%d_sm%d_rmw%d.npy'%(dth, sm_w, rmw))
# ar_sst = np.load('data/trend_am_sst_global_runac_d%d_sm%d_rmw%d.npy'%(dth, sm_w, rmw))
# lambda_cor_sst = np.load('data/trend_am_sst_global_runlambda_cor_d%d_sm%d_rmw%d.npy'%(dth, sm_w, rmw))
#
# count = 0
# for i in range(la):
# for j in range(lo):
# if np.sum(np.isnan(ssty[:, i, j])) == 0 and np.where(ssty[:, i, j] <= 0)[0].shape[0] == 0:
# ts_temp = ssty[:, i, j] - runmean(ssty[:, i, j], sm_w)
# if np.where(ts_temp == 0)[0].shape[0] == 0:
# # am_sst_global_runstd[:, i, j] = runstd(ts_temp, rmw)**2
# # var_sst[i, j] = st.linregress(sst_years[bound : - bound], am_sst_global_runstd[:, i, j][bound : - bound])[0]
# var_sst_p[i, j] = kendall_tau_test(am_sst_global_runstd[:, i, j][bound : - bound], 1000, var_sst[i, j])
#
# # am_sst_global_runac[:, i, j] = runac(ts_temp, rmw)
# # ar_sst[i, j] = st.linregress(sst_years[bound : - bound], am_sst_global_runac[:, i, j][bound : - bound])[0]
# # ar_sst_p[i, j] = kendall_tau_test(am_sst_global_runac[:, i, j][bound : - bound], 1000, ar_sst[i, j])
#
# # am_sst_global_runlambda_cor[:, i, j] = run_fit_a_ar1(ts_temp, rmw)
# # lambda_cor_sst[i, j] = st.linregress(sst_years[bound : - bound], am_sst_global_runlambda_cor[:, i, j][bound : - bound])[0]
# # lambda_cor_sst_p[i, j] = kendall_tau_test(am_sst_global_runlambda_cor[:, i, j][bound : - bound], 1000, lambda_cor_sst[i, j])
#
# count += 1
# print(count)
#
# np.save('data/am_sst_global_runstd_d%d_sm%d_rmw%d.npy'%(dth, sm_w, rmw), am_sst_global_runstd)
# np.save('data/am_sst_global_runac_d%d_sm%d_rmw%d.npy'%(dth, sm_w, rmw), am_sst_global_runac)
# np.save('data/am_sst_global_runlambda_cor_d%d_sm%d_rmw%d.npy'%(dth, sm_w, rmw), am_sst_global_runlambda_cor)
#
# np.save('data/trend_am_sst_global_runstd_d%d_sm%d_rmw%d.npy'%(dth, sm_w, rmw), var_sst)
# np.save('data/trend_am_sst_global_runac_d%d_sm%d_rmw%d.npy'%(dth, sm_w, rmw), ar_sst)
# np.save('data/trend_am_sst_global_runlambda_cor_d%d_sm%d_rmw%d.npy'%(dth, sm_w, rmw), lambda_cor_sst)
# np.save('data/trend_p_am_sst_global_runlambda_cor_d%d_sm%d_rmw%d.npy'%(dth, sm_w, rmw), lambda_cor_sst_p)
# np.save('data/trend_p_am_sst_global_runstd_d%d_sm%d_rmw%d.npy'%(dth, sm_w, rmw), var_sst_p)
# np.save('data/trend_p_am_sst_global_runac_d%d_sm%d_rmw%d.npy'%(dth, sm_w, rmw), ar_sst_p)
# am_sal_global = np.load('data/EN421_GLOBAL_salinity_am_d%d.npy'%dth)
#
#
#
# am_sal_global_runstd = np.load('data/am_sal_global_runstd_d%d_sm%d_rmw%d.npy'%(dth, sm_w, rmw))
# am_sal_global_runac = np.load('data/am_sal_global_runac_d%d_sm%d_rmw%d.npy'%(dth, sm_w, rmw))
# am_sal_global_runlambda = np.load('data/am_sal_global_runlambda_cor_d%d_sm%d_rmw%d.npy'%(dth, sm_w, rmw))
#
# m_am_sal_global_runstd = np.nanmean(am_sal_global_runstd, axis = 0)
# m_am_sal_global_runac = np.nanmean(am_sal_global_runac, axis = 0)
# m_am_sal_global_runlambda = np.nanmean(am_sal_global_runlambda, axis = 0)
#
# var_en4 = np.load('data/trend_am_sal_global_runstd_d%d_sm%d_rmw%d.npy'%(dth, sm_w, rmw))
# ar_en4 = np.load('data/trend_am_sal_global_runac_d%d_sm%d_rmw%d.npy'%(dth, sm_w, rmw))
# lambda_en4 = np.load('data/trend_am_sal_global_runlambda_cor_d%d_sm%d_rmw%d.npy'%(dth, sm_w, rmw))
#
# var_en4_p = np.load('data/trend_p_am_sal_global_runstd_d%d_sm%d_rmw%d.npy'%(dth, sm_w, rmw))
# ar_en4_p = np.load('data/trend_p_am_sal_global_runac_d%d_sm%d_rmw%d.npy'%(dth, sm_w, rmw))
# lambda_en4_p = np.load('data/trend_p_am_sal_global_runlambda_cor_d%d_sm%d_rmw%d.npy'%(dth, sm_w, rmw))
#
# m_am_sal_global_runstd, lonc = add_cyclic_point(m_am_sal_global_runstd, coord=lon)
# m_am_sal_global_runac, lonc = add_cyclic_point(m_am_sal_global_runac, coord=lon)
# m_am_sal_global_runlambda, lonc = add_cyclic_point(m_am_sal_global_runlambda, coord=lon)
#
# m_am_sal_global_runstd[m_am_sal_global_runstd == 0] = np.nan
# m_am_sal_global_runac[m_am_sal_global_runac == 0] = np.nan
# m_am_sal_global_runlambda[m_am_sal_global_runlambda == 0] = np.nan
#
# var_en4[var_en4 == 0] = np.nan
# ar_en4[ar_en4 == 0] = np.nan
# lambda_en4[lambda_en4 == 0] = np.nan
#
#
# var_en4, lonc = add_cyclic_point(var_en4, coord=lon)
# ar_en4, lonc = add_cyclic_point(ar_en4, coord=lon)
# lambda_en4, lonc = add_cyclic_point(lambda_en4, coord=lon)
#
# var_en4_p, lonc = add_cyclic_point(var_en4_p, coord=lon)
# ar_en4_p, lonc = add_cyclic_point(ar_en4_p, coord=lon)
# lambda_en4_p, lonc = add_cyclic_point(lambda_en4_p, coord=lon)
#
#
#
# am_sst_global_runstd = np.load('data/am_sst_global_runstd_d%d_sm%d_rmw%d.npy'%(dth, sm_w, rmw))
# am_sst_global_runac = np.load('data/am_sst_global_runac_d%d_sm%d_rmw%d.npy'%(dth, sm_w, rmw))
# am_sst_global_runlambda = np.load('data/am_sst_global_runlambda_cor_d%d_sm%d_rmw%d.npy'%(dth, sm_w, rmw))
#
# m_am_sst_global_runstd = np.nanmean(am_sst_global_runstd, axis = 0)
# m_am_sst_global_runac = np.nanmean(am_sst_global_runac, axis = 0)
# m_am_sst_global_runlambda = np.nanmean(am_sst_global_runlambda, axis = 0)
#
# var_sst = np.load('data/trend_am_sst_global_runstd_d%d_sm%d_rmw%d.npy'%(dth, sm_w, rmw))
# ar_sst = np.load('data/trend_am_sst_global_runac_d%d_sm%d_rmw%d.npy'%(dth, sm_w, rmw))
# lambda_sst = np.load('data/trend_am_sst_global_runlambda_cor_d%d_sm%d_rmw%d.npy'%(dth, sm_w, rmw))
#
# var_sst_p = np.load('data/trend_p_am_sst_global_runstd_d%d_sm%d_rmw%d.npy'%(dth, sm_w, rmw))
# ar_sst_p = np.load('data/trend_p_am_sst_global_runac_d%d_sm%d_rmw%d.npy'%(dth, sm_w, rmw))
# lambda_sst_p = np.load('data/trend_p_am_sst_global_runlambda_cor_d%d_sm%d_rmw%d.npy'%(dth, sm_w, rmw))
#
#
# m_am_sst_global_runstd, sst_lonc = add_cyclic_point(m_am_sst_global_runstd, coord=sst_lon)
# m_am_sst_global_runac, sst_lonc = add_cyclic_point(m_am_sst_global_runac, coord=sst_lon)
# m_am_sst_global_runlambda, sst_lonc = add_cyclic_point(m_am_sst_global_runlambda, coord=sst_lon)
#
# var_sst, sst_lonc = add_cyclic_point(var_sst, coord=sst_lon)
# ar_sst, sst_lonc = add_cyclic_point(ar_sst, coord=sst_lon)
# lambda_sst, sst_lonc = add_cyclic_point(lambda_sst, coord=sst_lon)
#
# var_sst_p, sst_lonc = add_cyclic_point(var_sst_p, coord=sst_lon)
# ar_sst_p, sst_lonc = add_cyclic_point(ar_sst_p, coord=sst_lon)
# lambda_sst_p, sst_lonc = add_cyclic_point(lambda_sst_p, coord=sst_lon)
#
#
# var_sst = var_sst * 100
# ar_sst = ar_sst * 100
# lambda_sst = lambda_sst * 100
#
# var_en4 = var_en4 * 100
# ar_en4 = ar_en4 * 100
# lambda_en4 = lambda_en4 * 100
#
# fig = plt.figure(figsize = (15,10))
#
# ax = fig.add_subplot(1, 3, 1, projection=ccrs.Orthographic(central_longitude=340))
# ax.coastlines()
# # cf = ax.contourf(lonc, lat, m_am_sal_global_runlambda, levels = np.linspace(-.9,-.3,13), extend = 'both', transform = data_crs)
# # cbar = plt.colorbar(cf, ax = ax, orientation = 'horizontal', pad = .01)
# cf = ax.contourf(lonc, lat, m_am_sal_global_runlambda, levels = np.linspace(-.9,-.3,20), extend = 'both', transform = data_crs)
# cbar = plt.colorbar(cf, ax = ax, orientation = 'horizontal', pad = .01, ticks = np.linspace(-.9,-.3,7))
#
# gl = ax.gridlines(linestyle=":", draw_labels=False)
#
#
# cbar.set_label(r'$\lambda$')
# ax.add_feature(cartopy.feature.LAND, color='k')
#
# # ax = fig.add_subplot(1, 3, 1)
# # cf = ax.contourf(sst_lonc, sst_lat, m_am_sst_global_runlambda)
#
# ax = fig.add_subplot(1, 3, 2, projection=ccrs.Orthographic(central_longitude=340))
# ax.coastlines()
# # cf = ax.contourf(lonc, lat, m_am_sal_global_runstd, levels = np.linspace(0., .012 ,13), extend = 'both', transform = data_crs)
# # cbar = plt.colorbar(cf, ax = ax, orientation = 'horizontal', pad = .01)
# cf = ax.contourf(lonc, lat, m_am_sal_global_runstd, levels = np.linspace(0., .012 ,20), extend = 'both', transform = data_crs)
# cbar = plt.colorbar(cf, ax = ax, orientation = 'horizontal', pad = .01, ticks = np.linspace(0., .012 ,7))
# ax.gridlines(linestyle=":", draw_labels=False)
# cbar.set_label(r'Var')
# ax.add_feature(cartopy.feature.LAND, color='k')
#
# ax = fig.add_subplot(1, 3, 3, projection=ccrs.Orthographic(central_longitude=340))
# ax.coastlines()
# # cf = ax.contourf(lonc, lat, m_am_sal_global_runac, levels = np.linspace(.2, .8,13), extend = 'both', transform = data_crs)
# # cbar = plt.colorbar(cf, ax = ax, orientation = 'horizontal', pad = .01)
# cf = ax.contourf(lonc, lat, m_am_sal_global_runac, levels = np.linspace(.2, .7,20), extend = 'both', transform = data_crs)
# cbar = plt.colorbar(cf, ax = ax, orientation = 'horizontal', pad = .01, ticks = np.linspace(.2, .7, 6))
# ax.gridlines(linestyle=":", draw_labels=False)
# cbar.set_label(r'AC1')
# ax.add_feature(cartopy.feature.LAND, color='k')
#
# fig.savefig('plots/Sal_meanEWS_spatial_d%d_sm%d_ws%d.pdf'%(dth, sm_w, rmw), bbox_inches = 'tight')
#
# fig = plt.figure(figsize = (15,10))
# ax = fig.add_subplot(1, 3, 1, projection=ccrs.Orthographic(central_longitude=340))
# ax.coastlines()
# # cf = ax.contourf(lonc, lat, lambda_en4, levels = np.linspace(-.6, .6, 6), extend = 'both', transform = data_crs, cmap = plt.cm.RdBu_r)
# # cbar = plt.colorbar(cf, ax = ax, orientation = 'horizontal', pad = .01)
# cf = ax.contourf(lonc, lat, lambda_en4, levels = np.linspace(-.8, .8, 20), extend = 'both', transform = data_crs, cmap = plt.cm.RdBu_r)
# cbar = plt.colorbar(cf, ax = ax, orientation = 'horizontal', pad = .01, ticks = np.linspace(-.8, .8, 6))
# ax.gridlines(linestyle=":", draw_labels=False)
# cbar.set_label(r'$\Delta \lambda$ / 100yr')
# ax.add_feature(cartopy.feature.LAND, color='k')
# ax = fig.add_subplot(1, 3, 2, projection=ccrs.Orthographic(central_longitude=340))
# ax.coastlines()
# # cf = ax.contourf(lonc, lat, var_en4, levels = np.linspace(-.01, .01, 6), extend = 'both', transform = data_crs, cmap = plt.cm.RdBu_r)
# # cbar = plt.colorbar(cf, ax = ax, orientation = 'horizontal', pad = .01)
# cf = ax.contourf(lonc, lat, var_en4, levels = np.linspace(-.01, .01, 20), extend = 'both', transform = data_crs, cmap = plt.cm.RdBu_r)
# cbar = plt.colorbar(cf, ax = ax, orientation = 'horizontal', pad = .01, ticks = np.linspace(-.01, .01, 6))
# ax.gridlines(linestyle=":", draw_labels=False)
# cbar.set_label(r'$\Delta$ Var / 100yr')
# ax.add_feature(cartopy.feature.LAND, color='k')
# ax = fig.add_subplot(1, 3, 3, projection=ccrs.Orthographic(central_longitude=340))
# ax.coastlines()
# # cf = ax.contourf(lonc, lat, ar_en4, levels = np.linspace(-.6, .6,6), extend = 'both', transform = data_crs, cmap = plt.cm.RdBu_r)
# # cbar = plt.colorbar(cf, ax = ax, orientation = 'horizontal', pad = .01)
# cf = ax.contourf(lonc, lat, ar_en4, levels = np.linspace(-.8, .8,20), extend = 'both', transform = data_crs, cmap = plt.cm.RdBu_r)
# cbar = plt.colorbar(cf, ax = ax, orientation = 'horizontal', pad = .01, ticks = np.linspace(-.8, .8,6))
# ax.gridlines(linestyle=":", draw_labels=False)
# cbar.set_label(r'$\Delta$ AC1 / 100yr')
# ax.add_feature(cartopy.feature.LAND, color='k')
#
# fig.savefig('plots/Sal_trendEWS_spatial_d%d_sm%d_ws%d.pdf'%(dth, sm_w, rmw), bbox_inches = 'tight')
#
#
# fig = plt.figure(figsize = (15,10))
#
# ax = fig.add_subplot(1, 3, 1, projection=ccrs.Orthographic(central_longitude=340))
# ax.coastlines()
# # cf = ax.contourf(sst_lonc, sst_lat, m_am_sst_global_runlambda, levels = np.linspace(-1.1,-.5,13), extend= 'both', transform = data_crs)
# # cbar = plt.colorbar(cf, ax = ax, orientation = 'horizontal', pad = .01)
# cf = ax.contourf(sst_lonc, sst_lat, m_am_sst_global_runlambda, levels = np.linspace(-1.1,-.5,20), extend= 'both', transform = data_crs)
# cbar = plt.colorbar(cf, ax = ax, orientation = 'horizontal', pad = .01, ticks = np.linspace(-1.1,-.5,7))
# gl = ax.gridlines(linestyle=":", draw_labels=False)
#
# cbar.set_label(r'$\lambda$')
# ax.add_feature(cartopy.feature.LAND, color='k')
#
# # ax = fig.add_subplot(1, 3, 1)
# # cf = ax.contourf(sst_lonc, sst_lat, m_am_sst_global_runlambda)
#
# ax = fig.add_subplot(1, 3, 2, projection=ccrs.Orthographic(central_longitude=340))
# ax.coastlines()
# # cf = ax.contourf(sst_lonc, sst_lat, m_am_sst_global_runstd, levels = np.linspace(0., .6,13), extend = 'both', transform = data_crs)
# # cbar = plt.colorbar(cf, ax = ax, orientation = 'horizontal', pad = .01)
# cf = ax.contourf(sst_lonc, sst_lat, m_am_sst_global_runstd, levels = np.linspace(0., .6,20), extend = 'both', transform = data_crs)
# cbar = plt.colorbar(cf, ax = ax, orientation = 'horizontal', pad = .01, ticks = np.linspace(0., .6,7))
# ax.gridlines(linestyle=":", draw_labels=False)
# cbar.set_label(r'Var')
# ax.add_feature(cartopy.feature.LAND, color='k')
#
# ax = fig.add_subplot(1, 3, 3, projection=ccrs.Orthographic(central_longitude=340))
# ax.coastlines()
# # cf = ax.contourf(sst_lonc, sst_lat, m_am_sst_global_runac, levels = np.linspace(-.1, .5,13), extend = 'both', transform = data_crs)
# # cbar = plt.colorbar(cf, ax = ax, orientation = 'horizontal', pad = .01)
# cf = ax.contourf(sst_lonc, sst_lat, m_am_sst_global_runac, levels = np.linspace(-.1, .5,20), extend = 'both', transform = data_crs)
# cbar = plt.colorbar(cf, ax = ax, orientation = 'horizontal', pad = .01, ticks = np.linspace(-.1, .5,7))
# ax.gridlines(linestyle=":", draw_labels=False)
# cbar.set_label(r'AC1')
# ax.add_feature(cartopy.feature.LAND, color='k')
#
# fig.savefig('plots/SST_meanEWS_spatial_d%d_sm%d_ws%d.pdf'%(dth, sm_w, rmw), bbox_inches = 'tight')
#
# fig = plt.figure(figsize = (15,10))
# ax = fig.add_subplot(1, 3, 1, projection=ccrs.Orthographic(central_longitude=340))
# ax.coastlines()
# # cf = ax.contourf(sst_lonc, sst_lat, lambda_sst, levels = np.linspace(-.6, .6, 6), extend = 'both', transform = data_crs, cmap = plt.cm.RdBu_r)
# # cbar = plt.colorbar(cf, ax = ax, orientation = 'horizontal', pad = .01)
# cf = ax.contourf(sst_lonc, sst_lat, lambda_sst, levels = np.linspace(-.6, .6, 20), extend = 'both', transform = data_crs, cmap = plt.cm.RdBu_r)
# cbar = plt.colorbar(cf, ax = ax, orientation = 'horizontal', pad = .01, ticks = np.linspace(-.6, .6, 6))
# ax.gridlines(linestyle=":", draw_labels=False)
# cbar.set_label(r'$\Delta \lambda$ / 100yr')
# ax.add_feature(cartopy.feature.LAND, color='k')
# ax = fig.add_subplot(1, 3, 2, projection=ccrs.Orthographic(central_longitude=340))
# ax.coastlines()
# # cf = ax.contourf(sst_lonc, sst_lat, var_sst, levels = np.linspace(-.2, .2, 6), extend = 'both', transform = data_crs, cmap = plt.cm.RdBu_r)
# # cbar = plt.colorbar(cf, ax = ax, orientation = 'horizontal', pad = .01)
# cf = ax.contourf(sst_lonc, sst_lat, var_sst, levels = np.linspace(-.2, .2, 20), extend = 'both', transform = data_crs, cmap = plt.cm.RdBu_r)
# cbar = plt.colorbar(cf, ax = ax, orientation = 'horizontal', pad = .01, ticks = np.linspace(-.2, .2, 6))
# ax.gridlines(linestyle=":", draw_labels=False)
# cbar.set_label(r'$\Delta$ Var / 100yr')
# ax.add_feature(cartopy.feature.LAND, color='k')
# ax = fig.add_subplot(1, 3, 3, projection=ccrs.Orthographic(central_longitude=340))
# ax.coastlines()
# # cf = ax.contourf(sst_lonc, sst_lat, ar_sst, levels = np.linspace(-.6, .6, 6), extend = 'both', transform = data_crs, cmap = plt.cm.RdBu_r)
# # cbar = plt.colorbar(cf, ax = ax, orientation = 'horizontal', pad = .01)
# cf = ax.contourf(sst_lonc, sst_lat, ar_sst, levels = np.linspace(-.6, .6, 20), extend = 'both', transform = data_crs, cmap = plt.cm.RdBu_r)
# cbar = plt.colorbar(cf, ax = ax, orientation = 'horizontal', pad = .01, ticks = np.linspace(-.6, .6, 6))
# ax.gridlines(linestyle=":", draw_labels=False)
# cbar.set_label(r'$\Delta$ AC1 / 100yr')
# ax.add_feature(cartopy.feature.LAND, color='k')
#
# fig.savefig('plots/SST_trendEWS_spatial_d%d_sm%d_ws%d.pdf'%(dth, sm_w, rmw), bbox_inches = 'tight')
area_ceaser_indices = trmm_indices_for_area2(area_ceaser_coords, sst_lat, sst_lon)
area_ceaser = np.ones(sst_la * sst_lo)
area_ceaser[area_ceaser_indices] = -1
area_ceaser = area_ceaser.reshape((sst_lat.shape[0], sst_lon.shape[0]))
sgi = area_ceaser_indices
area = np.ones(sst_la * sst_lo)
area[sgi] = -1
area = area.reshape((sst_lat.shape[0], sst_lon.shape[0]))
dipole1 = coordinate_indices_from_ra(sst_lat, sst_lon, 80, 45, 30, -70)
dipole2 = coordinate_indices_from_ra(sst_lat, sst_lon, 0, -45, 30, -70)
dipole1_area = np.ones(sst_la * sst_lo)
dipole1_area[dipole1] = -1
dipole1_area = dipole1_area.reshape((sst_lat.shape[0], sst_lon.shape[0]))
dipole2_area = np.ones(sst_la * sst_lo)
dipole2_area[dipole2] = -1
dipole2_area = dipole2_area.reshape((sst_lat.shape[0], sst_lon.shape[0]))
sst_trends = np.load('data/sst_trends.npy')
nsst_trends = np.load('data/nsst_trends.npy')
sal_trends = np.load('data/sal_trends.npy')
sst_trends, sst_lonc = add_cyclic_point(sst_trends, coord=sst_lon)
nsst_trends, sst_lonc = add_cyclic_point(nsst_trends, coord=sst_lon)
# area, sst_lonc = add_cyclic_point(area, coord=sst_lon)
# area_ceaser, sst_lonc = add_cyclic_point(area_ceaser, coord=sst_lon)
# dipole1_area, sst_lonc = add_cyclic_point(dipole1_area, coord=sst_lon)
# dipole2_area, sst_lonc = add_cyclic_point(dipole2_area, coord=sst_lon)
#
# sal_trends, lonc = add_cyclic_point(sal_trends, coord=lon)
#
#
# area_nn = np.ones((la,lo))
# area_nn[np.ix_(np.logical_and(lat > 44, lat < 66), np.logical_or(lon > 289, lon < 30))] = -1
# area_nn, lonc = add_cyclic_point(area_nn, coord=lon)
#
# area_n = np.ones((la, lo))
# area_n[np.ix_(np.logical_and(lat > 10, lat < 40), np.logical_or(lon > 289, lon < 30))] = -1
# area_n, lonc = add_cyclic_point(area_n, coord=lon)
#
# area_s = np.ones((la, lo))
# area_s[np.ix_(np.logical_and(lat > -34, lat < -10), np.logical_or(lon > 289, lon < 30))] = -1
# area_s, lonc = add_cyclic_point(area_s, coord=lon)
#
#
# area_klus = np.ones((la, lo))
# area_klus[np.ix_(np.logical_and(lat > 54, lat < 62), np.logical_and(lon > 298, lon < 334))] = -1
# area_klus, lonc = add_cyclic_point(area_klus, coord=lon)
#
#
#
# ## fig = plt.figure(figsize = (9,15))
# fig = plt.figure(figsize = (10,11))
# # ax = fig.add_subplot(2, 1, 1, projection=ccrs.Robinson())
# ax = fig.add_subplot(3, 2, 1, projection=ccrs.Orthographic(central_longitude=340))
# ax.text(0, 1, s = 'a', transform=ax.transAxes, fontsize=12, fontweight='bold', va='top', ha='right')
# ax.set_title('Sea-surface temperatures', fontweight="bold")
# # ax.coastlines()
# cf = ax.contourf(sst_lonc, sst_lat, sst_trends, levels = np.linspace(-.8,.8,20), cmap = plt.cm.RdBu_r, extend = 'both', transform = data_crs)
# # cbar = plt.colorbar(cf, ax = ax, orientation = 'horizontal', pad = .01, ticks = [-.8,-.4,0,.4,.8])
# cbar = plt.colorbar(cf, ax = ax, ticks = [-.8,-.4,0,.4,.8], shrink = .8)
# cbar.set_label(r'SST trend [K / 100yr]')
# # cs = ax.contour(sst_lonc, sst_lat, area, [0], linestyles = 'solid', linewidths = 2., colors = 'r', transform = data_crs)
# cs = ax.contour(sst_lonc, sst_lat, area_ceaser, [0], linestyles = 'solid', linewidths = 2., colors = 'b', transform = data_crs)
# cs = ax.contour(sst_lonc, sst_lat, dipole1_area, [0], linestyles = 'solid', linewidths = 2., colors = 'c', transform = data_crs)
# cs = ax.contour(sst_lonc, sst_lat, dipole2_area, [0], linestyles = 'solid', linewidths = 2., colors = 'm', transform = data_crs)
# gl = ax.gridlines(linestyle=":", draw_labels=False)
# gl.xlocator = mticker.FixedLocator(np.arange(-180,181,30))
# gl.ylocator = mticker.FixedLocator(np.arange(-90,90,30))
# ax.add_feature(cartopy.feature.LAND, color='.3')
# # ax = fig.add_subplot(2, 1, 2, projection=ccrs.Robinson())
#
#
# ax = fig.add_subplot(3, 2, 2, projection=ccrs.Orthographic(central_longitude=340))
# ax.text(0, 1, s = 'b', transform=ax.transAxes, fontsize=12, fontweight='bold', va='top', ha='right')
# ax.set_title('Salinity', fontweight="bold")
# # ax.coastlines()
# # cf = ax.contourf(lonc, lat, nsst_trends, levels = np.linspace(-1,3, 101), cmap = plt.cm.RdBu_r, extend = 'both', transform = data_crs)
# cf = ax.contourf(lonc, lat, sal_trends, levels = np.linspace(-.15,.15, 20), cmap = plt.cm.RdBu_r, extend = 'both', transform = data_crs)
# # cbar = plt.colorbar(cf, ax = ax, orientation = 'horizontal', pad = .01, ticks = [-.15,-.075,0,.075,.15])
# cbar = plt.colorbar(cf, ax = ax, ticks = [-.15,-.075,0,.075,.15], shrink = .8)
# # cbar.set_label(r'normalized SST trend')
# cbar.set_label(r'Salinity trends [psu / 100yr]')
# cs = ax.contour(lonc, lat, area_nn, [0], linestyles = 'solid', linewidths = 2., colors = 'k', transform = data_crs)
# cs = ax.contour(lonc, lat, area_n, [0], linestyles = 'solid', linewidths = 2., colors = 'orange', transform = data_crs)
# cs = ax.contour(lonc, lat, area_s, [0], linestyles = 'solid', linewidths = 2., colors = 'r', transform = data_crs)
# cs = ax.contour(lonc, lat, area_klus, [0], linestyles = 'solid', linewidths = 2., colors = 'y', transform = data_crs)
#
# ax.gridlines(linestyle=":", draw_labels=False)
# ax.add_feature(cartopy.feature.LAND, color='.3')
#
#
#
# ax = fig.add_subplot(3, 2, 3, projection=ccrs.Orthographic(central_longitude=340))
# ax.text(0, 1, s = 'c', transform=ax.transAxes, fontsize=12, fontweight='bold', va='top', ha='right')
# # ax.coastlines()
# # cf = ax.contourf(sst_lonc, sst_lat, m_am_sst_global_runlambda, levels = np.linspace(-1.1,-.5,13), extend= 'both', transform = data_crs)
# # cbar = plt.colorbar(cf, ax = ax, orientation = 'horizontal', pad = .01)
# cf = ax.contourf(sst_lonc, sst_lat, m_am_sst_global_runlambda, levels = np.linspace(-1.1,-.5,20), extend= 'both', transform = data_crs)
# # cbar = plt.colorbar(cf, ax = ax, orientation = 'horizontal', pad = .01, ticks = np.linspace(-1.1,-.5,7))
# cbar = plt.colorbar(cf, ax = ax, ticks = np.linspace(-1.1,-.5,7), shrink = .8)
# gl = ax.gridlines(linestyle=":", draw_labels=False)
# gl.xlocator = mticker.FixedLocator(np.arange(-180,181,30))
# gl.ylocator = mticker.FixedLocator(np.arange(-90,90,30))
#
# cbar.set_label(r'$\lambda$')
# ax.add_feature(cartopy.feature.LAND, color='.3')
#
#
# ax = fig.add_subplot(3, 2, 4, projection=ccrs.Orthographic(central_longitude=340))
# ax.text(0, 1, s = 'd', transform=ax.transAxes, fontsize=12, fontweight='bold', va='top', ha='right')
# # ax.coastlines()
# # cf = ax.contourf(lonc, lat, m_am_sal_global_runlambda, levels = np.linspace(-.9,-.3,13), extend = 'both', transform = data_crs)
# # cbar = plt.colorbar(cf, ax = ax, orientation = 'horizontal', pad = .01)
# cf = ax.contourf(lonc, lat, m_am_sal_global_runlambda, levels = np.linspace(-.9,-.3,20), extend = 'both', transform = data_crs)
# # cbar = plt.colorbar(cf, ax = ax, orientation = 'horizontal', pad = .01, ticks = np.linspace(-.9,-.3,7))
# cbar = plt.colorbar(cf, ax = ax, ticks = np.linspace(-.9,-.3,7), shrink = .8)
#
# ax.gridlines(linestyle=":", draw_labels=False)
# cbar.set_label(r'$\lambda$')
# ax.add_feature(cartopy.feature.LAND, color='.3')
#
# ax = fig.add_subplot(3, 2, 5, projection=ccrs.Orthographic(central_longitude=340))
# ax.text(0, 1, s = 'e', transform=ax.transAxes, fontsize=12, fontweight='bold', va='top', ha='right')
# # ax.coastlines()
# # cf = ax.contourf(sst_lonc, sst_lat, lambda_sst, levels = np.linspace(-.6, .6, 6), extend = 'both', transform = data_crs, cmap = plt.cm.RdBu_r)
# # cbar = plt.colorbar(cf, ax = ax, orientation = 'horizontal', pad = .01)
# cf = ax.contourf(sst_lonc, sst_lat, lambda_sst, levels = np.linspace(-.6, .6, 20), extend = 'both', transform = data_crs, cmap = plt.cm.RdBu_r)
# hatch = ax.contourf(sst_lonc, sst_lat, lambda_sst_p, levels = [0, .05, 2], transform = data_crs, colors = 'none', hatches = ['.....', None])
# # cbar = plt.colorbar(cf, ax = ax, orientation = 'horizontal', pad = .01, ticks = np.linspace(-.6, .6, 6))
# cbar = plt.colorbar(cf, ax = ax, ticks = np.linspace(-.6, .6, 6), shrink = .8)
# gl = ax.gridlines(linestyle=":", draw_labels=False)
# gl.xlocator = mticker.FixedLocator(np.arange(-180,181,30))
# gl.ylocator = mticker.FixedLocator(np.arange(-90,90,30))
#
# cbar.set_label(r'$\Delta \lambda$ / 100yr')
# ax.add_feature(cartopy.feature.LAND, color='.3')
#
# ax = fig.add_subplot(3, 2, 6, projection=ccrs.Orthographic(central_longitude=340))
# ax.text(0, 1, s = 'f', transform=ax.transAxes, fontsize=12, fontweight='bold', va='top', ha='right')
# # ax.coastlines()
# # cf = ax.contourf(lonc, lat, lambda_en4, levels = np.linspace(-.6, .6, 6), extend = 'both', transform = data_crs, cmap = plt.cm.RdBu_r)
# # cbar = plt.colorbar(cf, ax = ax, orientation = 'horizontal', pad = .01)
# cf = ax.contourf(lonc, lat, lambda_en4, levels = np.linspace(-.8, .8, 20), extend = 'both', transform = data_crs, cmap = plt.cm.RdBu_r)
# hatch = ax.contourf(lonc, lat, lambda_en4_p, levels = [0, .05, 2], transform = data_crs, colors = 'none', hatches = ['.....', None])
# # cbar = plt.colorbar(cf, ax = ax, orientation = 'horizontal', pad = .01, ticks = np.linspace(-.8, .8, 6))
# cbar = plt.colorbar(cf, ax = ax, ticks = np.linspace(-.8, .8, 6), shrink = .8)
# ax.gridlines(linestyle=":", draw_labels=False)
# cbar.set_label(r'$\Delta \lambda$ / 100yr')
# ax.add_feature(cartopy.feature.LAND, color='.3')
# plt.subplots_adjust(wspace = .02, hspace = .1)
# fig.savefig('plots/SST_SAL_EWS_global_trends_%s_sm%d_rmw%d_klus.pdf'%(sst_data, sm_w, rmw), bbox_inches = 'tight')
#
#
#
#
# fig = plt.figure(figsize = (10,11))
# ax = fig.add_subplot(3, 2, 1, projection=ccrs.Orthographic(central_longitude=340))
# ax.text(0, 1, s = 'a', transform=ax.transAxes, fontsize=12, fontweight='bold', va='top', ha='right')
# ax.set_title('Sea-surface temperatures', fontweight="bold")
# # ax.coastlines()
# # cf = ax.contourf(sst_lonc, sst_lat, m_am_sst_global_runlambda, levels = np.linspace(-1.1,-.5,13), extend= 'both', transform = data_crs)
# # cbar = plt.colorbar(cf, ax = ax, orientation = 'horizontal', pad = .01)
# cf = ax.contourf(sst_lonc, sst_lat, m_am_sst_global_runlambda, levels = np.linspace(-1.1,-.5,20), extend= 'both', transform = data_crs)
# # cbar = plt.colorbar(cf, ax = ax, orientation = 'horizontal', pad = .01, ticks = np.linspace(-1.1,-.5,7))
# cbar = plt.colorbar(cf, ax = ax, ticks = np.linspace(-1.1,-.5,7), shrink = .8)
# gl = ax.gridlines(linestyle=":", draw_labels=False)
# gl.xlocator = mticker.FixedLocator(np.arange(-180,181,30))
# gl.ylocator = mticker.FixedLocator(np.arange(-90,90,30))
#
# cbar.set_label(r'$\lambda$')
# ax.add_feature(cartopy.feature.LAND, color='k')
#
#
# ax = fig.add_subplot(3, 2, 2, projection=ccrs.Orthographic(central_longitude=340))
# ax.text(0, 1, s = 'b', transform=ax.transAxes, fontsize=12, fontweight='bold', va='top', ha='right')
# ax.set_title('Salinity', fontweight="bold")
# # ax.coastlines()
# # cf = ax.contourf(lonc, lat, m_am_sal_global_runlambda, levels = np.linspace(-.9,-.3,13), extend = 'both', transform = data_crs)
# # cbar = plt.colorbar(cf, ax = ax, orientation = 'horizontal', pad = .01)
# cf = ax.contourf(lonc, lat, m_am_sal_global_runlambda, levels = np.linspace(-.9,-.3,20), extend = 'both', transform = data_crs)
# # cbar = plt.colorbar(cf, ax = ax, orientation = 'horizontal', pad = .01, ticks = np.linspace(-.9,-.3,7))
# cbar = plt.colorbar(cf, ax = ax, ticks = np.linspace(-.9,-.3,7), shrink = .8)
# gl = ax.gridlines(linestyle=":", draw_labels=False)
# gl.xlocator = mticker.FixedLocator(np.arange(-180,181,30))
# gl.ylocator = mticker.FixedLocator(np.arange(-90,90,30))
#
# cbar.set_label(r'$\lambda$')
# ax.add_feature(cartopy.feature.LAND, color='k')
#
#
#
# ax = fig.add_subplot(3, 2, 3, projection=ccrs.Orthographic(central_longitude=340))
# ax.text(0, 1, s = 'c', transform=ax.transAxes, fontsize=12, fontweight='bold', va='top', ha='right')
# # ax.coastlines()
# # cf = ax.contourf(sst_lonc, sst_lat, m_am_sst_global_runlambda, levels = np.linspace(-1.1,-.5,13), extend= 'both', transform = data_crs)
# # cbar = plt.colorbar(cf, ax = ax, orientation = 'horizontal', pad = .01)
# cf = ax.contourf(sst_lonc, sst_lat, m_am_sst_global_runstd, levels = np.linspace(0.,.6,20), extend= 'both', transform = data_crs)
# # cbar = plt.colorbar(cf, ax = ax, orientation = 'horizontal', pad = .01, ticks = np.linspace(0.,.6,7))
# cbar = plt.colorbar(cf, ax = ax, ticks = np.linspace(0.,.6,7), shrink = .8)
# gl = ax.gridlines(linestyle=":", draw_labels=False)
# gl.xlocator = mticker.FixedLocator(np.arange(-180,181,30))
# gl.ylocator = mticker.FixedLocator(np.arange(-90,90,30))
#
# cbar.set_label(r'Var')
# ax.add_feature(cartopy.feature.LAND, color='k')
#
#
# ax = fig.add_subplot(3, 2, 4, projection=ccrs.Orthographic(central_longitude=340))
# ax.text(0, 1, s = 'd', transform=ax.transAxes, fontsize=12, fontweight='bold', va='top', ha='right')
# # ax.coastlines()
# # cf = ax.contourf(lonc, lat, m_am_sal_global_runlambda, levels = np.linspace(-.9,-.3,13), extend = 'both', transform = data_crs)
# # cbar = plt.colorbar(cf, ax = ax, orientation = 'horizontal', pad = .01)
# cf = ax.contourf(lonc, lat, m_am_sal_global_runstd, levels = np.linspace(0.,.012,20), extend = 'both', transform = data_crs)
# # cbar = plt.colorbar(cf, ax = ax, orientation = 'horizontal', pad = .01, ticks = np.linspace(0,.012,7))
# cbar = plt.colorbar(cf, ax = ax, ticks = np.linspace(0,.012,7), shrink = .8)
#
# gl = ax.gridlines(linestyle=":", draw_labels=False)
# gl.xlocator = mticker.FixedLocator(np.arange(-180,181,30))
# gl.ylocator = mticker.FixedLocator(np.arange(-90,90,30))
#
# cbar.set_label(r'Var')
# ax.add_feature(cartopy.feature.LAND, color='k')
#
#
# ax = fig.add_subplot(3, 2, 5, projection=ccrs.Orthographic(central_longitude=340))
# ax.text(0, 1, s = 'e', transform=ax.transAxes, fontsize=12, fontweight='bold', va='top', ha='right')
# # ax.coastlines()
# # cf = ax.contourf(sst_lonc, sst_lat, m_am_sst_global_runlambda, levels = np.linspace(-1.1,-.5,13), extend= 'both', transform = data_crs)
# # cbar = plt.colorbar(cf, ax = ax, orientation = 'horizontal', pad = .01)
# cf = ax.contourf(sst_lonc, sst_lat, m_am_sst_global_runac, levels = np.linspace(-.1,.5,20), extend= 'both', transform = data_crs)
# # cbar = plt.colorbar(cf, ax = ax, orientation = 'horizontal', pad = .01, ticks = np.linspace(-.1,.5,7))
# cbar = plt.colorbar(cf, ax = ax, ticks = np.linspace(-.1,.5,7), shrink = .8)
# gl = ax.gridlines(linestyle=":", draw_labels=False)
# gl.xlocator = mticker.FixedLocator(np.arange(-180,181,30))
# gl.ylocator = mticker.FixedLocator(np.arange(-90,90,30))
#
# cbar.set_label(r'AC1')
# ax.add_feature(cartopy.feature.LAND, color='k')
#
#
# ax = fig.add_subplot(3, 2, 6, projection=ccrs.Orthographic(central_longitude=340))
# ax.text(0, 1, s = 'f', transform=ax.transAxes, fontsize=12, fontweight='bold', va='top', ha='right')
# # ax.coastlines()
# # cf = ax.contourf(lonc, lat, m_am_sal_global_runlambda, levels = np.linspace(-.9,-.3,13), extend = 'both', transform = data_crs)
# # cbar = plt.colorbar(cf, ax = ax, orientation = 'horizontal', pad = .01)
# cf = ax.contourf(lonc, lat, m_am_sal_global_runac, levels = np.linspace(.2,.7,20), extend = 'both', transform = data_crs)
# # cbar = plt.colorbar(cf, ax = ax, orientation = 'horizontal', pad = .01, ticks = np.linspace(.2,.7,6))
# cbar = plt.colorbar(cf, ax = ax, ticks = np.linspace(.2,.7,6), shrink = .8)
# gl = ax.gridlines(linestyle=":", draw_labels=False)
# gl.xlocator = mticker.FixedLocator(np.arange(-180,181,30))
# gl.ylocator = mticker.FixedLocator(np.arange(-90,90,30))
#
# cbar.set_label(r'AC1')
# ax.add_feature(cartopy.feature.LAND, color='k')
#
#
#
# plt.subplots_adjust(wspace = .02, hspace = .1)
# fig.savefig('plots/SST_SAL_all_EWS_global_trends_%s_sm%d_rmw%d.pdf'%(sst_data, sm_w, rmw), bbox_inches = 'tight')
#
#
#
# fig = plt.figure(figsize = (10,11))
# # ax = fig.add_subplot(2, 1, 1, projection=ccrs.Robinson())
# ax = fig.add_subplot(3, 2, 1, projection=ccrs.Orthographic(central_longitude=340))
# ax.text(0, 1, s = 'a', transform=ax.transAxes, fontsize=12, fontweight='bold', va='top', ha='right')
# ax.set_title('Sea-surface temperatures', fontweight="bold")
# # ax.coastlines()
# # cf = ax.contourf(sst_lonc, sst_lat, lambda_sst, levels = np.linspace(-.6, .6, 6), extend = 'both', transform = data_crs, cmap = plt.cm.RdBu_r)
# # cbar = plt.colorbar(cf, ax = ax, orientation = 'horizontal', pad = .01)
# cf = ax.contourf(sst_lonc, sst_lat, lambda_sst, levels = np.linspace(-.6, .6, 20), extend = 'both', transform = data_crs, cmap = plt.cm.RdBu_r)
# hatch = ax.contourf(sst_lonc, sst_lat, lambda_sst_p, levels = [0, .05, 2], transform = data_crs, colors = 'none', hatches = ['.....', None])
# # cbar = plt.colorbar(cf, ax = ax, orientation = 'horizontal', pad = .01, ticks = np.linspace(-.6, .6, 6))
# cbar = plt.colorbar(cf, ax = ax, ticks = np.linspace(-.6, .6, 6), shrink = .8)
#
# gl = ax.gridlines(linestyle=":", draw_labels=False)
# gl.xlocator = mticker.FixedLocator(np.arange(-180,181,30))
# gl.ylocator = mticker.FixedLocator(np.arange(-90,90,30))
#
# cbar.set_label(r'$\Delta \lambda$ / 100yr')
# ax.add_feature(cartopy.feature.LAND, color='k')
#
# ax = fig.add_subplot(3, 2, 2, projection=ccrs.Orthographic(central_longitude=340))
# ax.text(0, 1, s = 'b', transform=ax.transAxes, fontsize=12, fontweight='bold', va='top', ha='right')
# ax.set_title('Salinity', fontweight="bold")
# # ax.coastlines()
# # cf = ax.contourf(lonc, lat, lambda_en4, levels = np.linspace(-.6, .6, 6), extend = 'both', transform = data_crs, cmap = plt.cm.RdBu_r)
# # cbar = plt.colorbar(cf, ax = ax, orientation = 'horizontal', pad = .01)
# cf = ax.contourf(lonc, lat, lambda_en4, levels = np.linspace(-.8, .8, 20), extend = 'both', transform = data_crs, cmap = plt.cm.RdBu_r)
# hatch = ax.contourf(lonc, lat, lambda_en4_p, levels = [0, .05, 2], transform = data_crs, colors = 'none', hatches = ['.....', None])
#
# # cbar = plt.colorbar(cf, ax = ax, orientation = 'horizontal', pad = .01, ticks = np.linspace(-.8, .8, 6))
# cbar = plt.colorbar(cf, ax = ax, ticks = np.linspace(-.8, .8, 6), shrink = .8)
# ax.gridlines(linestyle=":", draw_labels=False)
# cbar.set_label(r'$\Delta \lambda$ / 100yr')
# ax.add_feature(cartopy.feature.LAND, color='k')
#
# ax = fig.add_subplot(3, 2, 3, projection=ccrs.Orthographic(central_longitude=340))
# ax.text(0, 1, s = 'c', transform=ax.transAxes, fontsize=12, fontweight='bold', va='top', ha='right')
# # ax.coastlines()
# # cf = ax.contourf(sst_lonc, sst_lat, lambda_sst, levels = np.linspace(-.6, .6, 6), extend = 'both', transform = data_crs, cmap = plt.cm.RdBu_r)
# # cbar = plt.colorbar(cf, ax = ax, orientation = 'horizontal', pad = .01)
# cf = ax.contourf(sst_lonc, sst_lat, var_sst, levels = np.linspace(-.2, .2, 20), extend = 'both', transform = data_crs, cmap = plt.cm.RdBu_r)
# hatch = ax.contourf(sst_lonc, sst_lat, var_sst_p, levels = [0, .05, 2], transform = data_crs, colors = 'none', hatches = ['.....', None])
#
# # cbar = plt.colorbar(cf, ax = ax, orientation = 'horizontal', pad = .01, ticks = np.linspace(-.2, .2, 6))
# cbar = plt.colorbar(cf, ax = ax, ticks = np.linspace(-.2, .2, 6), shrink = .8)
# gl = ax.gridlines(linestyle=":", draw_labels=False)
# gl.xlocator = mticker.FixedLocator(np.arange(-180,181,30))
# gl.ylocator = mticker.FixedLocator(np.arange(-90,90,30))
#
# cbar.set_label(r'$\Delta$ Var / 100yr')
# ax.add_feature(cartopy.feature.LAND, color='k')
#
# ax = fig.add_subplot(3, 2, 4, projection=ccrs.Orthographic(central_longitude=340))
# ax.text(0, 1, s = 'd', transform=ax.transAxes, fontsize=12, fontweight='bold', va='top', ha='right')
# # ax.coastlines()
# # cf = ax.contourf(lonc, lat, lambda_en4, levels = np.linspace(-.6, .6, 6), extend = 'both', transform = data_crs, cmap = plt.cm.RdBu_r)
# # cbar = plt.colorbar(cf, ax = ax, orientation = 'horizontal', pad = .01)
# cf = ax.contourf(lonc, lat, var_en4, levels = np.linspace(-.01, .01, 20), extend = 'both', transform = data_crs, cmap = plt.cm.RdBu_r)
# hatch = ax.contourf(lonc, lat, var_en4_p, levels = [0, .05, 2], transform = data_crs, colors = 'none', hatches = ['.....', None])
#
# # cbar = plt.colorbar(cf, ax = ax, orientation = 'horizontal', pad = .01, ticks = np.linspace(-.01, .01, 6))
# cbar = plt.colorbar(cf, ax = ax, ticks = np.linspace(-.01, .01, 6), shrink = .8)
# ax.gridlines(linestyle=":", draw_labels=False)
# cbar.set_label(r'$\Delta$ Var / 100yr')
# ax.add_feature(cartopy.feature.LAND, color='k')
#
#
# ax = fig.add_subplot(3, 2, 5, projection=ccrs.Orthographic(central_longitude=340))
# ax.text(0, 1, s = 'e', transform=ax.transAxes, fontsize=12, fontweight='bold', va='top', ha='right')
# # ax.coastlines()
# # cf = ax.contourf(sst_lonc, sst_lat, lambda_sst, levels = np.linspace(-.6, .6, 6), extend = 'both', transform = data_crs, cmap = plt.cm.RdBu_r)
# # cbar = plt.colorbar(cf, ax = ax, orientation = 'horizontal', pad = .01)
# cf = ax.contourf(sst_lonc, sst_lat, ar_sst, levels = np.linspace(-.6, .6, 20), extend = 'both', transform = data_crs, cmap = plt.cm.RdBu_r)
# hatch = ax.contourf(sst_lonc, sst_lat, ar_sst_p, levels = [0, .05, 2], transform = data_crs, colors = 'none', hatches = ['.....', None])
#
# # cbar = plt.colorbar(cf, ax = ax, orientation = 'horizontal', pad = .01, ticks = np.linspace(-.6, .6, 6))
# cbar = plt.colorbar(cf, ax = ax, ticks = np.linspace(-.6, .6, 6), shrink = .8)
# gl = ax.gridlines(linestyle=":", draw_labels=False)
# gl.xlocator = mticker.FixedLocator(np.arange(-180,181,30))
# gl.ylocator = mticker.FixedLocator(np.arange(-90,90,30))
#
# cbar.set_label(r'$\Delta$ AC1 / 100yr')
# ax.add_feature(cartopy.feature.LAND, color='k')
#
# ax = fig.add_subplot(3, 2, 6, projection=ccrs.Orthographic(central_longitude=340))
# ax.text(0, 1, s = 'f', transform=ax.transAxes, fontsize=12, fontweight='bold', va='top', ha='right')
# # ax.coastlines()
# # cf = ax.contourf(lonc, lat, lambda_en4, levels = np.linspace(-.6, .6, 6), extend = 'both', transform = data_crs, cmap = plt.cm.RdBu_r)
# # cbar = plt.colorbar(cf, ax = ax, orientation = 'horizontal', pad = .01)
# cf = ax.contourf(lonc, lat, ar_en4, levels = np.linspace(-.8, .8, 20), extend = 'both', transform = data_crs, cmap = plt.cm.RdBu_r)
# hatch = ax.contourf(lonc, lat, ar_en4_p, levels = [0, .05, 2], transform = data_crs, colors = 'none', hatches = ['.....', None])
#
# # cbar = plt.colorbar(cf, ax = ax, orientation = 'horizontal', pad = .01, ticks = np.linspace(-.8, .8, 6))
# cbar = plt.colorbar(cf, ax = ax, ticks = np.linspace(-.8, .8, 6), shrink = .8)
# ax.gridlines(linestyle=":", draw_labels=False)
# cbar.set_label(r'$\Delta$ AC1 / 100yr')
# ax.add_feature(cartopy.feature.LAND, color='k')
#
# plt.subplots_adjust(wspace = .02, hspace = .1)
# fig.savefig('plots/SST_SAL_trends_EWS_global_trends_%s_sm%d_rmw%d.pdf'%(sst_data, sm_w, rmw), bbox_inches = 'tight')
#
#
# # # print(var_en4)
# # # print(ar_en4)
# # # fig = plt.figure(figsize = (12,6 ))
# # # ax = fig.add_subplot(311)
# # # ax.text(-.1, 1, s = 'a', transform=ax.transAxes, fontsize=12, fontweight='bold', va='top', ha='right')
# # # basemap(m_am_sal_global_runstd, lat, lon, res = 'c', lms = 2., proj = 'moll', shift = 0., contours = np.linspace(0, .02, 11), color = plt.cm.RdBu_r, alpha = .7, colorbar = True, extend = 'both', meridians = np.arange(0,360, 40), parallels = np.arange(-80,80,40), cbar_title = 'Variance')
# # # ax = fig.add_subplot(312)
# # # ax.text(-.1, 1, s = 'b', transform=ax.transAxes, fontsize=12, fontweight='bold', va='top', ha='right')
# # # basemap(m_am_sal_global_runac, lat, lon, res = 'c', lms = 2., proj = 'moll', shift = 0., contours = np.linspace(m_am_sal_global_runac.min(), m_am_sal_global_runac.max(), 11), color = plt.cm.RdBu_r, alpha = .7, colorbar = True, extend = 'both', meridians = np.arange(0,360, 40), parallels = np.arange(-80,80,40), cbar_title = 'AC1')
# # # ax = fig.add_subplot(313)
# # # ax.text(-.1, 1, s = 'c', transform=ax.transAxes, fontsize=12, fontweight='bold', va='top', ha='right')
# # # basemap(m_am_sal_global_runlambda, lat, lon, res = 'c', lms = 2., proj = 'moll', shift = 0., contours = np.linspace(m_am_sal_global_runlambda.min(), m_am_sal_global_runlambda.max(), 11), color = plt.cm.RdBu_r, alpha = .7, colorbar = True, extend = 'both', meridians = np.arange(0,360, 40), parallels = np.arange(-80,80,40), cbar_title = r'$\lambda$')
# # #
# # # fig.savefig('plots/EN4_EWSmean.pdf', bbox_inches = 'tight')
# # #
# # # fig = plt.figure(figsize = (12,6 ))
# # # ax = fig.add_subplot(311)
# # # ax.text(-.1, 1, s = 'a', transform=ax.transAxes, fontsize=12, fontweight='bold', va='top', ha='right')
# # # basemap(var_en4, lat, lon, res = 'c', lms = 2., proj = 'moll', shift = 0., contours = np.linspace(-.0002, .0002, 10), color = plt.cm.RdBu_r, alpha = .7, colorbar = True, extend = 'both', meridians = np.arange(0,360, 40), parallels = np.arange(-80,80,40), cbar_title = 'Variance')
# # # ax = fig.add_subplot(312)
# # # ax.text(-.1, 1, s = 'b', transform=ax.transAxes, fontsize=12, fontweight='bold', va='top', ha='right')
# # # basemap(ar_en4, lat, lon, res = 'c', lms = 2., proj = 'moll', shift = 0., contours = np.linspace(-.01, .01, 10), color = plt.cm.RdBu_r, alpha = .7, colorbar = True, extend = 'both', meridians = np.arange(0,360, 40), parallels = np.arange(-80,80,40), cbar_title = 'AC1')
# # # ax = fig.add_subplot(313)
# # # ax.text(-.1, 1, s = 'c', transform=ax.transAxes, fontsize=12, fontweight='bold', va='top', ha='right')
# # # basemap(lambda_en4, lat, lon, res = 'c', lms = 2., proj = 'moll', shift = 0., contours = np.linspace(-.01, .01, 10), color = plt.cm.RdBu_r, alpha = .7, colorbar = True, extend = 'both', meridians = np.arange(0,360, 40), parallels = np.arange(-80,80,40), cbar_title = r'$\lambda$')
# # #
# # # fig.savefig('plots/EN4_EWS_global.pdf', bbox_inches = 'tight')
# #
# #
# # #
# #
#
sal = np.load('data/EN421_NA_salinity_d%d.npy'%dth)
sal = (sal - sal.mean())# / sal.std()
sal_n = np.load('data/EN421_SSS_N_d%d.npy'%dth)
sal_s = np.load('data/EN421_SSS_S_d%d.npy'%dth)
sal_sg = np.load('data/EN421_SG_d%d.npy'%dth)