-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathprocess_simulation_nsidc.py
More file actions
4075 lines (3491 loc) · 223 KB
/
process_simulation_nsidc.py
File metadata and controls
4075 lines (3491 loc) · 223 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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Jun 21 14:48:41 2022
@author: drounce
"""
# Built-in libraries
import collections
import glob
import os
import pickle
import shutil
import time
import zipfile
# External libraries
import cartopy
import cartopy.crs as ccrs
from cartopy.io.shapereader import Reader
from cartopy.feature import ShapelyFeature
import matplotlib as mpl
import matplotlib.pyplot as plt
import matplotlib.path as mpath
from matplotlib.lines import Line2D
import matplotlib.patches as patches
from matplotlib.ticker import AutoMinorLocator
from matplotlib.ticker import MultipleLocator
import geopandas
import numpy as np
import pandas as pd
from scipy.stats import median_abs_deviation
from scipy.ndimage import generic_filter
from scipy.ndimage import uniform_filter
import xarray as xr
# Local libraries
import pygem.pygem_input as pygem_prms
import pygem.pygem_modelsetup as modelsetup
# ----- Processing options -----
option_process_nsidc_regional = False # Process data to produce NSIDC datasets
option_plot_nsidc_regional = False # Plot figures associated with regional NSIDC dataset
option_process_nsidc_glaciers = False # Process data to produce NSIDC datasets
option_process_nsidc_metadata = False # Add metadata to NSIDC datasets consistent with suggestions
option_process_nsidc_metadata_regional = False # Add metdata to NSIDC regional datasets consistent with suggestions
option_process_nsidc_metadata_runoff_ultee = True # Add metadata to NSIDC runoff datasets for ultee sims
option_update_tw_glaciers_nsidc_data_perglacier = False # Update data with new simulations for frontal ablation
option_update_tw_glaciers_nsidc_data_globalreg = False # Update data with new simulations for frontal ablation
option_update_tw_glaciers_zipped = False
# ----- Parameters -----
#regions = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19]
regions = [17]
normyear = 2015
# GCMs and RCP scenarios
gcm_names_rcps = ['CanESM2', 'CCSM4', 'CNRM-CM5', 'CSIRO-Mk3-6-0', 'GFDL-CM3',
'GFDL-ESM2M', 'GISS-E2-R', 'IPSL-CM5A-LR', 'MPI-ESM-LR', 'NorESM1-M']
gcm_names_ssps = ['BCC-CSM2-MR', 'CESM2', 'CESM2-WACCM', 'EC-Earth3', 'EC-Earth3-Veg', 'FGOALS-f3-L',
'GFDL-ESM4', 'INM-CM4-8', 'INM-CM5-0', 'MPI-ESM1-2-HR', 'MRI-ESM2-0', 'NorESM2-MM']
gcm_names_ssp119 = ['EC-Earth3', 'EC-Earth3-Veg', 'GFDL-ESM4', 'MRI-ESM2-0']
rcps = ['ssp119','ssp126', 'ssp245', 'ssp370', 'ssp585']
#rcps = ['ssp119']
#rcps = ['rcp26', 'rcp45', 'rcp85']
#rcps = ['rcp26', 'rcp45', 'rcp85', 'ssp119','ssp126', 'ssp245', 'ssp370', 'ssp585']
rgi_shp_fn = '/Users/drounce/Documents/Papers/pygem_oggm_global/qgis/rgi60_all_simplified2_robinson.shp'
rgi_regions_fn = '/Users/drounce/Documents/Papers/pygem_oggm_global/qgis/rgi60_regions_robinson-v2.shp'
rgi_reg_dict = {'all':'Global',
'all_no519':'Global, excl. GRL and ANT',
'global':'Global',
1:'Alaska',
2:'W Canada & US',
3:'Arctic Canada North',
4:'Arctic Canada South',
5:'Greenland Periphery',
6:'Iceland',
7:'Svalbard',
8:'Scandinavia',
9:'Russian Arctic',
10:'North Asia',
11:'Central Europe',
12:'Caucasus & Middle East',
13:'Central Asia',
14:'South Asia West',
15:'South Asia East',
16:'Low Latitudes',
17:'Southern Andes',
18:'New Zealand',
19:'Antarctic & Subantarctic'
}
rcp_namedict = {'rcp26':'RCP2.6',
'rcp45':'RCP4.5',
'rcp85':'RCP8.5',
'ssp119':'SSP1-1.9',
'ssp126':'SSP1-2.6',
'ssp245':'SSP2-4.5',
'ssp370':'SSP3-7.0',
'ssp585':'SSP5-8.5'}
# Colors list
rcp_colordict = {'rcp26':'#3D52A4', 'rcp45':'#76B8E5', 'rcp60':'#F47A20', 'rcp85':'#ED2024',
'ssp119':'blue', 'ssp126':'#3D52A4', 'ssp245':'#76B8E5', 'ssp370':'#F47A20', 'ssp585':'#ED2024'}
rcp_styledict = {'rcp26':':', 'rcp45':':', 'rcp85':':',
'ssp119':'-', 'ssp126':'-', 'ssp245':'-', 'ssp370':'-', 'ssp585':'-'}
time_start = time.time()
#%% ===== FUNCTIONS =====
def slr_mmSLEyr(reg_vol, reg_vol_bsl, option='oggm'):
""" Calculate annual SLR accounting for the ice below sea level
Options
-------
oggm : accounts for BSL and the differences in density (new)
farinotti : accounts for BSL but not the differences in density (Farinotti et al. 2019)
None : provides mass loss in units of mm SLE
"""
# Farinotti et al. (2019)
# reg_vol_asl = reg_vol - reg_vol_bsl
# return (-1*(reg_vol_asl[:,1:] - reg_vol_asl[:,0:-1]) *
# pygem_prms.density_ice / pygem_prms.density_water / pygem_prms.area_ocean * 1000)
if option == 'oggm':
# OGGM new approach
return (-1*(((reg_vol[:,1:] - reg_vol[:,0:-1]) * pygem_prms.density_ice / pygem_prms.density_water -
(reg_vol_bsl[:,1:] - reg_vol_bsl[:,0:-1])) / pygem_prms.area_ocean * 1000))
elif option == 'farinotti':
reg_vol_asl = reg_vol - reg_vol_bsl
return (-1*(reg_vol_asl[:,1:] - reg_vol_asl[:,0:-1]) *
pygem_prms.density_ice / pygem_prms.density_water / pygem_prms.area_ocean * 1000)
elif option == 'None':
# No correction
return -1*(reg_vol[:,1:] - reg_vol[:,0:-1]) * pygem_prms.density_ice / pygem_prms.density_water / pygem_prms.area_ocean * 1000
#%% ----- PROCESS REGIONAL DATA FOR NSIDC -----
# Make the data consistent with GlacierMIP2 to support ease-of-use and adoption from community
if option_process_nsidc_regional:
print('Processing regional datasets...')
nsidc_fp = '/Users/drounce/Documents/HiMAT/spc_backup/nsidc/'
regions_calving = [1,3,4,5,7,9,17,19]
years = np.arange(2000,2102)
dates_table = modelsetup.datesmodelrun(startyear=2000, endyear=2100, spinupyears=0, option_wateryear='calendar')
time_values = dates_table.loc[:,'date'].tolist()
# netcdf_fp_normal = '/Users/drounce/Documents/HiMAT/spc_backup/simulations/'
# netcdf_fp_wcalving = '/Users/drounce/Documents/HiMAT/spc_backup/simulations_calving_v5/'
pickle_fp_base_normal = '/Users/drounce/Documents/HiMAT/spc_backup/analysis/pickle/'
pickle_fp_base_wcalving = '/Users/drounce/Documents/HiMAT/spc_backup/analysis_calving_v6/pickle/'
if len(rcps) > 5:
assert True==False, 'Process RCPs and SSPs independently. Change rcps list.'
# ----- REGIONAL DATASETS -----
reg_vol_all = None
for reg in regions:
if reg in regions_calving:
# netcdf_fp_cmip5 = netcdf_fp_wcalving
pickle_fp_base = pickle_fp_base_wcalving
else:
# netcdf_fp_cmip5 = netcdf_fp_normal
pickle_fp_base = pickle_fp_base_normal
reg_vol_rcps = None
reg_vol_rcps_bsl = None
reg_area_rcps = None
reg_melt_rcps = None
reg_acc_rcps = None
reg_refreeze_rcps = None
reg_frontalablation_rcps = None
for rcp in rcps:
if 'rcp' in rcp:
gcm_names = gcm_names_rcps
elif 'ssp' in rcp:
gcm_names = gcm_names_ssps
reg_vol_rcp_gcms = None
reg_vol_rcp_gcms_bsl = None
reg_area_rcp_gcms = None
reg_melt_rcp_gcms = None
reg_acc_rcp_gcms = None
reg_refreeze_rcp_gcms = None
reg_frontalablation_rcp_gcms = None
for gcm_name in gcm_names:
print(' ', reg, rcp, gcm_name)
# Pickle filepath
pickle_fp = pickle_fp_base + str(reg).zfill(2) + '/O1Regions/' + gcm_name + '/' + rcp + '/'
# Pickle filenames
pickle_vol_fn = 'R' + str(reg) + '_' + rcp + '_' + gcm_name + '_vol_annual.pkl'
pickle_vol_fn_bsl = 'R' + str(reg) + '_' + rcp + '_' + gcm_name + '_vol_annual_bwl.pkl'
pickle_area_fn = 'R' + str(reg) + '_' + rcp + '_' + gcm_name + '_area_annual.pkl'
pickle_melt_fn = 'R' + str(reg) + '_' + rcp + '_' + gcm_name + '_melt_monthly.pkl'
pickle_acc_fn = 'R' + str(reg) + '_' + rcp + '_' + gcm_name + '_acc_monthly.pkl'
pickle_refreeze_fn = 'R' + str(reg) + '_' + rcp + '_' + gcm_name + '_refreeze_monthly.pkl'
pickle_frontalablation_fn = 'R' + str(reg) + '_' + rcp + '_' + gcm_name + '_frontalablation_monthly.pkl'
if not os.path.exists(pickle_fp + pickle_vol_fn):
reg_vol_rcpgcm = np.zeros(years.shape)
reg_vol_rcpgcm_bsl = np.zeros(years.shape)
reg_area_rcpgcm = np.zeros(years.shape)
reg_melt_rcpgcm = np.zeros(len(time_values))
reg_acc_rcpgcm = np.zeros(len(time_values))
reg_refreeze_rcpgcm = np.zeros(len(time_values))
reg_frontalablation_rcpgcm = np.zeros(len(time_values))
reg_vol_rcpgcm[:] = np.nan
reg_vol_rcpgcm_bsl[:] = np.nan
reg_area_rcpgcm[:] = np.nan
reg_melt_rcpgcm[:] = np.nan
reg_acc_rcpgcm[:] = np.nan
reg_refreeze_rcpgcm[:] = np.nan
reg_frontalablation_rcpgcm[:] = np.nan
else:
with open(pickle_fp + pickle_vol_fn, 'rb') as f:
reg_vol_rcpgcm = pickle.load(f)
if os.path.exists(pickle_fp + pickle_vol_fn_bsl):
with open(pickle_fp + pickle_vol_fn_bsl, 'rb') as f:
reg_vol_rcpgcm_bsl = pickle.load(f)
else:
reg_vol_rcpgcm_bsl = np.zeros(years.shape)
if reg_vol_rcpgcm_bsl is None:
reg_vol_rcpgcm_bsl = np.zeros(years.shape)
with open(pickle_fp + pickle_area_fn, 'rb') as f:
reg_area_rcpgcm = pickle.load(f)
with open(pickle_fp + pickle_melt_fn, 'rb') as f:
reg_melt_rcpgcm_monthly = pickle.load(f)
with open(pickle_fp + pickle_acc_fn, 'rb') as f:
reg_acc_rcpgcm_monthly = pickle.load(f)
with open(pickle_fp + pickle_refreeze_fn, 'rb') as f:
reg_refreeze_rcpgcm_monthly = pickle.load(f)
with open(pickle_fp + pickle_frontalablation_fn, 'rb') as f:
reg_frontalablation_rcpgcm_monthly = pickle.load(f)
# # Monthly to annual mass balance components
# reg_melt_rcpgcm = np.zeros(len(time_values))
# reg_melt_rcpgcm[:] = np.nan
# reg_melt_rcpgcm[:-1] = reg_melt_rcpgcm_monthly.reshape(int(reg_melt_rcpgcm_monthly.shape[0]/12),12).sum(1)
reg_melt_rcpgcm = reg_melt_rcpgcm_monthly
reg_acc_rcpgcm = reg_acc_rcpgcm_monthly
reg_refreeze_rcpgcm = reg_refreeze_rcpgcm_monthly
reg_frontalablation_rcpgcm = reg_frontalablation_rcpgcm_monthly
# Aggregate GCMs
if reg_vol_rcp_gcms is None:
reg_vol_rcp_gcms = reg_vol_rcpgcm.reshape(1,years.shape[0])
reg_vol_rcp_gcms_bsl = reg_vol_rcpgcm_bsl.reshape(1,years.shape[0])
reg_area_rcp_gcms = reg_area_rcpgcm.reshape(1,years.shape[0])
reg_melt_rcp_gcms = reg_melt_rcpgcm.reshape(1,len(time_values))
reg_acc_rcp_gcms = reg_acc_rcpgcm.reshape(1,len(time_values))
reg_refreeze_rcp_gcms = reg_refreeze_rcpgcm.reshape(1,len(time_values))
reg_frontalablation_rcp_gcms = reg_frontalablation_rcpgcm.reshape(1,len(time_values))
else:
reg_vol_rcp_gcms = np.concatenate((reg_vol_rcp_gcms, reg_vol_rcpgcm.reshape(1,years.shape[0])), axis=0)
reg_vol_rcp_gcms_bsl = np.concatenate((reg_vol_rcp_gcms_bsl, reg_vol_rcpgcm_bsl.reshape(1,years.shape[0])), axis=0)
reg_area_rcp_gcms = np.concatenate((reg_area_rcp_gcms, reg_area_rcpgcm.reshape(1,years.shape[0])), axis=0)
reg_melt_rcp_gcms = np.concatenate((reg_melt_rcp_gcms, reg_melt_rcpgcm.reshape(1,len(time_values))), axis=0)
reg_acc_rcp_gcms = np.concatenate((reg_acc_rcp_gcms, reg_acc_rcpgcm.reshape(1,len(time_values))), axis=0)
reg_refreeze_rcp_gcms = np.concatenate((reg_refreeze_rcp_gcms, reg_refreeze_rcpgcm.reshape(1,len(time_values))), axis=0)
reg_frontalablation_rcp_gcms = np.concatenate((reg_frontalablation_rcp_gcms, reg_frontalablation_rcpgcm.reshape(1,len(time_values))), axis=0)
# Aggregate RCPs
if reg_vol_rcps is None:
reg_vol_rcps = reg_vol_rcp_gcms[np.newaxis,:,:]
reg_vol_rcps_bsl = reg_vol_rcp_gcms_bsl[np.newaxis,:,:]
reg_area_rcps = reg_area_rcp_gcms[np.newaxis,:,:]
reg_melt_rcps = reg_melt_rcp_gcms[np.newaxis,:,:]
reg_acc_rcps = reg_acc_rcp_gcms[np.newaxis,:,:]
reg_refreeze_rcps = reg_refreeze_rcp_gcms[np.newaxis,:,:]
reg_frontalablation_rcps = reg_frontalablation_rcp_gcms[np.newaxis,:,:]
else:
reg_vol_rcps = np.concatenate((reg_vol_rcps, reg_vol_rcp_gcms[np.newaxis,:,:]), axis=0)
reg_vol_rcps_bsl = np.concatenate((reg_vol_rcps_bsl, reg_vol_rcp_gcms_bsl[np.newaxis,:,:]), axis=0)
reg_area_rcps = np.concatenate((reg_area_rcps, reg_area_rcp_gcms[np.newaxis,:,:]), axis=0)
reg_melt_rcps = np.concatenate((reg_melt_rcps, reg_melt_rcp_gcms[np.newaxis,:,:]), axis=0)
reg_acc_rcps = np.concatenate((reg_acc_rcps, reg_acc_rcp_gcms[np.newaxis,:,:]), axis=0)
reg_refreeze_rcps = np.concatenate((reg_refreeze_rcps, reg_refreeze_rcp_gcms[np.newaxis,:,:]), axis=0)
reg_frontalablation_rcps = np.concatenate((reg_frontalablation_rcps, reg_frontalablation_rcp_gcms[np.newaxis,:,:]), axis=0)
# Aggregate regions
if reg_vol_all is None:
reg_vol_all = reg_vol_rcps[np.newaxis,:,:,:]
reg_vol_all_bsl = reg_vol_rcps_bsl[np.newaxis,:,:,:]
reg_area_all = reg_area_rcps[np.newaxis,:,:,:]
reg_melt_all = reg_melt_rcps[np.newaxis,:,:,:]
reg_acc_all = reg_acc_rcps[np.newaxis,:,:,:]
reg_refreeze_all = reg_refreeze_rcps[np.newaxis,:,:,:]
reg_frontalablation_all = reg_frontalablation_rcps[np.newaxis,:,:,:]
else:
reg_vol_all = np.concatenate((reg_vol_all, reg_vol_rcps[np.newaxis,:,:,:]), axis=0)
reg_vol_all_bsl = np.concatenate((reg_vol_all_bsl, reg_vol_rcps_bsl[np.newaxis,:,:,:]), axis=0)
reg_area_all = np.concatenate((reg_area_all, reg_area_rcps[np.newaxis,:,:,:]), axis=0)
reg_melt_all = np.concatenate((reg_melt_all, reg_melt_rcps[np.newaxis,:,:,:]), axis=0)
reg_acc_all = np.concatenate((reg_acc_all, reg_acc_rcps[np.newaxis,:,:,:]), axis=0)
reg_refreeze_all = np.concatenate((reg_refreeze_all, reg_refreeze_rcps[np.newaxis,:,:,:]), axis=0)
reg_frontalablation_all = np.concatenate((reg_frontalablation_all, reg_frontalablation_rcps[np.newaxis,:,:,:]), axis=0)
# Convert volume (m3 ice) to mass (kg)
reg_mass_all = reg_vol_all * pygem_prms.density_ice
reg_mass_all_bsl = reg_vol_all_bsl * pygem_prms.density_ice
# Convert volume (m3 water) to mass (kg)
reg_melt_all = reg_melt_all * pygem_prms.density_water
reg_acc_all = reg_acc_all * pygem_prms.density_water
reg_refreeze_all = reg_refreeze_all * pygem_prms.density_water
reg_frontalablation_all = reg_frontalablation_all * pygem_prms.density_water
print('Check on SLE and conversions:')
print('AK [mm SLE]:', np.round(reg_mass_all[0,0,0,0] / 1e12 * 1/361.8,1))
print('AK [km2]:', np.round(reg_area_all[0,0,0,0] / 1e6,1))
#%% ===== CREATE NETCDF FILE =====
# Data with variable attributes
ds = xr.Dataset(
data_vars=dict(
reg_mass_annual=(["Region", "Scenario", "Climate_Model", "year"], reg_mass_all),
reg_mass_bsl_annual=(["Region", "Scenario", "Climate_Model", "year"], reg_mass_all_bsl),
reg_area_annual=(["Region", "Scenario", "Climate_Model", "year"], reg_area_all),
reg_melt_monthly=(["Region", "Scenario", "Climate_Model", "time"], reg_melt_all),
reg_acc_monthly=(["Region", "Scenario", "Climate_Model", "time"], reg_acc_all),
reg_refreeze_monthly=(["Region", "Scenario", "Climate_Model", "time"], reg_refreeze_all),
reg_frontalablation_monthly=(["Region", "Scenario", "Climate_Model", "time"], reg_frontalablation_all),
),
coords=dict(
Region=regions,
Scenario=np.arange(1,len(rcps)+1),
Climate_Model=np.arange(1,len(gcm_names)+1),
year=years,
time=time_values,
),
attrs={'source': 'PyGEMv0.1.0',
'institution': 'Carnegie Mellon University',
'history': 'Created by David Rounce (drounce@cmu.edu) on ' + pygem_prms.model_run_date,
'references': 'doi:10.3389/feart.2019.00331 and doi:10.1017/jog.2019.91'}
)
# Time attributes
ds.time.attrs['long_name'] = 'time'
ds.time.attrs['year_type'] = 'calendar year'
ds.time.attrs['comment'] = 'start of the month'
# Year attributes
ds.year.attrs['long_name'] = 'years'
ds.year.attrs['year_type'] = 'calendar year'
ds.year.attrs['range'] = '2000 - 2101'
ds.year.attrs['comment'] = 'years referring to the start of each year'
# Region attributes
ds.Region.attrs['long_name'] = 'Randolph Glacier Inventory Order 1 Region Name'
ds.Region.attrs['comment'] = 'RGIv6.0'
ds.Region.attrs['1'] = 'Alaska'
ds.Region.attrs['2'] = 'Western Canada and U.S.'
ds.Region.attrs['3'] = 'Arctic Canada North'
ds.Region.attrs['4'] = 'Arctic Canada South'
ds.Region.attrs['5'] = 'Greenland Periphery'
ds.Region.attrs['6'] = 'Iceland'
ds.Region.attrs['7'] = 'Svalbard'
ds.Region.attrs['8'] = 'Scandinavia'
ds.Region.attrs['9'] = 'Russian Arctic'
ds.Region.attrs['10'] = 'North Asia'
ds.Region.attrs['11'] = 'Central Europe'
ds.Region.attrs['12'] = 'Caucasus and Middle East'
ds.Region.attrs['13'] = 'Central Asia'
ds.Region.attrs['14'] = 'South Asia West'
ds.Region.attrs['15'] = 'South Asia East'
ds.Region.attrs['16'] = 'Low Latitudes'
ds.Region.attrs['17'] = 'Southern Andes'
ds.Region.attrs['18'] = 'New Zealand'
ds.Region.attrs['19'] = 'Antarctic and Subantarctic'
# Scenario and Climate Model attributes
if 'rcp' in rcp:
cmip_no = '5'
climate_model_dict = {
'long_name': 'General Circulation Model Name',
'comment': 'Models from the Coupled Model Intercomparison Project ' + cmip_no,
'1':'CanESM2',
'2':'CCSM4',
'3':'CNRM-CM5',
'4':'CSIRO-Mk3-6-0',
'5':'GFDL-CM3',
'6':'GFDL-ESM2M',
'7':'GISS-E2-R',
'8':'IPSL-CM5A-LR',
'9':'MPI-ESM-LR',
'10':'NorESM1-M'}
scenario_dict = {
'long_name': 'Representative Concentration Pathway',
'1':'RCP2.6',
'2':'RCP4.5',
'3':'RCP8.5'}
scenario_fn = 'rcps'
elif 'ssp' in rcp:
cmip_no = '6'
climate_model_dict = {
'long_name': 'General Circulation Model Name',
'comment': 'Models from the Coupled Model Intercomparison Project ' + cmip_no,
'1':'BCC-CSM2-MR',
'2':'CESM2',
'3':'CESM2-WACCM',
'4':'EC-Earth3',
'5':'EC-Earth3-Veg',
'6':'FGOALS-f3-L',
'7':'GFDL-ESM4',
'8':'INM-CM4-8',
'9':'INM-CM5-0',
'10':'MPI-ESM1-2-HR',
'11':'MRI-ESM2-0',
'12':'NorESM2-MM'}
scenario_dict = {
'long_name': 'Representative Concentration Pathway',
'comment': 'Only a subset of climate models had SSP1-1.9',
'1':'SSP1-1.9',
'2':'SSP1-2.6',
'3':'SSP2-4.5',
'4':'SSP3-7.0',
'5':'SSP5-8.5'}
scenario_fn = 'ssps'
for atr_name in climate_model_dict.keys():
ds.Climate_Model.attrs[atr_name] = climate_model_dict[atr_name]
for atr_name in scenario_dict.keys():
ds.Scenario.attrs[atr_name] = scenario_dict[atr_name]
# Mass attributes
ds.reg_mass_annual.attrs['long_name'] = 'Glacier mass'
ds.reg_mass_annual.attrs['temporal_resolution'] = 'annual'
ds.reg_mass_annual.attrs['units'] = 'kg'
ds.reg_mass_annual.attrs['comment'] = 'mass of ice based on area and ice thickness at start of the year and density of ice of 900 kg/m3'
# Mass below sea level attributes
ds.reg_mass_bsl_annual.attrs['long_name'] = 'Glacier mass below sea level'
ds.reg_mass_bsl_annual.attrs['temporal_resolution'] = 'annual'
ds.reg_mass_bsl_annual.attrs['units'] = 'kg'
ds.reg_mass_bsl_annual.attrs['comment'] = 'mass of ice below sea level based on area and ice thickness at start of the year, density of ice of 900 kg/m3, and sea level of 0 m a.s.l.'
# Area attributes
ds.reg_area_annual.attrs['long_name'] = 'Glacier area'
ds.reg_area_annual.attrs['temporal_resolution'] = 'annual'
ds.reg_area_annual.attrs['units'] = 'm2'
ds.reg_area_annual.attrs['comment'] = 'area at start of the year'
# Melt attributes
ds.reg_melt_monthly.attrs['long_name'] = 'Glacier melt'
ds.reg_melt_monthly.attrs['units'] = 'kg'
ds.reg_melt_monthly.attrs['temporal_resolution'] = 'monthly'
# Accumulation attributes
ds.reg_acc_monthly.attrs['long_name'] = 'Glacier accumulation'
ds.reg_acc_monthly.attrs['units'] = 'kg'
ds.reg_acc_monthly.attrs['temporal_resolution'] = 'monthly'
ds.reg_acc_monthly.attrs['comment'] = 'only the solid precipitation'
# Refreeze attributes
ds.reg_refreeze_monthly.attrs['long_name'] = 'Glacier refreeze'
ds.reg_refreeze_monthly.attrs['units'] = 'kg'
ds.reg_refreeze_monthly.attrs['temporal_resolution'] = 'monthly'
# Frontal ablation attributes
ds.reg_frontalablation_monthly.attrs['long_name'] = 'Glacier frontal ablation'
ds.reg_frontalablation_monthly.attrs['units'] = 'kg'
ds.reg_frontalablation_monthly.attrs['temporal_resolution'] = 'monthly'
ds.reg_frontalablation_monthly.attrs['comment'] = (
'mass losses from calving, subaerial frontal melting, sublimation above the ' +
'waterline and subaqueous frontal melting below the waterline; positive values indicate mass lost like melt;' +
' frontal ablation calculated on annual time scale but shown as monthly to be consistent with mass balance comopnents')
if not os.path.exists(nsidc_fp):
os.makedirs(nsidc_fp, exist_ok=True)
ds_fn = 'Global_reg_allvns_c2_ba1_50sets_2000_2100-' + scenario_fn + '.nc'
ds.to_netcdf(nsidc_fp + ds_fn)
# Close datasets
# ds.close()
#%% ---- PLOT REGIONAL DATASETS -----
if option_plot_nsidc_regional:
print('Plot regional datasets...')
nsidc_fp = '/Users/drounce/Documents/HiMAT/spc_backup/nsidc/'
# Add global region
regions.append('all')
regions_overview = regions[-1:] + regions[0:-1]
# Remove ssp119 for stats
rcps_all = rcps.copy()
if 'ssp119' in rcps:
rcps.remove('ssp119')
years = np.arange(2000,2102)
startyear = 2015
endyear = 2100
dates_table = modelsetup.datesmodelrun(startyear=2000, endyear=2100, spinupyears=0, option_wateryear='calendar')
time_values = dates_table.loc[:,'date'].tolist()
# Load data
if len(rcps) > 5:
assert True==False, 'Process RCPs and SSPs independently. Change rcps list.'
if 'ssp245' in rcps:
scenario_fn = 'ssps'
rcps_plot_mad = ['ssp126', 'ssp585']
elif 'rcp45' in rcps:
scenario_fn = 'rcps'
rcps_plot_mad = ['rcp26', 'rcp85']
ds_fn = 'Global_reg_allvns_c2_ba1_50sets_2000_2100-' + scenario_fn + '.nc'
ds = xr.open_dataset(nsidc_fp + ds_fn)
#%% ----- MULTI-GCM STATISTICS -----
normyear_idx = np.where(years == normyear)[0][0]
stats_overview_cns = ['Region', 'Scenario', 'n_gcms',
'Marzeion_slr_mmsle_mean', 'Edwards_slr_mmsle_mean',
'slr_mmSLE_med', 'slr_mmSLE_95', 'slr_mmSLE_mean', 'slr_mmSLE_std', 'slr_mmSLE_mad',
'mb_mmSLE_med', 'mb_mmSLE_95', 'mb_mmSLE_mean', 'mb_mmSLE_std', 'mb_mmSLE_mad',
'slr_correction_mmSLE',
'slr_2090-2100_mmSLEyr_med', 'slr_2090-2100_mmSLEyr_mean', 'slr_2090-2100_mmSLEyr_std', 'slr_2090-2100_mmSLEyr_mad',
'slr_max_mmSLEyr_med', 'slr_max_mmSLEyr_mean', 'slr_max_mmSLEyr_std', 'slr_max_mmSLEyr_mad',
'yr_max_slr_med', 'yr_max_slr_mean', 'yr_max_slr_std', 'yr_max_slr_mad',
'vol_lost_%_med', 'vol_lost_%_95', 'vol_lost_%_mean', 'vol_lost_%_std', 'vol_lost_%_mad',
'Marzeion_vol_lost_%_mean',
'area_lost_%_med', 'area_lost_%_mean', 'area_lost_%_std', 'area_lost_%_mad',
'mb_2090-2100_mmwea_med', 'mb_2090-2100_mmwea_mean', 'mb_2090-2100_mmwea_std', 'mb_2090-2100_mmwea_mad',
'mb_max_mmwea_med', 'mb_max_mmwea_mean', 'mb_max_mmwea_std', 'mb_max_mmwea_mad']
stats_overview_df = pd.DataFrame(np.zeros((len(regions)*len(rcps),len(stats_overview_cns))), columns=stats_overview_cns)
if 'ssp126' in rcps:
stats_overview_df.loc[0,'Edwards_slr_mmsle_mean'] = 80
stats_overview_df.loc[1,'Edwards_slr_mmsle_mean'] = 115
stats_overview_df.loc[3,'Edwards_slr_mmsle_mean'] = 170
if 'rcp26' in rcps:
stats_overview_df.loc[0,'Marzeion_slr_mmsle_mean'] = 79
stats_overview_df.loc[1,'Marzeion_slr_mmsle_mean'] = 119
stats_overview_df.loc[2,'Marzeion_slr_mmsle_mean'] = 159
stats_overview_df.loc[0,'Marzeion_vol_lost_%_mean'] = 18
stats_overview_df.loc[1,'Marzeion_vol_lost_%_mean'] = 27
stats_overview_df.loc[2,'Marzeion_vol_lost_%_mean'] = 36
ncount = 0
for nreg, reg in enumerate(regions_overview):
for rcp in rcps:
nrcp = rcps_all.index(rcp)
if reg in ['all']:
reg_vol = np.sum(ds.reg_mass_annual[:,nrcp,:,:].values, axis=0) / pygem_prms.density_ice
reg_vol_bsl = np.sum(ds.reg_mass_bsl_annual[:,nrcp,:,:].values, axis=0) / pygem_prms.density_ice
reg_area = np.sum(ds.reg_area_annual[:,nrcp,:,:].values, axis=0)
else:
reg_vol = ds.reg_mass_annual[reg-1,nrcp,:,:].values / pygem_prms.density_ice
reg_vol_bsl = ds.reg_mass_bsl_annual[reg-1,nrcp,:,:].values / pygem_prms.density_ice
reg_area = ds.reg_area_annual[reg-1,nrcp,:,:].values
# Cumulative Sea-level change [mm SLE]
# - accounts for water from glaciers below sea-level following Farinotti et al. (2019)
# for more detailed methods, see Fabien's blog post: https://nbviewer.jupyter.org/gist/jmalles/ca70090812e6499b34a22a3a7a7a8f2a
reg_slr = slr_mmSLEyr(reg_vol, reg_vol_bsl, option='oggm')
reg_slr_cum_raw = np.cumsum(reg_slr, axis=1)
reg_slr_cum = reg_slr_cum_raw - reg_slr_cum_raw[:,normyear_idx][:,np.newaxis]
reg_slr_cum_med = np.median(reg_slr_cum, axis=0)
reg_slr_cum_mean = np.mean(reg_slr_cum, axis=0)
reg_slr_cum_std = np.std(reg_slr_cum, axis=0)
reg_slr_cum_mad = median_abs_deviation(reg_slr_cum, axis=0)
# Mass change in SLE
reg_slr_nocorrection = slr_mmSLEyr(reg_vol, reg_vol_bsl, option='None')
reg_slr_nocorrection_cum_raw = np.cumsum(reg_slr_nocorrection, axis=1)
reg_slr_nocorrection_cum = reg_slr_nocorrection_cum_raw - reg_slr_nocorrection_cum_raw[:,normyear_idx][:,np.newaxis]
reg_slr_nocorrection_cum_med = np.median(reg_slr_nocorrection_cum, axis=0)
reg_slr_nocorrection_cum_mean = np.mean(reg_slr_nocorrection_cum, axis=0)
reg_slr_nocorrection_cum_std = np.std(reg_slr_nocorrection_cum, axis=0)
reg_slr_nocorrection_cum_mad = median_abs_deviation(reg_slr_nocorrection_cum, axis=0)
# Sea-level change rate [mm SLE yr-1]
reg_slr_20902100_med = np.median(reg_slr[:,-10:], axis=(0,1))
reg_slr_20902100_mean = np.mean(reg_slr[:,-10:], axis=(0,1))
reg_slr_20902100_std = np.std(reg_slr[:,-10:], axis=(0,1))
reg_slr_20902100_mad = median_abs_deviation(reg_slr[:,-10:], axis=(0,1))
# Sea-level change max rate
reg_slr_med_raw = np.median(reg_slr, axis=0)
reg_slr_mean_raw = np.mean(reg_slr, axis=0)
reg_slr_std_raw = np.std(reg_slr, axis=0)
reg_slr_mad_raw = median_abs_deviation(reg_slr, axis=0)
reg_slr_med = uniform_filter(reg_slr_med_raw, size=(11))
slr_max_idx = np.where(reg_slr_med == reg_slr_med.max())[0]
reg_slr_mean = uniform_filter(reg_slr_mean_raw, size=(11))
reg_slr_std = uniform_filter(reg_slr_std_raw, size=(11))
reg_slr_mad = uniform_filter(reg_slr_mad_raw, size=(11))
# Year of maximum sea-level change rate
# - use a median filter to sort through the peaks which otherwise don't get smoothed with mean
reg_slr_uniformfilter = np.zeros(reg_slr.shape)
for nrow in np.arange(reg_slr.shape[0]):
reg_slr_uniformfilter[nrow,:] = generic_filter(reg_slr[nrow,:], np.median, size=(11))
reg_yr_slr_max = years[np.argmax(reg_slr_uniformfilter, axis=1)]
reg_yr_slr_max[reg_yr_slr_max < normyear] = normyear
reg_yr_slr_max_med = np.median(reg_yr_slr_max)
reg_yr_slr_max_mean = np.mean(reg_yr_slr_max)
reg_yr_slr_max_std = np.std(reg_yr_slr_max)
reg_yr_slr_max_mad = median_abs_deviation(reg_yr_slr_max)
# Volume lost [%]
reg_vol_med = np.median(reg_vol, axis=0)
reg_vol_std = np.std(reg_vol, axis=0)
reg_vol_mean = np.mean(reg_vol, axis=0)
reg_vol_mad = median_abs_deviation(reg_vol, axis=0)
reg_vol_lost_med_norm = (1 - reg_vol_med / reg_vol_med[normyear_idx]) * 100
reg_vol_lost_mean_norm = (1 - reg_vol_mean / reg_vol_mean[normyear_idx]) * 100
reg_vol_lost_std_norm = reg_vol_std / reg_vol_med[normyear_idx] * 100
reg_vol_lost_mad_norm = reg_vol_mad / reg_vol_med[normyear_idx] * 100
# Area lost [%]
reg_area_med = np.median(reg_area, axis=0)
reg_area_std = np.std(reg_area, axis=0)
reg_area_mean = np.mean(reg_area, axis=0)
reg_area_mad = median_abs_deviation(reg_area, axis=0)
reg_area_lost_med_norm = (1 - reg_area_med / reg_area_med[normyear_idx]) * 100
reg_area_lost_mean_norm = (1 - reg_area_mean / reg_area_mean[normyear_idx]) * 100
reg_area_lost_std_norm = reg_area_std / reg_area_med[normyear_idx] * 100
reg_area_lost_mad_norm = reg_area_mad / reg_area_med[normyear_idx] * 100
# Specific mass balance [kg m-2 yr-1 or mm w.e. yr-1]
reg_mass = reg_vol * pygem_prms.density_ice
reg_mb = (reg_mass[:,1:] - reg_mass[:,0:-1]) / reg_area[:,0:-1]
reg_mb_20902100_med = np.median(reg_mb[:,-10:], axis=(0,1))
reg_mb_20902100_mean = np.mean(reg_mb[:,-10:], axis=(0,1))
reg_mb_20902100_std = np.std(reg_mb[:,-10:], axis=(0,1))
reg_mb_20902100_mad = median_abs_deviation(reg_mb[:,-10:], axis=(0,1))
# Mass balance max rate
reg_mb_med_raw = np.median(reg_mb, axis=0)
reg_mb_mean_raw = np.mean(reg_mb, axis=0)
reg_mb_std_raw = np.std(reg_mb, axis=0)
reg_mb_mad_raw = median_abs_deviation(reg_mb, axis=0)
reg_mb_med = uniform_filter(reg_mb_med_raw, size=(11))
mb_max_idx = np.where(reg_mb_med == reg_mb_med.min())[0]
reg_mb_mean = uniform_filter(reg_mb_mean_raw, size=(11))
reg_mb_std = uniform_filter(reg_mb_std_raw, size=(11))
reg_mb_mad = uniform_filter(reg_mb_mad_raw, size=(11))
# RECORD STATISTICS
stats_overview_df.loc[ncount,'Region'] = reg
stats_overview_df.loc[ncount,'Scenario'] = rcp
stats_overview_df.loc[ncount,'n_gcms'] = reg_vol.shape[0]
stats_overview_df.loc[ncount,'slr_mmSLE_med'] = reg_slr_cum_med[-1]
stats_overview_df.loc[ncount,'slr_mmSLE_mean'] = reg_slr_cum_mean[-1]
stats_overview_df.loc[ncount,'slr_mmSLE_std'] = reg_slr_cum_std[-1]
stats_overview_df.loc[ncount,'slr_mmSLE_mad'] = reg_slr_cum_mad[-1]
stats_overview_df.loc[ncount,'slr_max_mmSLEyr_med'] = np.max(reg_slr_med)
stats_overview_df.loc[ncount,'slr_max_mmSLEyr_mean'] = np.max(reg_slr_mean)
stats_overview_df.loc[ncount,'slr_max_mmSLEyr_std'] = reg_slr_std[slr_max_idx]
stats_overview_df.loc[ncount,'slr_max_mmSLEyr_mad'] = reg_slr_mad[slr_max_idx]
stats_overview_df.loc[ncount,'slr_2090-2100_mmSLEyr_med'] = reg_slr_20902100_med
stats_overview_df.loc[ncount,'slr_2090-2100_mmSLEyr_mean'] = reg_slr_20902100_mean
stats_overview_df.loc[ncount,'slr_2090-2100_mmSLEyr_std'] = reg_slr_20902100_std
stats_overview_df.loc[ncount,'slr_2090-2100_mmSLEyr_mad'] = reg_slr_20902100_mad
stats_overview_df.loc[ncount,'mb_mmSLE_med'] = reg_slr_nocorrection_cum_med[-1]
stats_overview_df.loc[ncount,'mb_mmSLE_mean'] = reg_slr_nocorrection_cum_mean[-1]
stats_overview_df.loc[ncount,'mb_mmSLE_std'] = reg_slr_nocorrection_cum_std[-1]
stats_overview_df.loc[ncount,'mb_mmSLE_mad'] = reg_slr_nocorrection_cum_mad[-1]
stats_overview_df.loc[ncount,'yr_max_slr_med'] = reg_yr_slr_max_med
stats_overview_df.loc[ncount,'yr_max_slr_mean'] = reg_yr_slr_max_mean
stats_overview_df.loc[ncount,'yr_max_slr_std'] = reg_yr_slr_max_std
stats_overview_df.loc[ncount,'yr_max_slr_mad'] = reg_yr_slr_max_mad
stats_overview_df.loc[ncount,'vol_lost_%_med'] = reg_vol_lost_med_norm[-1]
stats_overview_df.loc[ncount,'vol_lost_%_mean'] = reg_vol_lost_mean_norm[-1]
stats_overview_df.loc[ncount,'vol_lost_%_std'] = reg_vol_lost_std_norm[-1]
stats_overview_df.loc[ncount,'vol_lost_%_mad'] = reg_vol_lost_mad_norm[-1]
stats_overview_df.loc[ncount,'area_lost_%_med'] = reg_area_lost_med_norm[-1]
stats_overview_df.loc[ncount,'area_lost_%_mean'] = reg_area_lost_mean_norm[-1]
stats_overview_df.loc[ncount,'area_lost_%_std'] = reg_area_lost_std_norm[-1]
stats_overview_df.loc[ncount,'area_lost_%_mad'] = reg_area_lost_mad_norm[-1]
stats_overview_df.loc[ncount,'mb_2090-2100_mmwea_med'] = reg_mb_20902100_med
stats_overview_df.loc[ncount,'mb_2090-2100_mmwea_mean'] = reg_mb_20902100_mean
stats_overview_df.loc[ncount,'mb_2090-2100_mmwea_std'] = reg_mb_20902100_std
stats_overview_df.loc[ncount,'mb_2090-2100_mmwea_mad'] = reg_mb_20902100_mad
stats_overview_df.loc[ncount,'mb_max_mmwea_med'] = np.min(reg_mb_med)
stats_overview_df.loc[ncount,'mb_max_mmwea_mean'] = np.min(reg_mb_mean)
stats_overview_df.loc[ncount,'mb_max_mmwea_std'] = reg_mb_std[mb_max_idx]
stats_overview_df.loc[ncount,'mb_max_mmwea_mad'] = reg_mb_mad[mb_max_idx]
ncount += 1
stats_overview_df['slr_correction_mmSLE'] = stats_overview_df['mb_mmSLE_med'] - stats_overview_df['slr_mmSLE_med']
stats_overview_df['slr_mmSLE_95'] = 1.96*stats_overview_df['slr_mmSLE_std']
stats_overview_df['mb_mmSLE_95'] = 1.96*stats_overview_df['mb_mmSLE_std']
stats_overview_df['vol_lost_%_95'] = 1.96*stats_overview_df['vol_lost_%_std']
stats_overview_df['slr_Marzeion_dif%'] = 100* stats_overview_df['slr_mmSLE_med'] / stats_overview_df['Marzeion_slr_mmsle_mean']
stats_overview_df['slr_Edwards_dif%'] = 100 * stats_overview_df['slr_mmSLE_med'] / stats_overview_df['Edwards_slr_mmsle_mean']
nsidc_csv_fp = nsidc_fp + 'csv/'
if not os.path.exists(nsidc_csv_fp):
os.makedirs(nsidc_csv_fp, exist_ok=True)
stats_overview_df.to_csv(nsidc_csv_fp + 'stats_overview' + '-' + scenario_fn + '.csv', index=False)
#%%
# ----- FIGURE: ALL MULTI-GCM NORMALIZED VOLUME CHANGE -----
fig = plt.figure()
gs = fig.add_gridspec(nrows=6,ncols=4,wspace=0.3,hspace=0.4)
ax1 = fig.add_subplot(gs[0:2,0:2])
ax2 = fig.add_subplot(gs[0,3])
ax3 = fig.add_subplot(gs[1,2])
ax4 = fig.add_subplot(gs[1,3])
ax5 = fig.add_subplot(gs[2,0])
ax6 = fig.add_subplot(gs[2,1])
ax7 = fig.add_subplot(gs[2,2])
ax8 = fig.add_subplot(gs[2,3])
ax9 = fig.add_subplot(gs[3,0])
ax10 = fig.add_subplot(gs[3,1])
ax11 = fig.add_subplot(gs[3,2])
ax12 = fig.add_subplot(gs[3,3])
ax13 = fig.add_subplot(gs[4,0])
ax14 = fig.add_subplot(gs[4,1])
ax15 = fig.add_subplot(gs[4,2])
ax16 = fig.add_subplot(gs[4,3])
ax17 = fig.add_subplot(gs[5,0])
ax18 = fig.add_subplot(gs[5,1])
ax19 = fig.add_subplot(gs[5,2])
ax20 = fig.add_subplot(gs[5,3])
regions_ordered = ['all',19,3,1,5,9,4,7,17,13,6,14,2,15,8,10,11,16,12,18]
for nax, ax in enumerate([ax1,ax2,ax3,ax4,ax5,ax6,ax7,ax8,ax9,ax10,ax11,ax12,ax13,ax14,ax15,ax16,ax17,ax18,ax19,ax20]):
reg = regions_ordered[nax]
for rcp in rcps:
nrcp = rcps_all.index(rcp)
# Median and absolute median deviation
if reg in ['all']:
reg_vol = np.sum(ds.reg_mass_annual[:,nrcp,:,:].values, axis=0) / pygem_prms.density_ice
else:
reg_vol = ds.reg_mass_annual[reg-1,nrcp,:,:].values / pygem_prms.density_ice
reg_vol_med = np.median(reg_vol, axis=0)
reg_vol_mad = median_abs_deviation(reg_vol, axis=0)
reg_vol_med_norm = reg_vol_med / reg_vol_med[normyear_idx]
reg_vol_mad_norm = reg_vol_mad / reg_vol_med[normyear_idx]
ax.plot(years, reg_vol_med_norm, color=rcp_colordict[rcp], linestyle=rcp_styledict[rcp],
linewidth=1, zorder=4, label=rcp)
if rcp in rcps_plot_mad:
ax.fill_between(years,
reg_vol_med_norm + 1.96*reg_vol_mad_norm,
reg_vol_med_norm - 1.96*reg_vol_mad_norm,
alpha=0.2, facecolor=rcp_colordict[rcp], label=None)
if ax in [ax1,ax5,ax9,ax13,ax17]:
ax.set_ylabel('Mass (rel. to 2015)')
ax.set_xlim(startyear, endyear)
ax.xaxis.set_major_locator(MultipleLocator(50))
ax.xaxis.set_minor_locator(MultipleLocator(10))
ax.set_ylim(0,1.1)
ax.yaxis.set_major_locator(MultipleLocator(0.2))
ax.yaxis.set_minor_locator(MultipleLocator(0.1))
if nax == 0:
label_height=1.06
else:
label_height=1.14
ax.text(1, label_height, rgi_reg_dict[reg], size=10, horizontalalignment='right',
verticalalignment='top', transform=ax.transAxes)
ax.tick_params(axis='both', which='major', direction='inout', right=True)
ax.tick_params(axis='both', which='minor', direction='in', right=True)
if nax == 1:
if 'rcp26' in rcps and 'ssp126' in rcps and len(rcps)==7:
labels = ['SSP1-2.6', 'SSP2-4.5', 'SSP3-7.0', 'SSP5-8.5', 'RCP2.6', 'RCP4.5', 'RCP8.5']
ncols=2
elif 'rcp26' in rcps and 'ssp126' in rcps and len(rcps)==8:
labels = ['SSP1-1.9', 'SSP1-2.6', 'SSP2-4.5', 'SSP3-7.0', 'SSP5-8.5', 'RCP2.6', 'RCP4.5', 'RCP8.5']
ncols=2
elif 'rcp26' in rcps and len(rcps) == 3:
labels = ['RCP2.6', 'RCP4.5', 'RCP8.5']
ncols=1
elif 'ssp126' in rcps and len(rcps) == 4:
labels = ['SSP1-2.6', 'SSP2-4.5', 'SSP3-7.0', 'SSP5-8.5']
ncols=1
elif 'ssp126' in rcps and len(rcps) == 5:
labels = ['SSP1-1.9', 'SSP1-2.6', 'SSP2-4.5', 'SSP3-7.0', 'SSP5-8.5']
ncols = 1
ax.legend(loc=(-1.4,0.2), labels=labels, fontsize=10, ncol=ncols, columnspacing=0.5, labelspacing=0.25,
handlelength=1, handletextpad=0.25, borderpad=0, frameon=False
)
# Save figure
if 'rcp26' in rcps and 'ssp126' in rcps:
scenario_str = 'rcps_ssps'
elif 'rcp26' in rcps:
scenario_str = 'rcps'
elif 'ssp126' in rcps:
scenario_str = 'ssps'
fig_fn = ('allregions_volchange_norm_' + str(startyear) + '-' + str(endyear) + '_multigcm' +
'-' + scenario_str + '.png')
fig.set_size_inches(8.5,11)
nsidc_fig_fp = nsidc_fp + 'figures/'
if not os.path.exists(nsidc_fig_fp):
os.makedirs(nsidc_fig_fp, exist_ok=True)
fig.savefig(nsidc_fig_fp + fig_fn, bbox_inches='tight', dpi=300)
#%% ----- FIGURE: ALL MULTI-GCM NORMALIZED AREA CHANGE -----
fig = plt.figure()
gs = fig.add_gridspec(nrows=6,ncols=4,wspace=0.3,hspace=0.4)
ax1 = fig.add_subplot(gs[0:2,0:2])
ax2 = fig.add_subplot(gs[0,3])
ax3 = fig.add_subplot(gs[1,2])
ax4 = fig.add_subplot(gs[1,3])
ax5 = fig.add_subplot(gs[2,0])
ax6 = fig.add_subplot(gs[2,1])
ax7 = fig.add_subplot(gs[2,2])
ax8 = fig.add_subplot(gs[2,3])
ax9 = fig.add_subplot(gs[3,0])
ax10 = fig.add_subplot(gs[3,1])
ax11 = fig.add_subplot(gs[3,2])
ax12 = fig.add_subplot(gs[3,3])
ax13 = fig.add_subplot(gs[4,0])
ax14 = fig.add_subplot(gs[4,1])
ax15 = fig.add_subplot(gs[4,2])
ax16 = fig.add_subplot(gs[4,3])
ax17 = fig.add_subplot(gs[5,0])
ax18 = fig.add_subplot(gs[5,1])
ax19 = fig.add_subplot(gs[5,2])
ax20 = fig.add_subplot(gs[5,3])
regions_ordered = ['all',19,3,1,5,9,4,7,17,13,6,14,2,15,8,10,11,16,12,18]
for nax, ax in enumerate([ax1,ax2,ax3,ax4,ax5,ax6,ax7,ax8,ax9,ax10,ax11,ax12,ax13,ax14,ax15,ax16,ax17,ax18,ax19,ax20]):
reg = regions_ordered[nax]
for rcp in rcps:
nrcp = rcps_all.index(rcp)
# Median and absolute median deviation
if reg in ['all']:
reg_area = np.sum(ds.reg_area_annual[:,nrcp,:,:].values, axis=0)
else:
reg_area = ds.reg_area_annual[reg-1,nrcp,:,:].values
# Median and absolute median deviation
reg_area_med = np.median(reg_area, axis=0)
reg_area_mad = median_abs_deviation(reg_area, axis=0)
reg_area_med_norm = reg_area_med / reg_area_med[normyear_idx]
reg_area_mad_norm = reg_area_mad / reg_area_med[normyear_idx]
ax.plot(years, reg_area_med_norm, color=rcp_colordict[rcp], linestyle=rcp_styledict[rcp],
linewidth=1, zorder=4, label=rcp)
if rcp in rcps_plot_mad:
ax.fill_between(years,
reg_area_med_norm + 1.96*reg_area_mad_norm,
reg_area_med_norm - 1.96*reg_area_mad_norm,
alpha=0.2, facecolor=rcp_colordict[rcp], label=None)
if ax in [ax1,ax5,ax9,ax13,ax17]:
ax.set_ylabel('Area (rel. to 2015)')
ax.set_xlim(startyear, endyear)
ax.xaxis.set_major_locator(MultipleLocator(50))
ax.xaxis.set_minor_locator(MultipleLocator(10))
ax.set_ylim(0,1.1)
ax.yaxis.set_major_locator(MultipleLocator(0.2))
ax.yaxis.set_minor_locator(MultipleLocator(0.1))
if nax == 0:
label_height=1.06
else:
label_height=1.14
ax.text(1, label_height, rgi_reg_dict[reg], size=10, horizontalalignment='right',
verticalalignment='top', transform=ax.transAxes)
ax.tick_params(axis='both', which='major', direction='inout', right=True)
ax.tick_params(axis='both', which='minor', direction='in', right=True)
if nax == 1:
if 'rcp26' in rcps and 'ssp126' in rcps and len(rcps)==7:
labels = ['SSP1-2.6', 'SSP2-4.5', 'SSP3-7.0', 'SSP5-8.5', 'RCP2.6', 'RCP4.5', 'RCP8.5']
ncols=2
elif 'rcp26' in rcps and 'ssp126' in rcps and len(rcps)==8:
labels = ['SSP1-1.9', 'SSP1-2.6', 'SSP2-4.5', 'SSP3-7.0', 'SSP5-8.5', 'RCP2.6', 'RCP4.5', 'RCP8.5']
ncols=2
elif 'rcp26' in rcps and len(rcps) == 3:
labels = ['RCP2.6', 'RCP4.5', 'RCP8.5']
ncols=1
elif 'ssp126' in rcps and len(rcps) == 4:
labels = ['SSP1-2.6', 'SSP2-4.5', 'SSP3-7.0', 'SSP5-8.5']
ncols=1
elif 'ssp126' in rcps and len(rcps) == 5:
labels = ['SSP1-1.9', 'SSP1-2.6', 'SSP2-4.5', 'SSP3-7.0', 'SSP5-8.5']
ncols = 1
ax.legend(loc=(-1.4,0.2), labels=labels, fontsize=10, ncol=ncols, columnspacing=0.5, labelspacing=0.25,
handlelength=1, handletextpad=0.25, borderpad=0, frameon=False
)
# Save figure
if 'rcp26' in rcps and 'ssp126' in rcps:
scenario_str = 'rcps_ssps'
elif 'rcp26' in rcps:
scenario_str = 'rcps'
elif 'ssp126' in rcps:
scenario_str = 'ssps'
fig_fn = ('allregions_areachange_norm_' + str(startyear) + '-' + str(endyear) + '_multigcm' +
'-' + scenario_str + '.png')
fig.set_size_inches(8.5,11)
fig.savefig(nsidc_fig_fp + fig_fn, bbox_inches='tight', dpi=300)
#%% ----- FIGURE: ALL SPECIFIC MASS LOSS RATES - w running mean! -----
fig = plt.figure()
gs = fig.add_gridspec(nrows=6,ncols=4,wspace=0.3,hspace=0.4)
ax1 = fig.add_subplot(gs[0:2,0:2])
ax2 = fig.add_subplot(gs[0,3])
ax3 = fig.add_subplot(gs[1,2])
ax4 = fig.add_subplot(gs[1,3])
ax5 = fig.add_subplot(gs[2,0])
ax6 = fig.add_subplot(gs[2,1])
ax7 = fig.add_subplot(gs[2,2])
ax8 = fig.add_subplot(gs[2,3])
ax9 = fig.add_subplot(gs[3,0])
ax10 = fig.add_subplot(gs[3,1])
ax11 = fig.add_subplot(gs[3,2])
ax12 = fig.add_subplot(gs[3,3])
ax13 = fig.add_subplot(gs[4,0])
ax14 = fig.add_subplot(gs[4,1])
ax15 = fig.add_subplot(gs[4,2])
ax16 = fig.add_subplot(gs[4,3])
ax17 = fig.add_subplot(gs[5,0])
ax18 = fig.add_subplot(gs[5,1])
ax19 = fig.add_subplot(gs[5,2])
ax20 = fig.add_subplot(gs[5,3])
# Record max specific mass balance
mb_mwea_max_cns = ['Region']
for rcp in rcps:
mb_mwea_max_cns.append('mb_mwea_' + rcp)
mb_mwea_max_cns.append('mb_mwea_mad_' + rcp)
mb_mwea_max_cns.append('year_' + rcp)
mb_mwea_max_df = pd.DataFrame(np.zeros((len(regions),len(rcps)*3+1)), columns=mb_mwea_max_cns)
mb_mwea_max_df['Region'] = regions
mb_gta_max_cns = ['Region']
for rcp in rcps:
mb_gta_max_cns.append('mb_gta_' + rcp)
mb_gta_max_cns.append('mb_gta_mad_' + rcp)
mb_gta_max_cns.append('year_' + rcp)
mb_gta_max_df = pd.DataFrame(np.zeros((len(regions),len(rcps)*3+1)), columns=mb_gta_max_cns)
mb_gta_max_df['Region'] = regions
regions_ordered = ['all',19,3,1,5,9,4,7,17,13,6,14,2,15,8,10,11,16,12,18]
for nax, ax in enumerate([ax1,ax2,ax3,ax4,ax5,ax6,ax7,ax8,ax9,ax10,ax11,ax12,ax13,ax14,ax15,ax16,ax17,ax18,ax19,ax20]):
reg = regions_ordered[nax]
for rcp in rcps:
nrcp = rcps_all.index(rcp)
# Median and absolute median deviation
if reg in ['all']:
reg_vol = np.sum(ds.reg_mass_annual[:,nrcp,:,:].values, axis=0) / pygem_prms.density_ice
reg_area = np.sum(ds.reg_area_annual[:,nrcp,:,:].values, axis=0)
else:
reg_vol = ds.reg_mass_annual[reg-1,nrcp,:,:].values / pygem_prms.density_ice
reg_area = ds.reg_area_annual[reg-1,nrcp,:,:].values
# Median and absolute median deviation
reg_mass = reg_vol * pygem_prms.density_ice
# Specific mass change rate
reg_mb = (reg_mass[:,1:] - reg_mass[:,0:-1]) / reg_area[:,0:-1]
reg_mb_med_raw = np.median(reg_mb, axis=0)
reg_mb_mad_raw = median_abs_deviation(reg_mb, axis=0)
reg_mb_med = uniform_filter(reg_mb_med_raw, size=(11))
reg_mb_mad = uniform_filter(reg_mb_mad_raw, size=(11))
# Record max mb
reg_mb_gta = (reg_mass[:,1:] - reg_mass[:,0:-1]) / 1e12
reg_mb_gta_med_raw = np.median(reg_mb_gta, axis=0)
reg_mb_gta_mad_raw = median_abs_deviation(reg_mb_gta, axis=0)
reg_mb_gta_med = uniform_filter(reg_mb_gta_med_raw, size=(11))
reg_mb_gta_mad = uniform_filter(reg_mb_gta_mad_raw, size=(11))
mb_df_idx = regions.index(reg)
mb_max_idx = np.where(reg_mb_gta_med == reg_mb_gta_med.min())
mb_gta_max_df.loc[mb_df_idx,'mb_gta_' + rcp] = reg_mb_gta_med.min()
mb_gta_max_df.loc[mb_df_idx,'mb_gta_mad_' + rcp] = reg_mb_gta_mad[mb_max_idx]
mb_gta_max_df.loc[mb_df_idx,'year_' + rcp] = years[0:-1][mb_max_idx]
# print(reg, rcp, np.round(reg_mb_gta_med.sum()), 'Gt')