-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmiroc_run_plume_v2.py
110 lines (91 loc) · 4.49 KB
/
miroc_run_plume_v2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
'''
10 Dec 2021
Assessing all regions for MIROC rcp8.5 to make timeseries like for ERA-5
@vikki.thompson
'''
# Load neccessary libraries
import iris
import iris.coord_categorisation as icc
from iris.coord_categorisation import add_season_membership
import numpy as np
import matplotlib.pyplot as plt
import iris.plot as iplt
import cartopy.crs as ccrs
import cartopy as cart
import glob
import matplotlib.cm as mpl_cm
import sys
from iris.experimental.equalise_cubes import equalise_attributes
import scipy.stats as sps
from iris.analysis import geometry
# From Alan, keeps the 1's
mask_regs = [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,0,0,1,1,0,1,1,1,1,0,1,1,1,1,1,0,0,1,0,0,1,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,1,0,1,0,1,1,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,0,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,0,1,1,1,1,1,1,0,0,1,1,1,1,1,1,0,0,1,0,0,0,1,0,1,1,1,1,1,0,1,0,1,0,0,0,1,1,1,0,1,0,0,1,1,0,0,0,1,0,1,0,0,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,0,0,0,1,1,0,1,1,0,1,0,1,1,0,0,1,1,0,1,1,1,0]
# Running mean
ann_max = []
for each in np.arange(220, 237):
ann_max = []
print(each)
if mask_regs[each] == 0:
pass
if mask_regs[each] ==1:
file_list = glob.glob('/user/work/hh21501/miroc_regions/reg'+str(each)+'_*')
cubes = iris.load(file_list)
mod = cubes.concatenate()[0]
iris.coord_categorisation.add_year(mod, 'time') # add coord year
iris.coord_categorisation.add_month_number(mod, 'time')
# Running climatology - fixed mo
year_cons = iris.Constraint(year = lambda cell: 1981 <= cell <= 2010) # climatology period
mod_clim = mod.extract(year_cons)
month_mean = mod_clim.aggregated_by('month_number', iris.analysis.MEAN)
month_mean = month_mean.collapsed('realization', iris.analysis.MEAN)
max_val = month_mean.collapsed('month_number', iris.analysis.MAX).data # monthly max
month_number = np.where(month_mean.data == max_val)[0][0]+1 # month number of max
print(mod)
if month_number == 1:
mod_clim = mod.extract(iris.Constraint(time = lambda cell: cell.point.month == 1 or cell.point.month == 2 or cell.point.month == 12))
else:
mod_clim = mod.extract(iris.Constraint(time = lambda cell: month_number-1 <= cell.point.month <= month_number+1))
yr_extreme = []
# running climatology
for yr in np.arange(1960, 2101):
print(yr)
year_cons = iris.Constraint(year = lambda cell: yr-10 <= cell <= yr) # climatology period
mod_new = mod_clim.extract(year_cons)
clim_mean = np.mean(mod_new.data)
clim_sd = np.std(mod_new.data)
ann_max_ens = []
for ens in np.arange(50):
# Calculate extreme index & identify max each year
single_year = mod[ens,:].extract(iris.Constraint(year = lambda cell: cell == yr))
mod_index = (single_year - clim_mean)/clim_sd
ann_max_ens.append(np.max(mod_index.data)) # 49 numbers
print('Add to ann_max ', ens)
ann_max.append(ann_max_ens) # 49 x 141 numbers (1 region)
np.save('/user/work/hh21501/miroc_ts2/ann_max_index_reg'+str(each), ann_max)
'''
# Calculate % of regions above each sd/year
sd1_list=[]; sd2_list = []; sd3_list = []; sd4_list = []; sd5_list = []
for ens in np.arange(49):
sd1 = []; sd2 = []; sd3 = []; sd4 = []; sd5 = []
for yr in np.arange(141): # number of years
year_list = []
for each in ann_max:
year_list.append(each.data[ens, yr])
year_list = np.array(year_list)
sd1.append((((len(year_list[year_list > 1]))/len(year_list)) *100))
sd2.append((((len(year_list[year_list > 2]))/len(year_list)) *100))
sd3.append((((len(year_list[year_list > 3]))/len(year_list)) *100))
sd4.append((((len(year_list[year_list > 4]))/len(year_list)) *100))
sd5.append((((len(year_list[year_list > 5]))/len(year_list)) *100))
sd1_list.append(sd1)
sd2_list.append(sd2)
sd3_list.append(sd3)
sd4_list.append(sd4)
sd5_list.append(sd5)
# save data
np.save('/user/work/hh21501/miroc_ts/sd1_run_plume_mask', sd1_list)
np.save('/user/work/hh21501/miroc_ts/sd2_run_plume_mask', sd2_list)
np.save('/user/work/hh21501/miroc_ts/sd3_run_plume_mask', sd3_list)
np.save('/user/work/hh21501/miroc_ts/sd4_run_plume_mask', sd4_list)
np.save('/user/work/hh21501/miroc_ts/sd5_run_plume_mask', sd5_list)
'''