-
Notifications
You must be signed in to change notification settings - Fork 0
/
contourplots.m
348 lines (262 loc) · 9.88 KB
/
contourplots.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
% First we do the CFSR-Stuff
mnth = 1;
yr = 1989;
file1 = '/media/storage/Data/Mflux/CFSR/original/CFSR.VQ.1979-2009.nc';
file2 = '/media/storage/Data/Mflux/CFSR/original/CFSR.UQ.1979-2009.nc';
for i = 121:372
cfsr_flx{i-120,3} = nj_varget(file1, 'VQ', [i 1 1], [1 inf inf]);
cfsr_flx{i-120,4} = nj_varget(file2, 'UQ', [i 1 1], [1 inf inf]);
cfsr_flx{i-120,1} = mnth;
cfsr_flx{i-120,2} = yr;
mnth = mnth + 1;
if mnth == 13
mnth = 1;
yr = yr + 1;
end
end
lon = nj_varget(file1, 'lon');
lon_units = nj_attget(file1, 'lon', 'units');
lon_name = nj_attget(file1, 'lon', 'long_name');
lon_axis = nj_attget(file1, 'lon', '_CoordinateAxisType');
lat = nj_varget(file1, 'lat');
lat_units = nj_attget(file1, 'lat', 'units');
lat_name = nj_attget(file1, 'lat', 'long_name');
lat_axis = nj_attget(file1, 'lat', '_CoordinateAxisType');
% Now we compute the seasonal mean of the CFSR-fluxes
cfsr_v = comp_spat_mean(cfsr_flx, [1989, 2006], 'seasonal_1', [1 2 3], -9999);
cfsr_u = comp_spat_mean(cfsr_flx, [1989, 2006], 'seasonal_1', [1 2 4], -9999);
cfsr_v_ann = comp_spat_mean(cfsr_flx, [1989, 2006], 'annual_1', [1 2 3], -9999);
cfsr_u_ann = comp_spat_mean(cfsr_flx, [1989, 2006], 'annual_1', [1 2 4], -9999);
% Finally we compute the contour levels (i.e. the gradient)
for i = 1:4
cfsr_c{i} = abs(cfsr_v{i} + cfsr_u{i});
end
savename{1} = 'cfsr_uq_jfm.nc';
savename{2} = 'cfsr_vq_jfm.nc';
savename{3} = 'cfsr_uq_jas.nc';
savename{4} = 'cfsr_vq_jas.nc';
savename{5} = 'cfsr_c_jfm.nc';
savename{6} = 'cfsr_c_jas.nc';
savename{7} = 'cfsr_uq_ann.nc';
savename{8} = 'cfsr_vq_ann.nc';
data{1} = cfsr_u{1};
data{2} = cfsr_v{1};
data{3} = cfsr_u{3};
data{4} = cfsr_v{3};
data{5} = cfsr_c{1};
data{6} = cfsr_c{3};
data{7} = cfsr_u_ann;
data{8} = cfsr_v_ann;
varname{1} = 'UQ_JFM';
varname{2} = 'VQ_JFM';
varname{3} = 'UQ_JAS';
varname{4} = 'VQ_JAS';
varname{5} = 'C_JFM';
varname{6} = 'C_JAS';
varname{7} = 'UQ_ANN';
varname{8} = 'VQ_ANN';
for i = 1:8
ncid = netcdf.create(savename{i}, 'NC_WRITE');
lon_dim_id = netcdf.defDim(ncid, 'longitude', length(lon));
lat_dim_id = netcdf.defDim(ncid, 'latitude', length(lat));
lon_var_id = netcdf.defVar(ncid, 'longitude', 'double', lon_dim_id);
lat_var_id = netcdf.defVar(ncid, 'latitude', 'double', lat_dim_id);
data_var_id = netcdf.defVar(ncid, varname{i}, 'double', [lon_dim_id lat_dim_id]);
netcdf.endDef(ncid);
netcdf.putVar(ncid, lon_var_id, lon);
netcdf.putVar(ncid, lat_var_id, lat);
netcdf.putVar(ncid, data_var_id, data{i}');
netcdf.reDef(ncid)
netcdf.putAtt(ncid, lon_var_id, 'units', lon_units);
netcdf.putAtt(ncid, lon_var_id, 'long_name', lon_name);
netcdf.putAtt(ncid, lon_var_id, '_CoordinateAxisType', lon_axis);
netcdf.putAtt(ncid, lat_var_id, 'units', lat_units);
netcdf.putAtt(ncid, lat_var_id, 'long_name', lat_name);
netcdf.putAtt(ncid, lat_var_id, '_CoordinateAxisType', lat_axis);
netcdf.close(ncid);
end
% Alright... Let's go for MERRA
clear all
clc
mnth = 1;
yr = 1989;
for i = 121:372
if yr < 1993
stream = num2str(100);
elseif yr >= 1993 & yr < 2001
stream = num2str(200);
elseif yr >= 2001
stream = num2str(300);
end
if mnth < 10
txtmnth = ['0', num2str(mnth)];
else
txtmnth = num2str(mnth);
end
fname = ['/media/storage/Data/Mflux/MERRA/original/MERRA', stream, ...
'.prod.assim.tavgM_2d_int_Nx.', num2str(yr), txtmnth, '.SUB.nc'];
merra_flx{i-120,3} = nj_varget(fname, 'vflxqv');
merra_flx{i-120,4} = nj_varget(fname, 'uflxqv');
merra_flx{i-120,1} = mnth;
merra_flx{i-120,2} = yr;
mnth = mnth + 1;
if mnth == 13
mnth = 1;
yr = yr + 1;
end
end
lon = nj_varget(fname, 'longitude');
lon_units = nj_attget(fname, 'longitude', 'units');
lon_name = nj_attget(fname, 'longitude', 'long_name');
lon_axis = nj_attget(fname, 'longitude', '_CoordinateAxisType');
lat = nj_varget(fname, 'latitude');
lat_units = nj_attget(fname, 'latitude', 'units');
lat_name = nj_attget(fname, 'latitude', 'long_name');
lat_axis = nj_attget(fname, 'latitude', '_CoordinateAxisType');
merra_v = comp_spat_mean(merra_flx, [1989, 2006], 'seasonal_1', [1 2 3], -9999);
merra_u = comp_spat_mean(merra_flx, [1989, 2006], 'seasonal_1', [1 2 4], -9999);
merra_v_ann = comp_spat_mean(merra_flx, [1989, 2006], 'annual_1', [1 2 3], -9999);
merra_u_ann = comp_spat_mean(merra_flx, [1989, 2006], 'annual_1', [1 2 4], -9999);
% Finally we compute the contour levels (i.e. the gradient)
for i = 1:4
merra_c{i} = abs(merra_v{i} + merra_u{i});
end
savename{1} = 'merra_uq_jfm.nc';
savename{2} = 'merra_vq_jfm.nc';
savename{3} = 'merra_uq_jas.nc';
savename{4} = 'merra_vq_jas.nc';
savename{5} = 'merra_c_jfm.nc';
savename{6} = 'merra_c_jas.nc';
savename{7} = 'merra_uq_ann.nc';
savename{8} = 'merra_vq_ann.nc';
data{1} = merra_u{1};
data{2} = merra_v{1};
data{3} = merra_u{3};
data{4} = merra_v{3};
data{5} = merra_c{1};
data{6} = merra_c{3};
data{7} = merra_u_ann;
data{8} = merra_v_ann;
varname{1} = 'UQ_JFM';
varname{2} = 'VQ_JFM';
varname{3} = 'UQ_JAS';
varname{4} = 'VQ_JAS';
varname{5} = 'C_JFM';
varname{6} = 'C_JAS';
varname{7} = 'UQ_ANN';
varname{8} = 'VQ_ANN';
for i = 1:8
ncid = netcdf.create(savename{i}, 'NC_WRITE');
lon_dim_id = netcdf.defDim(ncid, 'longitude', length(lon));
lat_dim_id = netcdf.defDim(ncid, 'latitude', length(lat));
lon_var_id = netcdf.defVar(ncid, 'longitude', 'double', lon_dim_id);
lat_var_id = netcdf.defVar(ncid, 'latitude', 'double', lat_dim_id);
data_var_id = netcdf.defVar(ncid, varname{i}, 'double', [lon_dim_id lat_dim_id]);
netcdf.endDef(ncid);
netcdf.putVar(ncid, lon_var_id, lon);
netcdf.putVar(ncid, lat_var_id, lat);
netcdf.putVar(ncid, data_var_id, data{i}');
netcdf.reDef(ncid)
netcdf.putAtt(ncid, lon_var_id, 'units', lon_units);
netcdf.putAtt(ncid, lon_var_id, 'long_name', lon_name);
netcdf.putAtt(ncid, lon_var_id, '_CoordinateAxisType', lon_axis);
netcdf.putAtt(ncid, lat_var_id, 'units', lat_units);
netcdf.putAtt(ncid, lat_var_id, 'long_name', lat_name);
netcdf.putAtt(ncid, lat_var_id, '_CoordinateAxisType', lat_axis);
netcdf.close(ncid);
end
clear all
%
% AND FINALLY... DA ECMWF SHIT
clear all
mnth = 1;
yr = 1989;
fnme = '/media/storage/Data/Mflux/ECMWF/original/output.grib';
for i = 1:263
ecmwf_flx{i,3} = nj_varget(fnme, 'Vertical_integral_of_northward_water_vapour_flux', [i 1 1], [1 inf inf]);
ecmwf_flx{i,4} = nj_varget(fnme, 'Vertical_integral_of_eastward_water_vapour_flux', [i 1 1], [1 inf inf]);
ecmwf_flx{i,1} = mnth;
ecmwf_flx{i,2} = yr;
mnth = mnth + 1;
if mnth == 13
mnth = 1;
yr = yr + 1;
end
varname{7} = 'UQ_ANN';
varname{8} = 'VQ_ANN';
end
lon = nj_varget(fnme, 'lon');
lon_units = nj_attget(fnme, 'lon', 'units');
lon_name = nj_attget(fnme, 'lon', 'long_name');
lon_axis = nj_attget(fnme, 'lon', '_CoordinateAxisType');
lat = nj_varget(fnme, 'lat');
lat_units = nj_attget(fnme, 'lat', 'units');
lat_name = nj_attget(fnme, 'lat', 'long_name');
lat_axis = nj_attget(fnme, 'lat', '_CoordinateAxisType');
% Now we compute the seasonal mean of the CFSR-fluxes
ecmwf_v = comp_spat_mean(ecmwf_flx, [1989, 2006], 'seasonal_1', [1 2 3], -9999);
ecmwf_u = comp_spat_mean(ecmwf_flx, [1989, 2006], 'seasonal_1', [1 2 4], -9999);
ecmwf_v_ann = comp_spat_mean(ecmwf_flx, [1989, 2006], 'annual_1', [1 2 3], -9999);
ecmwf_u_ann = comp_spat_mean(ecmwf_flx, [1989, 2006], 'annual_1', [1 2 4], -9999);
% Finally we compute the contour levels (i.e. the gradient)
for i = 1:4
ecmwf_c{i} = abs(ecmwf_v{i} + ecmwf_u{i});
end
savename{1} = 'ecmwf_uq_jfm.nc';
savename{2} = 'ecmwf_vq_jfm.nc';
savename{3} = 'ecmwf_uq_jas.nc';
savename{4} = 'ecmwf_vq_jas.nc';
savename{5} = 'ecmwf_c_jfm.nc';
savename{6} = 'ecmwf_c_jas.nc';
savename{7} = 'ecmwf_uq_ann.nc';
savename{8} = 'ecmwf_vq_ann.nc';
data{1} = ecmwf_u{1};
data{2} = ecmwf_v{1};
data{3} = ecmwf_u{3};
data{4} = ecmwf_v{3};
data{5} = ecmwf_c{1};
data{6} = ecmwf_c{3};
data{7} = ecmwf_u_ann;
data{8} = ecmwf_v_ann;
varname{1} = 'UQ_JFM';
varname{2} = 'VQ_JFM';
varname{3} = 'UQ_JAS';
varname{4} = 'VQ_JAS';
varname{5} = 'C_JFM';
varname{6} = 'C_JAS';
varname{7} = 'UQ_ANN';
varname{8} = 'VQ_ANN';
for i = 1:8
ncid = netcdf.create(savename{i}, 'NC_WRITE');
lon_dim_id = netcdf.defDim(ncid, 'longitude', length(lon));
lat_dim_id = netcdf.defDim(ncid, 'latitude', length(lat));
lon_var_id = netcdf.defVar(ncid, 'longitude', 'double', lon_dim_id);
lat_var_id = netcdf.defVar(ncid, 'latitude', 'double', lat_dim_id);
data_var_id = netcdf.defVar(ncid, varname{i}, 'double', [lon_dim_id lat_dim_id]);
netcdf.endDef(ncid);
netcdf.putVar(ncid, lon_var_id, lon);
netcdf.putVar(ncid, lat_var_id, lat);
netcdf.putVar(ncid, data_var_id, data{i}');
netcdf.reDef(ncid)
netcdf.putAtt(ncid, lon_var_id, 'units', lon_units);
netcdf.putAtt(ncid, lon_var_id, 'long_name', lon_name);
netcdf.putAtt(ncid, lon_var_id, '_CoordinateAxisType', lon_axis);
netcdf.putAtt(ncid, lat_var_id, 'units', lat_units);
netcdf.putAtt(ncid, lat_var_id, 'long_name', lat_name);
netcdf.putAtt(ncid, lat_var_id, '_CoordinateAxisType', lat_axis);
netcdf.close(ncid);
end
clear all
load /media/storage/Data/Mflux/CFSR/CFSR_VIMFD.mat
cf = comp_spat_mean(cfsr_vimfd, [1989 2006], 'annual_1', [4 5 9], -9999);
A = grid2gmt(-cf, 0.5);
save cfsr_vimfc_ann.txt A -ascii
load /media/storage/Data/Mflux/ECMWF/ECMWF_VIMFD.mat
cf = comp_spat_mean(ecmwf_vimfd, [1989 2006], 'annual_1', [4 5 9], -9999);
A = grid2gmt(-cf, 0.5);
save ecmwf_vimfc_ann.txt A -ascii
load /media/storage/Data/Mflux/MERRA/MERRA_VIMFD.mat
cf = comp_spat_mean(merra_vimfd, [1989 2006], 'annual_1', [4 5 9], -9999);
A = grid2gmt(-cf, 0.5);
save merra_vimfc_ann.txt A -ascii
% Alright... Let's go for MERRA