MohamedAzizBhouri commited on
Commit
d173fd4
·
1 Parent(s): 792a3e7

Upload 284 files

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. .gitattributes +8 -0
  2. 0_data_process_CAM5.py +229 -0
  3. 0_data_process_SPCAM5.py +246 -0
  4. 1_create_train_test.py +144 -0
  5. 2_candle_plots_data_distr.py +175 -0
  6. 2_norm.py +94 -0
  7. 3_train_RPN_MF.py +325 -0
  8. 3_train_RPN_SF.py +238 -0
  9. 4_concat_param.py +429 -0
  10. 4_pred_RPN_LF.py +171 -0
  11. 4_pred_RPN_MF.py +190 -0
  12. 4_pred_RPN_SF.py +168 -0
  13. 4_pred_RPN_det.py +167 -0
  14. 5_mean_std_RPN_LF.py +55 -0
  15. 5_mean_std_RPN_MF.py +123 -0
  16. 5_mean_std_RPN_SF.py +57 -0
  17. 6_reshape_pred_RPN.py +110 -0
  18. 7_global_crps.py +220 -0
  19. 7_global_errors_temporal_errors.py +163 -0
  20. 7_long_lat_errors.py +95 -0
  21. 7_pressure_lat_errors.py +83 -0
  22. 8_long_lat_plots.py +234 -0
  23. 8_plot_global_errors.py +327 -0
  24. 8_pressure_lat_plots.py +130 -0
  25. 8_uncertainty_density_plot.py +231 -0
  26. 9_uncertainty_video.py +180 -0
  27. 9_uncertainty_video_daily.py +191 -0
  28. candle_plots_1st_lvl_SS_moist_tend.png +3 -0
  29. candle_plots_5_pr_lvls_heat_tend_and_spec_hum.png +3 -0
  30. glob_errors/CRPS_heat.png +3 -0
  31. glob_errors/CRPS_moist.png +3 -0
  32. glob_errors/MAE_det.npy +3 -0
  33. glob_errors/MAE_heat.png +3 -0
  34. glob_errors/MAE_moist.png +3 -0
  35. glob_errors/MAE_rpn_LF.npy +3 -0
  36. glob_errors/MAE_rpn_MF.npy +3 -0
  37. glob_errors/MAE_rpn_SF.npy +3 -0
  38. glob_errors/R2_w_neg_heat.png +3 -0
  39. glob_errors/R2_w_neg_moist.png +3 -0
  40. glob_errors/R2_wo_neg_heat.png +3 -0
  41. glob_errors/R2_wo_neg_moist.png +3 -0
  42. glob_errors/crps_rpn_LF.npy +3 -0
  43. glob_errors/crps_rpn_MF.npy +3 -0
  44. glob_errors/crps_rpn_SF.npy +3 -0
  45. glob_errors/r2_det.npy +3 -0
  46. glob_errors/r2_rpn_LF.npy +3 -0
  47. glob_errors/r2_rpn_MF.npy +3 -0
  48. glob_errors/r2_rpn_SF.npy +3 -0
  49. long_lat_plots/heat_MAE_long_lat_0.png +3 -0
  50. long_lat_plots/heat_MAE_long_lat_1.png +3 -0
.gitattributes CHANGED
@@ -53,3 +53,11 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
53
  *.jpg filter=lfs diff=lfs merge=lfs -text
54
  *.jpeg filter=lfs diff=lfs merge=lfs -text
55
  *.webp filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
 
 
 
 
53
  *.jpg filter=lfs diff=lfs merge=lfs -text
54
  *.jpeg filter=lfs diff=lfs merge=lfs -text
55
  *.webp filter=lfs diff=lfs merge=lfs -text
