-
Notifications
You must be signed in to change notification settings - Fork 0
/
RASOBS_GRAPH_DATA_RAW.m
467 lines (401 loc) · 16.4 KB
/
RASOBS_GRAPH_DATA_RAW.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
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
function [varargout] = RASOBS_GRAPH_DATA_RAW(varargin)
% Function for basic visualization from the radiosonde data
% privided by the Wyoming University and fetched by the Matlab/Octave
% function RASOBS_DOWNLOAD_DATA_RAW.
% This function is mostly useful for large dataset rather than for few
% or simgle radiosonde profiles.
%
% ---
% (c) 2018, P. Saavedra Garfias
% Geophysical Institute, UNIVERSITY OF BERGEN
% Email: [email protected]
% See: LICENSE
% ---------------------------------------------------------------
% ---------------------------------------------------------------
if nargin==0,
% open file browser to load .mat file
[data0, metvar, metadata] = update_matfile();
elseif nargin==1,
[data0, metvar, metadata] = update_matfile(varargin{1});
elseif nargin==2,
data0 = varargin{1};
metvar = varargin{2};
metadata = WyoRS_metadata();
elseif nargin==3,
data0 = varargin{1};
metvar = varargin{2};
metadata = varargin{3};
else
error('two arguments needed: data_profile and radiosonde_indexes');
end
% ----------------------------------------------
% Variables default Initialization
nsonde = length(data0); % PSG
isonde = min(5,nsonde); % initial radiosonde to display
span = 2; % +/- two time steps, it can be increased
rspan = min(nsonde,max(1,[isonde-span:isonde+span]));
nspan = length(rspan);
if nspan>nsonde,
disp('Too few Profiles found!, try with at least 5.');
end
% Here are defined fine-tune parameters Octave/Matlab dependent:
if exist('OCTAVE_VERSION','builtin'),
if any(ismember(available_graphics_toolkits , 'qt')),
graphics_toolkit('qt');
else
graphics_toolkit ('fltk');
warning(['Sorry, GUI controls not supported for Octave yet, only ' ...
'graph shown :(']);
end
% Fosi: FontSize.
FigPosition = [20 5 1000 950];
FoSi = 17;
colorlin = summer(nspan);
else
FigPosition = [20 5 1010 955];
FoSi = 11;
colorlin = summer(nspan);
end
i = min(find(rspan==isonde));
colorlin(i,:) = [0 0 0];
%% Including the Profile derivatives for T, Theta, Theta_v
data = Calculate_Derivatives(data0); % PSG
maxz = 0;
xvar = 'TEMP';
yvar = 'HGHT';
names = fieldnames(data);
nvar = length(names);
tmp = strfind(names,xvar);
idxvar = find(arrayfun(@(x) ~isempty(tmp{x}),...
[1:nvar]));
% Converting the OBST variable to Matlab datenum format:
Nobs = length(metvar.OBST);
tmp = cell2mat(textscan(sprintf('20%8.2f',metvar.OBST),...
'%4f%2f%5f',Nobs,'CollectOutput',1));
%% Convert the series of profiles into a homogeneus matrix:
[PROFILER, TimePROF, Tnumobs] = InitializeProfiler(data,metvar.OBST,12000);
%% Variables to plot in the time series of the RS indices:
tsvar = 13; % 'CAPE' default RS indices to show;
xvar = getfield(metvar,'OBST');
yvar = getfield(metvar, metadata.RSINDICES{tsvar,1});
%% Plotting figure, axes and GUIs
% creating the default figure:
figure;
set(gcf, 'Position', FigPosition, 'PaperPositionMode', 'auto');
clf;
%% Sub-plot 1 for the individual profiles
ha.ax(1) = subplot(6, 4, [1,2,5,6,9,10]);
hold on;
ha.hh = arrayfun(@(i){plot(data(i).TEMP,1e-3*data(i).HGHT,...
'DisplayName',sprintf('T0 %+2d',i-isonde),...
'LineWidth',2,'Tag','TEMP',...
'Color',colorlin(i-rspan(1)+1,:));...
},...
rspan,...
'UniformOutput',true);
maxz = 1e-3*max(arrayfun(@(i) max([data(i).HGHT]),rspan));
set(ha.hh{span+1},'LineWidth',3); % {isonde-span}
xlabel(sprintf('%s [%s]', metadata.PROFILE{idxvar,2:3}), 'FontSize',FoSi);
ylabel(sprintf('%s [K%s]', metadata.PROFILE{2,2:3}), 'FontSize',FoSi);
tmp = get(ha.ax(1), 'Position').*[1 1 1.1 1];
i = [nspan:-1:1]; % to get the middle line to the top
i(span+1) = '';
i = [span+1, i]; % putting the middle line to the top
if exist('OCTAVE_VERSION','builtin'),
objarray = cell2mat(ha.hh(i));
else
objarray = [ha.hh{i}]';
end
set(ha.ax(1),'YLim',[-.05 maxz],'Box','on','YGrid','on',...
'FontSize',FoSi,'Position',tmp,'Color',0.7*[1 1 1],...
'Children',objarray);
legend('show','location','southwest');
set(findobj('Tag','legend'),'FontSize',FoSi,'Color','none');
%% Sub-plot 4 for the Hodogram
ha.ax(4) = subplot(6,4,[7,8,11,12]); %axis('Position',[0.35 0.7 0.2 0.2]);
ha.hodog = Wind_hodograph(data(i(1+span)).SKNT,...
data(i(1+span)).DRCT,...
data(i(1+span)).HGHT,...
'heights', 0, 'axes', ha.ax(4));
%% Sub-plot 2 is for the 2D time series o RS profiles, default TEMP
ha.ax(2) = subplot(6,4,[13:20]); %4:5]);
if Nobs==1,
disp('With only one profile no time-series needed');
ha.p2d = pcolor([]);
else
ha.p2d = pcolor(repmat([1:Nobs]',1,size(PROFILER,2)),1e-3*PROFILER(:,:,2),PROFILER(:,:,3)); %TimePROF
%HH = 1e-3*PROFILER(:,:,2);
%CC = PROFILER(:,:,3);
%ha.p2d = scatter(TimePROF(:),HH(:),95,CC(:),'s','filled');
end
%axis xy;
shading flat;
axis tight;
tmp = get(ha.ax(2), 'Position').*[1 0.9 1 1.04];
ha.cob = colorbar;
set(ha.ax(2), 'Position', tmp, 'XLim', [1 Nobs]);
set(ha.cob, 'Position', [tmp(1)+tmp(3)+0.005 tmp(2) 0.025 tmp(4)],...
'FontSize', FoSi);
caxis([-30 25]);
ylabel('Height a.g.l. [km]','FontSize',FoSi);
%% Sub-plot 3 is for time series of Radiosonde Indices, default CAPE
ha.ax(3) = subplot(6,4,[21:24]);%,6);
hold on;
ha.htl = plot(Tnumobs(isonde)*[1 1], [min(yvar) max(yvar)],...
'--k', 'LineWidth', 2);
ha.hts = plot(Tnumobs, yvar, '-', 'LineWidth', 1.5,...
'Tag', metadata.RSINDICES{tsvar,1});
tmp = get(ha.ax(3), 'Position').*[1 1 1 1.1];
set(ha.ax(3), 'Box', 'on', 'YGrid', 'on', 'FontSize', FoSi, 'XLim', Tnumobs([1 end]),...
'Position', tmp, 'XTick',Tnumobs([1:fix(Nobs/10):end]), ...
'XTickLabel', datestr(Tnumobs([1:fix(Nobs/10):end]), 'mm/dd'));
ha.tsl = legend(ha.hts, metadata.RSINDICES{tsvar,2});
set(ha.tsl, 'FontSize', FoSi, 'Color', 'none');
ylabel(sprintf('%s [%s]', metadata.RSINDICES{tsvar,[1,3]}),...
'FontSize', FoSi);
xlabel('Observation date Month/Day', 'FontSize', FoSi);
tmp = get(ha.ax(3), 'XTick');
%set(ha.ax(2),'XTick',tmp,'XLim',Tnumobs([1 end]));
set(ha.ax, 'TickDir', 'out', 'Box', 'on', 'FontSize', FoSi, ...
'LineWidth', 2);
clear tmp;
%xlabel('Observation date Month/Day','FontSize',15);
% ------------------------------------------------------
% creating the basic GUI
% ------------------------------------------------------
% text with the number of profiles:
uicontrol('Style','text','Units','normalized',...
'Position',[0.1 0.95 0.2 0.0234],...
'String',sprintf('N = %d',nsonde),'FontSize',FoSi);
% Text indicating the actual showing time:
ha.tdate = uicontrol('style','text','Units','normalized',...
'Position',[0.3 0.95 0.37 0.0234],...
'String',['Date T0: ' datestr(Tnumobs(isonde),...
'dd.mm.yyyy @ HHZ')],...
'FontSize',FoSi);
% Slider for changing the showing time:
ha.SliderH = uicontrol('style','slider','Units','normalized',...
'Position',[0.68 0.95 0.3 0.0234],...
'min',1, 'max', length(xvar),'Value',isonde,...
'SliderStep',[0.05 0.05],...
'Callback',{@update_time0,ha,Tnumobs,data});
% ------ BUTTONS ------------------------------
% Button to select time point from time-series:
ha.SpotH = uicontrol('style','pushbutton','Units','normalized',...
'Position',[0.55 0.83 0.11 0.0234],...
'String','pick-up T0','Tag','pushme',...
'Callback',{@pick_time0,ha,Tnumobs,data});
% Button to open a new file:
ha.OpenfH = uicontrol('style','pushbutton','Units','normalized',...
'Position',[0.67 0.83 0.11 0.0234],...
'String','Open MAT',...
'Callback',{@update_matfile,ha});
% Button to close the GUI:
uicontrol('style','pushbutton','Units','normalized',...
'Position',[0.81 0.83 0.1 0.0234],...
'String','Close','Callback','close(gcf)');
% addlistener(SliderH, 'Value', 'PostSet', @callbackfn);
% ------------- DROP MENUS -------------------
% Menu with the Profile variables
uicontrol('style','text','String','Profile Variable:','FontSize',FoSi,...
'Units','normalized','Position',[0.55 0.9 0.15 0.0234]);
ha.ScrollH = uicontrol('style','popupmenu','String',names,...
'Units','normalized','Value',3,'Tag','ScrollH',...
'Position',[0.75 0.9 0.11 0.0234],...
'Callback',{@update_profile,ha,data,PROFILER,metadata.PROFILE});
% Menu with the Radiosonde Indices variables
uicontrol('style','text','String','Radiosonde Indices:','FontSize',FoSi,...
'Units','normalized','Position',[0.55 0.87 0.15 0.0234]);
ha.SIndexH = uicontrol('Style','popupmenu',...
'String',fieldnames(metvar),...
'Units','normalized','Value',13,...
'Position',[0.75 0.87 0.11 0.0234],...
'Callback',{@update_rsindices,ha,metvar,metadata.RSINDICES}); ...
if nargout==1,
% Optional output variable: the structure with handlers:
varargout{1}=ha;
end
return;
end % end of main function
%% Here come the callback sub-functions for the GUIs:
% --------------------------------------------------------------
% Sub-function to change the time for the displayed Profile
function update_time0(ho,eventdata,ha,xvar,data)
if ~ishandle(ho),
[ho,fo] = gcbo;
if isnumeric(fo), tt=fo; else tt=fo.Number; end;
end
k = round(get(ho,'Value'));
% changing the title:
set(ha.tdate,'String',['Date T0: ' datestr(xvar(k),'dd.mm.yyyy @ HHZ')]);
% changing the profile data
j = unique(min(max([k-2:k+2],1),length(data)));
ispan = [1:length(j)];
fieldvar = get(ha.hh{1},'Tag');
arrayfun(@(i) {set(ha.hh{i},...
'XData',getfield(data(j(i)),fieldvar),...
'YData',1e-3*data(j(i)).HGHT);},...
ispan,'UniformOutput',false);
% changing vertical line indicating time
set(ha.htl,'XData',[1 1]*xvar(k));
% updating Hodograph:
Wind_hodograph(data(k).SKNT, data(k).DRCT,...
data(k).HGHT,'update',ha.hodog);
return;
end
% -------------------------------------------------------------
% Sub-function to change the variable for the displayed Profile
function update_profile(h,eventdata,ha,data,PROFILER,meta)
[ho,fo] = gcbo;
k=get(ho,'Value');
if isnumeric(fo), tt=fo; else tt=fo.Number; end;
fnames = get(ho,'String');
Nobs = length(data);
nspan = fix(length(ha.hh)/2);
j=min(Nobs,max(1,[-nspan:nspan]+round(get(ha.SliderH,'Value'))));
% changing profile data:
arrayfun(@(i) {set(ha.hh{i},'XData',...
getfield(data(j(i)),fnames{k}),...
'Tag',fnames{k});},...
[1:length(j)],'UniformOutput',false);
% updating the x-axis legend:
%idx = arrayfun(@(i) strcmp(meta{i,1},fnames{k}),...
% [1:length(meta)],'UniformOutput',true);
idx = strcmp(fnames{k},meta);
set(get(ha.ax(1),'xlabel'),...
'String',sprintf('%s [%s]',meta{idx,2:3}));
axis tight;
% updating the 2D profiles:
tmp = PROFILER(:,:,k);
set(ha.p2d,'cdata',tmp);
tmp = quantile(tmp(:),[0.05 0.93]);
set(ha.ax(2),'CLim',tmp);
return;
end
% ----------------------------------------------------------------
% Sub-function to change the variable for the displayed RS indices
function update_rsindices(h,eventdata,ha,metvar,indimeta)
[ho,fo] = gcbo;
k = get(ho,'Value');
fname = get(ho,'String');
if strcmp(fname{k},'PROFILE_META'),
return;
end
yvar = getfield(metvar,fname{k});
if all(isnan(yvar)), yvar = []; end
set(ha.hts,'YData',yvar);
idx = strcmp(fname{k},indimeta);
set(get(ha.ax(3),'ylabel'),'String',...
sprintf('%s [%s]',indimeta{idx,[1 3]}));
set(ha.tsl,'String',indimeta{idx,2});
if isempty(yvar),
[vmin,vmax] = deal(-1,1);
else
[vmin,vmax] = deal(0.98*min(yvar),1.02*max(yvar));
end
set(ha.ax(3),'YLim',[vmin vmax]);
return;
end
% ---------------------------------------------------------
% Sub-function to load MAT file with structure variables
function [data, metvar, metadata] = update_matfile(varargin);
if nargin==0,
[matfile,matpath] = uigetfile({'*.mat','*.MAT'},...
'Select MAT file to open',...
'MultiSelect','off');
fname = fullfile(matpath,matfile);
else
fname = varargin{1};
end
if exist(fname, 'file'),
load(fname, 'data', 'metvar', 'metadata');
else
error([fname ' can not be load!']);
end
if ~exist('data', 'var') | ~exist('metvar', 'var'),
error('Structures "data" and/or "metvar" not found in MAT file');
elseif ~exist('metadata', 'var'),
% Checking whether MEATDATA has been assigned,
% otherwise read from function
warning('METADATA isn''t assigned, default metadata loaded.');
metadata = WyoRS_metadata();
%[ProfileMeta,NameIndices,DescriptionIndices,UnitsIndices] =
else
disp([fname ' loaded ;D']);
end
%if nargin>0,
% RASOBS_GRAPH_DATA_RAW(data,metvar,metadata);
%end
return;
end
% ----------------------------------------------------------
% Sub-function to pick-up a Time0 directly from axes:
function []=pick_time0(h,eventdata,ha,Tnum,data)
[x,y] = ginput(1);
if x<min(Tnum) | x>max(Tnum),
disp('Selection out of scope!');
return;
end
[tmp,idx] = min(abs(x-Tnum));
disp([datestr(Tnum(idx),'dd.mm.yyyy HH Z') '..selected!']);
set(ha.SliderH,'Value',idx);
update_time0(ha.SliderH,eventdata,ha,Tnum,data);
return;
end
%% HERE STARTS AUXILIARY FUNCTIONS
% ---------------------------------------------------------------
% Function to INITIALIZE the time-series Profiler:
function [PROFILER, TimePROF, Tnumobs] = InitializeProfiler(data,OBST,H_top);
names = fieldnames(data);
nvar = length(names);
Nobs = length(OBST);
% Converting the OBST variable to Matlab datenum format:
yy = round(OBST/1e4); % years-2000
mm = round((OBST-yy*1e4)/1e2); % months
dd = (OBST-yy*1e4-mm*1e2); % days+hour/24
Tnumobs = datenum(2000+yy, mm, dd);
%tmp = cell2mat(textscan(sprintf('20%8.2f',OBST),...
% '%4f%2f%5f',Nobs,'CollectOutput',1));
Tnumpro = [Tnumobs(1):median(diff(Tnumobs)):Tnumobs(end)]';
Npro = length(Tnumpro);
% index of the highest layer below 15km:
%hmax = arrayfun(@(i) max(find(data(i).HGHT<H_top)),[1:Nobs]);
hmax = 0;
PROFILER = NaN(Nobs, 100, nvar); %zeros(Npro, 100, nvar)*NaN;
for i=1:Nobs,
tmp = max(find(data(i).HGHT<H_top));
if ~isempty(tmp), hmax(i) = tmp; end
[tmp, idx] = min(abs(Tnumobs(i)-Tnumpro));
for j=1:nvar,
eval(['PROFILER(i, 1:hmax(i), j) = data(i).'...
names{j} '(1:hmax(i));']);
end
end
if max(hmax)<100, PROFILER(:,max(hmax)+1:end,:) = []; end
TimePROF = repmat(Tnumpro,1,max(hmax));
return;
end
% --------------------------------------------------------------
% Function to make the profiles derivatives respecto to Z
function data = Calculate_Derivatives(data0)
% new fields to include:
in_names = {'MIXR','THTA','THTV'}; % parameters to derive
%d1dz_names = {'D1QV','D1TH','D1TV'};
d2dz_names = {'D2QV','D2TH','D2TV'}; % 2nd derivatives
Nobs = length(data0);
%tmp1 = arrayfun(@(i) cellfun(@(x) diff(getfield(data0(i),x))./diff(data0(i).HGHT),...
% in_names,'UniformOutput',false),...
% [1:Nobs],'UniformOutput',false);
tmp2 = arrayfun(@(i) cellfun(@(x) diff(getfield(data0(i),x),2)./(diff(data0(i).HGHT(1:end-1))).^2,...
in_names,'UniformOutput',false),...
[1:Nobs],'UniformOutput',false);
%%qq=cell2struct(tmp1{1},d1dz_names,2);
for i=1:Nobs,
for j=1:length(d2dz_names),
%data0(i).(d1dz_names{j}) = [tmp1{i}{j}; NaN];
data0(i).(d2dz_names{j}) = [NaN; tmp2{i}{j}; NaN];
end
end
data = data0;
return;
end