-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot_pressure_WRF_BRIFS_OBS.m
433 lines (382 loc) · 15.4 KB
/
plot_pressure_WRF_BRIFS_OBS.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
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
function plot_pressure_WRF_BRIFS_OBS(strdate,dirname_out,dirname_plots)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% function plot_pressure_WRF_BRIFS(strdate,dirname_out,dirname_plots)
%
% Plot atmospheric pressure time series from WRF outputs at a given date.
%
% Input arguments:
% strdate: YYYYMMDD
% dirname_out: directory with WRF output files for that date
% dirname_plots: directory for plots
%
% Author: Baptiste Mourre - SOCIB
% Matjaz Licer - NIB MBS
% Date of creation: May-2015
% Last modification: 12-Apr-2016
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
disp([' Script plot_pressure_WRF_BRIFS_OBS executed on ' datestr(now)]);
% load colormap:
load('rt_colormaps.mat')
myCmap=rt_colormaps.barbara;
mydate=datenum(strdate,'yyyymmdd');
if ~exist(dirname_out)
disp([' ERROR: Directory ' dirname_out ' not found']);
return
end
if ~exist(dirname_plots)
disp([' ERROR: Directory ' dirname_plots ' not found']);
return
end
filelist=dir([dirname_out '/wrfout_d02_*']);
Icount=0;
firstfile=1;
if length(filelist)==0
disp([' ERROR: No WRF output files found for ' datestr(mydate)]);
return
end
%%
for kf=1:length(filelist)
fname=[dirname_out '/' filelist(kf).name];
disp([' Reading file ' fname '...']);
ttime=datenum(nc_varget(fname,'Times'));
if (max(ttime)<mydate)
disp([' Skip file ' fname ' :data in the past']);
continue
end
nt=length(ttime);
time(Icount+1:Icount+nt)=ttime;
if (firstfile==1)
lon_wrf=squeeze(nc_varget(fname,'XLONG',[0 0 0],[1 -1 -1]));
lat_wrf=squeeze(nc_varget(fname,'XLAT',[0 0 0],[1 -1 -1]));
[ny nx]=size(lon_wrf);
firstfile=0;
end
PSFC(Icount+1:Icount+nt,:,:)=nc_varget(fname,'PSFC');
HGT(Icount+1:Icount+nt,:,:)=nc_varget(fname,'HGT');
T2(Icount+1:Icount+nt,:,:)=nc_varget(fname,'T2');
Q2(Icount+1:Icount+nt,:,:)=nc_varget(fname,'Q2');
XLAND(Icount+1:Icount+nt,:,:)=nc_varget(fname,'XLAND');
Icount=Icount+nt;
end
nt=length(time);
% Compute MSLP
PSFC=PSFC/100; % Convert to hPa
MSLP=PSFC.*exp(9.81.*HGT./(287.*T2.*(1+0.61.*Q2)));
% Mask MSLP
MSLP_masked=MSLP;
MSLP_masked(XLAND==1)=NaN;
PSFC_masked=PSFC;
PSFC_masked(XLAND==1)=NaN;
% save([dirname_plots 'WRF_MSLP2D_' strdate '.mat'],'MSLP','T2','lon_wrf','lat_wrf','time')
%% read available observations on specified date strdate:
barometers = readPressureObservations(strdate)
%load color_gravonde
load med_coastline_nolakes.dat
define_colors
load('rt_colormaps.mat')
im=get_SOCIB_logo;
% Define Stations
lon(1)=0.83;lat(1)=36.5; % African coast 1
lon(2)=3.0;lat(2)=37.15; % African coast 2
lon(3)=1.5;lat(3)=37.8; % Middle Ibiza Africa
lon(4)=3.3;lat(4)=38.1; % Middle Mallorca Africa
lon(5)=4.48;lat(5)=38.7; % Middle Menorca Africa
lon(6)=1.45;lat(6)=38.85; % Ibiza
lon(7)=2.1;lat(7)=39.2; % Ibiza-Mallorca channel
lon(8)=2.7;lat(8)=39.5; % Palma
lon(9)=3.6;lat(9)=39.9; % Middle of the channel
lon(10)=3.8;lat(10)=39.98; % Ciutadella
lon(11)=4.4;lat(11)=39.84; % Maó
lon(12)=2.7;lat(12)=41.1; % Close to Cabo Begur
lon(13)=3.0;lat(13)=39.4; % Sarapita
lon(14)=1.3;lat(14)=39.0; % Sant Antoni
lon(15)=3.1;lat(15)=39.9; % Pollensa
lon(16)=4.3;lat(16)=39.9; % Lamola
lon(17)=3.2;lat(17)=39.7; % Colonia St Pere
lon(18)=2.4;lat(18)=39.5; % Andratx
Name(:, 1) ='African coast 1 ';
Name(:, 2) ='African coast 2 ';
Name(:, 3) ='Middle Ibiza-Africa ';
Name(:, 4) ='Middle Mallorca-Africa';
Name(:, 5) ='Middle Menorca-Africa ';
Name(:, 6) ='Ibiza ';
Name(:, 7) ='Middle Ibiza-Mallorca ';
Name(:, 8) ='Palma de Mallorca ';
Name(:, 9) ='Middle of Channel ';
Name(:, 10)='Ciutadella ';
Name(:, 11)='Mao ';
Name(:, 12)='Near Cabo Begur ';
Name(:, 13)='Sarapita ';
Name(:, 14)='Sant Antoni ';
Name(:, 15)='Pollensa ';
Name(:, 16)='Lamola ';
Name(:, 17)='Colonia Sant Pere ';
Name(:, 18)='Andratx ';
Name_simple(:, 1)='P01';
Name_simple(:, 2)='P02';
Name_simple(:, 3)='P03';
Name_simple(:, 4)='P04';
Name_simple(:, 5)='P05';
Name_simple(:, 6)='P06';
Name_simple(:, 7)='P07';
Name_simple(:, 8)='P08';
Name_simple(:, 9)='P09';
Name_simple(:, 10)='P10';
Name_simple(:, 11)='P11';
Name_simple(:, 12)='P12';
Name_simple(:, 13)='P13';
Name_simple(:, 14)='P14';
Name_simple(:, 15)='P15';
Name_simple(:, 16)='P16';
Name_simple(:, 17)='P17';
Name_simple(:, 18)='P18';
% Separate today and tomorrow figures
tt_today=find(time-mydate>=0 & time-mydate<=1);
tt_tomorrow=find(time-mydate>=1 & time-mydate<=2);
nt_today=length(tt_today);
nt_tomorrow=length(tt_tomorrow);
% testing time params --mlicer:
% tt_today=find(time-mydate>=0 & time-mydate<=0.01);
% tt_tomorrow=find(time-mydate>=1 & time-mydate<=1.01);
% nt_today=length(tt_today);
% nt_tomorrow=length(tt_tomorrow);
CAXIS_0_24=[nanmin(nanmin(MSLP_masked(tt_today,:))) nanmax(nanmax(MSLP_masked(tt_today,:)))];
CAXIS_24_48=[nanmin(nanmin(MSLP_masked(tt_tomorrow,:))) nanmax(nanmax(MSLP_masked(tt_tomorrow,:)))];
CAXIS_MEAN=[nanmin(nanmin(nanmean(MSLP_masked(tt_today,:)))) nanmax(nanmax(nanmean(MSLP_masked(tt_today,:))))];
display('Create atmospheric pressure maps 0-24h ...')
fname_avi_0_24=[dirname_plots, '/forecast_', strdate, '_0_24.avi'];
aviobj = avifile(fname_avi_0_24, 'quality', 30);
fig=figure;
if false % DISABLE TIMESERIES PLOTS (takes forever) --mlicer
for kt=1:nt_today
disp([' kt=' num2str(kt) ' over ' num2str(nt_today)]);
pcolor(lon_wrf,lat_wrf,double(squeeze(MSLP(tt_today(kt),:,:))))
hold on
plot(med_coastline_nolakes(:,1),med_coastline_nolakes(:,2),'k','LineWidth',1)
dasp(mean(lat_wrf(:)));
cbar=colorbar('fontsize',12,'position',[0.25 0.5 0.03 0.3]);
xlabel(cbar, ' (hPa)', 'fontsize',12)
shading flat
set(gca, 'fontsize', 12)
%colormap(colorred)
colormap(myCmap)
[cs,bh]=contour(lon_wrf,lat_wrf,double(squeeze(MSLP_masked(tt_today(kt),:,:))),[980:1:1030]','w','linewidth',1);
ht=clabel(cs,bh,'labelspacing',200,'fontsize',8,'color','w');
caxis(CAXIS_0_24);
text(-2,41.6,datestr(time(tt_today(kt)),'dd-mmm-yyyy HH:MM UTC'),'fontsize',12, 'color', 'k','backgroundcolor', 'w');
axis off
M(kt)=getframe;
clf
end
if (nt_today>0)
display(['Save movie atmospheric pressure maps 0-24h in file ' fname_avi_0_24])
aviobj = addframe(aviobj,M);
aviobj = close(aviobj);
clear M
end
close(fig)
display('Create atmospheric pressure maps 24-48h ...')
fname_avi_24_48=[dirname_plots, '/forecast_', strdate, '_24_48.avi'];
aviobj = avifile(fname_avi_24_48, 'quality', 30);
fig=figure;
for kt=1:nt_tomorrow
disp([' kt=' num2str(kt) ' over ' num2str(nt_tomorrow)]);
pcolor(lon_wrf,lat_wrf,double(squeeze(MSLP(tt_tomorrow(kt),:,:))))
hold on
plot(med_coastline_nolakes(:,1),med_coastline_nolakes(:,2),'k','LineWidth',1)
dasp(mean(lat_wrf(:)));
cbar=colorbar('fontsize',12,'position',[0.25 0.5 0.03 0.3]);
xlabel(cbar, ' (hPa)', 'fontsize',12)
shading flat
set(gca, 'fontsize', 12)
%colormap(colorred)
colormap(myCmap)
[cs,bh]=contour(lon_wrf,lat_wrf,double(squeeze(MSLP_masked(tt_tomorrow(kt),:,:))),[980:1:1030]','w','linewidth',1);
ht=clabel(cs,bh,'labelspacing',200,'fontsize',8,'color','w');
caxis(CAXIS_24_48);
text(-2,41.5,datestr(time(tt_tomorrow(kt)),'dd-mmm-yyyy HH:MM UTC'), 'fontsize', 12, 'color', 'k','backgroundcolor', 'w')
axis off
M(kt)=getframe;
clf
end
display(['Save movie atmospheric pressure maps 24-48h in file ' fname_avi_24_48])
if (nt_tomorrow>0)
aviobj = addframe(aviobj,M);
aviobj = close(aviobj);
clear M
end
close(fig)
end % DISABLE TIMESERIES PLOTS (takes forever) --mlicer
% Plot mean pressure map with point locations
figure
pcolor(lon_wrf,lat_wrf,double(squeeze(nanmean(MSLP(tt_today,:,:)))))
hold on
dasp(mean(lat_wrf(:)));
plot(med_coastline_nolakes(:,1),med_coastline_nolakes(:,2),'k','LineWidth',1)
cbar=colorbar;
%ylabel(cbar, 'hPa', 'fontsize', 20)
shading flat
set(gca, 'fontsize', 15)
%colormap(colorred)
colormap(myCmap)
[cs,bh]=contour(lon_wrf,lat_wrf,double(squeeze(nanmean(MSLP_masked(tt_today,:,:)))),[980:1:1030]','w','linewidth',2);
ht=clabel(cs,bh,'labelspacing',200,'fontsize',10,'color','w');
plot(lon, lat, 'd', 'markersize', 3,'Color',grey, 'linewidth', 1)
for k=[2:8 11 12]
text(lon(k)+0.1, lat(k), Name_simple(:, k)','Color',grey,'fontsize', 12)
end
for k=[1 9]
text(lon(k)-0.65, lat(k)+0.0, Name_simple(:, k)','Color',grey, 'fontsize', 12)
end
for k=[10]
text(lon(10)-0.3, lat(10)+0.2, Name_simple(:, 10)','Color',grey, 'fontsize', 12)
end
caxis(CAXIS_MEAN);
xlabel('Longitude (degE)', 'fontsize', 15)
ylabel('Latitude (degN)', 'fontsize', 15)
title(['Mean sea level pressure (hPa) for ' datestr(mydate,'dd-mmm-yyyy')], 'fontsize', 15);
% Add SOCIB logo
axes('position',[0.68,0.12,0.08,0.08])
imshow(im)
set(gcf,'renderer','zbuffer');
% printpspng([dirname_plots '/Map_locations_' strdate])
pngname = [dirname_plots '/BRIFS_mean_pressure_map_' strdate];
print('-dpng','-r300',pngname)
% Duplicate figure with new name
% printpspng([dirname_plots '/BRIFS_mean_pressure_map_' strdate]);
% Plot pressure time series at specified locations
P_stations=NaN*zeros(nt,length(lon));
for kt=1:nt
P_stations(kt,:)=interp2(lon_wrf,lat_wrf,squeeze(MSLP(kt,:,:)),lon,lat);
end
tt_48h=unique([tt_today;tt_tomorrow]);
figure('position', [0 0 1000 1000])
for ks=1:6
subplot(3,2,ks)
plot(time(tt_48h), P_stations(tt_48h, ks),'Color',steel, 'linewidth', 1)
set(gca, 'fontsize', 10)
set(gca,'XTick',(min(time(tt_48h)):0.25:max(time(tt_48h))));
set(gca,'XTickLabel',{datestr(min(time(tt_48h)),'dd-mmm-yyyy'),'','','',datestr(min(time(tt_48h)+1),'dd-mmm'),'','','',datestr(min(time(tt_48h)+2),'dd-mmm')});
%datetick('x','dd-mmm')
ylim_min=min(P_stations(tt_48h, ks))-(max(P_stations(tt_48h,ks))-min(P_stations(tt_48h, ks)))/10;
ylim_max=max(P_stations(tt_48h, ks))+(max(P_stations(tt_48h,ks))-min(P_stations(tt_48h, ks)))/10;
ylim([ylim_min ylim_max]);
text(min(xlim)+diff(xlim)/100,max(ylim)-diff(ylim)/10,Name(:, ks)','Color','r','fontsize', 15);
grid on
%xlabel([datestr(max(time(tt_today)),'yyyy')], 'fontsize', 12)
xlabel(['00:00 UTC 00:00 UTC 00:00 UTC' ], 'fontsize', 8)
if (ks==3)
ylabel('Sea level pressure (hPa)', 'fontsize', 15)
end
end
% Add SOCIB logo
axes('position',[0.46,0.88,0.06,0.06])
imshow(im)
set(gcf,'renderer','zbuffer');
saveas(gcf,[dirname_plots '/BRIFS_pressure_timeseries_P1_P6_' strdate],'png')
% printpspng([dirname_plots '/MSLP_part1_' strdate]);
% Duplicate figure with new name
% printpspng([dirname_plots '/BRIFS_pressure_timeseries_P1_P6_' strdate]);
figure('position', [0 0 1000 1000])
for ks=7:12
subplot(3,2,ks-6)
plot(time(tt_48h), P_stations(tt_48h, ks),'Color',steel, 'linewidth', 1)
set(gca, 'fontsize', 10)
set(gca,'XTick',(min(time(tt_48h)):0.25:max(time(tt_48h))));
set(gca,'XTickLabel',{datestr(min(time(tt_48h)),'dd-mmm'),'','','',datestr(min(time(tt_48h)+1),'dd-mmm'),'','','',datestr(min(time(tt_48h)+2),'dd-mmm')});
%datetick('x','dd-mmm')
ylim_min=min(P_stations(tt_48h, ks))-(max(P_stations(tt_48h,ks))-min(P_stations(tt_48h, ks)))/10;
ylim_max=max(P_stations(tt_48h, ks))+(max(P_stations(tt_48h,ks))-min(P_stations(tt_48h, ks)))/10;
ylim([ylim_min ylim_max]);
text(min(xlim)+diff(xlim)/100,max(ylim)-diff(ylim)/10,Name(:, ks)','Color','r','fontsize', 15);
grid on
%xlabel([datestr(max(time(tt_today)),'yyyy')], 'fontsize', 12)
xlabel(['00:00 UTC 00:00 UTC 00:00 UTC' ], 'fontsize', 8)
if (ks==9)
ylabel('Sea level pressure (hPa)', 'fontsize', 15)
end
end
% Add SOCIB logo
axes('position',[0.46,0.88,0.06,0.06])
imshow(im)
set(gcf,'renderer','zbuffer');
saveas(gcf,[dirname_plots '/BRIFS_pressure_timeseries_P7_P12_' strdate],'png')
% printpspng([dirname_plots '/MSLP_part2_' strdate]);
% Duplicate figure with new name
% printpspng([dirname_plots '/BRIFS_pressure_timeseries_P7_P12_' strdate]);
figure('position', [0 0 1000 1000])
for ks=13:18
subplot(3,2,ks-12)
% add observations to figures:
switch ks
case 13
if barometers.sarapita.dataExists
hold on
plot(barometers.sarapita.time, barometers.sarapita.AIR_PRE,'r', 'linewidth', 1)
xlim([min(time(tt_48h)),max(time(tt_48h))])
end
case 14
if barometers.santantoni.dataExists
hold on
plot(barometers.santantoni.time, barometers.santantoni.AIR_PRE,'r', 'linewidth', 1)
xlim([min(time(tt_48h)),max(time(tt_48h))])
end
case 15
if barometers.pollensa.dataExists
hold on
plot(barometers.pollensa.time, barometers.pollensa.AIR_PRE,'r', 'linewidth', 1)
xlim([min(time(tt_48h)),max(time(tt_48h))])
end
case 16
if barometers.lamola.dataExists
hold on
plot(barometers.lamola.time, barometers.lamola.AIR_PRE,'r', 'linewidth', 1)
xlim([min(time(tt_48h)),max(time(tt_48h))])
end
case 17
if barometers.coloniasantpere.dataExists
hold on
plot(barometers.coloniasantpere.time, barometers.coloniasantpere.AIR_PRE,'r', 'linewidth', 1)
xlim([min(time(tt_48h)),max(time(tt_48h))])
end
case 18
if barometers.andratx.dataExists
hold on
plot(barometers.andratx.time, barometers.andratx.AIR_PRE,'r', 'linewidth', 1)
xlim([min(time(tt_48h)),max(time(tt_48h))])
end
end
% add WRF:
plot(time(tt_48h), P_stations(tt_48h, ks),'Color',steel, 'linewidth', 1)
title(['WRF (blue) vs OBS (red): ' datestr(mydate,'yyyy mm dd')])
set(gca, 'fontsize', 10)
set(gca,'XTick',(min(time(tt_48h)):0.25:max(time(tt_48h))));
set(gca,'XTickLabel',{datestr(min(time(tt_48h)),'dd-mmm'),'','','',datestr(min(time(tt_48h)+1),'dd-mmm'),'','','',datestr(min(time(tt_48h)+2),'dd-mmm')});
%datetick('x','dd-mmm')
ylim_min=min(P_stations(tt_48h, ks))-(max(P_stations(tt_48h,ks))-min(P_stations(tt_48h, ks)))/10;
ylim_max=max(P_stations(tt_48h, ks))+(max(P_stations(tt_48h,ks))-min(P_stations(tt_48h, ks)))/10;
ylim([ylim_min ylim_max]);
text(min(xlim)+diff(xlim)/100,max(ylim)-diff(ylim)/10,Name(:, ks)','Color','r','fontsize', 15);
grid on
box on
%xlabel([datestr(max(time(tt_today)),'yyyy')], 'fontsize', 12)
xlabel(['00:00 UTC 00:00 UTC 00:00 UTC' ], 'fontsize', 8)
if (ks==15)
ylabel('Sea level pressure (hPa)', 'fontsize', 15)
end
end
% Add SOCIB logo
axes('position',[0.46,0.88,0.06,0.06])
imshow(im)
set(gcf,'renderer','zbuffer');
pngname = [dirname_plots '/BRIFS_pressure_timeseries_P13_P18_' strdate];
saveas(gcf,[dirname_plots '/BRIFS_pressure_timeseries_P13_P18_' strdate],'png')
print('-dpng','-r300',pngname)
% printpspng([dirname_plots '/MSLP_part2_' strdate]);
% Duplicate figure with new name
% printpspng([dirname_plots '/BRIFS_pressure_timeseries_P7_P12_' strdate]);
close all
matfilename = [dirname_plots '/pressure_WRF-OBS_' strdate '.mat']
save(matfilename,'lon','lat','Name','Name_simple','time','tt_48h','steel','mydate','im','P_stations','barometers')