56
+ videos[[:space:]]compressed/instant_heat_tend_259_compressed.mp4 filter=lfs diff=lfs merge=lfs -text
57
+ videos[[:space:]]compressed/instant_heat_tend_494_compressed.mp4 filter=lfs diff=lfs merge=lfs -text
58
+ videos[[:space:]]compressed/instant_heat_tend_761_1_compressed.mp4 filter=lfs diff=lfs merge=lfs -text
59
+ videos[[:space:]]compressed/instant_heat_tend_761_2_compressed.mp4 filter=lfs diff=lfs merge=lfs -text
60
+ videos[[:space:]]compressed/instant_moist_tend_259_compressed.mp4 filter=lfs diff=lfs merge=lfs -text
61
+ videos[[:space:]]compressed/instant_moist_tend_494_compressed.mp4 filter=lfs diff=lfs merge=lfs -text
62
+ videos[[:space:]]compressed/instant_moist_tend_761_1_compressed.mp4 filter=lfs diff=lfs merge=lfs -text
63
+ videos[[:space:]]compressed/instant_moist_tend_761_2_compressed.mp4 filter=lfs diff=lfs merge=lfs -text
0_data_process_CAM5.py ADDED
@@ -0,0 +1,229 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ """
4
+ Created on Mon Apr 3 11:22:45 2023
5
+
6
+ @author: mohamedazizbhouri
7
+ """
8
+
9
+ import os
10
+ current_dirs_parent = os.path.dirname(os.getcwd())
11
+ current_dirs_parent = os.path.dirname(current_dirs_parent)
12
+ import netCDF4 as nc
13
+ import numpy as onp
14
+
15
+ def read_data(ds0, ds1, ds2):
16
+
17
+ TBP = onp.transpose(ds0.variables['TBP'],axes=(1,0,2,3))
18
+ QBP = onp.transpose(ds0.variables['QBP'],axes=(1,0,2,3))
19
+ CLDLIQBP = onp.transpose(ds0.variables['CLDLIQBP'],axes=(1,0,2,3))
20
+ CLDICEBP = onp.transpose(ds0.variables['CLDICEBP'],axes=(1,0,2,3))
21
+
22
+ TBP = onp.reshape(TBP, (lev, time*lat*lon))
23
+ QBP = onp.reshape(QBP, (lev, time*lat*lon))
24
+ CLDLIQBP = onp.reshape(CLDLIQBP, (lev, time*lat*lon))
25
+ CLDICEBP = onp.reshape(CLDICEBP, (lev, time*lat*lon))
26
+
27
+ PS = onp.reshape(ds0.variables['PS'], (1, time*lat*lon))
28
+ SOLIN = onp.reshape(ds0.variables['SOLIN'], (1, time*lat*lon))
29
+ SHFLX = onp.reshape(ds0.variables['SHFLX'], (1, time*lat*lon))
30
+ LHFLX = onp.reshape(ds0.variables['LHFLX'], (1, time*lat*lon))
31
+
32
+ is_land = onp.reshape(ds0.variables['LANDFRAC'], (1, time*lat*lon)) > onp.reshape(ds0.variables['OCNFRAC'], (1, time*lat*lon))
33
+
34
+ inputs = onp.concatenate((TBP,QBP,CLDLIQBP,CLDICEBP,PS,SOLIN,SHFLX,LHFLX,is_land)).T
35
+
36
+ TBC = onp.transpose(ds1.variables['TBC'],axes=(1,0,2,3))
37
+ TBC = onp.reshape(TBC, (lev, time*lat*lon))
38
+ TBCTEND=(TBC-TBP)/DT
39
+
40
+ QBC = onp.transpose(ds1.variables['QBC'],axes=(1,0,2,3))
41
+ QBC = onp.reshape(QBC, (lev, time*lat*lon))
42
+ QBCTEND=(QBC-QBP)/DT
43
+
44
+ CLDLIQBC = onp.transpose(ds1.variables['CLDLIQBC'],axes=(1,0,2,3))
45
+ CLDLIQBC = onp.reshape(CLDLIQBC, (lev, time*lat*lon))
46
+ CLDLIQBCTEND=(CLDLIQBC-CLDLIQBP)/DT
47
+
48
+ CLDICEBC = onp.transpose(ds1.variables['CLDICEBC'],axes=(1,0,2,3))
49
+ CLDICEBC = onp.reshape(CLDICEBC, (lev, time*lat*lon))
50
+ CLDICEBCTEND=(CLDICEBC-CLDICEBP)/DT
51
+
52
+ NN2L_FLWDS = onp.reshape(ds2.variables['NN2L_FLWDS'], (1, time*lat*lon))
53
+
54
+ NN2L_NETSW = onp.reshape(ds2.variables['NN2L_NETSW'], (1, time*lat*lon))
55
+
56
+ NN2L_PRECC = onp.reshape(ds2.variables['NN2L_PRECC'], (1, time*lat*lon))
57
+
58
+ NN2L_PRECSC = onp.reshape(ds2.variables['NN2L_PRECSC'], (1, time*lat*lon))
59
+
60
+ NN2L_SOLL = onp.reshape(ds2.variables['NN2L_SOLL'], (1, time*lat*lon))
61
+
62
+ NN2L_SOLLD = onp.reshape(ds2.variables['NN2L_SOLLD'], (1, time*lat*lon))
63
+
64
+ NN2L_SOLS = onp.reshape(ds2.variables['NN2L_SOLS'], (1, time*lat*lon))
65
+
66
+ NN2L_SOLSD = onp.reshape(ds2.variables['NN2L_SOLSD'], (1, time*lat*lon))
67
+
68
+ outputs = onp.concatenate((TBCTEND,QBCTEND,CLDLIQBCTEND,CLDICEBCTEND,
69
+ NN2L_FLWDS,NN2L_NETSW,NN2L_PRECC,NN2L_PRECSC,
70
+ NN2L_SOLL,NN2L_SOLLD,NN2L_SOLS,NN2L_SOLSD)).T
71
+ return inputs, outputs
72
+
73
+ is_4K = 0
74
+ is_8K = 1
75
+ if is_4K == 1:
76
+ pp = current_dirs_parent+'/07088/tg863871/CESM2_case/CAM5_1024_NN_L26_Feb27_4K/archive/CAM5_1024_NN_L26_Feb27_4K/atm/hist/'
77
+ elif is_8K == 1:
78
+ pp = current_dirs_parent+'/07088/tg863871/CESM2_case/CAM5_1024_NN_L26_Apr26_8K/archive/CAM5_1024_NN_L26_Apr26_8K/atm/hist/'
79
+
80
+ case = 4
81
+ if is_4K == 1:
82
+ if case == 1:
83
+ l_year = ['2003']
84
+ l_month = ['01','03','05','07','08','10','12']
85
+ l_day = [1,7,13,19,25,31]
86
+ l_N = [5,5,5,5,5,0]
87
+ elif case == 2:
88
+ l_year = ['2004']
89
+ l_month = ['01']
90
+ l_day = [1,7,13,19,25,31]
91
+ l_N = [5,5,5,5,5,0]
92
+ elif case == 3:
93
+ l_year = ['2003']
94
+ l_month = ['02','04','06','09','11']
95
+ l_day = [1,7,13,19,25]
96
+ l_N_other = [5,5,5,5,5]
97
+ l_N_02 = [5,5,5,5,3]
98
+ elif case == 4:
99
+ l_year = ['2004']
100
+ l_month = ['02']
101
+ l_day = [1]
102
+ l_N = [2]
103
+ elif is_8K == 1:
104
+ if case == 1:
105
+ l_year = ['2004']
106
+ l_month = ['02']
107
+ l_day = [1,7,13,19,25]
108
+ l_N = [5,5,5,5,3]
109
+ elif case == 2:
110
+ l_year = ['2004']
111
+ l_month = ['03']
112
+ l_day = [1,7,13]
113
+ l_N = [5,5,0]
114
+ elif case == 3:
115
+ l_year = ['2003']
116
+ l_month = ['02','04','06','09','11']
117
+ l_day = [1,7,13,19,25]
118
+ l_N_other = [5,5,5,5,5]
119
+ l_N_02 = [5,5,5,5,3]
120
+ elif case == 4:
121
+ l_year = ['2004']
122
+ l_month = ['01']
123
+ l_day = [1,7,13,19,25,31]
124
+ l_N = [5,5,5,5,5,0]
125
+ elif case == 5:
126
+ l_year = ['2003']
127
+ l_month = ['01','03','05','07','08','10','12']
128
+ l_day = [1,7,13,19,25,31]
129
+ l_N = [5,5,5,5,5,0]
130
+
131
+ for k in range(len(l_year)):
132
+ i_year = l_year[k]
133
+
134
+ for i in range(len(l_month)):
135
+
136
+ i_month = l_month[i]
137
+
138
+ #case 1, 2, 4, 5
139
+ # nothing, l_N and l_day are the same for any i index
140
+ if case == 3:
141
+ if i_month == '02':
142
+ l_N = l_N_02
143
+ else:
144
+ l_N = l_N_other
145
+
146
+ for ii in range(len(l_day)):
147
+ i_day = l_day[ii]
148
+ N_day = l_N[ii]
149
+
150
+ if i_day<10:
151
+ i_day_str = '0'+str(i_day)
152
+ else:
153
+ i_day_str = str(i_day)
154
+
155
+ if is_4K == 1:
156
+ ds0 = nc.Dataset(pp+'CAM5_1024_NN_L26_Feb27_4K.cam.h0.'+i_year+'-'+i_month+'-'+i_day_str+'-01800.nc')
157
+ ds1 = nc.Dataset(pp+'CAM5_1024_NN_L26_Feb27_4K.cam.h1.'+i_year+'-'+i_month+'-'+i_day_str+'-01800.nc')
158
+ ds2 = nc.Dataset(pp+'CAM5_1024_NN_L26_Feb27_4K.cam.h2.'+i_year+'-'+i_month+'-'+i_day_str+'-01800.nc')
159
+ elif is_8K == 1:
160
+ ds0 = nc.Dataset(pp+'CAM5_1024_NN_L26_Apr26_8K.cam.h0.'+i_year+'-'+i_month+'-'+i_day_str+'-01800.nc')
161
+ ds1 = nc.Dataset(pp+'CAM5_1024_NN_L26_Apr26_8K.cam.h1.'+i_year+'-'+i_month+'-'+i_day_str+'-01800.nc')
162
+ ds2 = nc.Dataset(pp+'CAM5_1024_NN_L26_Apr26_8K.cam.h2.'+i_year+'-'+i_month+'-'+i_day_str+'-01800.nc')
163
+
164
+ DT = 30*60
165
+ lat = ds0.dimensions['lat'].size
166
+ time = ds0.dimensions['time'].size
167
+ lon = ds0.dimensions['lon'].size
168
+ lev = ds0.dimensions['lev'].size
169
+
170
+ inputs, outputs = read_data(ds0, ds1, ds2)
171
+
172
+ #due to zero solar insulation remove half of the points
173
+ name_end = ['01800','05400','09000','12600','16200',
174
+ '19800','23400','27000','30600','34200',
175
+ '37800','41400','45000','48600','52200',
176
+ '55800','59400','63000','66600','70200',
177
+ '73800','77400','81000','84600']
178
+
179
+ num_name = len(name_end)
180
+
181
+ for i in range(num_name-1):
182
+ if is_4K == 1:
183
+ ds0 = nc.Dataset(pp+'CAM5_1024_NN_L26_Feb27_4K.cam.h0.'+i_year+'-'+i_month+'-'+i_day_str+'-'+name_end[i+1]+'.nc')
184
+ ds1 = nc.Dataset(pp+'CAM5_1024_NN_L26_Feb27_4K.cam.h1.'+i_year+'-'+i_month+'-'+i_day_str+'-'+name_end[i+1]+'.nc')
185
+ ds2 = nc.Dataset(pp+'CAM5_1024_NN_L26_Feb27_4K.cam.h2.'+i_year+'-'+i_month+'-'+i_day_str+'-'+name_end[i+1]+'.nc')
186
+ elif is_8K == 1:
187
+ ds0 = nc.Dataset(pp+'CAM5_1024_NN_L26_Apr26_8K.cam.h0.'+i_year+'-'+i_month+'-'+i_day_str+'-'+name_end[i+1]+'.nc')
188
+ ds1 = nc.Dataset(pp+'CAM5_1024_NN_L26_Apr26_8K.cam.h1.'+i_year+'-'+i_month+'-'+i_day_str+'-'+name_end[i+1]+'.nc')
189
+ ds2 = nc.Dataset(pp+'CAM5_1024_NN_L26_Apr26_8K.cam.h2.'+i_year+'-'+i_month+'-'+i_day_str+'-'+name_end[i+1]+'.nc')
190
+
191
+ inputs_l, outputs_l = read_data(ds0, ds1, ds2)
192
+ inputs = onp.concatenate((inputs,inputs_l))
193
+ outputs = onp.concatenate((outputs,outputs_l))
194
+
195
+ for j in range(N_day):
196
+ print(j)
197
+ i_day += 1
198
+ if i_day<10:
199
+ i_day_str = '0'+str(i_day)
200
+ else:
201
+ i_day_str = str(i_day)
202
+ for i in range(num_name):
203
+ if is_4K == 1:
204
+ ds0 = nc.Dataset(pp+'CAM5_1024_NN_L26_Feb27_4K.cam.h0.'+i_year+'-'+i_month+'-'+i_day_str+'-'+name_end[i]+'.nc')
205
+ ds1 = nc.Dataset(pp+'CAM5_1024_NN_L26_Feb27_4K.cam.h1.'+i_year+'-'+i_month+'-'+i_day_str+'-'+name_end[i]+'.nc')
206
+ ds2 = nc.Dataset(pp+'CAM5_1024_NN_L26_Feb27_4K.cam.h2.'+i_year+'-'+i_month+'-'+i_day_str+'-'+name_end[i]+'.nc')
207
+ elif is_8K == 1:
208
+ ds0 = nc.Dataset(pp+'CAM5_1024_NN_L26_Apr26_8K.cam.h0.'+i_year+'-'+i_month+'-'+i_day_str+'-'+name_end[i]+'.nc')
209
+ ds1 = nc.Dataset(pp+'CAM5_1024_NN_L26_Apr26_8K.cam.h1.'+i_year+'-'+i_month+'-'+i_day_str+'-'+name_end[i]+'.nc')
210
+ ds2 = nc.Dataset(pp+'CAM5_1024_NN_L26_Apr26_8K.cam.h2.'+i_year+'-'+i_month+'-'+i_day_str+'-'+name_end[i]+'.nc')
211
+
212
+ inputs_l, outputs_l = read_data(ds0, ds1, ds2)
213
+ inputs = onp.concatenate((inputs,inputs_l))
214
+ outputs = onp.concatenate((outputs,outputs_l))
215
+
216
+ if i_day<10:
217
+ i_day_str = '0'+str(i_day)
218
+ else:
219
+ i_day_str = str(i_day)
220
+
221
+ if is_4K == 1:
222
+ onp.save('data_CAM5_4K/inputs_'+i_year+'_'+i_month+'_'+i_day_str,inputs)
223
+ onp.save('data_CAM5_4K/outputs_'+i_year+'_'+i_month+'_'+i_day_str,outputs)
224
+ elif is_8K == 1:
225
+ onp.save('data_CAM5_8K/inputs_'+i_year+'_'+i_month+'_'+i_day_str,inputs)
226
+ onp.save('data_CAM5_8K/outputs_'+i_year+'_'+i_month+'_'+i_day_str,outputs)
227
+
228
+ print('h0.'+i_year+'-'+i_month+'-'+i_day_str, ', train data shape: ',inputs.shape, outputs.shape) # (221184, 108) (221184, 112)
229
+
0_data_process_SPCAM5.py ADDED
@@ -0,0 +1,246 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ """
4
+ Created on Mon Apr 3 11:28:31 2023
5
+
6
+ @author: mohamedazizbhouri
7
+ """
8
+
9
+ import os
10
+ current_dirs_parent = os.path.dirname(os.getcwd())
11
+ current_dirs_parent = os.path.dirname(current_dirs_parent)
12
+ import netCDF4 as nc
13
+ import numpy as onp
14
+
15
+ def read_data(ds0, ds1, ds2):
16
+
17
+ TBP = onp.transpose(ds0.variables['TBP'],axes=(1,0,2,3))
18
+ QBP = onp.transpose(ds0.variables['QBP'],axes=(1,0,2,3))
19
+ CLDLIQBP = onp.transpose(ds0.variables['CLDLIQBP'],axes=(1,0,2,3))
20
+ CLDICEBP = onp.transpose(ds0.variables['CLDICEBP'],axes=(1,0,2,3))
21
+
22
+ TBP = onp.reshape(TBP, (lev, time*lat*lon))
23
+ QBP = onp.reshape(QBP, (lev, time*lat*lon))
24
+ CLDLIQBP = onp.reshape(CLDLIQBP, (lev, time*lat*lon))
25
+ CLDICEBP = onp.reshape(CLDICEBP, (lev, time*lat*lon))
26
+
27
+ PS = onp.reshape(ds0.variables['PS'], (1, time*lat*lon))
28
+ SOLIN = onp.reshape(ds0.variables['SOLIN'], (1, time*lat*lon))
29
+ SHFLX = onp.reshape(ds0.variables['SHFLX'], (1, time*lat*lon))
30
+ LHFLX = onp.reshape(ds0.variables['LHFLX'], (1, time*lat*lon))
31
+
32
+ is_land = onp.reshape(ds0.variables['LANDFRAC'], (1, time*lat*lon)) > onp.reshape(ds0.variables['OCNFRAC'], (1, time*lat*lon))
33
+
34
+ inputs = onp.concatenate((TBP,QBP,CLDLIQBP,CLDICEBP,PS,SOLIN,SHFLX,LHFLX,is_land)).T
35
+
36
+ TBC = onp.transpose(ds1.variables['TBC'],axes=(1,0,2,3))
37
+ TBC = onp.reshape(TBC, (lev, time*lat*lon))
38
+ TBCTEND=(TBC-TBP)/DT
39
+
40
+ QBC = onp.transpose(ds1.variables['QBC'],axes=(1,0,2,3))
41
+ QBC = onp.reshape(QBC, (lev, time*lat*lon))
42
+ QBCTEND=(QBC-QBP)/DT
43
+
44
+ CLDLIQBC = onp.transpose(ds1.variables['CLDLIQBC'],axes=(1,0,2,3))
45
+ CLDLIQBC = onp.reshape(CLDLIQBC, (lev, time*lat*lon))
46
+ CLDLIQBCTEND=(CLDLIQBC-CLDLIQBP)/DT
47
+
48
+ CLDICEBC = onp.transpose(ds1.variables['CLDICEBC'],axes=(1,0,2,3))
49
+ CLDICEBC = onp.reshape(CLDICEBC, (lev, time*lat*lon))
50
+ CLDICEBCTEND=(CLDICEBC-CLDICEBP)/DT
51
+
52
+ NN2L_FLWDS = onp.reshape(ds2.variables['NN2L_FLWDS'], (1, time*lat*lon))
53
+
54
+ NN2L_NETSW = onp.reshape(ds2.variables['NN2L_NETSW'], (1, time*lat*lon))
55
+
56
+ NN2L_PRECC = onp.reshape(ds2.variables['NN2L_PRECC'], (1, time*lat*lon))
57
+
58
+ NN2L_PRECSC = onp.reshape(ds2.variables['NN2L_PRECSC'], (1, time*lat*lon))
59
+
60
+ NN2L_SOLL = onp.reshape(ds2.variables['NN2L_SOLL'], (1, time*lat*lon))
61
+
62
+ NN2L_SOLLD = onp.reshape(ds2.variables['NN2L_SOLLD'], (1, time*lat*lon))
63
+
64
+ NN2L_SOLS = onp.reshape(ds2.variables['NN2L_SOLS'], (1, time*lat*lon))
65
+
66
+ NN2L_SOLSD = onp.reshape(ds2.variables['NN2L_SOLSD'], (1, time*lat*lon))
67
+
68
+ outputs = onp.concatenate((TBCTEND,QBCTEND,CLDLIQBCTEND,CLDICEBCTEND,
69
+ NN2L_FLWDS,NN2L_NETSW,NN2L_PRECC,NN2L_PRECSC,
70
+ NN2L_SOLL,NN2L_SOLLD,NN2L_SOLS,NN2L_SOLSD)).T
71
+ return inputs, outputs
72
+
73
+ is_4K = 0
74
+ is_hist = 1
75
+ if is_4K == 1:
76
+ pp = current_dirs_parent+'/07088/tg863871/CESM2_case/SPCAM_NN_4K/archive/SPCAM_NN_4K/atm/hist/'
77
+ elif is_hist == 1:
78
+ pp = current_dirs_parent+'/07088/tg863871/CESM2_case/SPCAM_NN_v2/archive/SPCAM_NN_v2/atm/hist/'
79
+
80
+ case = 4
81
+
82
+ if is_4K == 1:
83
+ if case == 1:
84
+ l_year = ['2003']
85
+ l_month = ['01','03','05','07','08','10','12']
86
+ l_day = [1,7,13,19,25,31]
87
+ l_N = [5,5,5,5,5,0]
88
+ elif case == 2:
89
+ l_year = ['2004']
90
+ l_month = ['01']
91
+ l_day = [1,7,13,19,25,31]
92
+ l_N = [5,5,5,5,5,0]
93
+ elif case == 3:
94
+ l_year = ['2003']
95
+ l_month = ['02','04','06','09','11']
96
+ l_day = [1,7,13,19,25]
97
+ l_N_other = [5,5,5,5,5]
98
+ l_N_02 = [5,5,5,5,3]
99
+ elif case == 4:
100
+ l_year = ['2004']
101
+ l_month = ['02']
102
+ l_day = [1]
103
+ l_N = [2]
104
+ elif is_hist == 1:
105
+ if case == 1:
106
+ l_year = ['2003']
107
+ l_month = ['01','03','05','07','08','10','12']
108
+ l_day = [1,7,13,19,25,31]
109
+ l_N = [5,5,5,5,5,0]
110
+ elif case == 2:
111
+ l_year = ['2004']
112
+ l_month = ['01','03','05','07','08']
113
+ l_day_other = [1,7,13,19,25,31]
114
+ l_N_other = [5,5,5,5,5,0]
115
+ l_day_08 = [1]
116
+ l_N_08 = [2]
117
+ elif case == 3:
118
+ l_year = ['2003']
119
+ l_month = ['02','04','06','09','11']
120
+ l_day = [1,7,13,19,25]
121
+ l_N_other = [5,5,5,5,5]
122
+ l_N_02 = [5,5,5,5,3]
123
+ elif case == 4:
124
+ l_year = ['2004']
125
+ l_month = ['02','04','06']
126
+ l_day = [1,7,13,19,25]
127
+ l_N_04_06 = [5,5,5,5,5]
128
+ l_N_02 = [5,5,5,5,3]
129
+
130
+ for k in range(len(l_year)):
131
+ i_year = l_year[k]
132
+
133
+ for i in range(len(l_month)):
134
+
135
+ i_month = l_month[i]
136
+
137
+ if is_4K == 1:
138
+ #case 1, 2, 4
139
+ # nothing, l_N and l_day are the same for any i index
140
+ if case == 3:
141
+ if i_month == '02':
142
+ l_N = l_N_02
143
+ else:
144
+ l_N = l_N_other
145
+ elif is_hist == 1:
146
+ #case 1
147
+ # nothing, l_N and l_day are the same for any i index
148
+ if case == 2:
149
+ if i_month == '08':
150
+ l_N = l_N_08
151
+ l_day = l_day_08
152
+ else:
153
+ l_N = l_N_other
154
+ l_day = l_day_other
155
+ elif case == 3:
156
+ if i_month == '02':
157
+ l_N = l_N_02
158
+ else:
159
+ l_N = l_N_other
160
+ elif case == 4:
161
+ if i_month == '02':
162
+ l_N = l_N_02
163
+ else:
164
+ l_N = l_N_04_06
165
+ for ii in range(len(l_day)):
166
+ i_day = l_day[ii]
167
+ N_day = l_N[ii]
168
+
169
+ if i_day<10:
170
+ i_day_str = '0'+str(i_day)
171
+ else:
172
+ i_day_str = str(i_day)
173
+
174
+ if is_4K == 1:
175
+ ds0 = nc.Dataset(pp+'SPCAM_NN_4K.cam.h0.'+i_year+'-'+i_month+'-'+i_day_str+'-01800.nc')
176
+ ds1 = nc.Dataset(pp+'SPCAM_NN_4K.cam.h1.'+i_year+'-'+i_month+'-'+i_day_str+'-01800.nc')
177
+ ds2 = nc.Dataset(pp+'SPCAM_NN_4K.cam.h2.'+i_year+'-'+i_month+'-'+i_day_str+'-01800.nc')
178
+ elif is_hist == 1:
179
+ ds0 = nc.Dataset(pp+'SPCAM_NN_v2.cam.h0.'+i_year+'-'+i_month+'-'+i_day_str+'-01800.nc')
180
+ ds1 = nc.Dataset(pp+'SPCAM_NN_v2.cam.h1.'+i_year+'-'+i_month+'-'+i_day_str+'-01800.nc')
181
+ ds2 = nc.Dataset(pp+'SPCAM_NN_v2.cam.h2.'+i_year+'-'+i_month+'-'+i_day_str+'-01800.nc')
182
+ DT = 30*60
183
+ lat = ds0.dimensions['lat'].size
184
+ time = ds0.dimensions['time'].size
185
+ lon = ds0.dimensions['lon'].size
186
+ lev = ds0.dimensions['lev'].size
187
+
188
+ inputs, outputs = read_data(ds0, ds1, ds2)
189
+
190
+ #due to zero solar insulation remove half of the points
191
+ name_end = ['01800','05400','09000','12600','16200',
192
+ '19800','23400','27000','30600','34200',
193
+ '37800','41400','45000','48600','52200',
194
+ '55800','59400','63000','66600','70200',
195
+ '73800','77400','81000','84600']
196
+
197
+ num_name = len(name_end)
198
+
199
+ for i in range(num_name-1):
200
+ if is_4K == 1:
201
+ ds0 = nc.Dataset(pp+'SPCAM_NN_4K.cam.h0.'+i_year+'-'+i_month+'-'+i_day_str+'-'+name_end[i+1]+'.nc')
202
+ ds1 = nc.Dataset(pp+'SPCAM_NN_4K.cam.h1.'+i_year+'-'+i_month+'-'+i_day_str+'-'+name_end[i+1]+'.nc')
203
+ ds2 = nc.Dataset(pp+'SPCAM_NN_4K.cam.h2.'+i_year+'-'+i_month+'-'+i_day_str+'-'+name_end[i+1]+'.nc')
204
+ elif is_hist == 1:
205
+ ds0 = nc.Dataset(pp+'SPCAM_NN_v2.cam.h0.'+i_year+'-'+i_month+'-'+i_day_str+'-'+name_end[i+1]+'.nc')
206
+ ds1 = nc.Dataset(pp+'SPCAM_NN_v2.cam.h1.'+i_year+'-'+i_month+'-'+i_day_str+'-'+name_end[i+1]+'.nc')
207
+ ds2 = nc.Dataset(pp+'SPCAM_NN_v2.cam.h2.'+i_year+'-'+i_month+'-'+i_day_str+'-'+name_end[i+1]+'.nc')
208
+ inputs_l, outputs_l = read_data(ds0, ds1, ds2)
209
+ inputs = onp.concatenate((inputs,inputs_l))
210
+ outputs = onp.concatenate((outputs,outputs_l))
211
+
212
+ for j in range(N_day):
213
+ print(j)
214
+ i_day += 1
215
+ if i_day<10:
216
+ i_day_str = '0'+str(i_day)
217
+ else:
218
+ i_day_str = str(i_day)
219
+ for i in range(num_name):
220
+ if is_4K == 1:
221
+ ds0 = nc.Dataset(pp+'SPCAM_NN_4K.cam.h0.'+i_year+'-'+i_month+'-'+i_day_str+'-'+name_end[i]+'.nc')
222
+ ds1 = nc.Dataset(pp+'SPCAM_NN_4K.cam.h1.'+i_year+'-'+i_month+'-'+i_day_str+'-'+name_end[i]+'.nc')
223
+ ds2 = nc.Dataset(pp+'SPCAM_NN_4K.cam.h2.'+i_year+'-'+i_month+'-'+i_day_str+'-'+name_end[i]+'.nc')
224
+ elif is_hist == 1:
225
+ ds0 = nc.Dataset(pp+'SPCAM_NN_v2.cam.h0.'+i_year+'-'+i_month+'-'+i_day_str+'-'+name_end[i]+'.nc')
226
+ ds1 = nc.Dataset(pp+'SPCAM_NN_v2.cam.h1.'+i_year+'-'+i_month+'-'+i_day_str+'-'+name_end[i]+'.nc')
227
+ ds2 = nc.Dataset(pp+'SPCAM_NN_v2.cam.h2.'+i_year+'-'+i_month+'-'+i_day_str+'-'+name_end[i]+'.nc')
228
+
229
+ inputs_l, outputs_l = read_data(ds0, ds1, ds2)
230
+ inputs = onp.concatenate((inputs,inputs_l))
231
+ outputs = onp.concatenate((outputs,outputs_l))
232
+
233
+ if i_day<10:
234
+ i_day_str = '0'+str(i_day)
235
+ else:
236
+ i_day_str = str(i_day)
237
+
238
+ if is_4K == 1:
239
+ onp.save('data_SPCAM5_4K/inputs_'+i_year+'_'+i_month+'_'+i_day_str,inputs)
240
+ onp.save('data_SPCAM5_4K/outputs_'+i_year+'_'+i_month+'_'+i_day_str,outputs)
241
+ elif is_hist == 1:
242
+ onp.save('data_SPCAM5_hist/inputs_'+i_year+'_'+i_month+'_'+i_day_str,inputs)
243
+ onp.save('data_SPCAM5_hist/outputs_'+i_year+'_'+i_month+'_'+i_day_str,outputs)
244
+
245
+ print('h0.'+i_year+'-'+i_month+'-'+i_day_str, ', train data shape: ',inputs.shape, outputs.shape) # (221184, 108) (221184, 112)
246
+
1_create_train_test.py ADDED
@@ -0,0 +1,144 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ """
4
+ Created on Wed Apr 12 12:04:50 2023
5
+
6
+ @author: mohamedazizbhouri
7
+ """
8
+
9
+ CAM_train_input = 0
10
+ CAM_train_output = 0
11
+ CAM_4K_input = 0
12
+ CAM_4K_output = 0
13
+
14
+ SPCAM_train_input = 0
15
+ SPCAM_train_output = 0
16
+ SPCAM_test_input = 0
17
+ SPCAM_test_output = 0
18
+
19
+ is_output_heat = 1
20
+
21
+ if SPCAM_train_input == 1 or SPCAM_train_output == 1:
22
+ pp_SPCAM = 'data_SPCAM5_hist/'
23
+ if SPCAM_test_input == 1 or SPCAM_test_output == 1:
24
+ pp_SPCAM ='data_SPCAM5_4K/'
25
+ if CAM_train_input == 1 or CAM_train_output == 1:
26
+ pp_CAM = 'data_CAM5_8K/'
27
+ if CAM_4K_input == 1 or CAM_4K_output == 1:
28
+ pp_CAM = 'data_CAM5_4K/'
29
+
30
+ import numpy as np
31
+
32
+ train_CAM =['2003_02_06','2003_02_12','2003_02_18','2003_02_24','2003_02_28',
33
+ '2003_03_06','2003_03_12','2003_03_18','2003_03_24','2003_03_30','2003_03_31',
34
+ '2003_04_06','2003_04_12','2003_04_18','2003_04_24','2003_04_30',
35
+ '2003_05_06','2003_05_12','2003_05_18','2003_05_24','2003_05_30','2003_05_31',
36
+ '2003_06_06','2003_06_12','2003_06_18','2003_06_24','2003_06_30',
37
+ '2003_07_06','2003_07_12','2003_07_18','2003_07_24','2003_07_30','2003_07_31',
38
+ '2003_08_06','2003_08_12','2003_08_18','2003_08_24','2003_08_30','2003_08_31',
39
+ '2003_09_06','2003_09_12','2003_09_18','2003_09_24','2003_09_30',
40
+ '2003_10_06','2003_10_12','2003_10_18','2003_10_24','2003_10_30','2003_10_31',
41
+ '2003_11_06','2003_11_12','2003_11_18','2003_11_24','2003_11_30',
42
+ '2003_12_06','2003_12_12','2003_12_18','2003_12_24','2003_12_30','2003_12_31',
43
+ '2004_01_06','2004_01_12','2004_01_18','2004_01_24','2004_01_30','2004_01_31']
44
+
45
+ train_SPCAM =['2003_02_06','2003_02_12','2003_02_18','2003_02_24','2003_02_28',
46
+ '2003_03_06','2003_03_12','2003_03_18','2003_03_24','2003_03_30','2003_03_31',
47
+ '2003_04_06','2003_04_12','2003_04_18','2003_04_24','2003_04_30']
48
+
49
+ test_SPCAM =['2003_02_06','2003_02_12','2003_02_18','2003_02_24','2003_02_28',
50
+ '2003_03_06','2003_03_12','2003_03_18','2003_03_24','2003_03_30','2003_03_31',
51
+ '2003_04_06','2003_04_12','2003_04_18','2003_04_24','2003_04_30',
52
+ '2003_05_06','2003_05_12','2003_05_18','2003_05_24','2003_05_30','2003_05_31',
53
+ '2003_06_06','2003_06_12','2003_06_18','2003_06_24','2003_06_30',
54
+ '2003_07_06','2003_07_12','2003_07_18','2003_07_24','2003_07_30','2003_07_31',
55
+ '2003_08_06','2003_08_12','2003_08_18','2003_08_24','2003_08_30','2003_08_31',
56
+ '2003_09_06','2003_09_12','2003_09_18','2003_09_24','2003_09_30',
57
+ '2003_10_06','2003_10_12','2003_10_18','2003_10_24','2003_10_30','2003_10_31',
58
+ '2003_11_06','2003_11_12','2003_11_18','2003_11_24','2003_11_30',
59
+ '2003_12_06','2003_12_12','2003_12_18','2003_12_24','2003_12_30','2003_12_31',
60
+ '2004_01_06','2004_01_12','2004_01_18','2004_01_24','2004_01_30','2004_01_31']
61
+
62
+ import gc
63
+
64
+ ind_input = np.concatenate( (np.arange(52),np.array([104,105,106,107])) )
65
+ if is_output_heat == 1:
66
+ ind_output = np.arange(26) # heat tend
67
+ else:
68
+ ind_output = 26+np.arange(26) # moist tend
69
+
70
+ if CAM_train_input == 1 or CAM_4K_input == 1:
71
+ train_CAM_in = np.load(pp_CAM+'inputs_'+train_CAM[0]+'.npy')[:,ind_input]
72
+ gc.collect()
73
+ for i in range(len(train_CAM)-1):
74
+ print(train_CAM[i+1])
75
+ train_CAM_in = np.concatenate((train_CAM_in,
76
+ np.load(pp_CAM+'inputs_'+train_CAM[i+1]+'.npy')[:,ind_input]),axis=0)
77
+ gc.collect()
78
+ np.save(pp_CAM+'all_inputs.npy',train_CAM_in)
79
+ print('Final data shape: ', train_CAM_in.shape)
80
+
81
+ if CAM_train_output == 1 or CAM_4K_output == 1:
82
+ train_CAM_out = np.load(pp_CAM+'outputs_'+train_CAM[0]+'.npy')[:,ind_output]
83
+ gc.collect()
84
+ for i in range(len(train_CAM)-1):
85
+ print(train_CAM[i+1])
86
+ train_CAM_out = np.concatenate((train_CAM_out,
87
+ np.load(pp_CAM+'outputs_'+train_CAM[i+1]+'.npy')[:,ind_output]),axis=0)
88
+ gc.collect()
89
+
90
+ if is_output_heat == 1:
91
+ np.save(pp_CAM+'all_outputs_heat.npy',train_CAM_out)
92
+ else:
93
+ np.save(pp_CAM+'all_outputs_moist.npy',train_CAM_out)
94
+ print('Final data shape: ', train_CAM_out.shape)
95
+
96
+ if SPCAM_train_input == 1:
97
+ train_SPCAM_in = np.load(pp_SPCAM+'inputs_'+train_SPCAM[0]+'.npy')[:,ind_input]
98
+ gc.collect()
99
+ for i in range(len(train_SPCAM)-1):
100
+ print(train_SPCAM[i+1])
101
+ train_SPCAM_in = np.concatenate((train_SPCAM_in,
102
+ np.load(pp_SPCAM+'inputs_'+train_SPCAM[i+1]+'.npy')[:,ind_input]),axis=0)
103
+ gc.collect()
104
+ np.save(pp_SPCAM+'three_month_inputs.npy',train_SPCAM_in)
105
+ print('Final data shape: ', train_SPCAM_in.shape)
106
+
107
+ if SPCAM_train_output == 1:
108
+ train_SPCAM_out = np.load(pp_SPCAM+'outputs_'+train_SPCAM[0]+'.npy')[:,ind_output]
109
+ gc.collect()
110
+ for i in range(len(train_SPCAM)-1):
111
+ print(train_SPCAM[i+1])
112
+ train_SPCAM_out = np.concatenate((train_SPCAM_out,
113
+ np.load(pp_SPCAM+'outputs_'+train_SPCAM[i+1]+'.npy')[:,ind_output]),axis=0)
114
+ gc.collect()
115
+ if is_output_heat == 1:
116
+ np.save(pp_SPCAM+'three_month_outputs_heat.npy',train_SPCAM_out)
117
+ else:
118
+ np.save(pp_SPCAM+'three_month_outputs_moist.npy',train_SPCAM_out)
119
+ print('Final data shape: ', train_SPCAM_out.shape)
120
+
121
+ if SPCAM_test_input == 1:
122
+ test_SPCAM_in = np.load(pp_SPCAM+'inputs_'+test_SPCAM[0]+'.npy')[:,ind_input]
123
+ gc.collect()
124
+ for i in range(len(test_SPCAM)-1):
125
+ print(test_SPCAM[i+1])
126
+ test_SPCAM_in = np.concatenate((test_SPCAM_in,
127
+ np.load(pp_SPCAM+'inputs_'+test_SPCAM[i+1]+'.npy')[:,ind_input]),axis=0)
128
+ gc.collect()
129
+ np.save(pp_SPCAM+'all_inputs.npy',test_SPCAM_in)
130
+ print('Final data shape: ', test_SPCAM_in.shape)
131
+
132
+ if SPCAM_test_output == 1:
133
+ test_SPCAM_out = np.load(pp_SPCAM+'outputs_'+test_SPCAM[0]+'.npy')[:,ind_output]
134
+ gc.collect()
135
+ for i in range(len(test_SPCAM)-1):
136
+ print(test_SPCAM[i+1])
137
+ test_SPCAM_out = np.concatenate((test_SPCAM_out,
138
+ np.load(pp_SPCAM+'outputs_'+test_SPCAM[i+1]+'.npy')[:,ind_output]),axis=0)
139
+ gc.collect()
140
+ if is_output_heat == 1:
141
+ np.save(pp_SPCAM+'all_outputs_heat.npy',test_SPCAM_out)
142
+ else:
143
+ np.save(pp_SPCAM+'all_outputs_moist.npy',test_SPCAM_out)
144
+ print('Final data shape: ', test_SPCAM_out.shape)
2_candle_plots_data_distr.py ADDED
@@ -0,0 +1,175 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ """
4
+ Created on Tue Apr 18 12:31:04 2023
5
+
6
+ @author: mohamedazizbhouri
7
+ """
8
+
9
+ import os
10
+ os.environ['KMP_DUPLICATE_LIB_OK']='True'
11
+
12
+ import numpy as np
13
+ import matplotlib as mpl
14
+
15
+ def figsize(scale, nplots = 1):
16
+ fig_width_pt = 390.0
17
+ inches_per_pt = 1.0/72.27 # Convert pt to inch
18
+ golden_mean = (np.sqrt(5.0)-1.0)/2.0 # Aesthetic ratio (you could change this)
19
+ fig_width = fig_width_pt*inches_per_pt*scale # width in inches
20
+ fig_height = nplots*fig_width*golden_mean # height in inches
21
+ fig_size = [fig_width,fig_height]
22
+ return fig_size
23
+
24
+ pgf_with_latex = {
25
+ "font.monospace": [],
26
+ "axes.labelsize": 32,
27
+ "axes.titlesize": 32,
28
+ "axes.linewidth": 3,
29
+ "font.size": 32,
30
+ "lines.linewidth": 3,
31
+ "legend.fontsize": 32,
32
+ "xtick.labelsize": 32,
33
+ "ytick.labelsize": 32,
34
+ "figure.figsize": figsize(1.0)}
35
+ mpl.rcParams.update(pgf_with_latex)
36
+
37
+ import matplotlib.pyplot as plt
38
+
39
+ plt.ticklabel_format(axis='both', style='sci', scilimits=(0,0))
40
+
41
+ def newfig(width, nplots = 1):
42
+ fig = plt.figure(figsize=figsize(width, nplots))
43
+ ax = fig.add_subplot(111)
44
+ return fig, ax
45
+
46
+ def savefig(filename, crop = True):
47
+ if crop == True:
48
+ plt.savefig('{}.png'.format(filename), bbox_inches='tight', pad_inches=0.1 , dpi = 300)
49
+ else:
50
+ plt.savefig('{}.png'.format(filename), dpi = 300)
51
+
52
+ plt.close('all')
53
+
54
+ is_5_pr_lvls_heat_tend_and_spec_hum = 1 # to plot 5 pressure levels for heat tendency and specific humidity
55
+ is_1st_lvl_SS_moist_tend = 1 # to plot highest pressure level (lowest altitude) for moist tendency
56
+
57
+ if 1==1:
58
+
59
+ with_fliers = False
60
+ print('loading data')
61
+
62
+ CAM5_4K = np.load('data_CAM5_4K/all_outputs_moist.npy')
63
+ CAM5_8K = np.load('data_CAM5_8K/all_outputs_moist.npy')
64
+ SPCAM5_hist = np.load('data_SPCAM5_hist/three_month_outputs_moist.npy')
65
+ SPCAM5_4K = np.load('data_SPCAM5_4K/all_outputs_moist.npy')
66
+
67
+ name = ['958 hPa']
68
+
69
+ CAM5_4K = np.array(CAM5_4K,dtype=np.float64)
70
+ CAM5_8K = np.array(CAM5_8K,dtype=np.float64)
71
+ SPCAM5_hist = np.array(SPCAM5_hist,dtype=np.float64)
72
+ SPCAM5_4K = np.array(SPCAM5_4K,dtype=np.float64)
73
+
74
+ print('data loaded, making candle plots')
75
+
76
+ Data_CAM5_4K = [CAM5_4K[:,25]]
77
+ Data_CAM5_8K = [CAM5_8K[:,25]]
78
+ Data_SPCAM5_hist = [SPCAM5_hist[:,25]]
79
+ Data_SPCAM5_4K = [SPCAM5_4K[:,25]]
80
+
81
+ fig = plt.figure()
82
+ fig.set_size_inches(8, 15)
83
+
84
+ for j in range(1):
85
+ ax = plt.subplot(1, 1, j+1)
86
+ ax.ticklabel_format(axis="y", style="sci", scilimits=(0,0))
87
+ bp1 = ax.boxplot([Data_SPCAM5_hist[j]], positions=[1], patch_artist=True, notch=True, boxprops=dict(facecolor="red"), showfliers=with_fliers)
88
+ bp2 = ax.boxplot([Data_SPCAM5_4K[j]], positions=[1.5], patch_artist=True, notch=True, boxprops=dict(facecolor="orange"), showfliers=with_fliers)
89
+ bp3 = ax.boxplot([Data_CAM5_4K[j]], positions=[2], patch_artist=True, notch=True, boxprops=dict(facecolor="blue"), showfliers=with_fliers)
90
+ bp4 = ax.boxplot([Data_CAM5_8K[j]], positions=[2.5], patch_artist=True, notch=True, boxprops=dict(facecolor="pink"), showfliers=with_fliers)
91
+ ax.ticklabel_format(axis="y", style="sci", scilimits=(0,0))
92
+ ax.set_xticklabels([])
93
+ ax.set_xticks([])
94
+ if j == 0:
95
+ ax.legend([bp1["boxes"][0], bp2["boxes"][0], bp3["boxes"][0], bp4["boxes"][0]],
96
+ ['SPCAM5 hist 3 m. (HF tr.)', 'SPCAM5 +4K 1 y. (HF ts.)', 'CAM5 +4K 1 y.', 'CAM5 +8K 1 y. (LF tr.)'], ncol=1, loc='upper center', bbox_to_anchor=[0.5, 1.3])#bbox_to_anchor=(2,1.2))#2.95, 1.5))
97
+ savefig('candle_plots_1st_lvl_SS_moist_tend', True)
98
+
99
+
100
+ if is_5_pr_lvls_heat_tend_and_spec_hum == 1:
101
+
102
+ with_fliers = False
103
+ print('loading data')
104
+
105
+ CAM5_4K_v1 = np.load('data_CAM5_4K/all_outputs_heat.npy')
106
+ CAM5_8K_v1 = np.load('data_CAM5_8K/all_outputs_heat.npy')
107
+ SPCAM5_hist_v1 = np.load('data_SPCAM5_hist/three_month_outputs_heat.npy')
108
+
109
+ CAM5_4K_v2 = np.load('data_CAM5_4K/all_inputs.npy')[:,26:26*2]
110
+ CAM5_8K_v2 = np.load('data_CAM5_8K/all_inputs.npy')[:,26:26*2]
111
+ SPCAM5_hist_v2 = np.load('data_SPCAM5_hist/three_month_inputs.npy')[:,26:26*2]
112
+
113
+ name = ['137 hPa', '259 hPa', '494 hPa', '761 hPa', '958 hPa']
114
+
115
+ name2 = ['3.5', '7.4', '14', '24', '37', '53', '70', '85', '100', '117',
116
+ '137', '160', '188', '221', '259', '305', '358', '420', '494',
117
+ '581', '673', '761', '837', '897', '937', '958']
118
+
119
+ CAM5_4K_v1 = np.array(CAM5_4K_v1,dtype=np.float64)
120
+ CAM5_8K_v1 = np.array(CAM5_8K_v1,dtype=np.float64)
121
+ SPCAM5_hist_v1 = np.array(SPCAM5_hist_v1,dtype=np.float64)
122
+
123
+ CAM5_4K_v2 = np.array(CAM5_4K_v2,dtype=np.float64)
124
+ CAM5_8K_v2 = np.array(CAM5_8K_v2,dtype=np.float64)
125
+ SPCAM5_hist_v2 = np.array(SPCAM5_hist_v2,dtype=np.float64)
126
+
127
+ print('data loaded, making candle plots')
128
+
129
+ Data_CAM5_4K_v1 = [CAM5_4K_v1[:,10],CAM5_4K_v1[:,14],CAM5_4K_v1[:,18],CAM5_4K_v1[:,21],CAM5_4K_v1[:,25]]
130
+ Data_CAM5_8K_v1 = [CAM5_8K_v1[:,10],CAM5_8K_v1[:,14],CAM5_8K_v1[:,18],CAM5_8K_v1[:,21],CAM5_8K_v1[:,25]]
131
+ Data_SPCAM5_hist_v1 = [SPCAM5_hist_v1[:,10],SPCAM5_hist_v1[:,14],SPCAM5_hist_v1[:,18],SPCAM5_hist_v1[:,21],SPCAM5_hist_v1[:,25]]
132
+
133
+ Data_CAM5_4K_v2 = [CAM5_4K_v2[:,10],CAM5_4K_v2[:,14],CAM5_4K_v2[:,18],CAM5_4K_v2[:,21],CAM5_4K_v2[:,25]]
134
+ Data_CAM5_8K_v2 = [CAM5_8K_v2[:,10],CAM5_8K_v2[:,14],CAM5_8K_v2[:,18],CAM5_8K_v2[:,21],CAM5_8K_v2[:,25]]
135
+ Data_SPCAM5_hist_v2 = [SPCAM5_hist_v2[:,10],SPCAM5_hist_v2[:,14],SPCAM5_hist_v2[:,18],SPCAM5_hist_v2[:,21],SPCAM5_hist_v2[:,25]]
136
+
137
+ fig = plt.figure()
138
+ fig.set_size_inches(32, 18)
139
+
140
+ for j in range(5):
141
+ ax = plt.subplot(2, 5, j+1)
142
+ ax.ticklabel_format(axis="y", style="sci", scilimits=(0,0))
143
+ bp1 = ax.boxplot([Data_SPCAM5_hist_v1[j]], positions=[1], patch_artist=True, notch=True, boxprops=dict(facecolor="red"), showfliers=with_fliers)
144
+ bp2 = ax.boxplot([Data_CAM5_4K_v1[j]], positions=[1.5], patch_artist=True, notch=True, boxprops=dict(facecolor="blue"), showfliers=with_fliers)
145
+ bp3 = ax.boxplot([Data_CAM5_8K_v1[j]], positions=[2], patch_artist=True, notch=True, boxprops=dict(facecolor="pink"), showfliers=with_fliers)
146
+ ax.ticklabel_format(axis="y", style="sci", scilimits=(0,0))
147
+
148
+ ax.set_xticklabels([])
149
+ ax.set_xticks([])
150
+ ax.set_xlabel(name[j])
151
+
152
+
153
+ if j == 0:
154
+ ax.set_ylabel('Heat tendency (K/s)')
155
+
156
+ if j == 2:
157
+ ax.legend([bp1["boxes"][0], bp2["boxes"][0], bp3["boxes"][0]],
158
+ ['SPCAM5 hist 3 m. (HF tr.)', 'CAM5 +4K 1 y.', 'CAM5 +8K 1 y.'], ncol=3, loc='upper center', bbox_to_anchor=[0.5, 1.25])#bbox_to_anchor=(2,1.2))#2.95, 1.5))
159
+ for j in range(5):
160
+ ax = plt.subplot(2, 5, 5+j+1)
161
+ ax.ticklabel_format(axis="y", style="sci", scilimits=(0,0))
162
+ bp1 = ax.boxplot([Data_SPCAM5_hist_v2[j]], positions=[1], patch_artist=True, notch=True, boxprops=dict(facecolor="red"), showfliers=with_fliers)
163
+ bp2 = ax.boxplot([Data_CAM5_4K_v2[j]], positions=[1.5], patch_artist=True, notch=True, boxprops=dict(facecolor="blue"), showfliers=with_fliers)
164
+ bp3 = ax.boxplot([Data_CAM5_8K_v2[j]], positions=[2], patch_artist=True, notch=True, boxprops=dict(facecolor="pink"), showfliers=with_fliers)
165
+ ax.ticklabel_format(axis="y", style="sci", scilimits=(0,0))
166
+
167
+ ax.set_xticklabels([])
168
+ ax.set_xticks([])
169
+ ax.set_xlabel(name[j])
170
+
171
+
172
+ if j == 0:
173
+ ax.set_ylabel('Specific humidity (kg/kg)')
174
+
175
+ savefig('candle_plots_5_pr_lvls_heat_tend_and_spec_hum', True)
2_norm.py ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ """
4
+ Created on Wed Apr 19 23:40:45 2023
5
+
6
+ @author: mohamedazizbhouri
7
+ """
8
+
9
+ import numpy as np
10
+
11
+ is_input = 0 # 0 or 1
12
+ case_var = 'moist' # 'moist' or 'heat' if is_input == 0
13
+ sim = 'CAM' # 'CAM' or 'SPCAM'
14
+
15
+ if sim == 'CAM':
16
+ if is_input == 1:
17
+ X = np.load('data_CAM5_8K/all_inputs.npy')
18
+ X = np.array(X,dtype=np.float64)
19
+
20
+ mu_X_CAM5, sigma_X_CAM5 = [], []
21
+ # we do not use the vectorial format of computing mean and std on purpose
22
+ # in order to avoid the risk of precision error given the dataset size
23
+ for i in range(X.shape[1]):
24
+ mu_X_CAM5.append(np.mean(X[:,i]))
25
+ sigma_X_CAM5.append(np.std(X[:,i]))
26
+ mu_X_CAM5 = np.array(np.array(mu_X_CAM5),dtype=np.float32)
27
+ sigma_X_CAM5 = np.array(np.array(sigma_X_CAM5),dtype=np.float32)
28
+ np.save('norm/mu_X_CAM5.npy',mu_X_CAM5)
29
+ np.save('norm/sigma_X_CAM5.npy',sigma_X_CAM5)
30
+ else:
31
+ if case_var == 'moist':
32
+ X = np.load('data_CAM5_8K/all_outputs_moist.npy')
33
+ X = np.array(X,dtype=np.float64)
34
+
35
+ mu_y_moist_CAM5, sigma_y_moist_CAM5 = [], []
36
+ for i in range(X.shape[1]):
37
+ mu_y_moist_CAM5.append(np.mean(X[:,i]))
38
+ sigma_y_moist_CAM5.append(np.std(X[:,i]))
39
+ mu_y_moist_CAM5 = np.array(np.array(mu_y_moist_CAM5),dtype=np.float32)
40
+ sigma_y_moist_CAM5 = np.array(np.array(sigma_y_moist_CAM5),dtype=np.float32)
41
+ np.save('norm/mu_y_moist_CAM5.npy',mu_y_moist_CAM5)
42
+ np.save('norm/sigma_y_moist_CAM5.npy',sigma_y_moist_CAM5)
43
+ else:
44
+ X = np.load('data_CAM5_8K/all_outputs_heat.npy')
45
+ X = np.array(X,dtype=np.float64)
46
+
47
+ mu_y_heat_CAM5, sigma_y_heat_CAM5 = [], []
48
+ for i in range(X.shape[1]):
49
+ mu_y_heat_CAM5.append(np.mean(X[:,i]))
50
+ sigma_y_heat_CAM5.append(np.std(X[:,i]))
51
+ mu_y_heat_CAM5 = np.array(np.array(mu_y_heat_CAM5),dtype=np.float32)
52
+ sigma_y_heat_CAM5 = np.array(np.array(sigma_y_heat_CAM5),dtype=np.float32)
53
+ np.save('norm/mu_y_heat_CAM5.npy',mu_y_heat_CAM5)
54
+ np.save('norm/sigma_y_heat_CAM5.npy',sigma_y_heat_CAM5)
55
+ elif sim == 'SPCAM':
56
+ if is_input == 1:
57
+ X = np.load('data_SPCAM5_hist/three_month_inputs.npy')
58
+ X = np.array(X,dtype=np.float64)
59
+
60
+ mu_X_SPCAM5, sigma_X_SPCAM5 = [], []
61
+ # we do not use the vectorial format of computing mean and std on purpose
62
+ # in order to avoid the risk of precision error given the dataset size
63
+ for i in range(X.shape[1]):
64
+ mu_X_SPCAM5.append(np.mean(X[:,i]))
65
+ sigma_X_SPCAM5.append(np.std(X[:,i]))
66
+ mu_X_SPCAM5 = np.array(np.array(mu_X_SPCAM5),dtype=np.float32)
67
+ sigma_X_SPCAM5 = np.array(np.array(sigma_X_SPCAM5),dtype=np.float32)
68
+ np.save('norm/mu_X_SPCAM5.npy',mu_X_SPCAM5)
69
+ np.save('norm/sigma_X_SPCAM5.npy',sigma_X_SPCAM5)
70
+ else:
71
+ if case_var == 'moist':
72
+ X = np.load('data_SPCAM5_hist/three_month_outputs_moist.npy')
73
+ X = np.array(X,dtype=np.float64)
74
+
75
+ mu_y_moist_SPCAM5, sigma_y_moist_SPCAM5 = [], []
76
+ for i in range(X.shape[1]):
77
+ mu_y_moist_SPCAM5.append(np.mean(X[:,i]))
78
+ sigma_y_moist_SPCAM5.append(np.std(X[:,i]))
79
+ mu_y_moist_SPCAM5 = np.array(np.array(mu_y_moist_SPCAM5),dtype=np.float32)
80
+ sigma_y_moist_SPCAM5 = np.array(np.array(sigma_y_moist_SPCAM5),dtype=np.float32)
81
+ np.save('norm/mu_y_moist_SPCAM5.npy',mu_y_moist_SPCAM5)
82
+ np.save('norm/sigma_y_moist_SPCAM5.npy',sigma_y_moist_SPCAM5)
83
+ else:
84
+ X = np.load('data_SPCAM5_hist/three_month_outputs_heat.npy')
85
+ X = np.array(X,dtype=np.float64)
86
+
87
+ mu_y_heat_SPCAM5, sigma_y_heat_SPCAM5 = [], []
88
+ for i in range(X.shape[1]):
89
+ mu_y_heat_SPCAM5.append(np.mean(X[:,i]))
90
+ sigma_y_heat_SPCAM5.append(np.std(X[:,i]))
91
+ mu_y_heat_SPCAM5 = np.array(np.array(mu_y_heat_SPCAM5),dtype=np.float32)
92
+ sigma_y_heat_SPCAM5 = np.array(np.array(sigma_y_heat_SPCAM5),dtype=np.float32)
93
+ np.save('norm/mu_y_heat_SPCAM5.npy',mu_y_heat_SPCAM5)
94
+ np.save('norm/sigma_y_heat_SPCAM5.npy',sigma_y_heat_SPCAM5)
3_train_RPN_MF.py ADDED
@@ -0,0 +1,325 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ """
4
+ Created on Mon May 1 17:19:00 2023
5
+
6
+ @author: mohamedazizbhouri
7
+ """
8
+
9
+ import os
10
+ os.environ['XLA_PYTHON_CLIENT_PREALLOCATE']='false'
11
+
12
+ from jax import numpy as np
13
+ from jax import vmap, jit, random
14
+ import numpy as onp
15
+
16
+ import time
17
+
18
+ ##########################################################
19
+ ##########################################################
20
+ ##########################################################
21
+
22
+ def leakyRELU(x):
23
+ return np.where(x > 0, x, x * 0.15)
24
+
25
+ def MLP(layers, activation=leakyRELU): # np.tanh
26
+ def init(rng_key):
27
+ def init_layer(key, d_in, d_out):
28
+ k1, k2 = random.split(key)
29
+ glorot_stddev = 1. / np.sqrt((d_in + d_out) / 2.)
30
+ W = glorot_stddev*random.normal(k1, (d_in, d_out))
31
+ b = np.zeros(d_out)
32
+ return W, b
33
+ key, *keys = random.split(rng_key, len(layers))
34
+ params = list(map(init_layer, keys, layers[:-1], layers[1:]))
35
+ return params
36
+ def apply(params, inputs):
37
+ for W, b in params[:-1]:
38
+ outputs = np.dot(inputs, W) + b
39
+ inputs = activation(outputs)
40
+ W, b = params[-1]
41
+ outputs = np.dot(inputs, W) + b
42
+ return outputs
43
+ return init, apply
44
+
45
+ ##########################################################
46
+ ##########################################################
47
+ ##########################################################
48
+
49
+ from jax import grad
50
+ from jax.example_libraries import optimizers
51
+ from functools import partial
52
+ import itertools
53
+
54
+ def exponential_decay_loc(step_size, decay_steps, decay_rate):
55
+ def schedule(i):
56
+ return step_size * decay_rate ** (i / decay_steps)
57
+ return schedule
58
+
59
+ # Define the model
60
+ class EnsembleRegression:
61
+ def __init__(self, layers_H, layers_L, ensemble_size, rng_key = random.PRNGKey(0)):
62
+ # Network initialization and evaluation functions
63
+ self.init_H, self.apply_H = MLP(layers_H)
64
+ self.init_prior_H, self.apply_prior_H = MLP(layers_H)
65
+
66
+ self.init_L, self.apply_L = MLP(layers_L)
67
+ self.init_prior_L, self.apply_prior_L = MLP(layers_L)
68
+
69
+ # Random keys
70
+ k1, k2, k3 = random.split(rng_key, 3)
71
+ keys_1 = random.split(k1, ensemble_size)
72
+ keys_2 = random.split(k2, ensemble_size)
73
+ keys_3 = random.split(k3, ensemble_size)
74
+
75
+ # Initialize
76
+ params = vmap(self.init_H)(keys_1)
77
+ params_prior = vmap(self.init_prior_H)(keys_2)
78
+
79
+ rng_key, _ = random.split(rng_key, 2)
80
+ k1, k2, k3 = random.split(rng_key, 3)
81
+ keys_1 = random.split(k1, ensemble_size)
82
+ keys_2 = random.split(k2, ensemble_size)
83
+ keys_3 = random.split(k3, ensemble_size)
84
+ params = params + vmap(self.init_L)(keys_1)
85
+ params_prior = params_prior + vmap(self.init_prior_L)(keys_2)
86
+
87
+ # Use optimizers to set optimizer initialization and update functions
88
+ lr = optimizers.exponential_decay(1e-4, decay_steps=1000, decay_rate=0.99)
89
+ self.opt_init, \
90
+ self.opt_update, \
91
+ self.get_params = optimizers.adam(lr)
92
+
93
+ self.opt_state = vmap(self.opt_init)(params)
94
+ self.prior_opt_state = vmap(self.opt_init)(params_prior)
95
+ self.key_opt_state = vmap(self.opt_init)(keys_3)
96
+
97
+ # Logger
98
+ self.itercount = itertools.count()
99
+ self.loss_log = []
100
+ self.loss_log_L = []
101
+ self.loss_log_H = []
102
+
103
+ # Define the forward pass
104
+ def net_forward_H(self, params, params_prior, inputs):
105
+ Y_pred = self.apply_H(params, inputs) + self.apply_prior_H(params_prior, inputs)
106
+ return Y_pred
107
+ def net_forward_L(self, params, params_prior, inputs):
108
+ Y_pred = self.apply_L(params, inputs) + self.apply_prior_L(params_prior, inputs)
109
+ return Y_pred
110
+
111
+ def loss(self, params, params_prior, batch, batch_L):
112
+ inputs, targets = batch
113
+ inputs_L, targets_L = batch_L
114
+ outputs = vmap(self.net_forward_H, (None, None, 0))(params[:len(layers_H)-1], params_prior[:len(layers_H)-1], inputs)
115
+ outputs_L = vmap(self.net_forward_L, (None, None, 0))(params[len(layers_H)-1:], params_prior[len(layers_H)-1:], inputs_L)
116
+ loss = np.mean((targets - outputs)**2) + alpha * np.mean((targets_L - outputs_L)**2)
117
+ return loss
118
+ def loss_H(self, params, params_prior, batch):
119
+ inputs, targets = batch
120
+ outputs = vmap(self.net_forward_H, (None, None, 0))(params, params_prior, inputs)
121
+ loss_H = np.mean((targets - outputs)**2)
122
+ return loss_H
123
+ def loss_L(self, params, params_prior, batch):
124
+ inputs, targets = batch
125
+ outputs = vmap(self.net_forward_L, (None, None, 0))(params, params_prior, inputs)
126
+ loss_L = np.mean((targets - outputs)**2)
127
+ return loss_L
128
+
129
+ # Define the update step
130
+ def step(self, i, opt_state, prior_opt_state, key_opt_state, batch, batch_L):
131
+ params = self.get_params(opt_state)
132
+ params_prior = self.get_params(prior_opt_state)
133
+ g = grad(self.loss)(params, params_prior, batch, batch_L)
134
+ return self.opt_update(i, g, opt_state)
135
+
136
+ def monitor_loss(self, opt_state, prior_opt_state, batch, batch_L):
137
+ params = self.get_params(opt_state)
138
+ params_prior = self.get_params(prior_opt_state)
139
+ loss_value = self.loss(params, params_prior, batch, batch_L)
140
+ return loss_value
141
+ def monitor_loss_H(self, opt_state, prior_opt_state, batch):
142
+ params = self.get_params(opt_state)[:len(layers_H)-1]
143
+ params_prior = self.get_params(prior_opt_state)[:len(layers_H)-1]
144
+ loss_value = self.loss_H(params, params_prior, batch)
145
+ return loss_value
146
+ def monitor_loss_L(self, opt_state, prior_opt_state, batch):
147
+ params = self.get_params(opt_state)[len(layers_H)-1:]
148
+ params_prior = self.get_params(prior_opt_state)[len(layers_H)-1:]
149
+ loss_value = self.loss_L(params, params_prior, batch)
150
+ return loss_value
151
+
152
+ def predict_L(self, x):
153
+ params = self.get_params(self.opt_state)[len(layers_H)-1:]
154
+ params_prior = self.get_params(self.prior_opt_state)[len(layers_H)-1:]
155
+ samples = self.posterior(params, params_prior, x)
156
+ return samples
157
+
158
+ # Evaluates predictions at test points
159
+ @partial(jit, static_argnums=(0,))
160
+ def posterior(self, params, params_prior, inputs):
161
+ samples = vmap(self.net_forward_L, (0, 0, 0))(params, params_prior, inputs)
162
+ return samples
163
+
164
+ def train(self, nIter = 1000):
165
+ # Define vectorized SGD step across the entire ensemble
166
+ v_step = jit(vmap(self.step, in_axes = (None, 0, 0, 0, 0, 0)))
167
+ v_monitor_loss = jit(vmap(self.monitor_loss, in_axes = (0, 0, 0, 0)))
168
+ v_monitor_loss_H = jit(vmap(self.monitor_loss_H, in_axes = (0, 0, 0)))
169
+ v_monitor_loss_L = jit(vmap(self.monitor_loss_L, in_axes = (0, 0, 0)))
170
+
171
+ # Main training loop
172
+ tt = time.time()
173
+ for it in range(nIter):
174
+ id_SF = it%nb_SF
175
+ id_b_MF = it%nb_MF
176
+ pred_L = self.predict_L( (batches_in_SF[0][id_SF][None,:,:]-mu_MF_in)/sigma_MF_in )
177
+ batch = pred_L, (batches_out_SF[0][id_SF][None,:,:]-mu_SF_out)/sigma_SF_out
178
+
179
+ batch_L = (batches_in_MF[0][id_b_MF][None,:,:]-mu_MF_in)/sigma_MF_in, (batches_out_MF[0][id_b_MF][None,:,:]-mu_MF_out)/sigma_MF_out
180
+
181
+ self.opt_state = v_step(it, self.opt_state, self.prior_opt_state, self.key_opt_state, batch, batch_L)
182
+
183
+ if it % nloss == 0:
184
+ loss_value = v_monitor_loss(self.opt_state, self.prior_opt_state, batch, batch_L)
185
+ loss_value_H = v_monitor_loss_H(self.opt_state, self.prior_opt_state, batch)
186
+ loss_value_L = v_monitor_loss_L(self.opt_state, self.prior_opt_state, batch_L)
187
+ self.loss_log.append(loss_value)
188
+ self.loss_log_H.append(loss_value_H)
189
+ self.loss_log_L.append(loss_value_L)
190
+ print(it, nIter, time.time() - tt, n_run_param)
191
+ tt = time.time()
192
+ if (it+1) % nsave == 0:
193
+ params = vmap(self.get_params)(self.opt_state)
194
+ params_H = params[:len(layers_H)-1]
195
+ params_L = params[len(layers_H)-1:]
196
+ for i in range(len(layers_H)-1):
197
+ for j in range(2):
198
+ np.save('MF_param/MF_param_'+str(n_run_param)+'/HF_params_'+str(i)+'_'+str(j),params_H[i][j])
199
+ for i in range(len(layers_L)-1):
200
+ for j in range(2):
201
+ np.save('MF_param/MF_param_'+str(n_run_param)+'/LF_params_'+str(i)+'_'+str(j),params_L[i][j])
202
+
203
+ ##########################################################
204
+ ##########################################################
205
+ ##########################################################
206
+
207
+ n_remove = 4
208
+ ind_input = np.concatenate( (np.arange(26),n_remove+26+np.arange(26-n_remove),np.array([52,53,54,55])) )
209
+ dim_xH = ind_input.shape[0]
210
+ dim_xL = ind_input.shape[0]
211
+
212
+ ind_output_heat = np.arange(26)
213
+ ind_output_moist = n_remove+np.arange(26-n_remove)
214
+
215
+ dim_yH = ind_output_heat.shape[0]+ind_output_moist.shape[0]
216
+ dim_yL = ind_output_heat.shape[0]+ind_output_moist.shape[0]
217
+
218
+ ensemble_size = 1
219
+
220
+ layers_H = [dim_yL, 512, 512, 512, 512, 512, 512, 512, dim_yH]
221
+ layers_L = [dim_xL, 512, 512, 512, 512, 512, 512, 512, dim_yL]
222
+
223
+ n_run_param = 0
224
+ batch_size_MF = 2048
225
+ batch_size_SF = 2048
226
+ nsave = 50000
227
+ nloss = 500
228
+ alpha = 1.0
229
+
230
+ nepoch = 5
231
+
232
+ mu_SF_out = onp.concatenate((onp.load('norm/mu_y_heat_CAM5.npy')[None,None,ind_output_heat],
233
+ onp.load('norm/mu_y_moist_CAM5.npy')[None,None,ind_output_moist]),axis=2)
234
+ sigma_SF_out = onp.concatenate((onp.load('norm/sigma_y_heat_CAM5.npy')[None,None,ind_output_heat],
235
+ onp.load('norm/sigma_y_moist_CAM5.npy')[None,None,ind_output_moist]),axis=2)
236
+
237
+ mu_MF_in = onp.load('norm/mu_X_CAM5.npy')[None,None,ind_input]
238
+ sigma_MF_in = onp.load('norm/sigma_X_CAM5.npy')[None,None,ind_input]
239
+ mu_MF_out = onp.concatenate((onp.load('norm/mu_y_heat_CAM5.npy')[None,None,ind_output_heat],
240
+ onp.load('norm/mu_y_moist_CAM5.npy')[None,None,ind_output_moist]),axis=2)
241
+ sigma_MF_out = onp.concatenate((onp.load('norm/sigma_y_heat_CAM5.npy')[None,None,ind_output_heat],
242
+ onp.load('norm/sigma_y_moist_CAM5.npy')[None,None,ind_output_moist]),axis=2)
243
+ print('loading data')
244
+
245
+ train_MF_in = onp.load('data_CAM5_8K/all_inputs.npy')[:,ind_input]
246
+ train_MF_out = onp.concatenate((onp.load('data_CAM5_8K/all_outputs_heat.npy')[:,ind_output_heat],
247
+ onp.load('data_CAM5_8K/all_outputs_moist.npy')[:,ind_output_moist]),axis=1)
248
+ train_SF_in = onp.load('data_SPCAM5_hist/three_month_inputs.npy')[:,ind_input]
249
+ train_SF_out = onp.concatenate((onp.load('data_SPCAM5_hist/three_month_outputs_heat.npy')[:,ind_output_heat],
250
+ onp.load('data_SPCAM5_hist/three_month_outputs_moist.npy')[:,ind_output_moist]),axis=1)
251
+ print('data loaded')
252
+
253
+ N_tot_MF = 121098240
254
+ N_tot_SF = 29528064
255
+
256
+ N_rpn_MF = 96878592
257
+ N_rpn_SF = 23623680
258
+
259
+ nb_MF = 47304
260
+ nb_SF = 11535
261
+
262
+ batches_in_MF = []
263
+ batches_out_MF = []
264
+ batches_in_SF = []
265
+ batches_out_SF = []
266
+
267
+ for i in range(ensemble_size):
268
+ print(i,ensemble_size)
269
+
270
+ idx_SF = onp.arange(N_rpn_SF)
271
+ idx_MF = onp.arange(N_tot_MF)
272
+
273
+ onp.random.seed(n_run_param)
274
+ onp.random.shuffle(idx_SF)
275
+
276
+ onp.random.seed(n_run_param)
277
+ onp.random.shuffle(idx_MF)
278
+
279
+ batches_in_MF_loc = []
280
+ batches_out_MF_loc = []
281
+ batches_in_SF_loc = []
282
+ batches_out_SF_loc = []
283
+
284
+ for j in range(nb_MF):
285
+ if j % (nb_MF%5000) == 0:
286
+ print(i,'MF',j,nb_MF)
287
+ batches_in_MF_loc.append( train_MF_in[idx_MF[:N_rpn_MF][j*batch_size_MF:(j+1)*batch_size_MF],:] )
288
+ batches_out_MF_loc.append( train_MF_out[idx_MF[:N_rpn_MF][j*batch_size_MF:(j+1)*batch_size_MF],:] )
289
+ for j in range(nb_SF):
290
+ if j % (nb_SF%5000) == 0:
291
+ print(i,'SF',j,nb_SF)
292
+ batches_in_SF_loc.append( train_SF_in[idx_SF[:N_rpn_SF][j*batch_size_SF:(j+1)*batch_size_SF],:] )
293
+ batches_out_SF_loc.append( train_SF_out[idx_SF[:N_rpn_SF][j*batch_size_SF:(j+1)*batch_size_SF],:] )
294
+ batches_in_MF.append(batches_in_MF_loc)
295
+ batches_out_MF.append(batches_out_MF_loc)
296
+ batches_in_SF.append(batches_in_SF_loc)
297
+ batches_out_SF.append(batches_out_SF_loc)
298
+
299
+ # Initialize model
300
+ model = EnsembleRegression(layers_H, layers_L, ensemble_size, rng_key = random.PRNGKey(0))
301
+
302
+ params_prior = vmap(model.get_params)(model.prior_opt_state)
303
+ params_prior_H = params_prior[:len(layers_H)-1]
304
+ params_prior_L = params_prior[len(layers_H)-1:]
305
+ print('saving parameters')
306
+ for i in range(len(layers_H)-1):
307
+ for j in range(2):
308
+ np.save('MF_param/MF_param_'+str(n_run_param)+'/HF_params_prior_'+str(i)+'_'+str(j),params_prior_H[i][j])
309
+ for i in range(len(layers_L)-1):
310
+ for j in range(2):
311
+ np.save('MF_param/MF_param_'+str(n_run_param)+'/LF_params_prior_'+str(i)+'_'+str(j),params_prior_L[i][j])
312
+ print('finished saving')
313
+
314
+ # Train model
315
+ model.train(nIter=nepoch*max(nb_MF,nb_SF))
316
+
317
+ params = vmap(model.get_params)(model.opt_state)
318
+ params_H = params[:len(layers_H)-1]
319
+ params_L = params[len(layers_H)-1:]
320
+ for i in range(len(layers_H)-1):
321
+ for j in range(2):
322
+ np.save('MF_param/MF_param_'+str(n_run_param)+'/HF_params_'+str(i)+'_'+str(j),params_H[i][j])
323
+ for i in range(len(layers_L)-1):
324
+ for j in range(2):
325
+ np.save('MF_param/MF_param_'+str(n_run_param)+'/LF_params_'+str(i)+'_'+str(j),params_L[i][j])
3_train_RPN_SF.py ADDED
@@ -0,0 +1,238 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ """
4
+ Created on Mon May 1 17:26:17 2023
5
+
6
+ @author: mohamedazizbhouri
7
+ """
8
+
9
+ import os
10
+ os.environ['XLA_PYTHON_CLIENT_PREALLOCATE']='false'
11
+
12
+ from jax import numpy as np
13
+ from jax import vmap, jit, random
14
+ import numpy as onp
15
+
16
+ import time
17
+
18
+ ##########################################################
19
+ ##########################################################
20
+ ##########################################################
21
+
22
+ def leakyRELU(x):
23
+ return np.where(x > 0, x, x * 0.15)
24
+
25
+ def MLP(layers, activation=leakyRELU): # np.tanh
26
+ def init(rng_key):
27
+ def init_layer(key, d_in, d_out):
28
+ k1, k2 = random.split(key)
29
+ glorot_stddev = 1. / np.sqrt((d_in + d_out) / 2.)
30
+ W = glorot_stddev*random.normal(k1, (d_in, d_out))
31
+ b = np.zeros(d_out)
32
+ return W, b
33
+ key, *keys = random.split(rng_key, len(layers))
34
+ params = list(map(init_layer, keys, layers[:-1], layers[1:]))
35
+ return params
36
+ def apply(params, inputs):
37
+ for W, b in params[:-1]:
38
+ outputs = np.dot(inputs, W) + b
39
+ inputs = activation(outputs)
40
+ W, b = params[-1]
41
+ outputs = np.dot(inputs, W) + b
42
+ return outputs
43
+ return init, apply
44
+
45
+ ##########################################################
46
+ ##########################################################
47
+ ##########################################################
48
+
49
+ from jax import grad
50
+ from jax.example_libraries import optimizers
51
+ import itertools
52
+
53
+ def exponential_decay_loc(step_size, decay_steps, decay_rate):
54
+ def schedule(i):
55
+ return step_size * decay_rate ** (i / decay_steps)
56
+ return schedule
57
+
58
+ # Define the model
59
+ class EnsembleRegression:
60
+ def __init__(self, layers, ensemble_size, rng_key = random.PRNGKey(0)):
61
+ # Network initialization and evaluation functions
62
+ self.init, self.apply = MLP(layers)
63
+ self.init_prior, self.apply_prior = MLP(layers)
64
+
65
+ # Random keys
66
+ k1, k2, k3 = random.split(rng_key, 3)
67
+ keys_1 = random.split(k1, ensemble_size)
68
+ keys_2 = random.split(k2, ensemble_size)
69
+ keys_3 = random.split(k3, ensemble_size)
70
+
71
+ # Initialize
72
+ params = vmap(self.init)(keys_1)
73
+ params_prior = vmap(self.init_prior)(keys_2)
74
+
75
+ # Use optimizers to set optimizer initialization and update functions
76
+ lr = optimizers.exponential_decay(1e-4, decay_steps=1000, decay_rate=0.99)
77
+ self.opt_init, \
78
+ self.opt_update, \
79
+ self.get_params = optimizers.adam(lr)
80
+
81
+ self.opt_state = vmap(self.opt_init)(params)
82
+ self.prior_opt_state = vmap(self.opt_init)(params_prior)
83
+ self.key_opt_state = vmap(self.opt_init)(keys_3)
84
+
85
+ # Logger
86
+ self.itercount = itertools.count()
87
+ self.loss_log = []
88
+
89
+ # Define the forward pass
90
+ def net_forward(self, params, params_prior, inputs):
91
+ Y_pred = self.apply(params, inputs) + self.apply_prior(params_prior, inputs)
92
+ return Y_pred
93
+
94
+ def loss(self, params, params_prior, batch):
95
+ inputs, targets = batch
96
+ # Compute forward pass
97
+ outputs = vmap(self.net_forward, (None, None, 0))(params, params_prior, inputs)
98
+ # Compute loss
99
+ loss = np.mean((targets - outputs)**2)
100
+ return loss
101
+
102
+ # Define the update step
103
+ def step(self, i, opt_state, prior_opt_state, key_opt_state, batch):
104
+ params = self.get_params(opt_state)
105
+ params_prior = self.get_params(prior_opt_state)
106
+ g = grad(self.loss)(params, params_prior, batch)
107
+ return self.opt_update(i, g, opt_state)
108
+
109
+ def monitor_loss(self, opt_state, prior_opt_state, batch):
110
+ params = self.get_params(opt_state)
111
+ params_prior = self.get_params(prior_opt_state)
112
+ loss_value = self.loss(params, params_prior, batch)
113
+ return loss_value
114
+
115
+ # Optimize parameters in a loop
116
+ def train(self, nIter = 1000):
117
+ # Define vectorized SGD step across the entire ensemble
118
+ v_step = jit(vmap(self.step, in_axes = (None, 0, 0, 0, 0)))
119
+ v_monitor_loss = jit(vmap(self.monitor_loss, in_axes = (0, 0, 0)))
120
+
121
+ # Main training loop
122
+ tt = time.time()
123
+ for it in range(nIter):
124
+ id_SF = (it+n_iter_prev)%nb_SF
125
+
126
+ inputs0_H = batches_in_SF[0][id_SF][None,:,:]
127
+ targets0_H = batches_out_SF[0][id_SF][None,:,:]
128
+ for ii in range(ensemble_size-1):
129
+ inputs0_H = onp.concatenate( (inputs0_H,batches_in_SF[ii+1][id_SF][None,:,:]), axis=0)
130
+ targets0_H = onp.concatenate( (targets0_H,batches_out_SF[ii+1][id_SF][None,:,:]), axis=0)
131
+
132
+ batch = (inputs0_H-mu_SF_in)/sigma_SF_in, (targets0_H-mu_SF_out)/sigma_SF_out
133
+
134
+ self.opt_state = v_step(it, self.opt_state, self.prior_opt_state, self.key_opt_state, batch)
135
+
136
+ if it % nloss == 0:
137
+ loss_value = v_monitor_loss(self.opt_state, self.prior_opt_state, batch)
138
+ self.loss_log.append(loss_value)
139
+
140
+ print(it, nIter, time.time() - tt, n_run_param)
141
+ tt = time.time()
142
+ if (it+1) % nsave == 0:
143
+ params = vmap(self.get_params)(self.opt_state)
144
+ for i in range(len(layers_H)-1):
145
+ for j in range(2):
146
+ np.save('SF_param/SF_param_'+str(n_run_param)+'/params_'+str(i)+'_'+str(j),params[i][j])
147
+
148
+ ##########################################################
149
+ ##########################################################
150
+ ##########################################################
151
+
152
+ n_remove = 4
153
+ ind_input = np.concatenate( (np.arange(26),n_remove+26+np.arange(26-n_remove),np.array([52,53,54,55])) )
154
+ dim_xH = ind_input.shape[0]
155
+ dim_xL = ind_input.shape[0]
156
+
157
+ ind_output_heat = np.arange(26)
158
+ ind_output_moist = n_remove+np.arange(26-n_remove)
159
+
160
+ dim_yH = ind_output_heat.shape[0]+ind_output_moist.shape[0]
161
+ dim_yL = ind_output_heat.shape[0]+ind_output_moist.shape[0]
162
+
163
+ ensemble_size = 1
164
+ layers_H = [dim_xH, 512, 512, 512, 512, 512, 512, 512, dim_yH]
165
+
166
+ n_iter_prev = 0
167
+
168
+ n_run_param = 0
169
+ batch_size_SF = 2048
170
+ nsave = 50000
171
+ nloss = 500
172
+
173
+ nepoch = 5
174
+
175
+ mu_SF_in = onp.load('norm/mu_X_SPCAM5.npy')[None,None,ind_input]
176
+ sigma_SF_in = onp.load('norm/sigma_X_SPCAM5.npy')[None,None,ind_input]
177
+
178
+ mu_SF_out = onp.concatenate((onp.load('norm/mu_y_heat_SPCAM5.npy')[None,None,ind_output_heat],
179
+ onp.load('norm/mu_y_moist_SPCAM5.npy')[None,None,ind_output_moist]),axis=2)
180
+ sigma_SF_out = onp.concatenate((onp.load('norm/sigma_y_heat_SPCAM5.npy')[None,None,ind_output_heat],
181
+ onp.load('norm/sigma_y_moist_SPCAM5.npy')[None,None,ind_output_moist]),axis=2)
182
+ print('loading data')
183
+
184
+ train_SF_in = onp.load('data_SPCAM5_hist/three_month_inputs.npy')[:,ind_input]
185
+ train_SF_out = onp.concatenate((onp.load('data_SPCAM5_hist/three_month_outputs_heat.npy')[:,ind_output_heat],
186
+ onp.load('data_SPCAM5_hist/three_month_outputs_moist.npy')[:,ind_output_moist]),axis=1)
187
+ print('data loaded')
188
+
189
+ N_tot_MF = 121098240
190
+ N_tot_SF = 29528064
191
+
192
+ N_rpn_MF = 96878592
193
+ N_rpn_SF = 23623680
194
+
195
+ nb_MF = 47304
196
+ nb_SF = 11535
197
+
198
+ batches_in_SF = []
199
+ batches_out_SF = []
200
+ for i in range(ensemble_size):
201
+ print(i,ensemble_size)
202
+
203
+ idx_SF = onp.arange(N_rpn_SF)
204
+
205
+ onp.random.seed(n_run_param)
206
+ onp.random.shuffle(idx_SF)
207
+
208
+ batches_in_SF_loc = []
209
+ batches_out_SF_loc = []
210
+
211
+ for j in range(nb_SF):
212
+ if j % (nb_SF%5000) == 0:
213
+ print(i,'SF',j,nb_SF)
214
+ batches_in_SF_loc.append( train_SF_in[idx_SF[:N_rpn_SF][j*batch_size_SF:(j+1)*batch_size_SF],:] )
215
+ batches_out_SF_loc.append( train_SF_out[idx_SF[:N_rpn_SF][j*batch_size_SF:(j+1)*batch_size_SF],:] )
216
+ batches_in_SF.append(batches_in_SF_loc)
217
+ batches_out_SF.append(batches_out_SF_loc)
218
+
219
+ model = EnsembleRegression(layers_H, ensemble_size, rng_key = random.PRNGKey(0))#n_run_param))
220
+
221
+ params_prior = vmap(model.get_params)(model.prior_opt_state)
222
+ params_prior_H = params_prior[:len(layers_H)-1]
223
+ params_prior_L = params_prior[len(layers_H)-1:]
224
+ print('saving parameters')
225
+ for i in range(len(layers_H)-1):
226
+ for j in range(2):
227
+ np.save('SF_param/SF_param_'+str(n_run_param)+'/params_prior_'+str(i)+'_'+str(j),params_prior_H[i][j])
228
+ print('finished saving')
229
+
230
+ # Train model
231
+ model.train(nIter=nepoch*max(nb_MF,nb_SF)-n_iter_prev)
232
+
233
+ params = vmap(model.get_params)(model.opt_state)
234
+ params_H = params[:len(layers_H)-1]
235
+ for i in range(len(layers_H)-1):
236
+ for j in range(2):
237
+ np.save('SF_param/SF_param_'+str(n_run_param)+'/params_'+str(i)+'_'+str(j),params_H[i][j])
238
+
4_concat_param.py ADDED
@@ -0,0 +1,429 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ """
4
+ Created on Tue Sep 5 13:42:56 2023
5
+
6
+ @author: mohamedazizbhouri
7
+ """
8
+
9
+ import numpy as np
10
+
11
+ N_param_gp = 128
12
+
13
+ is_MF = 0
14
+ is_LF = 0
15
+ is_SF = 1
16
+
17
+ if is_MF == 1:
18
+ HF_params_0_0 = np.load('MF_param/MF_param_0/HF_params_0_0.npy')
19
+ HF_params_0_1 = np.load('MF_param/MF_param_0/HF_params_0_1.npy')
20
+ HF_params_1_0 = np.load('MF_param/MF_param_0/HF_params_1_0.npy')
21
+ HF_params_1_1 = np.load('MF_param/MF_param_0/HF_params_1_1.npy')
22
+ HF_params_2_0 = np.load('MF_param/MF_param_0/HF_params_2_0.npy')
23
+ HF_params_2_1 = np.load('MF_param/MF_param_0/HF_params_2_1.npy')
24
+ HF_params_3_0 = np.load('MF_param/MF_param_0/HF_params_3_0.npy')
25
+ HF_params_3_1 = np.load('MF_param/MF_param_0/HF_params_3_1.npy')
26
+ HF_params_4_0 = np.load('MF_param/MF_param_0/HF_params_4_0.npy')
27
+ HF_params_4_1 = np.load('MF_param/MF_param_0/HF_params_4_1.npy')
28
+ HF_params_5_0 = np.load('MF_param/MF_param_0/HF_params_5_0.npy')
29
+ HF_params_5_1 = np.load('MF_param/MF_param_0/HF_params_5_1.npy')
30
+ HF_params_6_0 = np.load('MF_param/MF_param_0/HF_params_6_0.npy')
31
+ HF_params_6_1 = np.load('MF_param/MF_param_0/HF_params_6_1.npy')
32
+ HF_params_7_0 = np.load('MF_param/MF_param_0/HF_params_7_0.npy')
33
+ HF_params_7_1 = np.load('MF_param/MF_param_0/HF_params_7_1.npy')
34
+
35
+ HF_params_prior_0_0 = np.load('MF_param/MF_param_0/HF_params_prior_0_0.npy')
36
+ HF_params_prior_0_1 = np.load('MF_param/MF_param_0/HF_params_prior_0_1.npy')
37
+ HF_params_prior_1_0 = np.load('MF_param/MF_param_0/HF_params_prior_1_0.npy')
38
+ HF_params_prior_1_1 = np.load('MF_param/MF_param_0/HF_params_prior_1_1.npy')
39
+ HF_params_prior_2_0 = np.load('MF_param/MF_param_0/HF_params_prior_2_0.npy')
40
+ HF_params_prior_2_1 = np.load('MF_param/MF_param_0/HF_params_prior_2_1.npy')
41
+ HF_params_prior_3_0 = np.load('MF_param/MF_param_0/HF_params_prior_3_0.npy')
42
+ HF_params_prior_3_1 = np.load('MF_param/MF_param_0/HF_params_prior_3_1.npy')
43
+ HF_params_prior_4_0 = np.load('MF_param/MF_param_0/HF_params_prior_4_0.npy')
44
+ HF_params_prior_4_1 = np.load('MF_param/MF_param_0/HF_params_prior_4_1.npy')
45
+ HF_params_prior_5_0 = np.load('MF_param/MF_param_0/HF_params_prior_5_0.npy')
46
+ HF_params_prior_5_1 = np.load('MF_param/MF_param_0/HF_params_prior_5_1.npy')
47
+ HF_params_prior_6_0 = np.load('MF_param/MF_param_0/HF_params_prior_6_0.npy')
48
+ HF_params_prior_6_1 = np.load('MF_param/MF_param_0/HF_params_prior_6_1.npy')
49
+ HF_params_prior_7_0 = np.load('MF_param/MF_param_0/HF_params_prior_7_0.npy')
50
+ HF_params_prior_7_1 = np.load('MF_param/MF_param_0/HF_params_prior_7_1.npy')
51
+
52
+ for i in range(N_param_gp-1):
53
+
54
+ print(i)
55
+ HF_params_0_0 = np.concatenate( (HF_params_0_0,
56
+ np.load('MF_param/MF_param_'+str(i+1)+'/HF_params_0_0.npy')), axis = 0)
57
+ HF_params_0_1 = np.concatenate( (HF_params_0_1,
58
+ np.load('MF_param/MF_param_'+str(i+1)+'/HF_params_0_1.npy')), axis = 0)
59
+ HF_params_1_0 = np.concatenate( (HF_params_1_0,
60
+ np.load('MF_param/MF_param_'+str(i+1)+'/HF_params_1_0.npy')), axis = 0)
61
+ HF_params_1_1 = np.concatenate( (HF_params_1_1,
62
+ np.load('MF_param/MF_param_'+str(i+1)+'/HF_params_1_1.npy')), axis = 0)
63
+ HF_params_2_0 = np.concatenate( (HF_params_2_0,
64
+ np.load('MF_param/MF_param_'+str(i+1)+'/HF_params_2_0.npy')), axis = 0)
65
+ HF_params_2_1 = np.concatenate( (HF_params_2_1,
66
+ np.load('MF_param/MF_param_'+str(i+1)+'/HF_params_2_1.npy')), axis = 0)
67
+ HF_params_3_0 = np.concatenate( (HF_params_3_0,
68
+ np.load('MF_param/MF_param_'+str(i+1)+'/HF_params_3_0.npy')), axis = 0)
69
+ HF_params_3_1 = np.concatenate( (HF_params_3_1,
70
+ np.load('MF_param/MF_param_'+str(i+1)+'/HF_params_3_1.npy')), axis = 0)
71
+ HF_params_4_0 = np.concatenate( (HF_params_4_0,
72
+ np.load('MF_param/MF_param_'+str(i+1)+'/HF_params_4_0.npy')), axis = 0)
73
+ HF_params_4_1 = np.concatenate( (HF_params_4_1,
74
+ np.load('MF_param/MF_param_'+str(i+1)+'/HF_params_4_1.npy')), axis = 0)
75
+ HF_params_5_0 = np.concatenate( (HF_params_5_0,
76
+ np.load('MF_param/MF_param_'+str(i+1)+'/HF_params_5_0.npy')), axis = 0)
77
+ HF_params_5_1 = np.concatenate( (HF_params_5_1,
78
+ np.load('MF_param/MF_param_'+str(i+1)+'/HF_params_5_1.npy')), axis = 0)
79
+ HF_params_6_0 = np.concatenate( (HF_params_6_0,
80
+ np.load('MF_param/MF_param_'+str(i+1)+'/HF_params_6_0.npy')), axis = 0)
81
+ HF_params_6_1 = np.concatenate( (HF_params_6_1,
82
+ np.load('MF_param/MF_param_'+str(i+1)+'/HF_params_6_1.npy')), axis = 0)
83
+ HF_params_7_0 = np.concatenate( (HF_params_7_0,
84
+ np.load('MF_param/MF_param_'+str(i+1)+'/HF_params_7_0.npy')), axis = 0)
85
+ HF_params_7_1 = np.concatenate( (HF_params_7_1,
86
+ np.load('MF_param/MF_param_'+str(i+1)+'/HF_params_7_1.npy')), axis = 0)
87
+
88
+ HF_params_prior_0_0 = np.concatenate( (HF_params_prior_0_0,
89
+ np.load('MF_param/MF_param_'+str(i+1)+'/HF_params_prior_0_0.npy')), axis = 0)
90
+ HF_params_prior_0_1 = np.concatenate( (HF_params_prior_0_1,
91
+ np.load('MF_param/MF_param_'+str(i+1)+'/HF_params_prior_0_1.npy')), axis = 0)
92
+ HF_params_prior_1_0 = np.concatenate( (HF_params_prior_1_0,
93
+ np.load('MF_param/MF_param_'+str(i+1)+'/HF_params_prior_1_0.npy')), axis = 0)
94
+ HF_params_prior_1_1 = np.concatenate( (HF_params_prior_1_1,
95
+ np.load('MF_param/MF_param_'+str(i+1)+'/HF_params_prior_1_1.npy')), axis = 0)
96
+ HF_params_prior_2_0 = np.concatenate( (HF_params_prior_2_0,
97
+ np.load('MF_param/MF_param_'+str(i+1)+'/HF_params_prior_2_0.npy')), axis = 0)
98
+ HF_params_prior_2_1 = np.concatenate( (HF_params_prior_2_1,
99
+ np.load('MF_param/MF_param_'+str(i+1)+'/HF_params_prior_2_1.npy')), axis = 0)
100
+ HF_params_prior_3_0 = np.concatenate( (HF_params_prior_3_0,
101
+ np.load('MF_param/MF_param_'+str(i+1)+'/HF_params_prior_3_0.npy')), axis = 0)
102
+ HF_params_prior_3_1 = np.concatenate( (HF_params_prior_3_1,
103
+ np.load('MF_param/MF_param_'+str(i+1)+'/HF_params_prior_3_1.npy')), axis = 0)
104
+ HF_params_prior_4_0 = np.concatenate( (HF_params_prior_4_0,
105
+ np.load('MF_param/MF_param_'+str(i+1)+'/HF_params_prior_4_0.npy')), axis = 0)
106
+ HF_params_prior_4_1 = np.concatenate( (HF_params_prior_4_1,
107
+ np.load('MF_param/MF_param_'+str(i+1)+'/HF_params_prior_4_1.npy')), axis = 0)
108
+ HF_params_prior_5_0 = np.concatenate( (HF_params_prior_5_0,
109
+ np.load('MF_param/MF_param_'+str(i+1)+'/HF_params_prior_5_0.npy')), axis = 0)
110
+ HF_params_prior_5_1 = np.concatenate( (HF_params_prior_5_1,
111
+ np.load('MF_param/MF_param_'+str(i+1)+'/HF_params_prior_5_1.npy')), axis = 0)
112
+ HF_params_prior_6_0 = np.concatenate( (HF_params_prior_6_0,
113
+ np.load('MF_param/MF_param_'+str(i+1)+'/HF_params_prior_6_0.npy')), axis = 0)
114
+ HF_params_prior_6_1 = np.concatenate( (HF_params_prior_6_1,
115
+ np.load('MF_param/MF_param_'+str(i+1)+'/HF_params_prior_6_1.npy')), axis = 0)
116
+ HF_params_prior_7_0 = np.concatenate( (HF_params_prior_7_0,
117
+ np.load('MF_param/MF_param_'+str(i+1)+'/HF_params_prior_7_0.npy')), axis = 0)
118
+ HF_params_prior_7_1 = np.concatenate( (HF_params_prior_7_1,
119
+ np.load('MF_param/MF_param_'+str(i+1)+'/HF_params_prior_7_1.npy')), axis = 0)
120
+
121
+ np.save('MF_param/saved_param/HF_params_0_0.npy', HF_params_0_0)
122
+ np.save('MF_param/saved_param/HF_params_0_1.npy', HF_params_0_1)
123
+ np.save('MF_param/saved_param/HF_params_1_0.npy', HF_params_1_0)
124
+ np.save('MF_param/saved_param/HF_params_1_1.npy', HF_params_1_1)
125
+ np.save('MF_param/saved_param/HF_params_2_0.npy', HF_params_2_0)
126
+ np.save('MF_param/saved_param/HF_params_2_1.npy', HF_params_2_1)
127
+ np.save('MF_param/saved_param/HF_params_3_0.npy', HF_params_3_0)
128
+ np.save('MF_param/saved_param/HF_params_3_1.npy', HF_params_3_1)
129
+ np.save('MF_param/saved_param/HF_params_4_0.npy', HF_params_4_0)
130
+ np.save('MF_param/saved_param/HF_params_4_1.npy', HF_params_4_1)
131
+ np.save('MF_param/saved_param/HF_params_5_0.npy', HF_params_5_0)
132
+ np.save('MF_param/saved_param/HF_params_5_1.npy', HF_params_5_1)
133
+ np.save('MF_param/saved_param/HF_params_6_0.npy', HF_params_6_0)
134
+ np.save('MF_param/saved_param/HF_params_6_1.npy', HF_params_6_1)
135
+ np.save('MF_param/saved_param/HF_params_7_0.npy', HF_params_7_0)
136
+ np.save('MF_param/saved_param/HF_params_7_1.npy', HF_params_7_1)
137
+
138
+ np.save('MF_param/saved_param/HF_params_prior_0_0.npy', HF_params_prior_0_0)
139
+ np.save('MF_param/saved_param/HF_params_prior_0_1.npy', HF_params_prior_0_1)
140
+ np.save('MF_param/saved_param/HF_params_prior_1_0.npy', HF_params_prior_1_0)
141
+ np.save('MF_param/saved_param/HF_params_prior_1_1.npy', HF_params_prior_1_1)
142
+ np.save('MF_param/saved_param/HF_params_prior_2_0.npy', HF_params_prior_2_0)
143
+ np.save('MF_param/saved_param/HF_params_prior_2_1.npy', HF_params_prior_2_1)
144
+ np.save('MF_param/saved_param/HF_params_prior_3_0.npy', HF_params_prior_3_0)
145
+ np.save('MF_param/saved_param/HF_params_prior_3_1.npy', HF_params_prior_3_1)
146
+ np.save('MF_param/saved_param/HF_params_prior_4_0.npy', HF_params_prior_4_0)
147
+ np.save('MF_param/saved_param/HF_params_prior_4_1.npy', HF_params_prior_4_1)
148
+ np.save('MF_param/saved_param/HF_params_prior_5_0.npy', HF_params_prior_5_0)
149
+ np.save('MF_param/saved_param/HF_params_prior_5_1.npy', HF_params_prior_5_1)
150
+ np.save('MF_param/saved_param/HF_params_prior_6_0.npy', HF_params_prior_6_0)
151
+ np.save('MF_param/saved_param/HF_params_prior_6_1.npy', HF_params_prior_6_1)
152
+ np.save('MF_param/saved_param/HF_params_prior_7_0.npy', HF_params_prior_7_0)
153
+ np.save('MF_param/saved_param/HF_params_prior_7_1.npy', HF_params_prior_7_1)
154
+
155
+ if is_LF == 1:
156
+ LF_params_0_0 = np.load('MF_param/MF_param_0/LF_params_0_0.npy')
157
+ LF_params_0_1 = np.load('MF_param/MF_param_0/LF_params_0_1.npy')
158
+ LF_params_1_0 = np.load('MF_param/MF_param_0/LF_params_1_0.npy')
159
+ LF_params_1_1 = np.load('MF_param/MF_param_0/LF_params_1_1.npy')
160
+ LF_params_2_0 = np.load('MF_param/MF_param_0/LF_params_2_0.npy')
161
+ LF_params_2_1 = np.load('MF_param/MF_param_0/LF_params_2_1.npy')
162
+ LF_params_3_0 = np.load('MF_param/MF_param_0/LF_params_3_0.npy')
163
+ LF_params_3_1 = np.load('MF_param/MF_param_0/LF_params_3_1.npy')
164
+ LF_params_4_0 = np.load('MF_param/MF_param_0/LF_params_4_0.npy')
165
+ LF_params_4_1 = np.load('MF_param/MF_param_0/LF_params_4_1.npy')
166
+ LF_params_5_0 = np.load('MF_param/MF_param_0/LF_params_5_0.npy')
167
+ LF_params_5_1 = np.load('MF_param/MF_param_0/LF_params_5_1.npy')
168
+ LF_params_6_0 = np.load('MF_param/MF_param_0/LF_params_6_0.npy')
169
+ LF_params_6_1 = np.load('MF_param/MF_param_0/LF_params_6_1.npy')
170
+ LF_params_7_0 = np.load('MF_param/MF_param_0/LF_params_7_0.npy')
171
+ LF_params_7_1 = np.load('MF_param/MF_param_0/LF_params_7_1.npy')
172
+
173
+ LF_params_prior_0_0 = np.load('MF_param/MF_param_0/LF_params_prior_0_0.npy')
174
+ LF_params_prior_0_1 = np.load('MF_param/MF_param_0/LF_params_prior_0_1.npy')
175
+ LF_params_prior_1_0 = np.load('MF_param/MF_param_0/LF_params_prior_1_0.npy')
176
+ LF_params_prior_1_1 = np.load('MF_param/MF_param_0/LF_params_prior_1_1.npy')
177
+ LF_params_prior_2_0 = np.load('MF_param/MF_param_0/LF_params_prior_2_0.npy')
178
+ LF_params_prior_2_1 = np.load('MF_param/MF_param_0/LF_params_prior_2_1.npy')
179
+ LF_params_prior_3_0 = np.load('MF_param/MF_param_0/LF_params_prior_3_0.npy')
180
+ LF_params_prior_3_1 = np.load('MF_param/MF_param_0/LF_params_prior_3_1.npy')
181
+ LF_params_prior_4_0 = np.load('MF_param/MF_param_0/LF_params_prior_4_0.npy')
182
+ LF_params_prior_4_1 = np.load('MF_param/MF_param_0/LF_params_prior_4_1.npy')
183
+ LF_params_prior_5_0 = np.load('MF_param/MF_param_0/LF_params_prior_5_0.npy')
184
+ LF_params_prior_5_1 = np.load('MF_param/MF_param_0/LF_params_prior_5_1.npy')
185
+ LF_params_prior_6_0 = np.load('MF_param/MF_param_0/LF_params_prior_6_0.npy')
186
+ LF_params_prior_6_1 = np.load('MF_param/MF_param_0/LF_params_prior_6_1.npy')
187
+ LF_params_prior_7_0 = np.load('MF_param/MF_param_0/LF_params_prior_7_0.npy')
188
+ LF_params_prior_7_1 = np.load('MF_param/MF_param_0/LF_params_prior_7_1.npy')
189
+
190
+ for i in range(N_param_gp-1):
191
+
192
+ print(i)
193
+ LF_params_0_0 = np.concatenate( (LF_params_0_0,
194
+ np.load('MF_param/MF_param_'+str(i+1)+'/LF_params_0_0.npy')), axis = 0)
195
+ LF_params_0_1 = np.concatenate( (LF_params_0_1,
196
+ np.load('MF_param/MF_param_'+str(i+1)+'/LF_params_0_1.npy')), axis = 0)
197
+ LF_params_1_0 = np.concatenate( (LF_params_1_0,
198
+ np.load('MF_param/MF_param_'+str(i+1)+'/LF_params_1_0.npy')), axis = 0)
199
+ LF_params_1_1 = np.concatenate( (LF_params_1_1,
200
+ np.load('MF_param/MF_param_'+str(i+1)+'/LF_params_1_1.npy')), axis = 0)
201
+ LF_params_2_0 = np.concatenate( (LF_params_2_0,
202
+ np.load('MF_param/MF_param_'+str(i+1)+'/LF_params_2_0.npy')), axis = 0)
203
+ LF_params_2_1 = np.concatenate( (LF_params_2_1,
204
+ np.load('MF_param/MF_param_'+str(i+1)+'/LF_params_2_1.npy')), axis = 0)
205
+ LF_params_3_0 = np.concatenate( (LF_params_3_0,
206
+ np.load('MF_param/MF_param_'+str(i+1)+'/LF_params_3_0.npy')), axis = 0)
207
+ LF_params_3_1 = np.concatenate( (LF_params_3_1,
208
+ np.load('MF_param/MF_param_'+str(i+1)+'/LF_params_3_1.npy')), axis = 0)
209
+ LF_params_4_0 = np.concatenate( (LF_params_4_0,
210
+ np.load('MF_param/MF_param_'+str(i+1)+'/LF_params_4_0.npy')), axis = 0)
211
+ LF_params_4_1 = np.concatenate( (LF_params_4_1,
212
+ np.load('MF_param/MF_param_'+str(i+1)+'/LF_params_4_1.npy')), axis = 0)
213
+ LF_params_5_0 = np.concatenate( (LF_params_5_0,
214
+ np.load('MF_param/MF_param_'+str(i+1)+'/LF_params_5_0.npy')), axis = 0)
215
+ LF_params_5_1 = np.concatenate( (LF_params_5_1,
216
+ np.load('MF_param/MF_param_'+str(i+1)+'/LF_params_5_1.npy')), axis = 0)
217
+ LF_params_6_0 = np.concatenate( (LF_params_6_0,
218
+ np.load('MF_param/MF_param_'+str(i+1)+'/LF_params_6_0.npy')), axis = 0)
219
+ LF_params_6_1 = np.concatenate( (LF_params_6_1,
220
+ np.load('MF_param/MF_param_'+str(i+1)+'/LF_params_6_1.npy')), axis = 0)
221
+ LF_params_7_0 = np.concatenate( (LF_params_7_0,
222
+ np.load('MF_param/MF_param_'+str(i+1)+'/LF_params_7_0.npy')), axis = 0)
223
+ LF_params_7_1 = np.concatenate( (LF_params_7_1,
224
+ np.load('MF_param/MF_param_'+str(i+1)+'/LF_params_7_1.npy')), axis = 0)
225
+
226
+ LF_params_prior_0_0 = np.concatenate( (LF_params_prior_0_0,
227
+ np.load('MF_param/MF_param_'+str(i+1)+'/LF_params_prior_0_0.npy')), axis = 0)
228
+ LF_params_prior_0_1 = np.concatenate( (LF_params_prior_0_1,
229
+ np.load('MF_param/MF_param_'+str(i+1)+'/LF_params_prior_0_1.npy')), axis = 0)
230
+ LF_params_prior_1_0 = np.concatenate( (LF_params_prior_1_0,
231
+ np.load('MF_param/MF_param_'+str(i+1)+'/LF_params_prior_1_0.npy')), axis = 0)
232
+ LF_params_prior_1_1 = np.concatenate( (LF_params_prior_1_1,
233
+ np.load('MF_param/MF_param_'+str(i+1)+'/LF_params_prior_1_1.npy')), axis = 0)
234
+ LF_params_prior_2_0 = np.concatenate( (LF_params_prior_2_0,
235
+ np.load('MF_param/MF_param_'+str(i+1)+'/LF_params_prior_2_0.npy')), axis = 0)
236
+ LF_params_prior_2_1 = np.concatenate( (LF_params_prior_2_1,
237
+ np.load('MF_param/MF_param_'+str(i+1)+'/LF_params_prior_2_1.npy')), axis = 0)
238
+ LF_params_prior_3_0 = np.concatenate( (LF_params_prior_3_0,
239
+ np.load('MF_param/MF_param_'+str(i+1)+'/LF_params_prior_3_0.npy')), axis = 0)
240
+ LF_params_prior_3_1 = np.concatenate( (LF_params_prior_3_1,
241
+ np.load('MF_param/MF_param_'+str(i+1)+'/LF_params_prior_3_1.npy')), axis = 0)
242
+ LF_params_prior_4_0 = np.concatenate( (LF_params_prior_4_0,
243
+ np.load('MF_param/MF_param_'+str(i+1)+'/LF_params_prior_4_0.npy')), axis = 0)
244
+ LF_params_prior_4_1 = np.concatenate( (LF_params_prior_4_1,
245
+ np.load('MF_param/MF_param_'+str(i+1)+'/LF_params_prior_4_1.npy')), axis = 0)
246
+ LF_params_prior_5_0 = np.concatenate( (LF_params_prior_5_0,
247
+ np.load('MF_param/MF_param_'+str(i+1)+'/LF_params_prior_5_0.npy')), axis = 0)
248
+ LF_params_prior_5_1 = np.concatenate( (LF_params_prior_5_1,
249
+ np.load('MF_param/MF_param_'+str(i+1)+'/LF_params_prior_5_1.npy')), axis = 0)
250
+ LF_params_prior_6_0 = np.concatenate( (LF_params_prior_6_0,
251
+ np.load('MF_param/MF_param_'+str(i+1)+'/LF_params_prior_6_0.npy')), axis = 0)
252
+ LF_params_prior_6_1 = np.concatenate( (LF_params_prior_6_1,
253
+ np.load('MF_param/MF_param_'+str(i+1)+'/LF_params_prior_6_1.npy')), axis = 0)
254
+ LF_params_prior_7_0 = np.concatenate( (LF_params_prior_7_0,
255
+ np.load('MF_param/MF_param_'+str(i+1)+'/LF_params_prior_7_0.npy')), axis = 0)
256
+ LF_params_prior_7_1 = np.concatenate( (LF_params_prior_7_1,
257
+ np.load('MF_param/MF_param_'+str(i+1)+'/LF_params_prior_7_1.npy')), axis = 0)
258
+
259
+ np.save('MF_param/saved_param/LF_params_0_0.npy', LF_params_0_0)
260
+ np.save('MF_param/saved_param/LF_params_0_1.npy', LF_params_0_1)
261
+ np.save('MF_param/saved_param/LF_params_1_0.npy', LF_params_1_0)
262
+ np.save('MF_param/saved_param/LF_params_1_1.npy', LF_params_1_1)
263
+ np.save('MF_param/saved_param/LF_params_2_0.npy', LF_params_2_0)
264
+ np.save('MF_param/saved_param/LF_params_2_1.npy', LF_params_2_1)
265
+ np.save('MF_param/saved_param/LF_params_3_0.npy', LF_params_3_0)
266
+ np.save('MF_param/saved_param/LF_params_3_1.npy', LF_params_3_1)
267
+ np.save('MF_param/saved_param/LF_params_4_0.npy', LF_params_4_0)
268
+ np.save('MF_param/saved_param/LF_params_4_1.npy', LF_params_4_1)
269
+ np.save('MF_param/saved_param/LF_params_5_0.npy', LF_params_5_0)
270
+ np.save('MF_param/saved_param/LF_params_5_1.npy', LF_params_5_1)
271
+ np.save('MF_param/saved_param/LF_params_6_0.npy', LF_params_6_0)
272
+ np.save('MF_param/saved_param/LF_params_6_1.npy', LF_params_6_1)
273
+ np.save('MF_param/saved_param/LF_params_7_0.npy', LF_params_7_0)
274
+ np.save('MF_param/saved_param/LF_params_7_1.npy', LF_params_7_1)
275
+
276
+ np.save('MF_param/saved_param/LF_params_prior_0_0.npy', LF_params_prior_0_0)
277
+ np.save('MF_param/saved_param/LF_params_prior_0_1.npy', LF_params_prior_0_1)
278
+ np.save('MF_param/saved_param/LF_params_prior_1_0.npy', LF_params_prior_1_0)
279
+ np.save('MF_param/saved_param/LF_params_prior_1_1.npy', LF_params_prior_1_1)
280
+ np.save('MF_param/saved_param/LF_params_prior_2_0.npy', LF_params_prior_2_0)
281
+ np.save('MF_param/saved_param/LF_params_prior_2_1.npy', LF_params_prior_2_1)
282
+ np.save('MF_param/saved_param/LF_params_prior_3_0.npy', LF_params_prior_3_0)
283
+ np.save('MF_param/saved_param/LF_params_prior_3_1.npy', LF_params_prior_3_1)
284
+ np.save('MF_param/saved_param/LF_params_prior_4_0.npy', LF_params_prior_4_0)
285
+ np.save('MF_param/saved_param/LF_params_prior_4_1.npy', LF_params_prior_4_1)
286
+ np.save('MF_param/saved_param/LF_params_prior_5_0.npy', LF_params_prior_5_0)
287
+ np.save('MF_param/saved_param/LF_params_prior_5_1.npy', LF_params_prior_5_1)
288
+ np.save('MF_param/saved_param/LF_params_prior_6_0.npy', LF_params_prior_6_0)
289
+ np.save('MF_param/saved_param/LF_params_prior_6_1.npy', LF_params_prior_6_1)
290
+ np.save('MF_param/saved_param/LF_params_prior_7_0.npy', LF_params_prior_7_0)
291
+ np.save('MF_param/saved_param/LF_params_prior_7_1.npy', LF_params_prior_7_1)
292
+
293
+ if is_SF == 1:
294
+ SF_params_0_0 = np.load('SF_param/SF_param_0/params_0_0.npy')
295
+ SF_params_0_1 = np.load('SF_param/SF_param_0/params_0_1.npy')
296
+ SF_params_1_0 = np.load('SF_param/SF_param_0/params_1_0.npy')
297
+ SF_params_1_1 = np.load('SF_param/SF_param_0/params_1_1.npy')
298
+ SF_params_2_0 = np.load('SF_param/SF_param_0/params_2_0.npy')
299
+ SF_params_2_1 = np.load('SF_param/SF_param_0/params_2_1.npy')
300
+ SF_params_3_0 = np.load('SF_param/SF_param_0/params_3_0.npy')
301
+ SF_params_3_1 = np.load('SF_param/SF_param_0/params_3_1.npy')
302
+ SF_params_4_0 = np.load('SF_param/SF_param_0/params_4_0.npy')
303
+ SF_params_4_1 = np.load('SF_param/SF_param_0/params_4_1.npy')
304
+ SF_params_5_0 = np.load('SF_param/SF_param_0/params_5_0.npy')
305
+ SF_params_5_1 = np.load('SF_param/SF_param_0/params_5_1.npy')
306
+ SF_params_6_0 = np.load('SF_param/SF_param_0/params_6_0.npy')
307
+ SF_params_6_1 = np.load('SF_param/SF_param_0/params_6_1.npy')
308
+ SF_params_7_0 = np.load('SF_param/SF_param_0/params_7_0.npy')
309
+ SF_params_7_1 = np.load('SF_param/SF_param_0/params_7_1.npy')
310
+
311
+ SF_params_prior_0_0 = np.load('SF_param/SF_param_0/params_prior_0_0.npy')
312
+ SF_params_prior_0_1 = np.load('SF_param/SF_param_0/params_prior_0_1.npy')
313
+ SF_params_prior_1_0 = np.load('SF_param/SF_param_0/params_prior_1_0.npy')
314
+ SF_params_prior_1_1 = np.load('SF_param/SF_param_0/params_prior_1_1.npy')
315
+ SF_params_prior_2_0 = np.load('SF_param/SF_param_0/params_prior_2_0.npy')
316
+ SF_params_prior_2_1 = np.load('SF_param/SF_param_0/params_prior_2_1.npy')
317
+ SF_params_prior_3_0 = np.load('SF_param/SF_param_0/params_prior_3_0.npy')
318
+ SF_params_prior_3_1 = np.load('SF_param/SF_param_0/params_prior_3_1.npy')
319
+ SF_params_prior_4_0 = np.load('SF_param/SF_param_0/params_prior_4_0.npy')
320
+ SF_params_prior_4_1 = np.load('SF_param/SF_param_0/params_prior_4_1.npy')
321
+ SF_params_prior_5_0 = np.load('SF_param/SF_param_0/params_prior_5_0.npy')
322
+ SF_params_prior_5_1 = np.load('SF_param/SF_param_0/params_prior_5_1.npy')
323
+ SF_params_prior_6_0 = np.load('SF_param/SF_param_0/params_prior_6_0.npy')
324
+ SF_params_prior_6_1 = np.load('SF_param/SF_param_0/params_prior_6_1.npy')
325
+ SF_params_prior_7_0 = np.load('SF_param/SF_param_0/params_prior_7_0.npy')
326
+ SF_params_prior_7_1 = np.load('SF_param/SF_param_0/params_prior_7_1.npy')
327
+
328
+ for i in range(N_param_gp-1):
329
+
330
+ print(i)
331
+ SF_params_0_0 = np.concatenate( (SF_params_0_0,
332
+ np.load('SF_param/SF_param_'+str(i+1)+'/params_0_0.npy')), axis = 0)
333
+ SF_params_0_1 = np.concatenate( (SF_params_0_1,
334
+ np.load('SF_param/SF_param_'+str(i+1)+'/params_0_1.npy')), axis = 0)
335
+ SF_params_1_0 = np.concatenate( (SF_params_1_0,
336
+ np.load('SF_param/SF_param_'+str(i+1)+'/params_1_0.npy')), axis = 0)
337
+ SF_params_1_1 = np.concatenate( (SF_params_1_1,
338
+ np.load('SF_param/SF_param_'+str(i+1)+'/params_1_1.npy')), axis = 0)
339
+ SF_params_2_0 = np.concatenate( (SF_params_2_0,
340
+ np.load('SF_param/SF_param_'+str(i+1)+'/params_2_0.npy')), axis = 0)
341
+ SF_params_2_1 = np.concatenate( (SF_params_2_1,
342
+ np.load('SF_param/SF_param_'+str(i+1)+'/params_2_1.npy')), axis = 0)
343
+ SF_params_3_0 = np.concatenate( (SF_params_3_0,
344
+ np.load('SF_param/SF_param_'+str(i+1)+'/params_3_0.npy')), axis = 0)
345
+ SF_params_3_1 = np.concatenate( (SF_params_3_1,
346
+ np.load('SF_param/SF_param_'+str(i+1)+'/params_3_1.npy')), axis = 0)
347
+ SF_params_4_0 = np.concatenate( (SF_params_4_0,
348
+ np.load('SF_param/SF_param_'+str(i+1)+'/params_4_0.npy')), axis = 0)
349
+ SF_params_4_1 = np.concatenate( (SF_params_4_1,
350
+ np.load('SF_param/SF_param_'+str(i+1)+'/params_4_1.npy')), axis = 0)
351
+ SF_params_5_0 = np.concatenate( (SF_params_5_0,
352
+ np.load('SF_param/SF_param_'+str(i+1)+'/params_5_0.npy')), axis = 0)
353
+ SF_params_5_1 = np.concatenate( (SF_params_5_1,
354
+ np.load('SF_param/SF_param_'+str(i+1)+'/params_5_1.npy')), axis = 0)
355
+ SF_params_6_0 = np.concatenate( (SF_params_6_0,
356
+ np.load('SF_param/SF_param_'+str(i+1)+'/params_6_0.npy')), axis = 0)
357
+ SF_params_6_1 = np.concatenate( (SF_params_6_1,
358
+ np.load('SF_param/SF_param_'+str(i+1)+'/params_6_1.npy')), axis = 0)
359
+ SF_params_7_0 = np.concatenate( (SF_params_7_0,
360
+ np.load('SF_param/SF_param_'+str(i+1)+'/params_7_0.npy')), axis = 0)
361
+ SF_params_7_1 = np.concatenate( (SF_params_7_1,
362
+ np.load('SF_param/SF_param_'+str(i+1)+'/params_7_1.npy')), axis = 0)
363
+
364
+ SF_params_prior_0_0 = np.concatenate( (SF_params_prior_0_0,
365
+ np.load('SF_param/SF_param_'+str(i+1)+'/params_prior_0_0.npy')), axis = 0)
366
+ SF_params_prior_0_1 = np.concatenate( (SF_params_prior_0_1,
367
+ np.load('SF_param/SF_param_'+str(i+1)+'/params_prior_0_1.npy')), axis = 0)
368
+ SF_params_prior_1_0 = np.concatenate( (SF_params_prior_1_0,
369
+ np.load('SF_param/SF_param_'+str(i+1)+'/params_prior_1_0.npy')), axis = 0)
370
+ SF_params_prior_1_1 = np.concatenate( (SF_params_prior_1_1,
371
+ np.load('SF_param/SF_param_'+str(i+1)+'/params_prior_1_1.npy')), axis = 0)
372
+ SF_params_prior_2_0 = np.concatenate( (SF_params_prior_2_0,
373
+ np.load('SF_param/SF_param_'+str(i+1)+'/params_prior_2_0.npy')), axis = 0)
374
+ SF_params_prior_2_1 = np.concatenate( (SF_params_prior_2_1,
375
+ np.load('SF_param/SF_param_'+str(i+1)+'/params_prior_2_1.npy')), axis = 0)
376
+ SF_params_prior_3_0 = np.concatenate( (SF_params_prior_3_0,
377
+ np.load('SF_param/SF_param_'+str(i+1)+'/params_prior_3_0.npy')), axis = 0)
378
+ SF_params_prior_3_1 = np.concatenate( (SF_params_prior_3_1,
379
+ np.load('SF_param/SF_param_'+str(i+1)+'/params_prior_3_1.npy')), axis = 0)
380
+ SF_params_prior_4_0 = np.concatenate( (SF_params_prior_4_0,
381
+ np.load('SF_param/SF_param_'+str(i+1)+'/params_prior_4_0.npy')), axis = 0)
382
+ SF_params_prior_4_1 = np.concatenate( (SF_params_prior_4_1,
383
+ np.load('SF_param/SF_param_'+str(i+1)+'/params_prior_4_1.npy')), axis = 0)
384
+ SF_params_prior_5_0 = np.concatenate( (SF_params_prior_5_0,
385
+ np.load('SF_param/SF_param_'+str(i+1)+'/params_prior_5_0.npy')), axis = 0)
386
+ SF_params_prior_5_1 = np.concatenate( (SF_params_prior_5_1,
387
+ np.load('SF_param/SF_param_'+str(i+1)+'/params_prior_5_1.npy')), axis = 0)
388
+ SF_params_prior_6_0 = np.concatenate( (SF_params_prior_6_0,
389
+ np.load('SF_param/SF_param_'+str(i+1)+'/params_prior_6_0.npy')), axis = 0)
390
+ SF_params_prior_6_1 = np.concatenate( (SF_params_prior_6_1,
391
+ np.load('SF_param/SF_param_'+str(i+1)+'/params_prior_6_1.npy')), axis = 0)
392
+ SF_params_prior_7_0 = np.concatenate( (SF_params_prior_7_0,
393
+ np.load('SF_param/SF_param_'+str(i+1)+'/params_prior_7_0.npy')), axis = 0)
394
+ SF_params_prior_7_1 = np.concatenate( (SF_params_prior_7_1,
395
+ np.load('SF_param/SF_param_'+str(i+1)+'/params_prior_7_1.npy')), axis = 0)
396
+
397
+ np.save('SF_param/saved_param/SF_params_0_0.npy', SF_params_0_0)
398
+ np.save('SF_param/saved_param/SF_params_0_1.npy', SF_params_0_1)
399
+ np.save('SF_param/saved_param/SF_params_1_0.npy', SF_params_1_0)
400
+ np.save('SF_param/saved_param/SF_params_1_1.npy', SF_params_1_1)
401
+ np.save('SF_param/saved_param/SF_params_2_0.npy', SF_params_2_0)
402
+ np.save('SF_param/saved_param/SF_params_2_1.npy', SF_params_2_1)
403
+ np.save('SF_param/saved_param/SF_params_3_0.npy', SF_params_3_0)
404
+ np.save('SF_param/saved_param/SF_params_3_1.npy', SF_params_3_1)
405
+ np.save('SF_param/saved_param/SF_params_4_0.npy', SF_params_4_0)
406
+ np.save('SF_param/saved_param/SF_params_4_1.npy', SF_params_4_1)
407
+ np.save('SF_param/saved_param/SF_params_5_0.npy', SF_params_5_0)
408
+ np.save('SF_param/saved_param/SF_params_5_1.npy', SF_params_5_1)
409
+ np.save('SF_param/saved_param/SF_params_6_0.npy', SF_params_6_0)
410
+ np.save('SF_param/saved_param/SF_params_6_1.npy', SF_params_6_1)
411
+ np.save('SF_param/saved_param/SF_params_7_0.npy', SF_params_7_0)
412
+ np.save('SF_param/saved_param/SF_params_7_1.npy', SF_params_7_1)
413
+
414
+ np.save('SF_param/saved_param/SF_params_prior_0_0.npy', SF_params_prior_0_0)
415
+ np.save('SF_param/saved_param/SF_params_prior_0_1.npy', SF_params_prior_0_1)
416
+ np.save('SF_param/saved_param/SF_params_prior_1_0.npy', SF_params_prior_1_0)
417
+ np.save('SF_param/saved_param/SF_params_prior_1_1.npy', SF_params_prior_1_1)
418
+ np.save('SF_param/saved_param/SF_params_prior_2_0.npy', SF_params_prior_2_0)
419
+ np.save('SF_param/saved_param/SF_params_prior_2_1.npy', SF_params_prior_2_1)
420
+ np.save('SF_param/saved_param/SF_params_prior_3_0.npy', SF_params_prior_3_0)
421
+ np.save('SF_param/saved_param/SF_params_prior_3_1.npy', SF_params_prior_3_1)
422
+ np.save('SF_param/saved_param/SF_params_prior_4_0.npy', SF_params_prior_4_0)
423
+ np.save('SF_param/saved_param/SF_params_prior_4_1.npy', SF_params_prior_4_1)
424
+ np.save('SF_param/saved_param/SF_params_prior_5_0.npy', SF_params_prior_5_0)
425
+ np.save('SF_param/saved_param/SF_params_prior_5_1.npy', SF_params_prior_5_1)
426
+ np.save('SF_param/saved_param/SF_params_prior_6_0.npy', SF_params_prior_6_0)
427
+ np.save('SF_param/saved_param/SF_params_prior_6_1.npy', SF_params_prior_6_1)
428
+ np.save('SF_param/saved_param/SF_params_prior_7_0.npy', SF_params_prior_7_0)
429
+ np.save('SF_param/saved_param/SF_params_prior_7_1.npy', SF_params_prior_7_1)
4_pred_RPN_LF.py ADDED
@@ -0,0 +1,171 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ """
4
+ Created on Fri May 26 11:19:06 2023
5
+
6
+ @author: mohamedazizbhouri
7
+ """
8
+
9
+ import os
10
+ os.environ['XLA_PYTHON_CLIENT_PREALLOCATE']='false'
11
+
12
+ from jax import numpy as np
13
+ from jax import vmap, jit, random
14
+
15
+ import numpy as onp
16
+ import time
17
+
18
+ ##########################################################
19
+ ##########################################################
20
+ ##########################################################
21
+
22
+ def leakyRELU(x):
23
+ return np.where(x > 0, x, x * 0.15)
24
+
25
+ def MLP(layers, activation=leakyRELU):
26
+ def init(rng_key):
27
+ def init_layer(key, d_in, d_out):
28
+ k1, k2 = random.split(key)
29
+ glorot_stddev = 1. / np.sqrt((d_in + d_out) / 2.)
30
+ W = glorot_stddev*random.normal(k1, (d_in, d_out))
31
+ b = np.zeros(d_out)
32
+ return W, b
33
+ key, *keys = random.split(rng_key, len(layers))
34
+ params = list(map(init_layer, keys, layers[:-1], layers[1:]))
35
+ return params
36
+ def apply(params, inputs):
37
+ for W, b in params[:-1]:
38
+ outputs = np.dot(inputs, W) + b
39
+ inputs = activation(outputs)
40
+ W, b = params[-1]
41
+ outputs = np.dot(inputs, W) + b
42
+ return outputs
43
+ return init, apply
44
+
45
+ ##########################################################
46
+ ##########################################################
47
+ ##########################################################
48
+
49
+ from jax.example_libraries import optimizers
50
+ from functools import partial
51
+ import itertools
52
+
53
+ # Define the model
54
+ class EnsembleRegression:
55
+ def __init__(self, layers, ensemble_size, rng_key = random.PRNGKey(0)):
56
+ # Network initialization and evaluation functions
57
+ self.init, self.apply = MLP(layers)
58
+ self.init_prior, self.apply_prior = MLP(layers)
59
+
60
+ # Random keys
61
+ k1, k2, k3 = random.split(rng_key, 3)
62
+ keys_1 = random.split(k1, ensemble_size)
63
+ keys_2 = random.split(k2, ensemble_size)
64
+ keys_3 = random.split(k3, ensemble_size)
65
+
66
+ # Initialize
67
+ params = vmap(self.init)(keys_1)
68
+ params_prior = vmap(self.init_prior)(keys_2)
69
+
70
+ # Use optimizers to set optimizer initialization and update functions
71
+ lr = optimizers.exponential_decay(1e-4, decay_steps=1000, decay_rate=0.999)
72
+ lr = optimizers.exponential_decay(0.000227, decay_steps=1000, decay_rate=0.999)
73
+ self.opt_init, \
74
+ self.opt_update, \
75
+ self.get_params = optimizers.adam(lr)
76
+
77
+ self.opt_state = vmap(self.opt_init)(params)
78
+ self.prior_opt_state = vmap(self.opt_init)(params_prior)
79
+ self.key_opt_state = vmap(self.opt_init)(keys_3)
80
+
81
+ # Logger
82
+ self.itercount = itertools.count()
83
+ self.loss_log = []
84
+
85
+ # Define the forward pass
86
+ def net_forward(self, params, params_prior, inputs):
87
+ Y_pred = self.apply(params, inputs) + self.apply_prior(params_prior, inputs)
88
+ return Y_pred
89
+
90
+ # Evaluates predictions at test points
91
+ @partial(jit, static_argnums=(0,))
92
+ def posterior(self, params, inputs):
93
+ params, params_prior = params
94
+ samples = vmap(self.net_forward, (0, 0, 0))(params, params_prior, inputs)
95
+ return samples
96
+
97
+ ##########################################################
98
+ ##########################################################
99
+ ##########################################################
100
+
101
+ # Helper functions
102
+ normalize = lambda x, mu, std: (x-mu)/std
103
+
104
+ n_remove = 4
105
+ ind_input = np.concatenate( (np.arange(26),n_remove+26+np.arange(26-n_remove),np.array([52,53,54,55])) )
106
+ dim_xH = ind_input.shape[0]
107
+ dim_xL = ind_input.shape[0]
108
+
109
+ ind_output_heat = np.arange(26)
110
+ ind_output_moist = n_remove+np.arange(26-n_remove)
111
+
112
+ dim_yH = ind_output_heat.shape[0]+ind_output_moist.shape[0]
113
+ dim_yL = ind_output_heat.shape[0]+ind_output_moist.shape[0]
114
+
115
+ ensemble_size = 1
116
+
117
+ layers_L = [dim_xL, 512, 512, 512, 512, 512, 512, 512, dim_yL]
118
+
119
+ id_step = 1 # 1 or 2 for instance in case we dont have enough RAM memory to make
120
+ # predictions for the whole test dataset at once.
121
+ n_run_param = 0
122
+
123
+ key = random.PRNGKey(n_run_param)
124
+ model_L = EnsembleRegression(layers_L, ensemble_size, key)
125
+
126
+ mu_MF_in = onp.load('norm/mu_X_CAM5.npy')[None,ind_input]
127
+ sigma_MF_in = onp.load('norm/sigma_X_CAM5.npy')[None,ind_input]
128
+
129
+ print('loading NN parameters')
130
+
131
+ params_L = []
132
+ params_prior_L = []
133
+
134
+ for i in range(len(layers_L)-1):
135
+ params_L.append( ( np.load('MF_param/MF_param_'+str(n_run_param)+'/LF_params_'+str(i)+'_'+str(0)+'.npy')[0:1,:,:] ,
136
+ np.load('MF_param/MF_param_'+str(n_run_param)+'/LF_params_'+str(i)+'_'+str(1)+'.npy')[0:1,:] ) )
137
+ params_prior_L.append( ( np.load('MF_param/MF_param_'+str(n_run_param)+'/LF_params_prior_'+str(i)+'_'+str(0)+'.npy')[0:1,:,:] ,
138
+ np.load('MF_param/MF_param_'+str(n_run_param)+'/LF_params_prior_'+str(i)+'_'+str(1)+'.npy')[0:1,:] ) )
139
+
140
+ opt_params_L = (params_L, params_prior_L)
141
+
142
+ @jit
143
+ def predict_L(x):
144
+ # accepts and returns un-normalized data
145
+ x = np.tile(x[np.newaxis,:,:], (ensemble_size, 1, 1))
146
+ x = normalize(x, mu_MF_in, sigma_MF_in)
147
+ samples = model_L.posterior(opt_params_L, x)
148
+ return samples
149
+
150
+ ##################################
151
+ ############## test ##############
152
+ ##################################
153
+
154
+ print('loading test')
155
+ if id_step == 1:
156
+ t = time.time()
157
+ test_XH = onp.load('data_SPCAM5_4K/all_inputs.npy')[:59387904,ind_input]
158
+ print('test loaded', 'time (s):', time.time() - t)
159
+ elif id_step == 2:
160
+ t = time.time()
161
+ test_XH = onp.load('data_SPCAM5_4K/all_inputs.npy')[59387904:,ind_input]
162
+ print('test loaded', 'time (s):', time.time() - t)
163
+
164
+ print('n_run_param : ', n_run_param, 'id_step : ', id_step, 'Computing pred')
165
+ t = time.time()
166
+ samples_test_H = predict_L(test_XH)
167
+ print('Computing pred', 'time (s):', time.time() - t)
168
+ print('Saving pred')
169
+ t = time.time()
170
+ np.save('MF_param/MF_param_'+str(n_run_param)+'/LF_test_pred_'+str(id_step)+'.npy', samples_test_H)
171
+ print('Saving pred', 'time (s):', time.time() - t)
4_pred_RPN_MF.py ADDED
@@ -0,0 +1,190 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ """
4
+ Created on Wed May 3 17:32:12 2023
5
+
6
+ @author: mohamedazizbhouri
7
+ """
8
+
9
+ import os
10
+ os.environ['XLA_PYTHON_CLIENT_PREALLOCATE']='false'
11
+
12
+ from jax import numpy as np
13
+ from jax import vmap, jit, random
14
+
15
+ import numpy as onp
16
+ import time
17
+
18
+ ##########################################################
19
+ ##########################################################
20
+ ##########################################################
21
+
22
+ def leakyRELU(x):
23
+ return np.where(x > 0, x, x * 0.15)
24
+
25
+ def MLP(layers, activation=leakyRELU): # np.tanh
26
+ def init(rng_key):
27
+ def init_layer(key, d_in, d_out):
28
+ k1, k2 = random.split(key)
29
+ glorot_stddev = 1. / np.sqrt((d_in + d_out) / 2.)
30
+ W = glorot_stddev*random.normal(k1, (d_in, d_out))
31
+ b = np.zeros(d_out)
32
+ return W, b
33
+ key, *keys = random.split(rng_key, len(layers))
34
+ params = list(map(init_layer, keys, layers[:-1], layers[1:]))
35
+ return params
36
+ def apply(params, inputs):
37
+ for W, b in params[:-1]:
38
+ outputs = np.dot(inputs, W) + b
39
+ inputs = activation(outputs)
40
+ W, b = params[-1]
41
+ outputs = np.dot(inputs, W) + b
42
+ return outputs
43
+ return init, apply
44
+
45
+ ##########################################################
46
+ ##########################################################
47
+ ##########################################################
48
+
49
+ from jax.example_libraries import optimizers
50
+ from functools import partial
51
+ import itertools
52
+
53
+ # Define the model
54
+ class EnsembleRegression:
55
+ def __init__(self, layers, ensemble_size, rng_key = random.PRNGKey(0)):
56
+ # Network initialization and evaluation functions
57
+ self.init, self.apply = MLP(layers)
58
+ self.init_prior, self.apply_prior = MLP(layers)
59
+
60
+ # Random keys
61
+ k1, k2, k3 = random.split(rng_key, 3)
62
+ keys_1 = random.split(k1, ensemble_size)
63
+ keys_2 = random.split(k2, ensemble_size)
64
+ keys_3 = random.split(k3, ensemble_size)
65
+
66
+ # Initialize
67
+ params = vmap(self.init)(keys_1)
68
+ params_prior = vmap(self.init_prior)(keys_2)
69
+
70
+ # Use optimizers to set optimizer initialization and update functions
71
+ lr = optimizers.exponential_decay(1e-4, decay_steps=1000, decay_rate=0.999)
72
+ lr = optimizers.exponential_decay(0.000227, decay_steps=1000, decay_rate=0.999)
73
+ self.opt_init, \
74
+ self.opt_update, \
75
+ self.get_params = optimizers.adam(lr)
76
+
77
+ self.opt_state = vmap(self.opt_init)(params)
78
+ self.prior_opt_state = vmap(self.opt_init)(params_prior)
79
+ self.key_opt_state = vmap(self.opt_init)(keys_3)
80
+
81
+ # Logger
82
+ self.itercount = itertools.count()
83
+ self.loss_log = []
84
+
85
+ # Define the forward pass
86
+ def net_forward(self, params, params_prior, inputs):
87
+ Y_pred = self.apply(params, inputs) + self.apply_prior(params_prior, inputs)
88
+ return Y_pred
89
+
90
+ # Evaluates predictions at test points
91
+ @partial(jit, static_argnums=(0,))
92
+ def posterior(self, params, inputs):
93
+ params, params_prior = params
94
+ samples = vmap(self.net_forward, (0, 0, 0))(params, params_prior, inputs)
95
+ return samples
96
+
97
+ ##########################################################
98
+ ##########################################################
99
+ ##########################################################
100
+
101
+ # Helper functions
102
+ normalize = lambda x, mu, std: (x-mu)/std
103
+
104
+ n_remove = 4
105
+ ind_input = np.concatenate( (np.arange(26),n_remove+26+np.arange(26-n_remove),np.array([52,53,54,55])) )
106
+ dim_xH = ind_input.shape[0]
107
+ dim_xL = ind_input.shape[0]
108
+
109
+ ind_output_heat = np.arange(26)
110
+ ind_output_moist = n_remove+np.arange(26-n_remove)
111
+
112
+ dim_yH = ind_output_heat.shape[0]+ind_output_moist.shape[0]
113
+ dim_yL = ind_output_heat.shape[0]+ind_output_moist.shape[0]
114
+
115
+ ensemble_size = 1
116
+ i_ensemble = 0
117
+ layers_H = [dim_yL, 512, 512, 512, 512, 512, 512, 512, dim_yH]
118
+ layers_L = [dim_xL, 512, 512, 512, 512, 512, 512, 512, dim_yL]
119
+
120
+ id_step = 1 # 1 or 2 for instance in case we dont have enough RAM memory to make
121
+ # predictions for the whole test dataset at once.
122
+ n_run_param = 0
123
+
124
+ key = random.PRNGKey(n_run_param)
125
+ model_H = EnsembleRegression(layers_H, ensemble_size, key)
126
+ model_L = EnsembleRegression(layers_L, ensemble_size, key)
127
+
128
+ mu_MF_in = onp.load('norm/mu_X_CAM5.npy')[None,ind_input]
129
+ sigma_MF_in = onp.load('norm/sigma_X_CAM5.npy')[None,ind_input]
130
+
131
+ print('loading NN parameters')
132
+ params = []
133
+ params_prior = []
134
+
135
+ for i in range(len(layers_H)-1):
136
+ params.append( ( np.load('MF_param/MF_param_'+str(n_run_param)+'/HF_params_'+str(i)+'_'+str(0)+'.npy')[i_ensemble:i_ensemble+1,:,:] ,
137
+ np.load('MF_param/MF_param_'+str(n_run_param)+'/HF_params_'+str(i)+'_'+str(1)+'.npy')[i_ensemble:i_ensemble+1,:] ) )
138
+ params_prior.append( ( np.load('MF_param/MF_param_'+str(n_run_param)+'/HF_params_prior_'+str(i)+'_'+str(0)+'.npy')[i_ensemble:i_ensemble+1,:,:] ,
139
+ np.load('MF_param/MF_param_'+str(n_run_param)+'/HF_params_prior_'+str(i)+'_'+str(1)+'.npy')[i_ensemble:i_ensemble+1,:] ) )
140
+
141
+ opt_params_H = (params, params_prior)
142
+
143
+ params_L = []
144
+ params_prior_L = []
145
+
146
+ for i in range(len(layers_L)-1):
147
+ params_L.append( ( np.load('MF_param/MF_param_'+str(n_run_param)+'/LF_params_'+str(i)+'_'+str(0)+'.npy')[i_ensemble:i_ensemble+1,:,:] ,
148
+ np.load('MF_param/MF_param_'+str(n_run_param)+'/LF_params_'+str(i)+'_'+str(1)+'.npy')[i_ensemble:i_ensemble+1,:] ) )
149
+ params_prior_L.append( ( np.load('MF_param/MF_param_'+str(n_run_param)+'/LF_params_prior_'+str(i)+'_'+str(0)+'.npy')[i_ensemble:i_ensemble+1,:,:] ,
150
+ np.load('MF_param/MF_param_'+str(n_run_param)+'/LF_params_prior_'+str(i)+'_'+str(1)+'.npy')[i_ensemble:i_ensemble+1,:] ) )
151
+
152
+ opt_params_L = (params_L, params_prior_L)
153
+
154
+ @jit
155
+ def predict_L(x):
156
+ # accepts and returns un-normalized data
157
+ x = np.tile(x[np.newaxis,:,:], (ensemble_size, 1, 1))
158
+ samples = model_L.posterior(opt_params_L, x)
159
+ return samples
160
+
161
+ @jit
162
+ def predict_H(x):
163
+ # accepts and returns un-normalized data
164
+ xL = normalize(x, mu_MF_in, sigma_MF_in)
165
+ x = predict_L(xL)
166
+ samples = model_H.posterior(opt_params_H, x)
167
+ return samples
168
+
169
+ ##################################
170
+ ############## test ##############
171
+ ##################################
172
+ print('loading test')
173
+ if id_step == 1:
174
+ t = time.time()
175
+ test_XH = onp.load('data_SPCAM5_4K/all_inputs.npy')[:59387904,ind_input]
176
+ print('test loaded', 'time (s):', time.time() - t)
177
+ elif id_step == 2:
178
+ t = time.time()
179
+ test_XH = onp.load('data_SPCAM5_4K/all_inputs.npy')[59387904:,ind_input]
180
+ print('test loaded', 'time (s):', time.time() - t)
181
+
182
+ print('n_run_param : ', n_run_param, 'id_step : ', id_step, 'Computing pred')
183
+ t = time.time()
184
+ samples_test_H = predict_H(test_XH)
185
+ print('Computing pred', 'time (s):', time.time() - t)
186
+ print('Saving pred')
187
+ t = time.time()
188
+ np.save('MF_param/MF_param_'+str(n_run_param)+'/test_pred_'+str(id_step)+'.npy', samples_test_H)
189
+ print('Saving pred', 'time (s):', time.time() - t)
190
+
4_pred_RPN_SF.py ADDED
@@ -0,0 +1,168 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ """
4
+ Created on Thu May 4 10:34:47 2023
5
+
6
+ @author: mohamedazizbhouri
7
+ """
8
+
9
+ import os
10
+ os.environ['XLA_PYTHON_CLIENT_PREALLOCATE']='false'
11
+
12
+ from jax import numpy as np
13
+ from jax import vmap, jit, random
14
+
15
+ import numpy as onp
16
+ import time
17
+
18
+ ##########################################################
19
+ ##########################################################
20
+ ##########################################################
21
+
22
+ def leakyRELU(x):
23
+ return np.where(x > 0, x, x * 0.15)
24
+
25
+ def MLP(layers, activation=leakyRELU):
26
+ def init(rng_key):
27
+ def init_layer(key, d_in, d_out):
28
+ k1, k2 = random.split(key)
29
+ glorot_stddev = 1. / np.sqrt((d_in + d_out) / 2.)
30
+ W = glorot_stddev*random.normal(k1, (d_in, d_out))
31
+ b = np.zeros(d_out)
32
+ return W, b
33
+ key, *keys = random.split(rng_key, len(layers))
34
+ params = list(map(init_layer, keys, layers[:-1], layers[1:]))
35
+ return params
36
+ def apply(params, inputs):
37
+ for W, b in params[:-1]:
38
+ outputs = np.dot(inputs, W) + b
39
+ inputs = activation(outputs)
40
+ W, b = params[-1]
41
+ outputs = np.dot(inputs, W) + b
42
+ return outputs
43
+ return init, apply
44
+
45
+ ##########################################################
46
+ ##########################################################
47
+ ##########################################################
48
+
49
+ from jax.example_libraries import optimizers
50
+ from functools import partial
51
+ import itertools
52
+
53
+ # Define the model
54
+ class EnsembleRegression:
55
+ def __init__(self, layers, ensemble_size, rng_key = random.PRNGKey(0)):
56
+ # Network initialization and evaluation functions
57
+ self.init, self.apply = MLP(layers)
58
+ self.init_prior, self.apply_prior = MLP(layers)
59
+
60
+ # Random keys
61
+ k1, k2, k3 = random.split(rng_key, 3)
62
+ keys_1 = random.split(k1, ensemble_size)
63
+ keys_2 = random.split(k2, ensemble_size)
64
+ keys_3 = random.split(k2, ensemble_size)
65
+
66
+ # Initialize
67
+ params = vmap(self.init)(keys_1)
68
+ params_prior = vmap(self.init_prior)(keys_2)
69
+
70
+ # Use optimizers to set optimizer initialization and update functions
71
+ lr = optimizers.exponential_decay(1e-4, decay_steps=1000, decay_rate=0.999)
72
+ lr = optimizers.exponential_decay(0.000227, decay_steps=1000, decay_rate=0.999)
73
+ self.opt_init, \
74
+ self.opt_update, \
75
+ self.get_params = optimizers.adam(lr)
76
+
77
+ self.opt_state = vmap(self.opt_init)(params)
78
+ self.prior_opt_state = vmap(self.opt_init)(params_prior)
79
+ self.key_opt_state = vmap(self.opt_init)(keys_3)
80
+
81
+ # Logger
82
+ self.itercount = itertools.count()
83
+ self.loss_log = []
84
+
85
+ # Define the forward pass
86
+ def net_forward(self, params, params_prior, inputs):
87
+ Y_pred = self.apply(params, inputs) + self.apply_prior(params_prior, inputs)
88
+ return Y_pred
89
+
90
+ # Evaluates predictions at test points
91
+ @partial(jit, static_argnums=(0,))
92
+ def posterior(self, params, inputs):
93
+ params, params_prior = params
94
+ samples = vmap(self.net_forward, (0, 0, 0))(params, params_prior, inputs)
95
+ return samples
96
+
97
+ ##########################################################
98
+ ##########################################################
99
+ ##########################################################
100
+
101
+ # Helper functions
102
+ normalize = lambda x, mu, std: (x-mu)/std
103
+
104
+ n_remove = 4
105
+ ind_input = np.concatenate( (np.arange(26),n_remove+26+np.arange(26-n_remove),np.array([52,53,54,55])) )
106
+ dim_xH = ind_input.shape[0]
107
+ dim_xL = ind_input.shape[0]
108
+
109
+ ind_output_heat = np.arange(26)
110
+ ind_output_moist = n_remove+np.arange(26-n_remove)
111
+
112
+ dim_yH = ind_output_heat.shape[0]+ind_output_moist.shape[0]
113
+ dim_yL = ind_output_heat.shape[0]+ind_output_moist.shape[0]
114
+
115
+ ensemble_size = 1
116
+ layers_H = [dim_xH, 512, 512, 512, 512, 512, 512, 512, dim_yH]
117
+
118
+ id_step = 1 # 1 or 2 for instance in case we dont have enough RAM memory to make
119
+ # predictions for the whole test dataset at once.
120
+ n_run_param = 0
121
+
122
+ key = random.PRNGKey(n_run_param)
123
+ model_H = EnsembleRegression(layers_H, ensemble_size, key)
124
+
125
+ mu_SF_in = onp.load('norm/mu_X_SPCAM5.npy')[None,None,ind_input]
126
+ sigma_SF_in = onp.load('norm/sigma_X_SPCAM5.npy')[None,None,ind_input]
127
+
128
+ print('loading NN parameters')
129
+ params = []
130
+ params_prior = []
131
+ for i in range(len(layers_H)-1):
132
+ params.append( ( np.load('SF_param/SF_param_'+str(n_run_param)+'/params_'+str(i)+'_'+str(0)+'.npy') ,
133
+ np.load('SF_param/SF_param_'+str(n_run_param)+'/params_'+str(i)+'_'+str(1)+'.npy') ) )
134
+ params_prior.append( ( np.load('SF_param/SF_param_'+str(n_run_param)+'/params_prior_'+str(i)+'_'+str(0)+'.npy') ,
135
+ np.load('SF_param/SF_param_'+str(n_run_param)+'/params_prior_'+str(i)+'_'+str(1)+'.npy') ) )
136
+
137
+ opt_params_H = (params, params_prior)
138
+
139
+ @jit
140
+ def predict_H(x):
141
+ # accepts and returns un-normalized data
142
+ x = np.tile(x[np.newaxis,:,:], (ensemble_size, 1, 1))
143
+ x = normalize(x, mu_SF_in, sigma_SF_in)
144
+ samples = model_H.posterior(opt_params_H, x)
145
+ return samples
146
+
147
+ ##################################
148
+ ############## test ##############
149
+ ##################################
150
+
151
+ print('loading test')
152
+ if id_step == 1:
153
+ t = time.time()
154
+ test_XH = onp.load('data_SPCAM5_4K/all_inputs.npy')[:59387904,ind_input]
155
+ print('test loaded', 'time (s):', time.time() - t)
156
+ elif id_step == 2:
157
+ t = time.time()
158
+ test_XH = onp.load('data_SPCAM5_4K/all_inputs.npy')[59387904:,ind_input]
159
+ print('test loaded', 'time (s):', time.time() - t)
160
+
161
+ print('n_run_param : ', n_run_param, 'id_step : ', id_step, 'Computing pred')
162
+ t = time.time()
163
+ samples_test_H = predict_H(test_XH)
164
+ print('Computing pred', 'time (s):', time.time() - t)
165
+ print('Saving pred')
166
+ t = time.time()
167
+ np.save('SF_param/SF_param_'+str(n_run_param)+'/test_pred_'+str(id_step)+'.npy', samples_test_H)
168
+ print('Saving pred', 'time (s):', time.time() - t)
4_pred_RPN_det.py ADDED
@@ -0,0 +1,167 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ """
4
+ Created on Wed May 3 17:19:00 2023
5
+
6
+ @author: mohamedazizbhouri
7
+ """
8
+
9
+ import os
10
+ os.environ['XLA_PYTHON_CLIENT_PREALLOCATE']='false'
11
+
12
+ from jax import numpy as np
13
+ from jax import vmap, jit, random
14
+
15
+ import numpy as onp
16
+ import time
17
+
18
+ ##########################################################
19
+ ##########################################################
20
+ ##########################################################
21
+
22
+ def leakyRELU(x):
23
+ return np.where(x > 0, x, x * 0.15)
24
+
25
+ def MLP(layers, activation=leakyRELU):
26
+ def init(rng_key):
27
+ def init_layer(key, d_in, d_out):
28
+ k1, k2 = random.split(key)
29
+ glorot_stddev = 1. / np.sqrt((d_in + d_out) / 2.)
30
+ W = glorot_stddev*random.normal(k1, (d_in, d_out))
31
+ b = np.zeros(d_out)
32
+ return W, b
33
+ key, *keys = random.split(rng_key, len(layers))
34
+ params = list(map(init_layer, keys, layers[:-1], layers[1:]))
35
+ return params
36
+ def apply(params, inputs):
37
+ for W, b in params[:-1]:
38
+ outputs = np.dot(inputs, W) + b
39
+ inputs = activation(outputs)
40
+ W, b = params[-1]
41
+ outputs = np.dot(inputs, W) + b
42
+ return outputs
43
+ return init, apply
44
+
45
+ ##########################################################
46
+ ##########################################################
47
+ ##########################################################
48
+
49
+ from jax.example_libraries import optimizers
50
+ from functools import partial
51
+ import itertools
52
+
53
+ # Define the model
54
+ class EnsembleRegression:
55
+ def __init__(self, layers, ensemble_size, rng_key = random.PRNGKey(0)):
56
+ # Network initialization and evaluation functions
57
+ self.init, self.apply = MLP(layers)
58
+ self.init_prior, self.apply_prior = MLP(layers)
59
+
60
+ # Random keys
61
+ k1, k2, k3 = random.split(rng_key, 3)
62
+ keys_1 = random.split(k1, ensemble_size)
63
+ keys_2 = random.split(k2, ensemble_size)
64
+ keys_3 = random.split(k2, ensemble_size)
65
+
66
+ # Initialize
67
+ params = vmap(self.init)(keys_1)
68
+ params_prior = vmap(self.init_prior)(keys_2)
69
+
70
+ # Use optimizers to set optimizer initialization and update functions
71
+ lr = optimizers.exponential_decay(1e-4, decay_steps=1000, decay_rate=0.999)
72
+ lr = optimizers.exponential_decay(0.000227, decay_steps=1000, decay_rate=0.999)
73
+ self.opt_init, \
74
+ self.opt_update, \
75
+ self.get_params = optimizers.adam(lr)
76
+
77
+ self.opt_state = vmap(self.opt_init)(params)
78
+ self.prior_opt_state = vmap(self.opt_init)(params_prior)
79
+ self.key_opt_state = vmap(self.opt_init)(keys_3)
80
+
81
+ # Logger
82
+ self.itercount = itertools.count()
83
+ self.loss_log = []
84
+
85
+ # Define the forward pass
86
+ def net_forward(self, params, params_prior, inputs):
87
+ Y_pred = self.apply(params, inputs) + self.apply_prior(params_prior, inputs)
88
+ return Y_pred
89
+
90
+ # Evaluates predictions at test points
91
+ @partial(jit, static_argnums=(0,))
92
+ def posterior(self, params, inputs):
93
+ params, params_prior = params
94
+ samples = vmap(self.net_forward, (0, 0, 0))(params, params_prior, inputs)
95
+ return samples
96
+
97
+ ##########################################################
98
+ ##########################################################
99
+ ##########################################################
100
+
101
+ # Helper functions
102
+ normalize = lambda x, mu, std: (x-mu)/std
103
+
104
+ n_remove = 4
105
+ ind_input = np.concatenate( (np.arange(26),n_remove+26+np.arange(26-n_remove),np.array([52,53,54,55])) )
106
+ dim_xH = ind_input.shape[0]
107
+ dim_xL = ind_input.shape[0]
108
+
109
+ ind_output_heat = np.arange(26)
110
+ ind_output_moist = n_remove+np.arange(26-n_remove)
111
+
112
+ dim_yH = ind_output_heat.shape[0]+ind_output_moist.shape[0]
113
+ dim_yL = ind_output_heat.shape[0]+ind_output_moist.shape[0]
114
+
115
+ ensemble_size = 1
116
+ layers_H = [dim_xH, 512, 512, 512, 512, 512, 512, 512, dim_yH]
117
+
118
+ id_step = 1 # 1 or 2 for instance in case we dont have enough RAM memory to make
119
+ # predictions for the whole test dataset at once.
120
+
121
+ key = random.PRNGKey(0)
122
+ model_H = EnsembleRegression(layers_H, ensemble_size, key)
123
+
124
+ mu_SF_in = onp.load('norm/mu_X_SPCAM5.npy')[None,None,ind_input]
125
+ sigma_SF_in = onp.load('norm/sigma_X_SPCAM5.npy')[None,None,ind_input]
126
+
127
+ print('loading NN parameters')
128
+ params = []
129
+ params_prior = []
130
+ for i in range(len(layers_H)-1):
131
+ params.append( ( np.load('SF_param/SF_param_det/params_'+str(i)+'_'+str(0)+'.npy') ,
132
+ np.load('SF_param/SF_param_det/params_'+str(i)+'_'+str(1)+'.npy') ) )
133
+ params_prior.append( ( np.load('SF_param/SF_param_det/params_prior_'+str(i)+'_'+str(0)+'.npy') ,
134
+ np.load('SF_param/SF_param_det/params_prior_'+str(i)+'_'+str(1)+'.npy') ) )
135
+
136
+ opt_params_H = (params, params_prior)
137
+
138
+ @jit
139
+ def predict_H(x):
140
+ # accepts and returns un-normalized data
141
+ x = np.tile(x[np.newaxis,:,:], (ensemble_size, 1, 1))
142
+ x = normalize(x, mu_SF_in, sigma_SF_in)
143
+ samples = model_H.posterior(opt_params_H, x)
144
+ return samples
145
+
146
+ ##################################
147
+ ############## test ##############
148
+ ##################################
149
+
150
+ print('loading test')
151
+ if id_step == 1:
152
+ t = time.time()
153
+ test_XH = onp.load('data_SPCAM5_4K/all_inputs.npy')[:59387904,ind_input]
154
+ print('test loaded', 'time (s):', time.time() - t)
155
+ elif id_step == 2:
156
+ t = time.time()
157
+ test_XH = onp.load('data_SPCAM5_4K/all_inputs.npy')[59387904:,ind_input]
158
+ print('test loaded', 'time (s):', time.time() - t)
159
+
160
+ print('det NN, id_step : ', id_step, 'Computing pred')
161
+ t = time.time()
162
+ samples_test_H = predict_H(test_XH)
163
+ print('Computing pred', 'time (s):', time.time() - t)
164
+ print('Saving pred')
165
+ t = time.time()
166
+ np.save('SF_param/SF_param_det/test_pred_'+str(id_step)+'.npy', samples_test_H)
167
+ print('Saving pred', 'time (s):', time.time() - t)
5_mean_std_RPN_LF.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ """
4
+ Created on Fri May 26 23:27:52 2023
5
+
6
+ @author: mohamedazizbhouri
7
+ """
8
+
9
+ import numpy as onp
10
+ import time
11
+
12
+ n_remove = 4
13
+ ind_input = onp.concatenate( (onp.arange(26),n_remove+26+onp.arange(26-n_remove),onp.array([52,53,54,55])) )
14
+ dim_xH = ind_input.shape[0]
15
+ dim_xL = ind_input.shape[0]
16
+
17
+ ind_output_heat = onp.arange(26)
18
+ ind_output_moist = n_remove+onp.arange(26-n_remove)
19
+
20
+ dim_yH = ind_output_heat.shape[0]+ind_output_moist.shape[0]
21
+ dim_yL = ind_output_heat.shape[0]+ind_output_moist.shape[0]
22
+
23
+ mu_MF_out = onp.concatenate((onp.load('norm/mu_y_heat_CAM5.npy')[None,ind_output_heat],
24
+ onp.load('norm/mu_y_moist_CAM5.npy')[None,ind_output_moist]),axis=1)
25
+ sigma_MF_out = onp.concatenate((onp.load('norm/sigma_y_heat_CAM5.npy')[None,ind_output_heat],
26
+ onp.load('norm/sigma_y_moist_CAM5.npy')[None,ind_output_moist]),axis=1)
27
+
28
+ is_comp_mean = 1
29
+ id_step = 2
30
+ N_rpn = 128
31
+ print('loading data')
32
+
33
+ if is_comp_mean == 1: # RPN mean computation
34
+ samples_test_H = onp.load('MF_param/MF_param_'+str(0)+'/LF_test_pred_'+str(id_step)+'.npy')[0,:,:]/N_rpn
35
+ t = time.time()
36
+ for i in range(N_rpn-1):
37
+ print(id_step,i,N_rpn-1)
38
+ samples_test_H = samples_test_H + onp.load('MF_param/MF_param_'+str(i+1)+'/LF_test_pred_'+str(id_step)+'.npy')[0,:,:]/N_rpn
39
+ print(time.time()-t)
40
+ t = time.time()
41
+ samples_test_H = mu_MF_out + sigma_MF_out * samples_test_H
42
+ onp.save('MF_param/mean_RPN_LF_'+str(id_step)+'.npy',samples_test_H)
43
+ else: # RPN std computation
44
+ mu = onp.load('MF_param/mean_RPN_LF_'+str(id_step)+'.npy')
45
+
46
+ sigma = (mu_MF_out + onp.load('MF_param/MF_param_'+str(0)+'/LF_test_pred_'+str(id_step)+'.npy')[0,:,:] * sigma_MF_out - mu)**2/N_rpn
47
+ t = time.time()
48
+ for i in range(N_rpn-1):
49
+ print(id_step,i,N_rpn-1)
50
+ sigma = sigma + (mu_MF_out + onp.load('MF_param/MF_param_'+str(i+1)+'/LF_test_pred_'+str(id_step)+'.npy')[0,:,:] * sigma_MF_out - mu)**2/N_rpn
51
+ print(time.time()-t)
52
+ t = time.time()
53
+ sigma = onp.sqrt(sigma)
54
+ onp.save('MF_param/std_RPN_LF_'+str(id_step)+'.npy',sigma)
55
+
5_mean_std_RPN_MF.py ADDED
@@ -0,0 +1,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ """
4
+ Created on Thu May 4 10:20:14 2023
5
+
6
+ @author: mohamedazizbhouri
7
+ """
8
+
9
+ import numpy as onp
10
+ import time
11
+
12
+ n_remove = 4
13
+ ind_output_heat = onp.arange(26)
14
+ ind_output_moist = n_remove+onp.arange(26-n_remove)
15
+
16
+ is_MF = 1
17
+ is_SF = 0
18
+ is_LF = 0
19
+
20
+ if is_MF == 1:
21
+ mu_SF_out = onp.concatenate((onp.load('norm/mu_y_heat_CAM5.npy')[None,ind_output_heat],
22
+ onp.load('norm/mu_y_moist_CAM5.npy')[None,ind_output_moist]),axis=1)
23
+ sigma_SF_out = onp.concatenate((onp.load('norm/sigma_y_heat_CAM5.npy')[None,ind_output_heat],
24
+ onp.load('norm/sigma_y_moist_CAM5.npy')[None,ind_output_moist]),axis=1)
25
+
26
+ is_comp_mean = 1
27
+ id_step = 1
28
+ N_rpn = 128
29
+ print('loading data')
30
+
31
+ if is_comp_mean == 1: # RPN mean computation
32
+ samples_test_H = onp.load('MF_param/MF_param_'+str(0)+'/test_pred_'+str(id_step)+'.npy')[0,:,:]/N_rpn
33
+ t = time.time()
34
+ for i in range(N_rpn-1):
35
+ print(id_step,i,N_rpn-1)
36
+ samples_test_H = samples_test_H +onp.load('MF_param/MF_param_'+str(i+1)+'/test_pred_'+str(id_step)+'.npy')[0,:,:]/N_rpn
37
+ print(time.time()-t)
38
+ t = time.time()
39
+ samples_test_H = mu_SF_out + sigma_SF_out * samples_test_H
40
+ onp.save('MF_param/mean_RPN_MF_'+str(id_step)+'.npy',samples_test_H)
41
+ else: # RPN std computation
42
+ mu = onp.load('MF_param/mean_RPN_MF_'+str(id_step)+'.npy')
43
+
44
+ sigma = (mu_SF_out + onp.load('MF_param/MF_param_'+str(0)+'/test_pred_'+str(id_step)+'.npy')[0,:,:] * sigma_SF_out - mu)**2/N_rpn
45
+ t = time.time()
46
+ for i in range(N_rpn-1):
47
+ print(id_step,i,N_rpn-1)
48
+ sigma = sigma + (mu_SF_out + onp.load('MF_param/MF_param_'+str(0)+'/test_pred_'+str(id_step)+'.npy')[0,:,:] * sigma_SF_out - mu)**2/N_rpn
49
+ print(time.time()-t)
50
+ t = time.time()
51
+ sigma = onp.sqrt(sigma)
52
+ onp.save('MF_param/std_RPN_MF_'+str(id_step)+'.npy',sigma)
53
+
54
+ if is_SF == 1:
55
+ mu_SF_out = onp.concatenate((onp.load('norm/mu_y_heat_SPCAM5.npy')[None,ind_output_heat],
56
+ onp.load('norm/mu_y_moist_SPCAM5.npy')[None,ind_output_moist]),axis=1)
57
+ sigma_SF_out = onp.concatenate((onp.load('norm/sigma_y_heat_SPCAM5.npy')[None,ind_output_heat],
58
+ onp.load('norm/sigma_y_moist_SPCAM5.npy')[None,ind_output_moist]),axis=1)
59
+
60
+ is_comp_mean = 1
61
+ N_rpn = 128
62
+ print('loading data')
63
+
64
+ if is_comp_mean == 1: # RPN mean computation
65
+ samples_test_H = onp.concatenate( (onp.load('SF_param/SF_param_'+str(0)+'/test_pred_1.npy'),
66
+ onp.load('SF_param/SF_param_'+str(0)+'/test_pred_2.npy')), axis=1)[0,:,:]/N_rpn
67
+ t = time.time()
68
+ for i in range(N_rpn-1):
69
+ print(i,N_rpn-1)
70
+ samples_test_H = samples_test_H + onp.concatenate( (onp.load('SF_param/SF_param_'+str(i+1)+'/test_pred_1.npy'),
71
+ onp.load('SF_param/SF_param_'+str(i+1)+'/test_pred_2.npy')), axis=1)[0,:,:]/N_rpn
72
+ print(time.time()-t)
73
+ t = time.time()
74
+ samples_test_H = mu_SF_out + sigma_SF_out * samples_test_H
75
+ onp.save('SF_param/mean_RPN_SF.npy',samples_test_H)
76
+ else: # RPN std computation
77
+ mu = onp.load('SF_param/mean_RPN_SF.npy')
78
+ sigma = (mu_SF_out + onp.concatenate( (onp.load('SF_param/SF_param_'+str(0)+'/test_pred_1.npy'),
79
+ onp.load('SF_param/SF_param_'+str(0)+'/test_pred_2.npy')), axis=1)[0,:,:] * sigma_SF_out - mu)**2/N_rpn
80
+ t = time.time()
81
+ for i in range(N_rpn-1):
82
+ print(i,N_rpn-1)
83
+ sigma = sigma + (mu_SF_out + onp.concatenate( (onp.load('SF_param/SF_param_'+str(i+1)+'/test_pred_1.npy'),
84
+ onp.load('SF_param/SF_param_'+str(i+1)+'/test_pred_2.npy')), axis=1)[0,:,:] * sigma_SF_out - mu)**2/N_rpn
85
+ print(time.time()-t)
86
+ t = time.time()
87
+ sigma = onp.sqrt(sigma)
88
+ onp.save('SF_param/std_RPN_SF.npy',sigma)
89
+
90
+ if is_LF == 1:
91
+ mu_MF_out = onp.concatenate((onp.load('norm/mu_y_heat_CAM5.npy')[None,ind_output_heat],
92
+ onp.load('norm/mu_y_moist_CAM5.npy')[None,ind_output_moist]),axis=1)
93
+ sigma_MF_out = onp.concatenate((onp.load('norm/sigma_y_heat_CAM5.npy')[None,ind_output_heat],
94
+ onp.load('norm/sigma_y_moist_CAM5.npy')[None,ind_output_moist]),axis=1)
95
+
96
+ is_comp_mean = 1
97
+ id_step = 2
98
+ N_rpn = 128
99
+ print('loading data')
100
+
101
+ if is_comp_mean == 1: # RPN mean computation
102
+ samples_test_H = onp.load('MF_param/MF_param_'+str(0)+'/LF_test_pred_'+str(id_step)+'.npy')[0,:,:]/N_rpn
103
+ t = time.time()
104
+ for i in range(N_rpn-1):
105
+ print(id_step,i,N_rpn-1)
106
+ samples_test_H = samples_test_H + onp.load('MF_param/MF_param_'+str(i+1)+'/LF_test_pred_'+str(id_step)+'.npy')[0,:,:]/N_rpn
107
+ print(time.time()-t)
108
+ t = time.time()
109
+ samples_test_H = mu_MF_out + sigma_MF_out * samples_test_H
110
+ onp.save('MF_param/mean_RPN_LF_'+str(id_step)+'.npy',samples_test_H)
111
+ else: # RPN std computation
112
+ mu = onp.load('MF_param/mean_RPN_LF_'+str(id_step)+'.npy')
113
+
114
+ sigma = (mu_MF_out + onp.load('MF_param/MF_param_'+str(0)+'/LF_test_pred_'+str(id_step)+'.npy')[0,:,:] * sigma_MF_out - mu)**2/N_rpn
115
+ t = time.time()
116
+ for i in range(N_rpn-1):
117
+ print(id_step,i,N_rpn-1)
118
+ sigma = sigma + (mu_MF_out + onp.load('MF_param/MF_param_'+str(i+1)+'/LF_test_pred_'+str(id_step)+'.npy')[0,:,:] * sigma_MF_out - mu)**2/N_rpn
119
+ print(time.time()-t)
120
+ t = time.time()
121
+ sigma = onp.sqrt(sigma)
122
+ onp.save('MF_param/std_RPN_LF_'+str(id_step)+'.npy',sigma)
123
+
5_mean_std_RPN_SF.py ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ """
4
+ Created on Thu May 4 20:12:05 2023
5
+
6
+ @author: mohamedazizbhouri
7
+ """
8
+
9
+ import numpy as onp
10
+ import time
11
+
12
+ n_remove = 4
13
+ ind_input = onp.concatenate( (onp.arange(26),n_remove+26+onp.arange(26-n_remove),onp.array([52,53,54,55])) )
14
+ dim_xH = ind_input.shape[0]
15
+ dim_xL = ind_input.shape[0]
16
+
17
+ ind_output_heat = onp.arange(26)
18
+ ind_output_moist = n_remove+onp.arange(26-n_remove)
19
+
20
+ dim_yH = ind_output_heat.shape[0]+ind_output_moist.shape[0]
21
+ dim_yL = ind_output_heat.shape[0]+ind_output_moist.shape[0]
22
+
23
+ mu_SF_out = onp.concatenate((onp.load('norm/mu_y_heat_SPCAM5.npy')[None,ind_output_heat],
24
+ onp.load('norm/mu_y_moist_SPCAM5.npy')[None,ind_output_moist]),axis=1)
25
+ sigma_SF_out = onp.concatenate((onp.load('norm/sigma_y_heat_SPCAM5.npy')[None,ind_output_heat],
26
+ onp.load('norm/sigma_y_moist_SPCAM5.npy')[None,ind_output_moist]),axis=1)
27
+
28
+ is_comp_mean = 1
29
+ N_rpn = 128
30
+ print('loading data')
31
+
32
+ if is_comp_mean == 1: # RPN mean computation
33
+ samples_test_H = onp.concatenate( (onp.load('SF_param/SF_param_'+str(0)+'/test_pred_1.npy'),
34
+ onp.load('SF_param/SF_param_'+str(0)+'/test_pred_2.npy')), axis=1)[0,:,:]/N_rpn
35
+ t = time.time()
36
+ for i in range(N_rpn-1):
37
+ print(i,N_rpn-1)
38
+ samples_test_H = samples_test_H + onp.concatenate( (onp.load('SF_param/SF_param_'+str(i+1)+'/test_pred_1.npy'),
39
+ onp.load('SF_param/SF_param_'+str(i+1)+'/test_pred_2.npy')), axis=1)[0,:,:]/N_rpn
40
+ print(time.time()-t)
41
+ t = time.time()
42
+ samples_test_H = mu_SF_out + sigma_SF_out * samples_test_H
43
+ onp.save('SF_param/mean_RPN_SF.npy',samples_test_H)
44
+ else: # RPN std computation
45
+ mu = onp.load('SF_param/mean_RPN_SF.npy')
46
+ sigma = (mu_SF_out + onp.concatenate( (onp.load('SF_param/SF_param_'+str(0)+'/test_pred_1.npy'),
47
+ onp.load('SF_param/SF_param_'+str(0)+'/test_pred_2.npy')), axis=1)[0,:,:] * sigma_SF_out - mu)**2/N_rpn
48
+ t = time.time()
49
+ for i in range(N_rpn-1):
50
+ print(i,N_rpn-1)
51
+ sigma = sigma + (mu_SF_out + onp.concatenate( (onp.load('SF_param/SF_param_'+str(i+1)+'/test_pred_1.npy'),
52
+ onp.load('SF_param/SF_param_'+str(i+1)+'/test_pred_2.npy')), axis=1)[0,:,:] * sigma_SF_out - mu)**2/N_rpn
53
+ print(time.time()-t)
54
+ t = time.time()
55
+ sigma = onp.sqrt(sigma)
56
+ onp.save('SF_param/std_RPN_SF.npy',sigma)
57
+
6_reshape_pred_RPN.py ADDED
@@ -0,0 +1,110 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ """
4
+ Created on Sat May 27 20:02:33 2023
5
+
6
+ @author: mohamedazizbhouri
7
+ """
8
+ import numpy as onp
9
+
10
+ lat = 96
11
+ lon = 144
12
+ dim_y = 48
13
+
14
+ is_create_Npts_per_file = 0
15
+
16
+ is_det = 0
17
+ is_rpn_SF = 0
18
+ is_rpn_MF = 0
19
+ is_test_data = 0
20
+ is_LF = 1
21
+
22
+ test_SPCAM =['2003_02_06','2003_02_12','2003_02_18','2003_02_24','2003_02_28',
23
+ '2003_03_06','2003_03_12','2003_03_18','2003_03_24','2003_03_30','2003_03_31',
24
+ '2003_04_06','2003_04_12','2003_04_18','2003_04_24','2003_04_30',
25
+ '2003_05_06','2003_05_12','2003_05_18','2003_05_24','2003_05_30','2003_05_31',
26
+ '2003_06_06','2003_06_12','2003_06_18','2003_06_24','2003_06_30',
27
+ '2003_07_06','2003_07_12','2003_07_18','2003_07_24','2003_07_30','2003_07_31',
28
+ '2003_08_06','2003_08_12','2003_08_18','2003_08_24','2003_08_30','2003_08_31',
29
+ '2003_09_06','2003_09_12','2003_09_18','2003_09_24','2003_09_30',
30
+ '2003_10_06','2003_10_12','2003_10_18','2003_10_24','2003_10_30','2003_10_31',
31
+ '2003_11_06','2003_11_12','2003_11_18','2003_11_24','2003_11_30',
32
+ '2003_12_06','2003_12_12','2003_12_18','2003_12_24','2003_12_30','2003_12_31',
33
+ '2004_01_06','2004_01_12','2004_01_18','2004_01_24','2004_01_30','2004_01_31']
34
+
35
+ if is_create_Npts_per_file == 1:
36
+ print('create Npts_per_file')
37
+ Npts_per_file = []
38
+ for i in range(len(test_SPCAM)):
39
+ Npts_per_file.append( onp.load('data_SPCAM5_4K/inputs_'+test_SPCAM[i]+'.npy').shape[0] )
40
+ Npts_per_file = onp.array(Npts_per_file)
41
+ onp.save('data_SPCAM5_4K/Npts_per_file_test.npy',Npts_per_file)
42
+ print('Npts_per_file created')
43
+ else:
44
+ Npts_per_file = onp.load('data_SPCAM5_4K/Npts_per_file_test.npy')
45
+
46
+ def reshape_loc_onp(pred, dim_y):
47
+ pred_loc = pred[:Npts_per_file[0],:]
48
+ pred = pred[Npts_per_file[0]:,:]
49
+ nt_total = pred_loc.shape[0]//(lat*lon)
50
+ pred_array = onp.reshape(pred_loc.T, (dim_y,nt_total,lat,lon))
51
+
52
+ for i in range(len(test_SPCAM)-1):
53
+ print(i,len(test_SPCAM)-1)
54
+ pred_loc = pred[:Npts_per_file[i+1],:]
55
+ pred = pred[Npts_per_file[i+1]:,:]
56
+ nt_total = pred_loc.shape[0]//(lat*lon)
57
+
58
+ pred_array = onp.concatenate( (pred_array, onp.reshape(pred_loc.T, (dim_y,nt_total,lat,lon))),axis=1)
59
+ return pred_array
60
+
61
+ if is_det == 1:
62
+ print('load and reshape det')
63
+ n_run = 128
64
+ case_var = 'all'
65
+ samples_test_H = reshape_loc_onp( onp.concatenate( (onp.load('SF_param/SF_param_det/test_pred_1.npy')[0,:,:],
66
+ onp.load('SF_param/SF_param_det/test_pred_2.npy')[0,:,:]), axis=0 ), dim_y )
67
+ onp.save('SF_param/SF_param_det/test_pred_reshaped.npy', samples_test_H)
68
+
69
+ if is_LF == 1:
70
+ print('load and reshape det')
71
+
72
+ mean_rpn_LF = reshape_loc_onp( onp.concatenate( (onp.load('MF_param/mean_RPN_LF_1.npy'),
73
+ onp.load('MF_param/mean_RPN_LF_2.npy')), axis=0), dim_y ) # dim_y x nt x lon x lat
74
+ std_rpn_LF = reshape_loc_onp( onp.concatenate( (onp.load('MF_param/std_RPN_LF_1.npy'),
75
+ onp.load('MF_param/std_RPN_LF_2.npy')), axis=0), dim_y ) # dim_y x nt x lon x lat
76
+
77
+ onp.save('MF_param/mean_RPN_LF_reshaped.npy', mean_rpn_LF)
78
+ onp.save('MF_param/std_RPN_LF_reshaped.npy', std_rpn_LF)
79
+
80
+ if is_rpn_SF == 1:
81
+ print('load and reshape rpn SF')
82
+ mean_rpn = reshape_loc_onp( onp.load('SF_param/mean_RPN_SF.npy'), dim_y ) # dim_y x nt x lon x lat
83
+ std_rpn = reshape_loc_onp( onp.load('SF_param/std_RPN_SF.npy'), dim_y )
84
+
85
+ onp.save('SF_param/mean_RPN_SF_reshaped.npy', mean_rpn)
86
+ onp.save('SF_param/std_RPN_SF_reshaped.npy', std_rpn)
87
+
88
+ if is_rpn_MF == 1:
89
+ print('load and reshape rpn MF')
90
+ mean_rpn_MF = reshape_loc_onp( onp.concatenate( (onp.load('MF_param/mean_RPN_MF_1.npy'),
91
+ onp.load('MF_param/mean_RPN_MF_2.npy')), axis=0), dim_y ) # dim_y x nt x lon x lat
92
+ std_rpn_MF = reshape_loc_onp( onp.concatenate( (onp.load('MF_param/std_RPN_MF_1.npy'),
93
+ onp.load('MF_param/std_RPN_MF_2.npy')), axis=0), dim_y ) # dim_y x nt x lon x lat
94
+
95
+ onp.save('MF_param/mean_RPN_MF_reshaped.npy', mean_rpn_MF)
96
+ onp.save('MF_param/std_RPN_MF_reshaped.npy', std_rpn_MF)
97
+
98
+ if is_test_data == 1:
99
+ print('load and reshape test')
100
+
101
+ n_remove = 4
102
+ ind_output_heat = onp.arange(26)
103
+ ind_output_moist = n_remove+onp.arange(26-n_remove)
104
+ test_yH = onp.concatenate((onp.load('data_SPCAM5_4K/all_outputs_heat.npy')[:,ind_output_heat],
105
+ onp.load('data_SPCAM5_4K/all_outputs_moist.npy')[:,ind_output_moist]),axis=1)
106
+
107
+ test_yH = reshape_loc_onp(test_yH, dim_y)
108
+
109
+ onp.save('data_SPCAM5_4K/all_outputs_reshaped.npy', test_yH)
110
+
7_global_crps.py ADDED
@@ -0,0 +1,220 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ """
4
+ Created on Mon Aug 7 14:20:34 2023
5
+
6
+ @author: mohamedazizbhouri
7
+ """
8
+
9
+ import numpy as onp
10
+ import time
11
+
12
+ from matplotlib import pyplot as plt
13
+ plt.close('all')
14
+
15
+ plt.rcParams.update(plt.rcParamsDefault)
16
+ plt.rc('font', family='serif')
17
+ plt.rcParams.update({'font.size': 32,
18
+ 'lines.linewidth': 2,
19
+ 'axes.labelsize': 32,
20
+ 'axes.titlesize': 32,
21
+ 'xtick.labelsize': 32,
22
+ 'ytick.labelsize': 32,
23
+ 'legend.fontsize': 32,
24
+ 'axes.linewidth': 2,
25
+ "pgf.texsystem": "pdflatex"
26
+ })
27
+
28
+ dim_y = 48
29
+ dim_heat = 26
30
+ dim_moist = 22
31
+ n_remove = 4
32
+ ind_input = onp.concatenate( (onp.arange(26),n_remove+26+onp.arange(26-n_remove),onp.array([52,53,54,55])) )
33
+ dim_xH = ind_input.shape[0]
34
+ dim_xL = ind_input.shape[0]
35
+
36
+ ind_output_heat = onp.arange(26)
37
+ ind_output_moist = n_remove+onp.arange(26-n_remove)
38
+
39
+ mu_error_out = onp.concatenate((onp.zeros((1,dim_heat),dtype=onp.float32),
40
+ onp.zeros((1,dim_moist),dtype=onp.float32)),axis=1)
41
+
42
+ sigma_error_out = onp.concatenate((1/1004.6*onp.ones((1,dim_heat),dtype=onp.float32),
43
+ 1/2.26e6*onp.ones((1,dim_moist),dtype=onp.float32)),axis=1)
44
+
45
+ is_reshape_single_pred = 1
46
+
47
+ is_MF = 0
48
+ is_LF = 0
49
+ is_SF = 1
50
+
51
+ if is_reshape_single_pred == 1:
52
+
53
+ test_SPCAM =['2003_02_06','2003_02_12','2003_02_18','2003_02_24','2003_02_28',
54
+ '2003_03_06','2003_03_12','2003_03_18','2003_03_24','2003_03_30','2003_03_31',
55
+ '2003_04_06','2003_04_12','2003_04_18','2003_04_24','2003_04_30',
56
+ '2003_05_06','2003_05_12','2003_05_18','2003_05_24','2003_05_30','2003_05_31',
57
+ '2003_06_06','2003_06_12','2003_06_18','2003_06_24','2003_06_30',
58
+ '2003_07_06','2003_07_12','2003_07_18','2003_07_24','2003_07_30','2003_07_31',
59
+ '2003_08_06','2003_08_12','2003_08_18','2003_08_24','2003_08_30','2003_08_31',
60
+ '2003_09_06','2003_09_12','2003_09_18','2003_09_24','2003_09_30',
61
+ '2003_10_06','2003_10_12','2003_10_18','2003_10_24','2003_10_30','2003_10_31',
62
+ '2003_11_06','2003_11_12','2003_11_18','2003_11_24','2003_11_30',
63
+ '2003_12_06','2003_12_12','2003_12_18','2003_12_24','2003_12_30','2003_12_31',
64
+ '2004_01_06','2004_01_12','2004_01_18','2004_01_24','2004_01_30','2004_01_31']
65
+
66
+ Npts_per_file = onp.load('data_SPCAM5_4K/Npts_per_file_test.npy')
67
+
68
+ def reshape_loc_onp(pred, dim_y):
69
+ pred_loc = pred[:Npts_per_file[0],:]
70
+ pred = pred[Npts_per_file[0]:,:]
71
+ nt_total = pred_loc.shape[0]//(lat*lon)
72
+ pred_array = onp.reshape(pred_loc.T, (dim_y,nt_total,lat,lon))
73
+
74
+ for i in range(len(test_SPCAM)-1):
75
+ print(i,len(test_SPCAM)-1)
76
+ pred_loc = pred[:Npts_per_file[i+1],:]
77
+ pred = pred[Npts_per_file[i+1]:,:]
78
+ nt_total = pred_loc.shape[0]//(lat*lon)
79
+
80
+ pred_array = onp.concatenate( (pred_array, onp.reshape(pred_loc.T, (dim_y,nt_total,lat,lon))),axis=1)
81
+ return pred_array
82
+
83
+ case_var = 'all'
84
+ lat = 96
85
+ lon = 144
86
+ N_dt_day = 24 # we have a dt=1hour
87
+ def daily_avg(test):
88
+ test_daily = []
89
+ N_time_steps = test.shape[1]
90
+ for i in range(test.shape[0]):
91
+ test_daily.append( onp.mean( test[i,:,:,:].reshape( (N_time_steps//N_dt_day, N_dt_day, lat, lon) ), axis=1 ) )
92
+ return onp.array(test_daily) # dim_y x N_day x lat x lon
93
+
94
+ if is_MF == 1 or is_LF == 1:
95
+ mu_SF_out = onp.concatenate((onp.load('norm/mu_y_heat_CAM5.npy')[None,ind_output_heat],
96
+ onp.load('norm/mu_y_moist_CAM5.npy')[None,ind_output_moist]),axis=1)
97
+ sigma_SF_out = onp.concatenate((onp.load('norm/sigma_y_heat_CAM5.npy')[None,ind_output_heat],
98
+ onp.load('norm/sigma_y_moist_CAM5.npy')[None,ind_output_moist]),axis=1)
99
+
100
+ if is_SF == 1:
101
+ mu_SF_out = onp.concatenate((onp.load('norm/mu_y_heat_SPCAM5.npy')[None,ind_output_heat],
102
+ onp.load('norm/mu_y_moist_SPCAM5.npy')[None,ind_output_moist]),axis=1)
103
+ sigma_SF_out = onp.concatenate((onp.load('norm/sigma_y_heat_SPCAM5.npy')[None,ind_output_heat],
104
+ onp.load('norm/sigma_y_moist_SPCAM5.npy')[None,ind_output_moist]),axis=1)
105
+
106
+ tt = time.time()
107
+ for i in range(32):
108
+ ieff = i + 0
109
+ print(ieff,time.time()-tt)
110
+ tt = time.time()
111
+ if is_MF == 1:
112
+ samples_test_H = onp.concatenate( (onp.load('MF_param/MF_param_'+str(ieff)+'/test_pred_1.npy')[0,:,:],
113
+ onp.load('MF_param/MF_param_'+str(ieff)+'/test_pred_2.npy')[0,:,:]),axis=0)
114
+ if is_SF == 1:
115
+ samples_test_H = onp.concatenate( (onp.load('SF_param/SF_param_'+str(ieff)+'/test_pred_1.npy')[0,:,:],
116
+ onp.load('SF_param/SF_param_'+str(ieff)+'/test_pred_1.npy')[0,:,:]),axis=0)
117
+ if is_LF == 1:
118
+ samples_test_H = onp.concatenate( (onp.load('MF_param/MF_param_'+str(ieff)+'/LF_test_pred_1.npy')[0,:,:],
119
+ onp.load('MF_param/MF_param_'+str(ieff)+'/LF_test_pred_2.npy')[0,:,:]),axis=0)
120
+ samples_test_H = mu_SF_out + sigma_SF_out * samples_test_H
121
+ samples_test_H = (samples_test_H - mu_error_out) / sigma_error_out
122
+
123
+ samples_test_H = reshape_loc_onp(samples_test_H, dim_y)
124
+ samples_test_H = daily_avg(samples_test_H)
125
+ samples_test_H = samples_test_H.reshape((dim_y, samples_test_H.shape[1]*lat*lon))
126
+ samples_test_H = samples_test_H.T
127
+ print(samples_test_H.shape)
128
+ # Npts x dim_y
129
+ if is_MF == 1:
130
+ onp.save('MF_param/MF_param_'+str(ieff)+'/test_pred_reshaped.npy', samples_test_H)
131
+ if is_SF == 1:
132
+ onp.save('SF_param/SF_param_'+str(ieff)+'/test_pred_reshaped.npy', samples_test_H)
133
+ if is_LF == 1:
134
+ onp.save('MF_param/MF_param_'+str(ieff)+'/LF_test_pred_reshaped.npy', samples_test_H)
135
+
136
+ test = onp.load('data_SPCAM5_4K/all_outputs_reshaped.npy')
137
+ test = daily_avg(test)
138
+ test = test.reshape((dim_y, test.shape[1]*lat*lon)) # dim_y x N_samples
139
+ test = test.T
140
+ test = (test - mu_error_out) / sigma_error_out
141
+ onp.save('data_SPCAM5_4K/all_outputs_reshaped_temp_avg.npy', test)
142
+
143
+ else:
144
+
145
+ test = onp.load('data_SPCAM5_4K/all_outputs_reshaped_temp_avg.npy')
146
+ test = onp.array(test,dtype=onp.float64)
147
+
148
+ def crps(outputs, target, weights=None):
149
+ """
150
+ Computes the Continuous Ranked Probability Score (CRPS) between the target and the ecdf for each output variable and then takes a weighted average over them.
151
+
152
+ Input
153
+ -----
154
+ outputs - float[B, F, S] samples from the model
155
+ target - float[B, F] ground truth target
156
+ """
157
+ tt = time.time()
158
+ n = outputs.shape[2]
159
+ y_hats = onp.sort(outputs, axis=-1)
160
+ print('sort',time.time()-tt)
161
+
162
+ tt = time.time()
163
+ # E[Y - y]
164
+ mae = onp.abs(target[..., None] - y_hats).mean(axis=(0, -1))
165
+ print('abs',time.time()-tt)
166
+
167
+ tt = time.time()
168
+ # E[Y - Y'] ~= sum_i sum_j |Y_i - Y_j| / (2 * n * (n-1))
169
+ diff = y_hats[..., 1:] - y_hats[..., :-1]
170
+ print('abs2',time.time()-tt)
171
+
172
+ tt = time.time()
173
+ count = onp.arange(1, n) * onp.arange(n - 1, 0, -1)
174
+ print('arange',time.time()-tt)
175
+
176
+ tt = time.time()
177
+ crps = mae - (diff * count).sum(axis=-1).mean(axis=0) / (2 * n * (n-1))
178
+ print('crps final',time.time()-tt)
179
+ return crps
180
+
181
+ if is_MF == 1:
182
+ ieff = 0
183
+ pred_daily = onp.load('MF_param/MF_param_'+str(ieff)+'/test_pred_reshaped.npy')[:,:,None]
184
+ for i in range(31):
185
+ print(i)
186
+ ieff = i+1
187
+ pred_daily = onp.concatenate( (pred_daily,onp.load('MF_param/MF_param_'+str(ieff)+'/test_pred_reshaped.npy')[:,:,None]),axis=2)
188
+ pred_daily = onp.array(pred_daily,dtype=onp.float64)
189
+
190
+ crps_f = crps(pred_daily, test)
191
+ onp.save('glob_errors/crps_rpn_MF.npy',crps_f)
192
+
193
+ if is_SF == 1:
194
+ ieff = 0
195
+ pred_daily = onp.load('SF_param/SF_param_'+str(ieff)+'/test_pred_reshaped.npy')[:,:,None]
196
+ for i in range(31):
197
+ print(i)
198
+ ieff = i+1
199
+ pred_daily = onp.concatenate( (pred_daily,onp.load('SF_param/SF_param_'+str(ieff)+'/test_pred_reshaped.npy')[:,:,None]),axis=2)
200
+ pred_daily = onp.array(pred_daily,dtype=onp.float64)
201
+
202
+ crps_f = crps(pred_daily, test)
203
+ print(crps_f.shape)
204
+ print(onp.array(crps_f).shape)
205
+ onp.save('glob_errors/crps_rpn_SF.npy',crps_f)
206
+
207
+ if is_LF == 1:
208
+ ieff = 0
209
+ pred_daily = onp.load('MF_param/MF_param_'+str(ieff)+'/LF_test_pred_reshaped.npy')[:,:,None]
210
+ for i in range(31):
211
+ print(i)
212
+ ieff = i+1
213
+ pred_daily = onp.concatenate( (pred_daily,onp.load('MF_param/MF_param_'+str(ieff)+'/LF_test_pred_reshaped.npy')[:,:,None]),axis=2)
214
+ pred_daily = onp.array(pred_daily,dtype=onp.float64)
215
+
216
+ crps_f = crps(pred_daily, test)
217
+ print(crps_f.shape)
218
+ print(onp.array(crps_f).shape)
219
+ onp.save('glob_errors/crps_rpn_LF.npy',crps_f)
220
+
7_global_errors_temporal_errors.py ADDED
@@ -0,0 +1,163 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ """
4
+ Created on Sat May 27 20:48:41 2023
5
+
6
+ @author: mohamedazizbhouri
7
+ """
8
+ from matplotlib import pyplot as plt
9
+ import numpy as onp
10
+
11
+ plt.rcParams.update(plt.rcParamsDefault)
12
+ plt.rc('font', family='serif')
13
+ plt.rcParams.update({'font.size': 32,
14
+ 'lines.linewidth': 2,
15
+ 'axes.labelsize': 32,
16
+ 'axes.titlesize': 32,
17
+ 'xtick.labelsize': 32,
18
+ 'ytick.labelsize': 32,
19
+ 'legend.fontsize': 32,
20
+ 'axes.linewidth': 2,
21
+ "pgf.texsystem": "pdflatex"
22
+ })
23
+ plt.close('all')
24
+
25
+ lat = 96
26
+ lon = 144
27
+
28
+ is_glob_err = 0
29
+ is_temp_MAE = 0
30
+ is_temp_r2 = 1
31
+
32
+ dim_y = 48
33
+ dim_heat = 26
34
+ dim_moist = 22
35
+
36
+ mu_error_out = onp.concatenate((onp.zeros((1,dim_heat),dtype=onp.float32),
37
+ onp.zeros((1,dim_moist),dtype=onp.float32)),axis=1)
38
+ mu_error_out = mu_error_out.T[:,:,None,None]
39
+
40
+ sigma_error_out = onp.concatenate((1/1004.6*onp.ones((1,dim_heat),dtype=onp.float32),
41
+ 1/2.26e6*onp.ones((1,dim_moist),dtype=onp.float32)),axis=1)
42
+
43
+ sigma_error_out = sigma_error_out.T[:,:,None,None]
44
+
45
+ test = (onp.load('data_SPCAM5_4K/all_outputs_reshaped.npy') - mu_error_out) / sigma_error_out
46
+ test = onp.array(test,dtype=onp.float64)
47
+
48
+ n_run = 128
49
+ pred_det = (onp.load('SF_param/SF_param_det/test_pred_reshaped.npy') - mu_error_out) / sigma_error_out
50
+ pred_det = onp.array(pred_det,dtype=onp.float64)
51
+
52
+ pred_rpn = onp.load('SF_param/mean_RPN_SF_reshaped.npy')
53
+ pred_rpn = (pred_rpn - mu_error_out) / sigma_error_out
54
+ pred_rpn = onp.array(pred_rpn,dtype=onp.float64)
55
+
56
+ pred_rpn_MF = onp.load('MF_param/mean_RPN_MF_reshaped.npy')
57
+ pred_rpn_MF = (pred_rpn_MF - mu_error_out) / sigma_error_out
58
+ pred_rpn_MF = onp.array(pred_rpn_MF,dtype=onp.float64)
59
+
60
+ pred_rpn_LF = onp.load('MF_param/mean_RPN_LF_reshaped.npy')
61
+ pred_rpn_LF = (pred_rpn_LF - mu_error_out) / sigma_error_out
62
+ pred_rpn_LF = onp.array(pred_rpn_LF,dtype=onp.float64)
63
+
64
+ N_dt_day = 24 # we have a dt=1hour
65
+ def daily_avg(test):
66
+ test_daily = []
67
+ N_time_steps = test.shape[1]
68
+ for i in range(test.shape[0]):
69
+ test_daily.append( onp.mean( test[i,:,:,:].reshape( (N_time_steps//N_dt_day, N_dt_day, lat, lon) ), axis=1 ) )
70
+ return onp.array(test_daily) # dim_y x N_day x lat x lon
71
+ pred_det = daily_avg(pred_det)
72
+ pred_rpn = daily_avg(pred_rpn)
73
+ pred_rpn_MF = daily_avg(pred_rpn_MF)
74
+ pred_rpn_LF = daily_avg(pred_rpn_LF)
75
+ test = daily_avg(test)
76
+
77
+ if is_glob_err == 1:
78
+ MAE_det = onp.mean(onp.abs(pred_det-test),axis=(1,2,3)) # dim_y x nt
79
+ MAE_rpn_SF = onp.mean(onp.abs(pred_rpn-test),axis=(1,2,3)) # dim_y x nt
80
+ MAE_rpn_MF = onp.mean( onp.abs(pred_rpn_MF - test) ,axis=(1,2,3))
81
+ MAE_rpn_LF = onp.mean( onp.abs(pred_rpn_LF - test) ,axis=(1,2,3))
82
+
83
+ onp.save('glob_errors/MAE_det.npy',MAE_det)
84
+ onp.save('glob_errors/MAE_rpn_SF.npy',MAE_rpn_SF)
85
+ onp.save('glob_errors/MAE_rpn_MF.npy',MAE_rpn_MF)
86
+ onp.save('glob_errors/MAE_rpn_LF.npy',MAE_rpn_LF)
87
+
88
+ r2_det = 1 - onp.sum( (test-pred_det)**2, axis=(1,2,3) ) / onp.sum( (test-onp.mean(test,axis=(1,2,3))[:,None,None,None])**2, axis=(1,2,3) )
89
+ r2_rpn = 1 - onp.sum( (test-pred_rpn)**2, axis=(1,2,3) ) / onp.sum( (test-onp.mean(test,axis=(1,2,3))[:,None,None,None])**2, axis=(1,2,3) )
90
+ r2_rpn_MF = 1 - onp.sum( (test-pred_rpn_MF)**2, axis=(1,2,3) ) / onp.sum( (test-onp.mean(test,axis=(1,2,3))[:,None,None,None])**2, axis=(1,2,3) )
91
+ r2_rpn_LF = 1 - onp.sum( (test-pred_rpn_LF)**2, axis=(1,2,3) ) / onp.sum( (test-onp.mean(test,axis=(1,2,3))[:,None,None,None])**2, axis=(1,2,3) )
92
+
93
+ onp.save('glob_errors/r2_det.npy',r2_det)
94
+ onp.save('glob_errors/r2_rpn_SF.npy',r2_rpn)
95
+ onp.save('glob_errors/r2_rpn_MF.npy',r2_rpn_MF)
96
+ onp.save('glob_errors/r2_rpn_LF.npy',r2_rpn_LF)
97
+
98
+ if is_temp_MAE == 1:
99
+ x_labels = ['02/2003','03/2003','04/2003','05/2003','06/2003','07/2003',
100
+ '08/2003','09/2003','10/2003','11/2003','12/2003','01/2004','02/2004']
101
+
102
+ print('Compute MAE')
103
+ err_det = onp.mean(onp.abs(pred_det-test),axis=(2,3)) # dim_y x nt
104
+ err_rpn = onp.mean(onp.abs(pred_rpn-test),axis=(2,3)) # dim_y x nt
105
+ err_rpn_MF = onp.mean( onp.abs(pred_rpn_MF - test) ,axis=(2,3))
106
+ err_rpn_LF = onp.mean( onp.abs(pred_rpn_LF - test) ,axis=(2,3))
107
+
108
+ for i in range(dim_y):
109
+ fig = plt.figure(figsize=(15,8))
110
+ ax = fig.add_subplot(111)
111
+ x_labels = ['02/2003','03/2003','04/2003','05/2003','06/2003','07/2003',
112
+ '08/2003','09/2003','10/2003','11/2003','12/2003','01/2004','02/2004']
113
+ ax.set_xticks(onp.linspace(0,err_det.shape[1]-1,13))
114
+ ax.set_xticklabels(x_labels, rotation =45, fontsize=22)
115
+ ax.yaxis.set_tick_params(labelsize=22)
116
+ ax.plot(onp.arange(err_det.shape[1]), err_det[i,:], color='blue', linewidth=3, label = "Det. NN")
117
+ ax.plot(onp.arange(err_det.shape[1]), err_rpn[i,:], '--', color='black', linewidth=3, label = "SF-RPN")
118
+ ax.plot(onp.arange(err_det.shape[1]), err_rpn_LF[i,:], '--', color='orange', linewidth=3, label = "LF-RPN")
119
+ ax.plot(onp.arange(err_det.shape[1]), err_rpn_MF[i,:], color='red', linewidth=3, label = "MF-RPN")
120
+ ax.set_ylabel('MAE')
121
+ ax.set_xlabel('Time')
122
+ ax.grid()
123
+ ax.legend(bbox_to_anchor=[0.5, 1.2], loc='center', ncol=4)
124
+
125
+ if i > 25:
126
+ plt.savefig('temp_plots/moist_MAE_temp_'+str(i-26+4)+'.png', bbox_inches='tight', pad_inches=0.1 , dpi = 300)
127
+
128
+ else:
129
+ plt.savefig('temp_plots/heat_MAE_temp_'+str(i)+'.png', bbox_inches='tight', pad_inches=0.1 , dpi = 300)
130
+
131
+ if is_temp_r2 == 1:
132
+ x_labels = ['02/2003','03/2003','04/2003','05/2003','06/2003','07/2003',
133
+ '08/2003','09/2003','10/2003','11/2003','12/2003','01/2004','02/2004']
134
+
135
+ print('Compute R^2')
136
+ r2_det = 1 - onp.sum( (test-pred_det)**2, axis=(2,3) ) / onp.sum( (test-onp.mean(test,axis=(2,3))[:,:,None,None])**2, axis=(2,3) )
137
+ r2_rpn_SF = 1 - onp.sum( (test-pred_rpn)**2, axis=(2,3) ) / onp.sum( (test-onp.mean(test,axis=(2,3))[:,:,None,None])**2, axis=(2,3) )
138
+ r2_rpn_MF = 1 - onp.sum( (test-pred_rpn_MF)**2, axis=(2,3) ) / onp.sum( (test-onp.mean(test,axis=(2,3))[:,:,None,None])**2, axis=(2,3) )
139
+ r2_rpn_LF = 1 - onp.sum( (test-pred_rpn_LF)**2, axis=(2,3) ) / onp.sum( (test-onp.mean(test,axis=(2,3))[:,:,None,None])**2, axis=(2,3) )
140
+
141
+ for i in range(dim_y):
142
+ fig = plt.figure(figsize=(15,8))
143
+ ax = fig.add_subplot(111)
144
+
145
+ ax.set_xticks(onp.linspace(0,r2_det.shape[1]-1,13))
146
+ ax.set_xticklabels(x_labels, rotation =45, fontsize=22)
147
+ ax.yaxis.set_tick_params(labelsize=22)
148
+ ax.plot(onp.arange(r2_det.shape[1]), r2_det[i,:], color='blue', linewidth=3, label = "Det. NN")
149
+ ax.plot(onp.arange(r2_det.shape[1]), r2_rpn_SF[i,:], '--', color='black', linewidth=3, label = "SF-RPN")
150
+ ax.plot(onp.arange(r2_det.shape[1]), r2_rpn_LF[i,:], '--', color='orange', linewidth=3, label = "LF-RPN")
151
+ ax.plot(onp.arange(r2_det.shape[1]), r2_rpn_MF[i,:], color='red', linewidth=3, label = "MF-RPN")
152
+ ax.set_ylabel('$R^2$')
153
+ ax.set_xlabel('Time')
154
+ ax.grid()
155
+ ax.legend(bbox_to_anchor=[0.5, 1.2], loc='center', ncol=4)
156
+
157
+ if i > 25:
158
+ plt.savefig('temp_plots/moist_r2_temp_'+str(i-26+4)+'.png', bbox_inches='tight', pad_inches=0.1 , dpi = 300)
159
+
160
+ else:
161
+ plt.savefig('temp_plots/heat_r2_temp_'+str(i)+'.png', bbox_inches='tight', pad_inches=0.1 , dpi = 300)
162
+
163
+
7_long_lat_errors.py ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ """
4
+ Created on Thu Jun 8 00:59:59 2023
5
+
6
+ @author: mohamedazizbhouri
7
+ """
8
+ import numpy as onp
9
+
10
+ lat = 96
11
+ lon = 144
12
+
13
+ dim_y = 48
14
+ dim_heat = 26
15
+ dim_moist = 22
16
+
17
+ mu_error_out = onp.concatenate((onp.zeros((1,dim_heat),dtype=onp.float32),
18
+ onp.zeros((1,dim_moist),dtype=onp.float32)),axis=1)
19
+ mu_error_out = mu_error_out.T[:,:,None,None]
20
+
21
+ sigma_error_out = onp.concatenate((1/1004.6*onp.ones((1,dim_heat),dtype=onp.float32),
22
+ 1/2.26e6*onp.ones((1,dim_moist),dtype=onp.float32)),axis=1)
23
+
24
+ sigma_error_out = sigma_error_out.T[:,:,None,None]
25
+
26
+ is_det = 0
27
+ is_SF = 0
28
+ is_rpn_MF = 0
29
+ is_LF = 1
30
+
31
+ N_dt_day = 24 # we have a dt=1hour
32
+
33
+ test = (onp.load('data_SPCAM5_4K/all_outputs_reshaped.npy') - mu_error_out) / sigma_error_out
34
+ test = onp.array(test,dtype=onp.float64)
35
+
36
+ def daily_avg(test):
37
+ test_daily = []
38
+ N_time_steps = test.shape[1]
39
+ for i in range(test.shape[0]):
40
+ test_daily.append( onp.mean( test[i,:,:,:].reshape( (N_time_steps//N_dt_day, N_dt_day, lat, lon) ), axis=1 ) )
41
+ return onp.array(test_daily)
42
+
43
+ test = daily_avg(test)
44
+
45
+ if is_det == 1:
46
+
47
+ pred = (onp.load('SF_param/SF_param_det/test_pred_reshaped.npy') - mu_error_out) / sigma_error_out
48
+ pred = onp.array(pred,dtype=onp.float64)
49
+ pred = daily_avg(pred)
50
+ print('Compute MAE')
51
+ err = onp.mean(onp.abs(pred-test),axis=1) # dim_y x lon x lat
52
+ onp.save('SF_results/MAE_det_long_lat.npy',err)
53
+
54
+ print('Compute R^2')
55
+ r2 = 1 - onp.sum( (test-pred)**2, axis=1 ) / onp.sum( (test-onp.mean(test,axis=1)[:,None,:,:])**2, axis=1 )
56
+ onp.save('SF_results/r2_det_long_lat.npy',r2)
57
+
58
+ if is_LF == 1:
59
+ pred = (onp.load('MF_param/mean_RPN_LF_reshaped.npy') - mu_error_out) / sigma_error_out
60
+ pred = onp.array(pred,dtype=onp.float64)
61
+ pred = daily_avg(pred)
62
+ print('Compute MAE')
63
+ err = onp.mean(onp.abs(pred-test),axis=1) # dim_y x lon x lat
64
+ onp.save('MF_results/MAE_LF_long_lat.npy',err)
65
+
66
+ print('Compute R^2')
67
+ r2 = 1 - onp.sum( (test-pred)**2, axis=1 ) / onp.sum( (test-onp.mean(test,axis=1)[:,None,:,:])**2, axis=1 )
68
+ onp.save('MF_results/r2_LF_long_lat',r2)
69
+
70
+ if is_SF == 1:
71
+ pred = (onp.load('SF_param/mean_RPN_SF_reshaped.npy') - mu_error_out) / sigma_error_out
72
+ pred = onp.array(pred,dtype=onp.float64)
73
+ pred = daily_avg(pred)
74
+ print('Compute MAE')
75
+ err = onp.mean(onp.abs(pred-test),axis=1) # dim_y x lon x lat
76
+ onp.save('SF_results/MAE_SF_long_lat.npy', err)
77
+
78
+ print('Compute R^2')
79
+ r2 = 1 - onp.sum( (test-pred)**2, axis=1)/onp.sum( (test-onp.mean(test,axis=1)[:,None,:,:])**2, axis=1)
80
+ onp.save('SF_results/r2_SF_long_lat.npy', r2)
81
+
82
+ if is_rpn_MF == 1:
83
+ pred = (onp.load('MF_param/mean_RPN_MF_reshaped.npy') - mu_error_out) / sigma_error_out
84
+ pred = onp.array(pred,dtype=onp.float64)
85
+ pred = daily_avg(pred)
86
+ print('Compute MAE')
87
+ err = onp.mean( onp.abs(pred - test) ,axis=1)
88
+ onp.save('MF_results/MAE_MF_long_lat.npy', err)
89
+
90
+ print('Compute R^2')
91
+ r2 = 1 - onp.sum( (test-pred)**2, axis=1)/onp.sum( (test-onp.mean(test,axis=1)[:,None,:,:])**2, axis=1)
92
+ onp.save('MF_results/r2_MF_long_lat.npy', r2)
93
+
94
+
95
+
7_pressure_lat_errors.py ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ """
4
+ Created on Wed Jun 21 09:14:29 2023
5
+
6
+ @author: mohamedazizbhouri
7
+ """
8
+ import numpy as onp
9
+
10
+ lat = 96
11
+ lon = 144
12
+
13
+ dim_heat = 26
14
+ dim_moist = 22
15
+ mu_error_out = onp.concatenate((onp.zeros((1,dim_heat),dtype=onp.float32),
16
+ onp.zeros((1,dim_moist),dtype=onp.float32)),axis=1)
17
+ mu_error_out = mu_error_out.T[:,:,None,None]
18
+ sigma_error_out = onp.concatenate((1/1004.6*onp.ones((1,dim_heat),dtype=onp.float32),
19
+ 1/2.26e6*onp.ones((1,dim_moist),dtype=onp.float32)),axis=1)
20
+ sigma_error_out = sigma_error_out.T[:,:,None,None]
21
+
22
+ is_det = 0
23
+ is_SF = 0
24
+ is_MF = 0
25
+ is_LF = 1
26
+
27
+ N_dt_day = 24 # we have a dt=1hour
28
+
29
+ test = (onp.load('data_SPCAM5_4K/all_outputs_reshaped.npy') - mu_error_out) / sigma_error_out
30
+ test = onp.array(test,dtype=onp.float64)
31
+
32
+ def daily_avg(test):
33
+ test_daily = []
34
+ N_time_steps = test.shape[1]
35
+ for i in range(test.shape[0]):
36
+ test_daily.append( onp.mean( test[i,:,:,:].reshape( (N_time_steps//N_dt_day, N_dt_day, lat, lon) ), axis=1 ) )
37
+ return onp.array(test_daily)
38
+
39
+ test = daily_avg(test)
40
+
41
+ if is_LF == 1:
42
+ pred = (onp.load('MF_param/mean_RPN_LF_reshaped.npy') - mu_error_out) / sigma_error_out
43
+ pred = onp.array(pred,dtype=onp.float64)
44
+ pred = daily_avg(pred)
45
+ pred = onp.mean(pred, axis = 3)
46
+ test = onp.mean(test, axis = 3)
47
+
48
+ print('Compute R^2')
49
+ r2 = 1 - onp.sum( (test-pred)**2, axis=1)/onp.sum( (test-onp.mean(test,axis=1)[:,None,:])**2, axis=1)
50
+ onp.save('MF_results/r2_LF_pres_lat.npy', r2)
51
+
52
+ if is_det == 1:
53
+ pred = (onp.load('SF_param/SF_param_det/test_pred_reshaped.npy') - mu_error_out) / sigma_error_out
54
+ pred = onp.array(pred,dtype=onp.float64)
55
+ pred = daily_avg(pred)
56
+ pred = onp.mean(pred, axis = 3)
57
+ test = onp.mean(test, axis = 3)
58
+
59
+ print('Compute R^2')
60
+ r2 = 1 - onp.sum( (test-pred)**2, axis=1)/onp.sum( (test-onp.mean(test,axis=1)[:,None,:])**2, axis=1)
61
+ onp.save('SF_results/r2_det_pres_lat.npy',r2)
62
+
63
+ if is_SF == 1:
64
+ pred = (onp.load('SF_param/mean_RPN_SF_reshaped.npy') - mu_error_out) / sigma_error_out
65
+ pred = onp.array(pred,dtype=onp.float64)
66
+ pred = daily_avg(pred)
67
+ pred = onp.mean(pred, axis = 3)
68
+ test = onp.mean(test, axis = 3)
69
+
70
+ print('Compute R^2')
71
+ r2 = 1 - onp.sum( (test-pred)**2, axis=1)/onp.sum( (test-onp.mean(test,axis=1)[:,None,:])**2, axis=1)
72
+ onp.save('SF_results/r2_SF_pres_lat.npy', r2)
73
+
74
+ if is_MF == 1:
75
+ pred = (onp.load('MF_param/mean_RPN_MF_reshaped.npy') - mu_error_out) / sigma_error_out
76
+ pred = onp.array(pred,dtype=onp.float64)
77
+ pred = daily_avg(pred)
78
+ pred = onp.mean(pred, axis = 3)
79
+ test = onp.mean(test, axis = 3)
80
+
81
+ print('Compute R^2')
82
+ r2 = 1 - onp.sum( (test-pred)**2, axis=1)/onp.sum( (test-onp.mean(test,axis=1)[:,None,:])**2, axis=1)
83
+ onp.save('MF_results/r2_MF_pres_lat.npy', r2)
8_long_lat_plots.py ADDED
@@ -0,0 +1,234 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ """
4
+ Created on Fri Jun 9 07:14:37 2023
5
+
6
+ @author: mohamedazizbhouri
7
+ """
8
+ from matplotlib import pyplot as plt
9
+ import numpy as np
10
+
11
+ plt.rcParams.update(plt.rcParamsDefault)
12
+ plt.rc('font', family='serif')
13
+ plt.rcParams.update({'font.size': 16,
14
+ 'lines.linewidth': 2,
15
+ 'axes.labelsize': 20,
16
+ 'axes.titlesize': 20,
17
+ 'xtick.labelsize': 16,
18
+ 'ytick.labelsize': 16,
19
+ 'legend.fontsize': 20,
20
+ 'axes.linewidth': 2,
21
+ "pgf.texsystem": "pdflatex"
22
+ })
23
+
24
+ lat = 96
25
+ lon = 144
26
+ x = np.linspace(0, 360-360/144, lon)
27
+ y = np.linspace(-90, 90, lat)
28
+ X, Y = np.meshgrid(x, y)
29
+
30
+ from mpl_toolkits.basemap import Basemap
31
+
32
+ dim_y = 26+22
33
+
34
+ MAE_det = np.load('SF_results/MAE_det_long_lat.npy')
35
+ r2_det = np.load('SF_results/r2_det_long_lat.npy')
36
+
37
+ MAE_SF = np.load('SF_results/MAE_SF_long_lat.npy')
38
+ r2_SF = np.load('SF_results/r2_SF_long_lat.npy')
39
+
40
+ MAE_MF = np.load('MF_results/MAE_MF_long_lat.npy')
41
+ r2_MF = np.load('MF_results/r2_MF_long_lat.npy')
42
+
43
+ MAE_LF = np.load('MF_results/MAE_LF_long_lat.npy')
44
+ r2_LF = np.load('MF_results/r2_LF_long_lat.npy')
45
+
46
+ dim_heat = 26
47
+ dim_moist = 22
48
+ mu_error_out = np.concatenate((np.zeros((1,dim_heat),dtype=np.float32),
49
+ np.zeros((1,dim_moist),dtype=np.float32)),axis=1)
50
+ mu_error_out = mu_error_out.T[:,:,None,None]
51
+ sigma_error_out = np.concatenate((1/1004.6*np.ones((1,dim_heat),dtype=np.float32),
52
+ 1/2.26e6*np.ones((1,dim_moist),dtype=np.float32)),axis=1)
53
+ sigma_error_out = sigma_error_out.T[:,:,None,None]
54
+
55
+ print('Create err plots')
56
+
57
+ is_uncert = 1
58
+ is_MAE = 1
59
+ is_R2 = 1
60
+
61
+ if is_uncert == 1: # uncertainty plots
62
+ std_rpn_MF = np.load('MF_param/std_RPN_MF_reshaped.npy')/ sigma_error_out
63
+
64
+ std_rpn_MF = np.mean(std_rpn_MF, axis=1)
65
+ for i in range(dim_y):
66
+ fig = plt.figure(figsize=(10.5, 14))
67
+ ax = fig.add_subplot(211)
68
+ ax.set_title("MAE")
69
+ m = Basemap(projection='robin',lon_0=-180)
70
+ MAE_MF_p = MAE_MF[i,:,:]
71
+ contour_plot = m.pcolormesh(X, Y,MAE_MF_p, latlon = True, cmap='Blues_r')
72
+ m.drawcoastlines(linewidth=2.0, color='0.25')
73
+ m.colorbar(contour_plot)
74
+
75
+ ax = fig.add_subplot(212)
76
+ ax.set_title("Uncertainty "+r'$\sigma_M$')
77
+ m = Basemap(projection='robin',lon_0=-180)
78
+ std_rpn_MF_p = std_rpn_MF[i,:,:]
79
+ contour_plot = m.pcolormesh(X, Y, std_rpn_MF_p, latlon = True, cmap='Blues_r')
80
+ m.drawcoastlines(linewidth=2.0, color='0.25')
81
+ m.colorbar(contour_plot)
82
+
83
+ plt.subplots_adjust(hspace=-0.35)
84
+
85
+ if i > 25:
86
+ plt.savefig('long_lat_uncert_plots/MF_moist_long_lat_uncert_'+str(i-26+4)+'.png', bbox_inches='tight', pad_inches=0.1 , dpi = 300)
87
+
88
+ else:
89
+ plt.savefig('long_lat_uncert_plots/MF_heat_long_lat_uncert_'+str(i)+'.png', bbox_inches='tight', pad_inches=0.1 , dpi = 300)
90
+
91
+ std_rpn_SF = np.load('SF_param/std_RPN_SF_reshaped.npy')/ sigma_error_out
92
+ std_rpn_SF = np.mean(std_rpn_SF, axis=1)
93
+ for i in range(dim_y):
94
+ fig = plt.figure(figsize=(10.5, 14))
95
+ ax = fig.add_subplot(211)
96
+ ax.set_title("MAE")
97
+ m = Basemap(projection='robin',lon_0=-180)
98
+ MAE_SF_p = MAE_SF[i,:,:]
99
+ contour_plot = m.pcolormesh(X, Y, MAE_SF_p, latlon = True, cmap='Blues_r')
100
+ m.drawcoastlines(linewidth=2.0, color='0.25')
101
+ m.colorbar(contour_plot)
102
+ ax = fig.add_subplot(212)
103
+ ax.set_title("Uncertainty "+r'$\sigma_M$')
104
+ m = Basemap(projection='robin',lon_0=-180)
105
+ std_rpn_SF_p = std_rpn_SF[i,:,:]
106
+ contour_plot = m.pcolormesh(X, Y, std_rpn_SF_p, latlon = True, cmap='Blues_r')
107
+ m.drawcoastlines(linewidth=2.0, color='0.25')
108
+ m.colorbar(contour_plot)
109
+ plt.subplots_adjust(hspace=-0.35)
110
+ if i > 25:
111
+ plt.savefig('long_lat_uncert_plots/SF_moist_long_lat_uncert_'+str(i-26+4)+'.png', bbox_inches='tight', pad_inches=0.1 , dpi = 300)
112
+
113
+ else:
114
+ plt.savefig('long_lat_uncert_plots/SF_moist_long_lat_uncert_'+str(i)+'.png', bbox_inches='tight', pad_inches=0.1 , dpi = 300)
115
+
116
+ std_rpn_LF = np.load('MF_param/std_RPN_LF_reshaped.npy')/ sigma_error_out
117
+ std_rpn_LF = np.mean(std_rpn_LF, axis=1)
118
+ for i in range(dim_y):
119
+ fig = plt.figure(figsize=(10.5, 14))
120
+ ax = fig.add_subplot(211)
121
+ ax.set_title("MAE")
122
+ m = Basemap(projection='robin',lon_0=-180)
123
+ MAE_LF_p = MAE_LF[i,:,:]
124
+ contour_plot = m.pcolormesh(X, Y, MAE_LF_p, latlon = True, cmap='Blues_r')
125
+ m.drawcoastlines(linewidth=2.0, color='0.25')
126
+ m.colorbar(contour_plot)
127
+ ax = fig.add_subplot(212)
128
+ ax.set_title("Uncertainty "+r'$\sigma_M$')
129
+ m = Basemap(projection='robin',lon_0=-180)
130
+ std_rpn_LF_p = std_rpn_LF[i,:,:]
131
+ contour_plot = m.pcolormesh(X, Y, std_rpn_LF_p, latlon = True, cmap='Blues_r')
132
+ m.drawcoastlines(linewidth=2.0, color='0.25')
133
+ m.colorbar(contour_plot)
134
+ plt.subplots_adjust(hspace=-0.35)
135
+ if i > 25:
136
+ plt.savefig('long_lat_uncert_plots/LF_moist_long_lat_uncert_'+str(i-26+4)+'.png', bbox_inches='tight', pad_inches=0.1 , dpi = 300)
137
+
138
+ else:
139
+ plt.savefig('long_lat_uncert_plots/LF_moist_long_lat_uncert_'+str(i)+'.png', bbox_inches='tight', pad_inches=0.1 , dpi = 300)
140
+
141
+ else:
142
+ if is_MAE == 1:
143
+ for i in range(dim_y):
144
+
145
+ mmin = min( np.min(MAE_det[i,:,:]), np.min(MAE_SF[i,:,:]), np.min(MAE_MF[i,:,:]), np.min(MAE_LF[i,:,:]) )
146
+ mmax = max( np.max(MAE_det[i,:,:]), np.max(MAE_SF[i,:,:]), np.max(MAE_MF[i,:,:]), np.max(MAE_LF[i,:,:]) )
147
+ levels = np.linspace(mmin, mmax, 8)
148
+ fig = plt.figure(figsize=(21, 14))
149
+ ax = fig.add_subplot(221)
150
+ ax.set_title("Deterministic NN")
151
+ m = Basemap(projection='robin',lon_0=-180)
152
+ MAE_det_p = MAE_det[i,:,:]
153
+ contour_plot = m.pcolormesh(X, Y,MAE_det_p, latlon = True, cmap='Blues', vmin=mmin, vmax=mmax)
154
+ m.drawcoastlines(linewidth=2.0, color='0.25')
155
+ m.colorbar(contour_plot)
156
+
157
+ ax = fig.add_subplot(222)
158
+ ax.set_title("SF-HF-RPN")
159
+ m = Basemap(projection='robin',lon_0=-180)
160
+ MAE_SF_p = MAE_SF[i,:,:]
161
+ contour_plot = m.pcolormesh(X, Y, MAE_SF_p, latlon = True, cmap='Blues', vmin=mmin, vmax=mmax)
162
+ m.drawcoastlines(linewidth=2.0, color='0.25')
163
+ m.colorbar(contour_plot)
164
+
165
+ ax = fig.add_subplot(224)
166
+ ax.set_title("MF-RPN")
167
+ m = Basemap(projection='robin',lon_0=-180)
168
+ MAE_MF_p = MAE_MF[i,:,:]
169
+ contour_plot = m.pcolormesh(X, Y,MAE_MF_p, latlon = True, cmap='Blues', vmin=mmin, vmax=mmax)
170
+ m.drawcoastlines(linewidth=2.0, color='0.25')
171
+ m.colorbar(contour_plot)
172
+
173
+ ax = fig.add_subplot(223)
174
+ ax.set_title("LF-RPN")
175
+ m = Basemap(projection='robin',lon_0=-180)
176
+ MAE_LF_p = MAE_LF[i,:,:]
177
+ contour_plot = m.pcolormesh(X, Y, MAE_LF_p, latlon = True, cmap='Blues', vmin=mmin, vmax=mmax)
178
+ m.drawcoastlines(linewidth=2.0, color='0.25')
179
+ m.colorbar(contour_plot)
180
+
181
+ plt.subplots_adjust(wspace=0.15, hspace=-0.35)
182
+ if i > 25:
183
+ plt.savefig('long_lat_plots/moist_MAE_long_lat_'+str(i-26+4)+'.png', bbox_inches='tight', pad_inches=0.1 , dpi = 300)
184
+ else:
185
+ plt.savefig('long_lat_plots/heat_MAE_long_lat_'+str(i)+'.png', bbox_inches='tight', pad_inches=0.1 , dpi = 300)
186
+
187
+ if is_R2 == 1:
188
+ for i in range(dim_y):
189
+
190
+ mmin = max(min( np.min(r2_det[i,:,:]), np.min(r2_SF[i,:,:]), np.min(r2_MF[i,:,:]), np.min(r2_LF[i,:,:])), -10 )
191
+ levels = np.linspace(0, 1, 5)
192
+ fig = plt.figure(figsize=(21, 14))
193
+ ax = fig.add_subplot(221)
194
+ ax.set_title("Deterministic NN")
195
+ m = Basemap(projection='robin',lon_0=-180)
196
+ r2_det_p = r2_det[i,:,:]
197
+ contour_plot = m.pcolormesh(X, Y, r2_det_p, latlon = True, cmap='Blues', vmin=0, vmax=1)
198
+ m.contour(X, Y, r2_det_p, [0.7], latlon = True, colors='pink', linewidths=[2])
199
+ m.drawcoastlines(linewidth=2.0, color='0.25')
200
+ m.colorbar(contour_plot)
201
+
202
+ ax = fig.add_subplot(222)
203
+ ax.set_title("SF-HF-RPN")
204
+ m = Basemap(projection='robin',lon_0=-180)
205
+ r2_SF_p = r2_SF[i,:,:]
206
+ contour_plot = m.pcolormesh(X, Y, r2_SF_p, latlon = True, cmap='Blues', vmin=0, vmax=1)
207
+ m.contour(X, Y, r2_SF_p, [0.7], latlon = True, colors='pink', linewidths=[2])
208
+ m.drawcoastlines(linewidth=2.0, color='0.25')
209
+ m.colorbar(contour_plot)
210
+
211
+ ax = fig.add_subplot(224)
212
+ ax.set_title("MF-RPN")
213
+ m = Basemap(projection='robin',lon_0=-180)
214
+ r2_MF_p = r2_MF[i,:,:]
215
+ contour_plot = m.pcolormesh(X, Y, r2_MF_p, latlon = True, cmap='Blues', vmin=0, vmax=1)
216
+ m.contour(X, Y, r2_MF_p, [0.7], latlon = True, colors='pink', linewidths=[2])
217
+ m.drawcoastlines(linewidth=2.0, color='0.25')
218
+ m.colorbar(contour_plot)
219
+
220
+ ax = fig.add_subplot(223)
221
+ ax.set_title("LF-RPN")
222
+ m = Basemap(projection='robin',lon_0=-180)
223
+ r2_LF_p = r2_LF[i,:,:]
224
+ contour_plot = m.pcolormesh(X, Y, r2_LF_p, latlon = True, cmap='Blues', vmin=0, vmax=1)
225
+ m.contour(X, Y, r2_LF_p, [0.7], latlon = True, colors='pink', linewidths=[2])
226
+ m.drawcoastlines(linewidth=2.0, color='0.25')
227
+ m.colorbar(contour_plot)
228
+
229
+ plt.subplots_adjust(wspace=0.15, hspace=-0.35)
230
+ if i > 25:
231
+ plt.savefig('long_lat_plots/moist_r2_long_lat_'+str(i-26+4)+'.png', bbox_inches='tight', pad_inches=0.1 , dpi = 300)
232
+ else:
233
+ plt.savefig('long_lat_plots/heat_r2_long_lat_'+str(i)+'.png', bbox_inches='tight', pad_inches=0.1 , dpi = 300)
234
+
8_plot_global_errors.py ADDED
@@ -0,0 +1,327 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ """
4
+ Created on Tue May 16 16:02:19 2023
5
+
6
+ @author: mohamedazizbhouri
7
+ """
8
+ from matplotlib import pyplot as plt
9
+ import numpy as onp
10
+
11
+ #values of average pressure for different vertical levels
12
+ press = ('3.5', '7.4', '14', '24', '37', '53', '70', '85', '100', '117',
13
+ '137', '160', '188', '221', '259', '305', '358', '420', '494',
14
+ '581', '673', '761', '837', '897', '937', '958')
15
+
16
+ plt.rcParams.update(plt.rcParamsDefault)
17
+ plt.rc('font', family='serif')
18
+ plt.rcParams.update({'font.size': 32,
19
+ 'lines.linewidth': 2,
20
+ 'axes.labelsize': 32,
21
+ 'axes.titlesize': 32,
22
+ 'xtick.labelsize': 32,
23
+ 'ytick.labelsize': 32,
24
+ 'legend.fontsize': 32,
25
+ 'axes.linewidth': 2,
26
+ "pgf.texsystem": "pdflatex"
27
+ })
28
+ plt.close('all')
29
+
30
+ R2_w_neg = 1
31
+ R2_wo_neg = 0
32
+ MAE = 0
33
+ CRPS = 0
34
+
35
+ if R2_wo_neg == 1: # global R^2 plots without negative values
36
+ nn = 26
37
+ MF = onp.load('glob_errors/r2_rpn_MF.npy')[:26]
38
+ SF = onp.load('glob_errors/r2_rpn_SF.npy')[:26]
39
+ LF = onp.load('glob_errors/r2_rpn_LF.npy')[:26]
40
+ det = onp.load('glob_errors/r2_det.npy')[:26]
41
+ MF[MF<0] = 0
42
+ SF[SF<0] = 0
43
+ LF[LF<0] = 0
44
+ det[det<0] = 0
45
+ xx = onp.arange(nn)
46
+ fig , ax = plt.subplots(figsize=(12,8))
47
+ ax.plot(xx, det, color='blue')
48
+ ax.plot(xx, SF, '--', color='black')
49
+ ax.plot(xx, LF, '--', color='orange')
50
+ ax.plot(xx, MF, color='red')
51
+ ax.set_xlabel('Pressure (hPa)')
52
+ ax.set_xticks(onp.arange(nn))
53
+ ax.set_xticklabels(press, rotation =60, fontsize = 20)
54
+ ax.tick_params(axis='x',colors='grey')
55
+ ax.set_ylim([0,1])
56
+ ax.set_ylabel('$R^2$')
57
+ plt.grid()
58
+ ax.legend(['Det. NN', 'SF-HF-RPN', 'LF-RPN', 'MF-RPN'], bbox_to_anchor=[0.5, 1.2], loc='center', ncol=4)
59
+ plt.show()
60
+ plt.savefig('glob_errors/R2_w_neg_heat.png', bbox_inches='tight', pad_inches=0.1 , dpi = 300)
61
+
62
+ nn = 22
63
+ MF = onp.load('glob_errors/r2_rpn_MF.npy')[26:]
64
+ SF = onp.load('glob_errors/r2_rpn_SF.npy')[26:]
65
+ LF = onp.load('glob_errors/r2_rpn_LF.npy')[26:]
66
+ det = onp.load('glob_errors/r2_det.npy')[26:]
67
+ MF[MF<0] = 0
68
+ SF[SF<0] = 0
69
+ LF[LF<0] = 0
70
+ det[det<0] = 0
71
+ press = press[4:]
72
+ xx = onp.arange(nn)
73
+ fig , ax = plt.subplots(figsize=(12,8))
74
+ ax.plot(xx, det, color='blue')
75
+ ax.plot(xx, SF, '--', color='black')
76
+ ax.plot(xx, LF, '--', color='orange')
77
+ ax.plot(xx, MF, color='red')
78
+ ax.set_xlabel('Pressure (hPa)')
79
+ ax.set_xticks(onp.arange(nn))
80
+ ax.set_xticklabels(press, rotation =60, fontsize = 20)
81
+ ax.tick_params(axis='x',colors='grey')
82
+ ax.set_ylim([0,1])
83
+ ax.set_ylabel('$R^2$')
84
+ plt.grid()
85
+ ax.legend(['Det. NN', 'SF-HF-RPN', 'LF-RPN', 'MF-RPN'], bbox_to_anchor=[0.5, 1.2], loc='center', ncol=4)
86
+ plt.show()
87
+ plt.savefig('glob_errors/R2_w_neg_moist.png', bbox_inches='tight', pad_inches=0.1 , dpi = 300)
88
+
89
+ if MAE == 1: # gloab MAE plots
90
+ nn = 26
91
+ MF = onp.load('glob_errors/MAE_rpn_MF.npy')[:26]
92
+ SF = onp.load('glob_errors/MAE_rpn_SF.npy')[:26]
93
+ LF = onp.load('glob_errors/MAE_rpn_LF.npy')[:26]
94
+ det = onp.load('glob_errors/MAE_det.npy')[:26]
95
+ xx = onp.arange(nn)
96
+ fig , ax = plt.subplots(figsize=(12,8))
97
+ plt.yscale("log")
98
+ ax.plot(xx, det, color='blue')
99
+ ax.plot(xx, SF, '--', color='black')
100
+ ax.plot(xx, LF, '--', color='orange')
101
+ ax.plot(xx, MF, color='red')
102
+ ax.set_xlabel('Pressure (hPa)')
103
+ ax.set_xticks(onp.arange(nn))
104
+ ax.set_xticklabels(press, rotation =60, fontsize = 20)
105
+ ax.tick_params(axis='x',colors='grey')
106
+ plt.ylabel('MAE')
107
+ plt.grid()
108
+ ax.legend(['Det. NN', 'SF-HF-RPN', 'LF-RPN', 'MF-RPN'], bbox_to_anchor=[0.5, 1.2], loc='center', ncol=4)
109
+ plt.show()
110
+ plt.savefig('glob_errors/MAE_heat.png', bbox_inches='tight', pad_inches=0.1 , dpi = 300)
111
+
112
+ nn = 22
113
+ MF = onp.load('glob_errors/MAE_rpn_MF.npy')[26:]
114
+ SF = onp.load('glob_errors/MAE_rpn_SF.npy')[26:]
115
+ LF = onp.load('glob_errors/MAE_rpn_LF.npy')[26:]
116
+ det = onp.load('glob_errors/MAE_det.npy')[26:]
117
+ press = press[4:]
118
+ xx = onp.arange(nn)
119
+ fig , ax = plt.subplots(figsize=(12,8))
120
+ plt.yscale("log")
121
+ ax.plot(xx, det, color='blue')
122
+ ax.plot(xx, SF, '--', color='black')
123
+ ax.plot(xx, LF, '--', color='orange')
124
+ ax.plot(xx, MF, color='red')
125
+ ax.set_xlabel('Pressure (hPa)')
126
+ ax.set_xticks(onp.arange(nn))
127
+ ax.set_xticklabels(press, rotation =60, fontsize = 20)
128
+ ax.tick_params(axis='x',colors='grey')
129
+ plt.ylabel('MAE')
130
+ plt.grid()
131
+ ax.legend(['Det. NN', 'SF-HF-RPN', 'LF-RPN', 'MF-RPN'], bbox_to_anchor=[0.5, 1.2], loc='center', ncol=4)
132
+ plt.show()
133
+ plt.savefig('glob_errors/MAE_moist.png', bbox_inches='tight', pad_inches=0.1 , dpi = 300)
134
+
135
+ if R2_w_neg == 1: # global R^2 plots with negative values
136
+ nn = 26
137
+ MF = onp.load('glob_errors/r2_rpn_MF.npy')[:26]
138
+ SF = onp.load('glob_errors/r2_rpn_SF.npy')[:26]
139
+ LF = onp.load('glob_errors/r2_rpn_LF.npy')[:26]
140
+ det = onp.load('glob_errors/r2_det.npy')[:26]
141
+ MF[MF<0] = 0
142
+ SF[SF<0] = 0
143
+ LF[LF<0] = 0
144
+ det[det<0] = 0
145
+ xx = onp.arange(nn)
146
+ # values below are optained from r2_rpn_MF.npy, r2_rpn_SF.npy, r2_rpn_LF.npy and r2_det.npy
147
+ det_r = ['-2.3', '-2.4', '-2.1', '-1.6', '-0.6', '', '-26', '-43', '-15',
148
+ '-13', '-11', '-3.5', '-3.2', '-2.4', '-1.2', '-0.4', '', '',
149
+ '', '', '-0.01', '-0.2', '-0.4', '-0.01', '-2.6', '', '-5']
150
+ SF_r = ['-3.5', '-2.6', '-2.4', '-1.9', '-0.9', '', '-64', '-70', '-5.2',
151
+ '-13', '-4.9', '-2.6', '-2.1', '-1.1', '-0.9', '-0.8', '', '', '',
152
+ '', '', '', '', '', '-0.6', '']
153
+ LF_r = ['-5.6', '', '', '', '', '', '', '-1.4', '-0.3', '-0.6', '', '',
154
+ '', '', '', '', '', '', '', '', '', '', '', '', '-0.3', '-0.1']
155
+ fig , ax = plt.subplots(figsize=(12,8))
156
+ ax.plot(xx, det, color='blue')
157
+ ii= 0
158
+ for x,y in zip(xx,det):
159
+ ax.annotate(det_r[ii],
160
+ (x,y),
161
+ textcoords="offset points",
162
+ xytext = (0,-60),
163
+ ha='center',
164
+ color = 'blue',
165
+ fontsize = 20,
166
+ rotation = -60)
167
+ ii+=1
168
+ ax.plot(xx, SF, '--', color='black')
169
+ ii= 0
170
+ for x,y in zip(xx,SF):
171
+ ax.annotate(SF_r[ii],
172
+ (x,y),
173
+ textcoords="offset points",
174
+ xytext = (0,-120),
175
+ ha='center',
176
+ color = 'black',
177
+ fontsize = 20,
178
+ rotation = -60)
179
+ ii+=1
180
+ ax.plot(xx, LF, '--', color='orange')
181
+ ii= 0
182
+ for x,y in zip(xx,LF):
183
+ ax.annotate(LF_r[ii],
184
+ (x,y),
185
+ textcoords="offset points",
186
+ xytext = (0,-180),
187
+ ha='center',
188
+ color = 'orange',
189
+ fontsize = 20,
190
+ rotation = -60)
191
+ ii+=1
192
+ ax.plot(xx, MF, color='red')
193
+ ax.set_ylim([0,1])
194
+ ax.set_xlabel('Pressure (hPa)')
195
+ ax.xaxis.set_label_coords(0.5, -0.55)
196
+ ax.set_xticks(onp.arange(nn))
197
+ ax.set_xticklabels(press, rotation =60, fontsize = 20, y=-0.4)
198
+ ax.tick_params(axis='x',colors='grey')
199
+ ax.set_ylabel('$R^2$')
200
+ plt.grid()
201
+ ax.legend(['Det. NN', 'SF-HF-RPN', 'LF-RPN', 'MF-RPN'], bbox_to_anchor=[0.5, 1.2], loc='center', ncol=4)
202
+ plt.show()
203
+ plt.savefig('glob_errors/R2_w_neg_heat.png', bbox_inches='tight', pad_inches=0.1 , dpi = 300)
204
+
205
+ nn = 22
206
+ MF = onp.load('glob_errors/r2_rpn_MF.npy')[26:]
207
+ SF = onp.load('glob_errors/r2_rpn_SF.npy')[26:]
208
+ LF = onp.load('glob_errors/r2_rpn_LF.npy')[26:]
209
+ det = onp.load('glob_errors/r2_det.npy')[26:]
210
+ press = press[4:]
211
+ MF[MF<0] = 0
212
+ SF[SF<0] = 0
213
+ LF[LF<0] = 0
214
+ det[det<0] = 0
215
+ xx = onp.arange(nn)
216
+ det_r = ['-94', '-97', '-11', '-14', '-4.4', '-4.9', '-3.3', '-2.7', '-1.6',
217
+ '-1.2', '-0.4', '-0.3', '', '', '', '', '-2.7', '-1.0', '-0.7',
218
+ '-0.6', '-1.2', '']
219
+ SF_r = ['-145', '-71', '-16', '-14', '9.1', '6.3', '-3.9', '-2.8', '-1.8',
220
+ '-1.3', '-0.9', '-0.8', '-0.2', '', '', '', '-0.5', '-0.01', '-0.2',
221
+ '-0.2', '-0.03', '']
222
+ LF_r = ['', '-7.0', '-108', '-225', '-29', '-4.2', '', '', '',
223
+ '', '', '', '', '', '', '', '', '', '', '-2.1', '-0.6', '-0.6']
224
+ MF_r = ['', '', '-0.9', '-2.2', '-0.3', '', '', '', '', '', '', '', '', '',
225
+ '', '', '', '', '', '', '', '']
226
+ fig , ax = plt.subplots(figsize=(12,8))
227
+ ax.plot(xx, det, color='blue')
228
+ ii= 0
229
+ for x,y in zip(xx,det):
230
+ ax.annotate(det_r[ii],
231
+ (x,y),
232
+ textcoords="offset points",
233
+ xytext = (0,-50),
234
+ ha='center',
235
+ color = 'blue',
236
+ fontsize = 20,
237
+ rotation = -60)
238
+ ii+=1
239
+ ax.plot(xx, SF, '--', color='black')
240
+ ii= 0
241
+ for x,y in zip(xx,SF):
242
+ ax.annotate(SF_r[ii],
243
+ (x,y),
244
+ textcoords="offset points",
245
+ xytext = (0,-100),
246
+ ha='center',
247
+ color = 'black',
248
+ fontsize = 20,
249
+ rotation = -60)
250
+ ii+=1
251
+ ax.plot(xx, LF, '--', color='orange')
252
+ ii= 0
253
+ for x,y in zip(xx,LF):
254
+ ax.annotate(LF_r[ii],
255
+ (x,y),
256
+ textcoords="offset points",
257
+ xytext = (0,-150),
258
+ ha='center',
259
+ color = 'orange',
260
+ fontsize = 20,
261
+ rotation = -60)
262
+ ii+=1
263
+ ax.plot(xx, MF, color='red')
264
+ ii= 0
265
+ for x,y in zip(xx,MF):
266
+ ax.annotate(MF_r[ii],
267
+ (x,y),
268
+ textcoords="offset points",
269
+ xytext = (0,-200),
270
+ ha='center',
271
+ color = 'red',
272
+ fontsize = 20,
273
+ rotation = -60)
274
+ ii+=1
275
+ ax.set_ylim([0,1])
276
+ ax.set_xlabel('Pressure (hPa)')
277
+ ax.xaxis.set_label_coords(0.5, -0.6)
278
+ ax.set_xticks(onp.arange(nn))
279
+ ax.set_xticklabels(press, rotation =60, fontsize = 20, y=-0.45)
280
+ ax.tick_params(axis='x',colors='grey')
281
+ ax.set_ylabel('$R^2$')
282
+ plt.grid()
283
+ ax.legend(['Det. NN', 'SF-HF-RPN', 'LF-RPN', 'MF-RPN'], bbox_to_anchor=[0.5, 1.2], loc='center', ncol=4)
284
+ plt.show()
285
+ plt.savefig('glob_errors/R2_w_neg_moist.png', bbox_inches='tight', pad_inches=0.1 , dpi = 300)
286
+
287
+ if CRPS == 1: # global CRPS plots
288
+ nn = 26
289
+ MF = onp.load('glob_errors/crps_rpn_MF.npy')[:26]
290
+ SF = onp.load('glob_errors/crps_rpn_SF.npy')[:26]
291
+ LF = onp.load('glob_errors/crps_rpn_LF.npy')[:26]
292
+ xx = onp.arange(nn)
293
+ fig , ax = plt.subplots(figsize=(12,8))
294
+ plt.yscale("log")
295
+ ax.plot(xx, SF, '--', color='black')
296
+ ax.plot(xx, LF, '--', color='orange')
297
+ ax.plot(xx, MF, color='red')
298
+ ax.set_xlabel('Pressure (hPa)')
299
+ ax.set_xticks(onp.arange(nn))
300
+ ax.set_xticklabels(press, rotation =60, fontsize = 20)
301
+ ax.tick_params(axis='x',colors='grey')
302
+ plt.ylabel('CRPS')
303
+ plt.grid()
304
+ ax.legend(['Det. NN', 'SF-HF-RPN', 'LF-RPN', 'MF-RPN'], bbox_to_anchor=[0.5, 1.2], loc='center', ncol=4)
305
+ plt.show()
306
+ plt.savefig('glob_errors/CRPS_heat.png', bbox_inches='tight', pad_inches=0.1 , dpi = 300)
307
+
308
+ nn = 22
309
+ MF = onp.load('glob_errors/crps_rpn_MF.npy')[26:]
310
+ SF = onp.load('glob_errors/crps_rpn_SF.npy')[26:]
311
+ LF = onp.load('glob_errors/crps_rpn_LF.npy')[26:]
312
+ press = press[4:]
313
+ xx = onp.arange(nn)
314
+ fig , ax = plt.subplots(figsize=(12,8))
315
+ plt.yscale("log")
316
+ ax.plot(xx, SF, '--', color='black')
317
+ ax.plot(xx, LF, '--', color='orange')
318
+ ax.plot(xx, MF, color='red')
319
+ ax.set_xlabel('Pressure (hPa)')
320
+ ax.set_xticks(onp.arange(nn))
321
+ ax.set_xticklabels(press, rotation =60, fontsize = 20)
322
+ ax.tick_params(axis='x',colors='grey')
323
+ plt.ylabel('CRPS')
324
+ plt.grid()
325
+ ax.legend(['Det. NN', 'SF-HF-RPN', 'LF-RPN', 'MF-RPN'], bbox_to_anchor=[0.5, 1.2], loc='center', ncol=4)
326
+ plt.show()
327
+ plt.savefig('glob_errors/CRPS_moist.png', bbox_inches='tight', pad_inches=0.1 , dpi = 300)
8_pressure_lat_plots.py ADDED
@@ -0,0 +1,130 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ """
4
+ Created on Wed Jun 21 09:32:40 2023
5
+
6
+ @author: mohamedazizbhouri
7
+ """
8
+ from matplotlib import pyplot as plt
9
+ import numpy as np
10
+
11
+ plt.rcParams.update(plt.rcParamsDefault)
12
+ plt.rc('font', family='serif')
13
+ plt.rcParams.update({'font.size': 46,
14
+ 'lines.linewidth': 3,
15
+ 'axes.labelsize': 46,
16
+ 'axes.titlesize': 46,
17
+ 'xtick.labelsize': 46,
18
+ 'ytick.labelsize': 46,
19
+ 'legend.fontsize': 46,
20
+ 'axes.linewidth': 3,
21
+ "pgf.texsystem": "pdflatex"
22
+ })
23
+
24
+ lat = 96
25
+ x = np.linspace(-90, 90, lat)
26
+ y = np.array([3.5, 7.4, 14, 24, 37, 53, 70, 85, 100, 117,
27
+ 137, 160, 188, 221, 259, 305, 358, 420, 494,
28
+ 581, 673, 761, 837, 897, 937, 958])
29
+ X, Y = np.meshgrid(x, y)
30
+ Xm, Ym = np.meshgrid(x, y[4:])
31
+
32
+ r2_det = np.load('SF_results/r2_det_pres_lat.npy')
33
+ r2_SF = np.load('SF_results/r2_SF_pres_lat.npy')
34
+ r2_MF = np.load('MF_results/r2_MF_pres_lat.npy.npy')
35
+ r2_LF = np.load('MF_results/r2_LF_pres_lat.npy.npy')
36
+
37
+ dim_heat = 26
38
+
39
+ print('Create err plots')
40
+
41
+ mmin = 0
42
+ mmax = 1
43
+ levels = np.linspace(mmin, mmax, 8)
44
+ fig = plt.figure(figsize=(40, 15))
45
+
46
+ ax = fig.add_subplot(141)
47
+ ax.set_title("Deterministic NN")
48
+ contour_plot = ax.pcolor(X, Y, r2_det[:dim_heat,:],cmap='Blues', vmin = mmin, vmax = mmax)
49
+ ax.contour(X, Y, r2_det[:dim_heat,:], [0.7], colors='pink', linewidths=[4])
50
+ ax.contour(X, Y, r2_det[:dim_heat,:], [0.9], colors='orange', linewidths=[4])
51
+ ax.set_ylim(ax.get_ylim()[::-1])
52
+ ax.set_ylabel("Pressure (hPa)")
53
+
54
+ ax = fig.add_subplot(142)
55
+ ax.set_title("SF-HF-RPN")
56
+ contour_plot = ax.pcolor(X, Y, r2_SF[:dim_heat,:],cmap='Blues', vmin = mmin, vmax = mmax)
57
+ ax.contour(X, Y, r2_SF[:dim_heat,:], [0.7], colors='pink', linewidths=[4])
58
+ ax.contour(X, Y, r2_SF[:dim_heat,:], [0.9], colors='orange', linewidths=[4])
59
+ ax.set_ylim(ax.get_ylim()[::-1])
60
+ ax.set_yticks([])
61
+ ax.set_xlabel("Degrees Latitude")
62
+ ax.xaxis.set_label_coords(1.12, -0.1)
63
+
64
+ ax = fig.add_subplot(143)
65
+ ax.set_title("LF-RPN")
66
+ contour_plot = ax.pcolor(X, Y, r2_LF[:dim_heat,:],cmap='Blues', vmin = mmin, vmax = mmax)
67
+ ax.contour(X, Y, r2_LF[:dim_heat,:], [0.7], colors='pink', linewidths=[4])
68
+ ax.contour(X, Y, r2_LF[:dim_heat,:], [0.9], colors='orange', linewidths=[4])
69
+ ax.set_ylim(ax.get_ylim()[::-1])
70
+ ax.set_yticks([])
71
+
72
+ ax = fig.add_subplot(144)
73
+ ax.set_title("MF-RPN")
74
+ contour_plot = ax.pcolor(X, Y, r2_MF[:dim_heat,:],cmap='Blues', vmin = mmin, vmax = mmax)
75
+ ax.contour(X, Y, r2_MF[:dim_heat,:], [0.7], colors='pink', linewidths=[4])
76
+ ax.contour(X, Y, r2_MF[:dim_heat,:], [0.9], colors='orange', linewidths=[4])
77
+ ax.set_ylim(ax.get_ylim()[::-1])
78
+ ax.set_yticks([])
79
+ p3 = ax.get_position().get_points().flatten()
80
+
81
+ cbar_ax = fig.add_axes([0.92, 0.12, 0.02, 0.76])
82
+ fig.colorbar(contour_plot, label=r'$\mathrm{R^2}$', cax=cbar_ax)
83
+ plt.suptitle("Heat tendency")
84
+ plt.savefig('r2_press_lat_heat.png', bbox_inches='tight', pad_inches=0.1 , dpi = 300)
85
+
86
+ mmin = 0
87
+ mmax = 1
88
+ levels = np.linspace(mmin, mmax, 8)
89
+ fig = plt.figure(figsize=(40, 15))
90
+
91
+ ax = fig.add_subplot(141)
92
+ ax.set_title("Deterministic NN")
93
+ contour_plot = ax.pcolor(Xm, Ym, r2_det[dim_heat:,:],cmap='Blues', vmin = mmin, vmax = mmax)
94
+ ax.contour(Xm, Ym, r2_det[dim_heat:,:], [0.7], colors='pink', linewidths=[4])
95
+ ax.contour(Xm, Ym, r2_det[dim_heat:,:], [0.9], colors='orange', linewidths=[4])
96
+ ax.set_ylim(ax.get_ylim()[::-1])
97
+ ax.set_ylabel("Pressure (hPa)")
98
+
99
+ ax = fig.add_subplot(142)
100
+ ax.set_title("SF-HF-RPN")
101
+ contour_plot = ax.pcolor(Xm, Ym, r2_SF[dim_heat:,:],cmap='Blues', vmin = mmin, vmax = mmax)
102
+ ax.contour(Xm, Ym, r2_SF[dim_heat:,:], [0.7], colors='pink', linewidths=[4])
103
+ ax.contour(Xm, Ym, r2_SF[dim_heat:,:], [0.9], colors='orange', linewidths=[4])
104
+ ax.set_ylim(ax.get_ylim()[::-1])
105
+ ax.set_yticks([])
106
+ ax.set_xlabel("Degrees Latitude")
107
+ ax.xaxis.set_label_coords(1.12, -0.1)
108
+
109
+ ax = fig.add_subplot(143)
110
+ ax.set_title("LF-RPN")
111
+ contour_plot = ax.pcolor(Xm, Ym, r2_LF[dim_heat:,:],cmap='Blues', vmin = mmin, vmax = mmax)
112
+ ax.contour(Xm, Ym, r2_LF[dim_heat:,:], [0.7], colors='pink', linewidths=[4])
113
+ ax.contour(Xm, Ym, r2_LF[dim_heat:,:], [0.9], colors='orange', linewidths=[4])
114
+ ax.set_ylim(ax.get_ylim()[::-1])
115
+ ax.set_yticks([])
116
+
117
+ ax = fig.add_subplot(144)
118
+ ax.set_title("MF-RPN")
119
+ contour_plot = ax.pcolor(Xm, Ym, r2_MF[dim_heat:,:],cmap='Blues', vmin = mmin, vmax = mmax)
120
+ ax.contour(Xm, Ym, r2_MF[dim_heat:,:], [0.7], colors='pink', linewidths=[4])
121
+ ax.contour(Xm, Ym, r2_MF[dim_heat:,:], [0.9], colors='orange', linewidths=[4])
122
+ ax.set_ylim(ax.get_ylim()[::-1])
123
+ ax.set_yticks([])
124
+ p3 = ax.get_position().get_points().flatten()
125
+
126
+ cbar_ax = fig.add_axes([0.92, 0.12, 0.02, 0.76])
127
+ fig.colorbar(contour_plot, label=r'$\mathrm{R^2}$', cax=cbar_ax)
128
+ plt.suptitle("Moisture tendency")
129
+ plt.savefig('r2_press_lat_moist.png', bbox_inches='tight', pad_inches=0.1 , dpi = 300)
130
+
8_uncertainty_density_plot.py ADDED
@@ -0,0 +1,231 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ """
4
+ Created on Wed Aug 2 17:42:05 2023
5
+
6
+ @author: mohamedazizbhouri
7
+ """
8
+ from matplotlib import pyplot as plt
9
+ import numpy as onp
10
+
11
+ from scipy.stats import kde
12
+
13
+ plt.rcParams.update(plt.rcParamsDefault)
14
+ plt.rc('font', family='serif')
15
+ plt.rcParams.update({'font.size': 36,
16
+ 'lines.linewidth': 2,
17
+ 'axes.labelsize': 36,
18
+ 'axes.titlesize': 36,
19
+ 'xtick.labelsize': 36,
20
+ 'ytick.labelsize': 36,
21
+ 'legend.fontsize': 36,
22
+ 'axes.linewidth': 2,
23
+ "pgf.texsystem": "pdflatex"
24
+ })
25
+ plt.rcParams['agg.path.chunksize'] = 20000
26
+
27
+ lat = 96
28
+ lon = 144
29
+ nt_total = 365*24
30
+
31
+ dim_y = 48
32
+ dim_heat = 26
33
+ dim_moist = 22
34
+ mu_error_out = onp.concatenate((onp.zeros((1,dim_heat),dtype=onp.float32),
35
+ onp.zeros((1,dim_moist),dtype=onp.float32)),axis=1)
36
+ sigma_error_out = onp.concatenate((1/1004.6*onp.ones((1,dim_heat),dtype=onp.float32),
37
+ 1/2.26e6*onp.ones((1,dim_moist),dtype=onp.float32)),axis=1)
38
+ mu_error_out = onp.array(mu_error_out,dtype=onp.float64)
39
+ sigma_error_out = onp.array(sigma_error_out,dtype=onp.float64)
40
+
41
+ is_SF = 0
42
+ is_MF = 0
43
+ is_LF = 1
44
+
45
+ ilist = [14, 18, 21, 36, 40, 43] # indices for tendencies at pressure levels 259, 494 and 761 hPa
46
+ ipress = [259, 494, 761, 259, 294, 761]
47
+ itend = ['heat', 'heat', 'heat', 'moist', 'moist', 'moist']
48
+ nbins = 100
49
+ epsilon = 0.125
50
+ fact_time = 4
51
+ fact_lon = 8
52
+ fact_lat = 8
53
+
54
+ onp.random.seed(1234)
55
+
56
+ import time
57
+
58
+ if is_MF == 1:
59
+ print('loading')
60
+ mean_rpn_MF = onp.load('MF_param/mean_RPN_MF_reshaped.npy')[:,::fact_time,::fact_lat,::fact_lon]
61
+ mean_rpn_MF = onp.array(mean_rpn_MF,dtype=onp.float64)
62
+ mean_rpn_MF = onp.reshape( mean_rpn_MF, ( dim_y, (nt_total*lat*lon)//(fact_time*fact_lon*fact_lat) ) )
63
+ mean_rpn_MF = mean_rpn_MF.T
64
+ mean_rpn_MF = (mean_rpn_MF-mu_error_out) / sigma_error_out
65
+
66
+ std_rpn_MF = onp.load('MF_param/std_RPN_MF_reshaped.npy')[:,::fact_time,::fact_lat,::fact_lon]
67
+ std_rpn_MF = onp.array(std_rpn_MF,dtype=onp.float64)
68
+ std_rpn_MF = onp.reshape( std_rpn_MF, ( dim_y, (nt_total*lat*lon)//(fact_time*fact_lon*fact_lat) ) )
69
+ std_rpn_MF = std_rpn_MF.T
70
+ std_rpn_MF = std_rpn_MF / sigma_error_out
71
+
72
+ test_yH = onp.load('data_SPCAM5_4K/all_outputs_reshaped.npy')[:,::fact_time,::fact_lat,::fact_lon]
73
+ test_yH = onp.array(test_yH,dtype=onp.float64)
74
+ test_yH = onp.reshape( test_yH, ( dim_y, (nt_total*lat*lon)//(fact_time*fact_lon*fact_lat) ) )
75
+ test_yH = test_yH.T
76
+ test_yH = (test_yH-mu_error_out) / sigma_error_out
77
+
78
+ for ii in range(len(ilist)):
79
+ i = ilist[ii]
80
+ print(i)
81
+ err_MF = onp.abs(mean_rpn_MF[:,i]-test_yH[:,i])
82
+ x = err_MF
83
+ y = std_rpn_MF[:,i]
84
+ Ntot = x.shape[0]
85
+ y = y[~onp.isnan(x)]
86
+ x = x[~onp.isnan(x)]
87
+ x = x[~onp.isnan(y)]
88
+ y = y[~onp.isnan(y)]
89
+ ind = onp.argsort(x)
90
+ x = x[ind]
91
+ y = y[ind]
92
+ x = x[:Ntot-int(epsilon*Ntot)]
93
+ y = y[:Ntot-int(epsilon*Ntot)]
94
+ ind = onp.argsort(y)
95
+ x = x[ind]
96
+ y = y[ind]
97
+ x = onp.sqrt(x[:Ntot-2*int(epsilon*Ntot)])
98
+ y = y[:Ntot-2*int(epsilon*Ntot)]
99
+
100
+ tt = time.time()
101
+ k = kde.gaussian_kde([x,y])
102
+ xi, yi = onp.mgrid[x.min():x.max():nbins*1j, y.min():y.max():nbins*1j]
103
+ zi = k(onp.vstack([xi.flatten(), yi.flatten()]))
104
+ zi = zi.reshape(xi.shape)
105
+ print('gaussian_kde', time.time()-tt )
106
+
107
+ fig = plt.figure(figsize=(12,12))
108
+ ax = fig.add_subplot(111)
109
+ plt.pcolormesh(xi, yi, zi, shading='gouraud', cmap=plt.cm.jet)
110
+ ax.ticklabel_format(axis="y", style="sci", scilimits=(0,0))
111
+ plt.colorbar()
112
+ ax.set_xlabel('Error')
113
+ ax.set_ylabel(r'$\sigma_M$')
114
+ plt.savefig('uncertainty_density_plots/MF_uncert_dens_'+itend[ii]+'_'+str(ipress[ii])+'_hPa.png', bbox_inches='tight', pad_inches=0.1 , dpi = 300)
115
+
116
+ if is_LF == 1:
117
+ print('loading')
118
+ mean_rpn_MF = onp.load('MF_param/mean_RPN_LF_reshaped.npy')[:,::fact_time,::fact_lat,::fact_lon]
119
+ mean_rpn_MF = onp.array(mean_rpn_MF,dtype=onp.float64)
120
+ mean_rpn_MF = onp.reshape( mean_rpn_MF, ( dim_y, (nt_total*lat*lon)//(fact_time*fact_lon*fact_lat) ) )
121
+ mean_rpn_MF = mean_rpn_MF.T
122
+ mean_rpn_MF = (mean_rpn_MF-mu_error_out) / sigma_error_out
123
+
124
+ std_rpn_MF = onp.load('MF_param/std_RPN_LF_reshaped.npy')[:,::fact_time,::fact_lat,::fact_lon]
125
+ std_rpn_MF = onp.array(std_rpn_MF,dtype=onp.float64)
126
+ std_rpn_MF = onp.reshape( std_rpn_MF, ( dim_y, (nt_total*lat*lon)//(fact_time*fact_lon*fact_lat) ) )
127
+ std_rpn_MF = std_rpn_MF.T
128
+ std_rpn_MF = std_rpn_MF / sigma_error_out
129
+
130
+ test_yH = onp.load('data_SPCAM5_4K/all_outputs_reshaped.npy')[:,::fact_time,::fact_lat,::fact_lon]
131
+ test_yH = onp.array(test_yH,dtype=onp.float64)
132
+ test_yH = onp.reshape( test_yH, ( dim_y, (nt_total*lat*lon)//(fact_time*fact_lon*fact_lat) ) )
133
+ test_yH = test_yH.T
134
+ test_yH = (test_yH-mu_error_out) / sigma_error_out
135
+
136
+ for ii in range(len(ilist)):
137
+ i = ilist[ii]
138
+ print(i)
139
+ err_MF = onp.abs(mean_rpn_MF[:,i]-test_yH[:,i])
140
+ x = err_MF
141
+ y = std_rpn_MF[:,i]
142
+ Ntot = x.shape[0]
143
+ y = y[~onp.isnan(x)]
144
+ x = x[~onp.isnan(x)]
145
+ x = x[~onp.isnan(y)]
146
+ y = y[~onp.isnan(y)]
147
+ ind = onp.argsort(x)
148
+ x = x[ind]
149
+ y = y[ind]
150
+ x = x[:Ntot-int(epsilon*Ntot)]
151
+ y = y[:Ntot-int(epsilon*Ntot)]
152
+ ind = onp.argsort(y)
153
+ x = x[ind]
154
+ y = y[ind]
155
+ x = onp.sqrt(x[:Ntot-2*int(epsilon*Ntot)])
156
+ y = y[:Ntot-2*int(epsilon*Ntot)]
157
+
158
+ tt = time.time()
159
+ k = kde.gaussian_kde([x,y])
160
+ xi, yi = onp.mgrid[x.min():x.max():nbins*1j, y.min():y.max():nbins*1j]
161
+ zi = k(onp.vstack([xi.flatten(), yi.flatten()]))
162
+ zi = zi.reshape(xi.shape)
163
+ print('gaussian_kde', time.time()-tt )
164
+
165
+ fig = plt.figure(figsize=(12,12))
166
+ ax = fig.add_subplot(111)
167
+ plt.pcolormesh(xi, yi, zi, shading='gouraud', cmap=plt.cm.jet)
168
+ ax.ticklabel_format(axis="y", style="sci", scilimits=(0,0))
169
+ plt.colorbar()
170
+ ax.set_xlabel('Error')
171
+ ax.set_ylabel(r'$\sigma_M$')
172
+ plt.savefig('uncertainty_density_plots/LF_uncert_dens_'+itend[ii]+'_'+str(ipress[ii])+'_hPa.png', bbox_inches='tight', pad_inches=0.1 , dpi = 300)
173
+
174
+ if is_SF == 1:
175
+ print('loading')
176
+ mean_rpn = onp.load('SF_param/mean_RPN_SF_reshaped.npy')[:,::fact_time,::fact_lat,::fact_lon]
177
+ mean_rpn = onp.array(mean_rpn,dtype=onp.float64)
178
+ mean_rpn = onp.reshape( mean_rpn, ( dim_y, (nt_total*lat*lon)//(fact_time*fact_lon*fact_lat) ) )
179
+ mean_rpn = mean_rpn.T
180
+ mean_rpn = (mean_rpn-mu_error_out) / sigma_error_out
181
+
182
+ std_rpn = onp.load('SF_param/std_RPN_SF_reshaped.npy')[:,::fact_time,::fact_lat,::fact_lon]
183
+ std_rpn = onp.array(std_rpn,dtype=onp.float64)
184
+ std_rpn = onp.reshape( std_rpn, ( dim_y, (nt_total*lat*lon)//(fact_time*fact_lon*fact_lat) ) )
185
+ std_rpn = std_rpn.T
186
+ std_rpn = std_rpn / sigma_error_out
187
+
188
+ test_yH = onp.load('data_SPCAM5_4K/all_outputs_reshaped.npy')[:,::fact_time,::fact_lat,::fact_lon]
189
+ test_yH = onp.array(test_yH,dtype=onp.float64)
190
+ test_yH = onp.reshape( test_yH, ( dim_y, (nt_total*lat*lon)//(fact_time*fact_lon*fact_lat) ) )
191
+ test_yH = test_yH.T
192
+ test_yH = (test_yH-mu_error_out) / sigma_error_out
193
+
194
+ for ii in range(len(ilist)):
195
+ i = ilist[ii]
196
+ print(i)
197
+ err = onp.abs(mean_rpn[:,i]-test_yH[:,i])
198
+ x = err
199
+ y = std_rpn[:,i]
200
+ Ntot = x.shape[0]
201
+ y = y[~onp.isnan(x)]
202
+ x = x[~onp.isnan(x)]
203
+ x = x[~onp.isnan(y)]
204
+ y = y[~onp.isnan(y)]
205
+ ind = onp.argsort(x)
206
+ x = x[ind]
207
+ y = y[ind]
208
+ x = x[:Ntot-int(epsilon*Ntot)]
209
+ y = y[:Ntot-int(epsilon*Ntot)]
210
+ ind = onp.argsort(y)
211
+ x = x[ind]
212
+ y = y[ind]
213
+ x = onp.sqrt(x[:Ntot-2*int(epsilon*Ntot)])
214
+ y = y[:Ntot-2*int(epsilon*Ntot)]
215
+
216
+ tt = time.time()
217
+ k = kde.gaussian_kde([x,y])
218
+ xi, yi = onp.mgrid[x.min():x.max():nbins*1j, y.min():y.max():nbins*1j]
219
+ zi = k(onp.vstack([xi.flatten(), yi.flatten()]))
220
+ zi = zi.reshape(xi.shape)
221
+ print('gaussian_kde', time.time()-tt )
222
+
223
+ fig = plt.figure(figsize=(12,12))
224
+ ax = fig.add_subplot(111)
225
+ plt.pcolormesh(xi, yi, zi, shading='gouraud', cmap=plt.cm.jet)
226
+ ax.ticklabel_format(axis="y", style="sci", scilimits=(0,0))
227
+ plt.colorbar()
228
+ ax.set_xlabel('Error')
229
+ ax.set_ylabel(r'$\sigma_M$')
230
+ plt.savefig('uncertainty_density_plots/SF_uncert_dens_'+itend[ii]+'_'+str(ipress[ii])+'_hPa.png', bbox_inches='tight', pad_inches=0.1 , dpi = 300)
231
+
9_uncertainty_video.py ADDED
@@ -0,0 +1,180 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ """
4
+ Created on Fri Sep 8 07:35:08 2023
5
+
6
+ @author: mohamedazizbhouri
7
+ """
8
+ from matplotlib import pyplot as plt
9
+ import numpy as np
10
+ from mpl_toolkits.basemap import Basemap
11
+ from moviepy.editor import VideoClip
12
+ from moviepy.video.io.bindings import mplfig_to_npimage
13
+
14
+ plt.rcParams.update(plt.rcParamsDefault)
15
+ plt.rc('font', family='serif')
16
+ plt.rcParams.update({'font.size': 16,
17
+ 'lines.linewidth': 2,
18
+ 'axes.labelsize': 20,
19
+ 'axes.titlesize': 20,
20
+ 'xtick.labelsize': 16,
21
+ 'ytick.labelsize': 16,
22
+ 'legend.fontsize': 20,
23
+ 'axes.linewidth': 2,
24
+ "pgf.texsystem": "pdflatex"
25
+ })
26
+
27
+ lat = 96
28
+ lon = 144
29
+
30
+ x = np.linspace(0, 360-360/144, lon)
31
+ y = np.linspace(-90, 90, lat)
32
+ X, Y = np.meshgrid(x, y)
33
+
34
+ dim_heat = 26
35
+ dim_moist = 22
36
+ mu_error_out = np.concatenate((np.zeros((1,dim_heat),dtype=np.float32),
37
+ np.zeros((1,dim_moist),dtype=np.float32)),axis=1)
38
+ mu_error_out = mu_error_out.T[:,:,None,None]
39
+ sigma_error_out = np.concatenate((1/1004.6*np.ones((1,dim_heat),dtype=np.float32),
40
+ 1/2.26e6*np.ones((1,dim_moist),dtype=np.float32)),axis=1)
41
+ sigma_error_out = sigma_error_out.T[:,:,None,None]
42
+
43
+ y_var = 43 # 14, 18, 21, 36, 40, 43
44
+
45
+ if y_var == 14:
46
+ ttl = 'Heat tendency at 259 hPa'
47
+ ttl_s = 'videos/instant_heat_tend_259.mp4'
48
+ elif y_var == 18:
49
+ ttl = 'Heat tendency at 494 hPa'
50
+ ttl_s = 'videos/instant_heat_tend_494.mp4'
51
+ elif y_var == 21:
52
+ ttl = 'Heat tendency at 761 hPa'
53
+ ttl_s = 'videos/instant_heat_tend_761.mp4'
54
+ elif y_var == 36:
55
+ ttl = 'Moisture tendency at 259 hPa'
56
+ ttl_s = 'videos/instant_moist_tend_259.mp4'
57
+ elif y_var == 40:
58
+ ttl = 'Moisture tendency at 494 hPa'
59
+ ttl_s = 'videos/instant_moist_tend_494.mp4'
60
+ elif y_var == 43:
61
+ ttl = 'Moisture tendency at 761 hPa'
62
+ ttl_s = 'videos/instant_moist_tend_761.mp4'
63
+
64
+ test = (np.load('data_SPCAM5_4K/all_outputs_reshaped.npy')[y_var:y_var+1,:,:,:] - mu_error_out) / sigma_error_out
65
+ test = np.array(test,dtype=np.float64)
66
+
67
+ months = ['Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec', 'Jan']
68
+ days = np.array([28, 28+31, 28+31+30, 28+31+30+31, 28+31+30+31+30, 28+31+30+31+30+31,
69
+ 28+31+30+31+30+31+31, 28+31+30+31+30+31+31+30, 28+31+30+31+30+31+31+30+31,
70
+ 28+31+30+31+30+31+31+30+31+30, 28+31+30+31+30+31+31+30+31+30+31,
71
+ 28+31+30+31+30+31+31+30+31+30+31+31])
72
+ hours = 24*days
73
+
74
+ std_rpn_MF = np.load('MF_param/mean_RPN_MF_reshaped.npy')[y_var:y_var+1,:,:,:]/ sigma_error_out
75
+ mean_rpn_MF = (np.load('MF_param/std_RPN_MF_reshaped.npy')[y_var:y_var+1,:,:,:] - mu_error_out) / sigma_error_out
76
+ mean_rpn_MF = np.array(mean_rpn_MF,dtype=np.float64)
77
+ std_rpn_MF = np.array(std_rpn_MF,dtype=np.float64)
78
+
79
+ std_rpn_LF = np.load('MF_param/mean_RPN_LF_reshaped.npy')[y_var:y_var+1,:,:,:]/ sigma_error_out
80
+ mean_rpn_LF = (np.load('MF_param/std_RPN_LF_reshaped.npy')[y_var:y_var+1,:,:,:] - mu_error_out) / sigma_error_out
81
+ mean_rpn_LF = np.array(mean_rpn_LF,dtype=np.float64)
82
+ std_rpn_LF = np.array(std_rpn_LF,dtype=np.float64)
83
+
84
+ std_rpn_SF = np.load('SF_param/mean_RPN_SF_reshaped.npy')[y_var:y_var+1,:,:,:]/ sigma_error_out
85
+ mean_rpn_SF = (np.load('SF_param/std_RPN_SF_reshaped.npy')[y_var:y_var+1,:,:,:] - mu_error_out) / sigma_error_out
86
+ std_rpn_SF = np.array(std_rpn_SF,dtype=np.float64)
87
+ mean_rpn_SF = np.array(mean_rpn_SF,dtype=np.float64)
88
+
89
+ MAE_MF = np.abs( test-mean_rpn_MF )
90
+ MAE_LF = np.abs( test-mean_rpn_LF )
91
+ MAE_SF = np.abs( test-mean_rpn_SF )
92
+
93
+ N_frame = std_rpn_MF.shape[1]
94
+
95
+ fps = 5
96
+ duration = N_frame / fps
97
+
98
+ fig = plt.figure(figsize=(31.5, 14))
99
+
100
+ def create_fr(t):
101
+ print(t,int(t*fps))
102
+ fig.clf()
103
+
104
+ ax1 = fig.add_subplot(231)
105
+ ax1.set_title("MF-RPN - MAE")
106
+ m = Basemap(projection='robin',lon_0=-180)
107
+ contour_plot = m.pcolormesh(X, Y, MAE_MF[0,int(t*fps),:,:], latlon = True,cmap='Blues_r')
108
+ m.drawcoastlines(linewidth=2.0, color='0.25')
109
+
110
+ ax2 = fig.add_subplot(234)
111
+ ax2.set_title("MF-RPN - Uncertainty "+r'$\sigma_M$')
112
+ m = Basemap(projection='robin',lon_0=-180)
113
+ contour_plot = m.pcolormesh(X, Y, std_rpn_MF[0,int(t*fps),:,:], latlon = True,cmap='Blues_r')
114
+ m.drawcoastlines(linewidth=2.0, color='0.25')
115
+ #############################################
116
+ ax1 = fig.add_subplot(232)
117
+ ax1.set_title("SF-RPN - MAE")
118
+ m = Basemap(projection='robin',lon_0=-180)
119
+ contour_plot = m.pcolormesh(X, Y, MAE_SF[0,int(t*fps),:,:], latlon = True,cmap='Blues_r')
120
+ m.drawcoastlines(linewidth=2.0, color='0.25')
121
+
122
+ ax2 = fig.add_subplot(235)
123
+ ax2.set_title("SF-RPN - Uncertainty "+r'$\sigma_M$')
124
+ m = Basemap(projection='robin',lon_0=-180)
125
+ contour_plot = m.pcolormesh(X, Y, std_rpn_SF[0,int(t*fps),:,:], latlon = True,cmap='Blues_r')
126
+ m.drawcoastlines(linewidth=2.0, color='0.25')
127
+ #############################################
128
+ ax1 = fig.add_subplot(233)
129
+ ax1.set_title("LF-RPN - MAE")
130
+ m = Basemap(projection='robin',lon_0=-180)
131
+ contour_plot = m.pcolormesh(X, Y, MAE_LF[0,int(t*fps),:,:], latlon = True,cmap='Blues_r')
132
+ m.drawcoastlines(linewidth=2.0, color='0.25')
133
+
134
+ ax2 = fig.add_subplot(236)
135
+ ax2.set_title("LF-RPN - Uncertainty "+r'$\sigma_M$')
136
+ m = Basemap(projection='robin',lon_0=-180)
137
+ contour_plot = m.pcolormesh(X, Y, std_rpn_LF[0,int(t*fps),:,:], latlon = True,cmap='Blues_r')
138
+ m.drawcoastlines(linewidth=2.0, color='0.25')
139
+
140
+ imonths = np.argmax(hours>int(t*fps))
141
+ nhour = int(t*fps) % 24
142
+ if nhour<10:
143
+ nhour = '0'+str(nhour)
144
+ else:
145
+ nhour = str(nhour)
146
+
147
+ if imonths == 0:
148
+ nday = 1+int(t*fps)//24
149
+ else:
150
+ nday = int(t*fps)//24-days[imonths-1]+1
151
+
152
+ if nday<10:
153
+ nday = '0'+str(nday)
154
+ else:
155
+ nday = str(nday)
156
+ if imonths == 11:
157
+ ty = '2004'
158
+ else:
159
+ ty = '2003'
160
+
161
+ fig.suptitle(ttl + ' ; '+nday+' '+months[imonths]+' '+ty+' ; '+nhour+':00')
162
+
163
+ plt.margins(x=0)
164
+ plt.margins(y=0)
165
+ plt.subplots_adjust(hspace=-0.3)
166
+ fig.subplots_adjust(top=0.85)
167
+ plt.tight_layout()
168
+
169
+ fig.canvas.draw()
170
+ cbar_ax = fig.add_axes([0.05, 0.02, 0.9, 0.05])
171
+ cbar = fig.colorbar(contour_plot, orientation='horizontal', cax=cbar_ax)
172
+ cbar.set_ticks([])
173
+
174
+ return mplfig_to_npimage(fig)
175
+
176
+ animation = VideoClip(create_fr, duration = duration)
177
+
178
+ animation.write_videofile(ttl_s,fps=fps,threads=16,
179
+ logger=None,codec="mpeg4",preset="slow",ffmpeg_params=['-b:v','10000k'])
180
+
9_uncertainty_video_daily.py ADDED
@@ -0,0 +1,191 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ """
4
+ Created on Fri Sep 8 08:12:39 2023
5
+
6
+ @author: mohamedazizbhouri
7
+ """
8
+ from matplotlib import pyplot as plt
9
+ import numpy as np
10
+ from mpl_toolkits.basemap import Basemap
11
+ from moviepy.editor import VideoClip
12
+ from moviepy.video.io.bindings import mplfig_to_npimage
13
+
14
+ plt.rcParams.update(plt.rcParamsDefault)
15
+ plt.rc('font', family='serif')
16
+ plt.rcParams.update({'font.size': 16,
17
+ 'lines.linewidth': 2,
18
+ 'axes.labelsize': 20,
19
+ 'axes.titlesize': 20,
20
+ 'xtick.labelsize': 16,
21
+ 'ytick.labelsize': 16,
22
+ 'legend.fontsize': 20,
23
+ 'axes.linewidth': 2,
24
+ "pgf.texsystem": "pdflatex"
25
+ })
26
+
27
+ lat = 96
28
+ lon = 144
29
+
30
+ x = np.linspace(0, 360-360/144, lon)
31
+ y = np.linspace(-90, 90, lat)
32
+ X, Y = np.meshgrid(x, y)
33
+
34
+ dim_heat = 26
35
+ dim_moist = 22
36
+ mu_error_out = np.concatenate((np.zeros((1,dim_heat),dtype=np.float32),
37
+ np.zeros((1,dim_moist),dtype=np.float32)),axis=1)
38
+ mu_error_out = mu_error_out.T[:,:,None,None]
39
+ sigma_error_out = np.concatenate((1/1004.6*np.ones((1,dim_heat),dtype=np.float32),
40
+ 1/2.26e6*np.ones((1,dim_moist),dtype=np.float32)),axis=1)
41
+ sigma_error_out = sigma_error_out.T[:,:,None,None]
42
+
43
+ y_var = 43 # 14, 18, 21, 36, 40, 43
44
+
45
+ if y_var == 14:
46
+ ttl = 'Heat tendency at 259 hPa'
47
+ ttl_s = 'videos/daily_heat_tend_259.mp4'
48
+ elif y_var == 18:
49
+ ttl = 'Heat tendency at 494 hPa'
50
+ ttl_s = 'videos/daily_heat_tend_494.mp4'
51
+ elif y_var == 21:
52
+ ttl = 'Heat tendency at 761 hPa'
53
+ ttl_s = 'videos/daily_heat_tend_761.mp4'
54
+ elif y_var == 36:
55
+ ttl = 'Moisture tendency at 259 hPa'
56
+ ttl_s = 'videos/daily_moist_tend_259.mp4'
57
+ elif y_var == 40:
58
+ ttl = 'Moisture tendency at 494 hPa'
59
+ ttl_s = 'videos/daily_moist_tend_494.mp4'
60
+ elif y_var == 43:
61
+ ttl = 'Moisture tendency at 761 hPa'
62
+ ttl_s = 'videos/daily_moist_tend_761.mp4'
63
+
64
+ test = (np.load('data_SPCAM5_4K/all_outputs_reshaped.npy')[y_var:y_var+1,:,:,:] - mu_error_out) / sigma_error_out
65
+ test = np.array(test,dtype=np.float64)
66
+
67
+ N_dt_day = 24 # we have a dt=1hour
68
+ def daily_avg(test):
69
+ test_daily = []
70
+ N_time_steps = test.shape[1]
71
+ for i in range(test.shape[0]):
72
+ test_daily.append( np.mean( test[i,:,:,:].reshape( (N_time_steps//N_dt_day, N_dt_day, lat, lon) ), axis=1 ) )
73
+ return np.array(test_daily)
74
+
75
+ months = ['Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec', 'Jan']
76
+ days = np.array([28, 28+31, 28+31+30, 28+31+30+31, 28+31+30+31+30, 28+31+30+31+30+31,
77
+ 28+31+30+31+30+31+31, 28+31+30+31+30+31+31+30, 28+31+30+31+30+31+31+30+31,
78
+ 28+31+30+31+30+31+31+30+31+30, 28+31+30+31+30+31+31+30+31+30+31,
79
+ 28+31+30+31+30+31+31+30+31+30+31+31])
80
+
81
+ std_rpn_MF = np.load('MF_param/mean_RPN_MF_reshaped.npy')[y_var:y_var+1,:,:,:]/ sigma_error_out
82
+ mean_rpn_MF = (np.load('MF_param/std_RPN_MF_reshaped.npy')[y_var:y_var+1,:,:,:] - mu_error_out) / sigma_error_out
83
+ mean_rpn_MF = np.array(mean_rpn_MF,dtype=np.float64)
84
+ std_rpn_MF = np.array(std_rpn_MF,dtype=np.float64)
85
+
86
+ std_rpn_LF = np.load('MF_param/mean_RPN_LF_reshaped.npy')[y_var:y_var+1,:,:,:]/ sigma_error_out
87
+ mean_rpn_LF = (np.load('MF_param/std_RPN_LF_reshaped.npy')[y_var:y_var+1,:,:,:] - mu_error_out) / sigma_error_out
88
+ mean_rpn_LF = np.array(mean_rpn_LF,dtype=np.float64)
89
+ std_rpn_LF = np.array(std_rpn_LF,dtype=np.float64)
90
+
91
+ std_rpn_SF = np.load('SF_param/mean_RPN_SF_reshaped.npy')[y_var:y_var+1,:,:,:]/ sigma_error_out
92
+ mean_rpn_SF = (np.load('SF_param/std_RPN_SF_reshaped.npy')[y_var:y_var+1,:,:,:] - mu_error_out) / sigma_error_out
93
+ std_rpn_SF = np.array(std_rpn_SF,dtype=np.float64)
94
+ mean_rpn_SF = np.array(mean_rpn_SF,dtype=np.float64)
95
+
96
+ test = daily_avg(test)
97
+
98
+ mean_rpn_MF = daily_avg(mean_rpn_MF)
99
+ MAE_MF = np.abs( test-mean_rpn_MF )
100
+ std_rpn_MF = daily_avg(std_rpn_MF )
101
+
102
+ mean_rpn_LF = daily_avg(mean_rpn_LF)
103
+ MAE_LF = np.abs( test-mean_rpn_LF )
104
+ std_rpn_LF = daily_avg(std_rpn_LF )
105
+
106
+ mean_rpn_SF = daily_avg(mean_rpn_SF)
107
+ MAE_SF = np.abs( test-mean_rpn_SF )
108
+ std_rpn_SF = daily_avg(std_rpn_SF )
109
+
110
+ N_frame = std_rpn_MF.shape[1]
111
+
112
+ fps = 5
113
+ duration = N_frame / fps
114
+
115
+ fig = plt.figure(figsize=(31.5, 14))
116
+
117
+ def create_fr(t):
118
+ print(t,int(t*fps))
119
+ fig.clf()
120
+
121
+ ax1 = fig.add_subplot(231)
122
+ ax1.set_title("MF-RPN - MAE")
123
+ m = Basemap(projection='robin',lon_0=-180)
124
+ contour_plot = m.pcolormesh(X, Y, MAE_MF[0,int(t*fps),:,:], latlon = True,cmap='Blues_r')
125
+ m.drawcoastlines(linewidth=2.0, color='0.25')
126
+
127
+ ax2 = fig.add_subplot(234)
128
+ ax2.set_title("MF-RPN - Uncertainty "+r'$\sigma_M$')
129
+ m = Basemap(projection='robin',lon_0=-180)
130
+ contour_plot = m.pcolormesh(X, Y, std_rpn_MF[0,int(t*fps),:,:], latlon = True,cmap='Blues_r')
131
+ m.drawcoastlines(linewidth=2.0, color='0.25')
132
+ #############################################
133
+ ax1 = fig.add_subplot(232)
134
+ ax1.set_title("SF-RPN - MAE")
135
+ m = Basemap(projection='robin',lon_0=-180)
136
+ contour_plot = m.pcolormesh(X, Y, MAE_SF[0,int(t*fps),:,:], latlon = True,cmap='Blues_r')
137
+ m.drawcoastlines(linewidth=2.0, color='0.25')
138
+
139
+ ax2 = fig.add_subplot(235)
140
+ ax2.set_title("SF-RPN - Uncertainty "+r'$\sigma_M$')
141
+ m = Basemap(projection='robin',lon_0=-180)
142
+ contour_plot = m.pcolormesh(X, Y, std_rpn_SF[0,int(t*fps),:,:], latlon = True,cmap='Blues_r')
143
+ m.drawcoastlines(linewidth=2.0, color='0.25')
144
+ #############################################
145
+ ax1 = fig.add_subplot(233)
146
+ ax1.set_title("LF-RPN - MAE")
147
+ m = Basemap(projection='robin',lon_0=-180)
148
+ contour_plot = m.pcolormesh(X, Y, MAE_LF[0,int(t*fps),:,:], latlon = True,cmap='Blues_r')
149
+ m.drawcoastlines(linewidth=2.0, color='0.25')
150
+
151
+ ax2 = fig.add_subplot(236)
152
+ ax2.set_title("LF-RPN - Uncertainty "+r'$\sigma_M$')
153
+ m = Basemap(projection='robin',lon_0=-180)
154
+ contour_plot = m.pcolormesh(X, Y, std_rpn_LF[0,int(t*fps),:,:], latlon = True,cmap='Blues_r')
155
+ m.drawcoastlines(linewidth=2.0, color='0.25')
156
+
157
+ imonths = np.argmax(days>int(t*fps))
158
+ if imonths == 0:
159
+ nday = 1+int(t*fps)
160
+ else:
161
+ nday = int(t*fps)-days[imonths-1]+1
162
+
163
+ if nday<10:
164
+ nday = '0'+str(nday)
165
+ else:
166
+ nday = str(nday)
167
+ if imonths == 11:
168
+ ty = '2004'
169
+ else:
170
+ ty = '2003'
171
+
172
+ fig.suptitle(ttl + ' ; '+nday+' '+months[imonths]+' '+ty)
173
+
174
+ plt.margins(x=0)
175
+ plt.margins(y=0)
176
+ plt.subplots_adjust(hspace=-0.3)
177
+ fig.subplots_adjust(top=0.85)
178
+ plt.tight_layout()
179
+
180
+ fig.canvas.draw()
181
+ cbar_ax = fig.add_axes([0.05, 0.02, 0.9, 0.05])
182
+ cbar = fig.colorbar(contour_plot, orientation='horizontal', cax=cbar_ax)
183
+ cbar.set_ticks([])
184
+
185
+ return mplfig_to_npimage(fig)
186
+
187
+ animation = VideoClip(create_fr, duration = duration)
188
+
189
+ animation.write_videofile(ttl_s,fps=fps,threads=16,
190
+ logger=None,codec="mpeg4",preset="slow",ffmpeg_params=['-b:v','10000k'])
191
+
candle_plots_1st_lvl_SS_moist_tend.png ADDED

Git LFS Details

  • SHA256: 017f0c19493f124245d934bf809d5c642f5c7441935d5c6af8d2247a67625e97
  • Pointer size: 131 Bytes
  • Size of remote file: 178 kB
candle_plots_5_pr_lvls_heat_tend_and_spec_hum.png ADDED

Git LFS Details

  • SHA256: aac763f4e6ad1ad106cf699d829152557346fbc1e328c02e96cb68324965a1d0
  • Pointer size: 131 Bytes
  • Size of remote file: 625 kB
glob_errors/CRPS_heat.png ADDED

Git LFS Details

  • SHA256: ea868af0069a2f67d40b6bc6dfbb559c704bc2ec30e8061376306239862a3ee6
  • Pointer size: 131 Bytes
  • Size of remote file: 455 kB
glob_errors/CRPS_moist.png ADDED

Git LFS Details

  • SHA256: 67059c273d9d476c3189fa9acb6d56e7e2b144800420cedf94783179b91c9252
  • Pointer size: 131 Bytes
  • Size of remote file: 419 kB
glob_errors/MAE_det.npy ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c342cc7ec43ca5c6164d304ca6c7b4447bf99a3f02fd54ffc7e4efc89f124e0a
3
+ size 512
glob_errors/MAE_heat.png ADDED

Git LFS Details

  • SHA256: 0c3c3eff8ee8f9cff4e39d9ddd21ed0d431c6441f1a44896479ad154c67040a2
  • Pointer size: 131 Bytes
  • Size of remote file: 510 kB
glob_errors/MAE_moist.png ADDED

Git LFS Details

  • SHA256: 666df21cda06c77715d00028f1db40e1961ba3b5b06e3cf44fcdbd7e49bc588c
  • Pointer size: 131 Bytes
  • Size of remote file: 470 kB
glob_errors/MAE_rpn_LF.npy ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:562a07db14263eae7d1261dd7c56359b5c38149b753d0d0a810a74c0fe30a151
3
+ size 512
glob_errors/MAE_rpn_MF.npy ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5577c7592c0214e8782e1aa48d00d27ad45ba48015d89ab49922a5a9a4020f55
3
+ size 512
glob_errors/MAE_rpn_SF.npy ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ce893d9f63d38d7ec447d849e67a7c17ea39bd0afbc8f33dd5f420502e027425
3
+ size 512
glob_errors/R2_w_neg_heat.png ADDED

Git LFS Details

  • SHA256: cadd4599bdc6707b859695d9f2f988244dd7cded5e3c36645580ffabb1357f7e
  • Pointer size: 131 Bytes
  • Size of remote file: 781 kB
glob_errors/R2_w_neg_moist.png ADDED

Git LFS Details

  • SHA256: 72dbc7f868d75060a81fd6fee1cefd542e03899f6fff7992b664ebd1694034f1
  • Pointer size: 131 Bytes
  • Size of remote file: 753 kB
glob_errors/R2_wo_neg_heat.png ADDED

Git LFS Details

  • SHA256: fe0e4f65f53e7d23df3f04ab5208d67cc6344b5425ecfd7450c2b555d7e720dc
  • Pointer size: 131 Bytes
  • Size of remote file: 588 kB
glob_errors/R2_wo_neg_moist.png ADDED

Git LFS Details

  • SHA256: b6a6e4b6e79e2710c2148ee1c53b1b14a569f02f756df1cc484b584121ce5750
  • Pointer size: 131 Bytes
  • Size of remote file: 521 kB
glob_errors/crps_rpn_LF.npy ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d4cf1a806aae144f312e9b52cdb5c6baf929a610808733849249c137ab6d1c53
3
+ size 512
glob_errors/crps_rpn_MF.npy ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:bcd62b16e0a312312891e7ee91e681b1d829641ca4a9c96e0367b96471361db1
3
+ size 512
glob_errors/crps_rpn_SF.npy ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d49f7e362a73d790bbe5086bf82401ce9c33ec854d7db9ff3bff8b2f3156259e
3
+ size 512
glob_errors/r2_det.npy ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3fbca7a2cb93a40551df4069a12ef51f12cd2f869babd12166da51e268ea5108
3
+ size 512
glob_errors/r2_rpn_LF.npy ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d4f687a080dfe89d723c164b090f01ee94411ad122391dc91a00ec25bf7701b4
3
+ size 512
glob_errors/r2_rpn_MF.npy ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1fdb303fb32516358605e33d67cd5b150217db22d19bf3304d35822f3250d18a
3
+ size 512
glob_errors/r2_rpn_SF.npy ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8936fef5314015e37d42ee8bf9ceed196f95067d4712b5517280c77224357e76
3
+ size 512
long_lat_plots/heat_MAE_long_lat_0.png ADDED

Git LFS Details

  • SHA256: bce19542ab422feb9bf57d975f60dec1f11883ebebd3479de1189bf457435157
  • Pointer size: 132 Bytes
  • Size of remote file: 1.83 MB
long_lat_plots/heat_MAE_long_lat_1.png ADDED

Git LFS Details

  • SHA256: aa8e5ffc9a8e144ad57a8c8af2fb218bf297f25ec611b2790f87dd6a4fc1585b
  • Pointer size: 132 Bytes
  • Size of remote file: 1.8 MB