-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobsplot.m
More file actions
executable file
·1520 lines (1222 loc) · 47.6 KB
/
Copy pathobsplot.m
File metadata and controls
executable file
·1520 lines (1222 loc) · 47.6 KB
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
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
function obsplot(arg,varargin)
% OBSPLOT Plot observation attributes.
%
% OBSPLOT(ODS) produces a plot summarizing the data in the
% ods structure ODS, and provides various methods for
% subsetting and replotting the data.
% 25Oct2001 Dick Dee (dee@gmao.gsfc.nasa.gov)
% 23Apr2004 Dick Dee - ECMWF version
% 18Nov2004 Dick Dee - GSI version
% 15Apr2025 Wesley Davis (wjdavis5@ndc.nasa.gov) matlab2024a update
if ischar(arg), % must be a callback
feval(arg,varargin{:}) % simply pass to the callback routine..
return % .. and get out.
else % otherwise this will set up a new plot
ods = arg; % first arg is always the ods structure with the data
if nargin>1,
interactive = false;
caller = varargin{1};
else
interactive = true;
end
end
if interactive,
hGui = findobj('Tag','ObsviewGui'); % get handle to obsview gui, if it exists
else
hGui = [];
end
% possibly remove data that failed QC
if ~isempty(hGui)&&strcmp(get(findobj(hGui,'Tag','qcxclear'),'Checked'),'on'),
ods = odssubset(ods,ods.qcx==0);
ods.ssqcx = 0;
end
nall = length(ods.kt)
if nall==0, return, end % must have data to plot.
% decide whether to create a new figure window or plot in an existing window
if ~isempty(hGui), newfig = strcmp(get(findobj(hGui,'Tag','newfig'),'Checked'),'on');
else, newfig = 0; end
if ~newfig, % see if we can find a previous obsplot figure window
hFig = gcbf;
if ~strcmp(get(hFig,'Tag'),'obsplot'),
h = findobj('Type','figure','Tag','obsplot');
if ~isempty(h), hFig = h(end); else, newfig = 1; end
end
end
if newfig,
hFig = figure; % create a new figure window ...
set(hFig,'Tag','obsplot','Color','w',...
'DefaultTextFontUnits','normalized','DefaultTextFontSize',0.08)
if interactive,
scr = get(0,'Screensize'); psize = min(0.9*scr(3:4));
set(hFig,'Units','pixels','Position',psize*[0.1 0.1 1 8.5/11],...
'MenuBar','none','DockControls','off')
watchon; % this might take a while
end
else
figure(hFig) % ... or use an existing figure
clf
end
% set coloring indices
if ~isempty(hGui),
coloring = getappdata(hGui,'Coloring');
preserve = strcmp(get(findobj(hGui,'Tag','keepcolors'),'Checked'),'on');
else % defaults:
if length(unique(ods.kx))==1
coloring.attr = 'qcx';
else
coloring.attr = 'kx';
end
coloring.cmap = 'jet';
preserve = false;
end
if ~(isfield(ods,'cidx') & preserve),
ods = setcidx(ods,coloring);
end
[KTPRS,KTSFC,KTRAD,SENSORS] = dconfig('KTPRS','KTSFC','KTRAD','SENSORS');
% count pressure-level/surface/radiance data
nprs = sum(ismember(ods.kt,KTPRS));
nsfc = sum(ismember(ods.kt,KTSFC));
nrad = sum(ismember(ods.kt,KTRAD));
% see which sensors are present in the data
sns = [];
for i = 1:length(SENSORS),
if any(ismember(SENSORS(i).kxs,ods.kx)), sns = [sns i]; end
end
% create the different components of the figure
TtlPosition = [0.05 0.92 0.90 0.05]; % titles
MapPosition = [0.05 0.45 0.65 0.40]; % map with obs locations
LevPosition = [0.73 0.45 0.16 0.40]; % pressure distribution
ChnPosition = [0.73 0.45 0.16 0.40]; % channel distribution
KtsPosition = [0.05 0.25 0.40 0.12]; % data type distribution
KxsPosition = [0.05 0.05 0.40 0.12]; % data source distribution
QcxPosition = [0.50 0.25 0.20 0.12]; % QC exclusion flag distribution
QchPosition = [0.73 0.25 0.20 0.12]; % QC history flag distribution
SnsPosition = [0.50 0.05 0.40 0.12]; % radiance data
hMapAxes = axes('Parent',hFig,'Tag','map','Position',MapPosition,'NextPlot','add',...
'FontUnits','normalized','FontSize',0.04);
figure(hFig), title('Observation Locations','Color','b','FontSize',0.06);
pmap('create',hMapAxes,ods)
if nprs>0, % ods contains pressure-level data
hLevAxes = axes('Parent',hFig,'Tag','lev','Position',LevPosition,'NextPlot','add',...
'FontUnits','normalized','FontSize',0.04);
figure(hFig)
title({'Vertical Distribution','of Pressure-Level Data'},...
'Color','b','FontSize',0.06);
plev('create',hLevAxes,ods)
elseif nrad>0 & length(sns)==1, % radiance data from a single sensor
hChnAxes = axes('Parent',hFig,'Tag','chn','Position',ChnPosition,'NextPlot','add',...
'FontUnits','normalized','FontSize',0.04);
figure(hFig)
title({'Channel Distribution',['for ' SENSORS(sns).id ' Data']},...
'Color','b','FontSize',0.06);
pchn('create',hChnAxes,ods)
end
hKtsAxes = axes('Parent',hFig,'Tag','kt','Position',KtsPosition,'NextPlot','add',...
'FontUnits','normalized','FontSize',0.12);
figure(hFig), title('Data Types','Color','b','FontSize',0.18)
pkts('create',hKtsAxes,ods)
hKxsAxes = axes('Parent',hFig,'Tag','kx','Position',KxsPosition,'NextPlot','add',...
'FontUnits','normalized','FontSize',0.12);
figure(hFig), title('Data Sources','Color','b','FontSize',0.18)
pkxs('create',hKxsAxes,ods)
if nrad>0, % ods contains radiance data
hSnsAxes = axes('Parent',hFig,'Tag','sn','Position',SnsPosition,'NextPlot','add',...
'FontUnits','normalized','FontSize',0.12);
figure(hFig), title('Sensor Distribution for Radiance Data',...
'Color','b','FontSize',0.18)
psns('create',hSnsAxes,ods)
end
hQcxAxes = axes('Parent',hFig,'Tag','qcx','Position',QcxPosition,'NextPlot','add',...
'FontUnits','normalized','FontSize',0.12);
figure(hFig), title('QC Exclusion','Color','b','FontSize',0.18)
pqcx('create',hQcxAxes,ods)
if ~ishandle(hQcxAxes), QchPosition = [0.50 0.25 0.40 0.12]; end
hQchAxes = axes('Parent',hFig,'Tag','qch','Position',QchPosition,'NextPlot','add',...
'FontUnits','normalized','FontSize',0.12);
figure(hFig), title('QC History','Color','b','FontSize',0.18)
pqch('create',hQchAxes,ods)
hTtlAxes = axes('Parent',hFig,'Tag','title','Position',TtlPosition,'NextPlot','add',...
'Visible','off',...
'DefaultTextFontUnits','normalized','DefaultTextFontSize',0.4);
ptitle(hTtlAxes,ods,nall,nprs,nsfc,nrad)
if interactive
% define some mouse actions
set(hFig,'WindowButtonMotionFcn','obsplot pmap pointer')
set([hMapAxes; allchild(hMapAxes)],'ButtonDownFcn','obsmap pobslist')
% store the data with the plot
set(hFig,'Userdata',ods)
% create toolbar and menubar
mktoolbar(hFig)
mkmenubar(hFig)
% create color legend
plegend('create',hMapAxes,ods.cinfo,'NorthEast')
watchoff; % done
end
%-------------------------------------------------------------------------
function panel(action,varargin)
switch action
case 'newfig'
tag = varargin{1};
hFig = gcbf;
hAxes = findobj(hFig,'Type','axes','Tag',tag);
hf = figure('Units','normalized','MenuBar','none',...
'DockControls','off',...
'Position',[0.1 0.2 0.8 0.8],'Visible','off');
mktoolbar(hf)
mkmenubar(hf)
delete(findobj(hf,'Type','uimenu','Tag','Copy'))
delete(findobj(hf,'Type','uimenu','Tag','Delete'))
ha = copyobj(hAxes,hf);
set(ha,'Units','normalized','Position',[0.1 0.15 0.8 0.7])
ht = findobj(ha,'Type','text'); nt = numel(ht); % text objects
fs = max(8,14-round(nt/10)); % adjust for crowded plots
set(ht,'FontUnits','points','FontSize',fs);
set(ha,'FontUnits','points','FontSize',fs); % tick labels
set(findall(ha,'Type','text','HandleVisibility','off'),...
'FontUnits','points','FontSize',20) % title
set(hf,'Userdata',get(hFig,'Userdata'))
if strcmp(tag,'map'), % extra work for map panel
hMenu = findobj(hFig,'Type','uimenu','Tag','showlegend');
hNewMenu = findobj(hf,'Type','uimenu','Tag','showlegend');
set(hNewMenu,'Checked',get(hMenu,'Checked'));
ods = get(hf,'Userdata');
plegend('create',ha,ods.cinfo,'NorthEastOutside')
xlim = get(ha,'XLim'); ylim = get(ha,'YLim');
asr = max(7/10,min(10/7,diff(xlim)*cos(mean(ylim)*pi/180)/diff(ylim)));
w = 0.8; h = 0.8;
if asr>1, h = h/asr; else, w = w*asr; end
set(hf,'Position',[0.1 0.2 w h],...
'WindowButtonMotionFcn','obsplot pmap pointer')
set(hf,'Units','pixels')
end
set(hf,'Visible','on')
case 'delete'
tag = varargin{1};
hFig = gcbf;
delete(findobj(hFig,'Type','axes','Tag',tag));
set(findobj(hFig,'Type','uimenu','Tag',tag),'enable','off')
end
%-------------------------------------------------------------------------
function pmap(action,varargin)
switch action
case 'create'
hAxes = varargin{1};
ods = varargin{2};
hFig = get(hAxes,'Parent');
figure(hFig)
if isfield(ods,'sslon')&&any(ods.sslon), xlim = ods.sslon; else, xlim = [-180 180]; end
if isfield(ods,'sslat')&&any(ods.sslat), ylim = ods.sslat; else, ylim = [ -90 90]; end
% determine longitude limits xlim such that:
% -360<xlim(1)<xlim(2)<360 and xlim(2)-xlim(1)<=360
xlim = -180 + mod(xlim + 180,360); % xlim in [-180,180)
if xlim(1)==xlim(2), % this means all longitudes: global map
clon = 0; % by default, center global map at lon=0
hGui = findobj('Tag','ObsviewGui')
%any(hGui)
%exist(hGui)
%isempty(hGui)
if ~isempty(hGui), % possible override by obsview gui option
if strcmp(get(findobj(hGui,'Tag','dateline'),'Checked'),'on'), clon = 180; end
end
xlim = clon + [-180 180];
elseif 0<=xlim(2)&&xlim(2)<xlim(1),
xlim(1) = xlim(1) - 360;
elseif xlim(2)<0 &&xlim(2)<xlim(1),
xlim(2) = xlim(2) + 360;
end
set(hAxes,'XLim',xlim,'YLim',ylim,...
'Box','on','XGrid','on','YGrid','on',...
'Color',[0.8 0.9 1.0]);
if diff(xlim)==360, set(hAxes,'XTick',linspace(xlim(1),xlim(2),7)); end
if diff(ylim)==180, set(hAxes,'YTick',-60:30:60); end
pcoast(hAxes)
lon = ods.lon;
if xlim(1)<-180, i = (lon>xlim(1)+360); lon(i) = lon(i) - 360; end
if xlim(2)> 180, i = (lon<xlim(2)-360); lon(i) = lon(i) + 360; end
iz = 0;
for ix = 1:length(ods.cinfo),
ic = ods.cidx==ix;
if any(ic),
iz = iz + 1;
hLine = plot(lon(ic), ods.lat(ic), ...
'.','Markersize',12,'Color',ods.cinfo(ix).rgb,'Tag','obsloc');
set(hLine,'UserData',ix,'ZData',iz*ones(1,sum(ic)))
% disp([int2str(iz) ': ' ods.cinfo(ix).txt])
end
end
case 'domain'
[h,hFig] = gcbo; % handles to cbo (h) and figure (hFig)
hAxes = findobj(hFig,'Type','axes','Tag','map'); % handle to map axes
region = lower(varargin{1});
switch region
case {'zoom'},
xlim = get(hAxes,'XLim'); ylim = get(hAxes,'YLim');
if isequal(xlim,[-180 180])&&isequal(ylim,[-90 90]),
warndlg({'You must first zoom in on the region you want:' ...
' ' ...
'Press the zoom button on the figure window toolbar.' ...
'Then click, or click and drag, on the map to zoom.' ...
'Press the button again to get out of zoom mode.' ...
' ' ...
'Then select this option again.'}, ...
'How to select data by zoom')
return
end
xlim = -180 + mod(xlim + 180,360); % xlim in [-180,180)
if xlim(1)==xlim(2), xlim = [-180 180]; end
case {'northernhemisphere(>20n)'}, xlim = [-180 180]; ylim = [ 20 90];
case {'southernhemisphere(>20s)'}, xlim = [-180 180]; ylim = [ -90 -20];
case {'tropics(20s-20n)'}, xlim = [-180 180]; ylim = [ -20 20];
case {'northamerica'}, xlim = [-172 -52]; ylim = [ 16 72];
case {'unitedstates'}, xlim = [-124 -72]; ylim = [ 25 50];
case {'northatlantic'}, xlim = [ -70 0]; ylim = [ 10 70];
case {'europe'}, xlim = [ -13 25]; ylim = [ 35 72];
case {'asia'}, xlim = [ 25 170]; ylim = [ 5 80];
case {'arctica'}, xlim = [-180 180]; ylim = [ 60 90];
case {'pacific'}, xlim = [ 130 -120]; ylim = [ -60 40];
case {'easternpacific'}, xlim = [ 130 180]; ylim = [ 0 40];
case {'westernpacific'}, xlim = [-180 -120]; ylim = [ -60 40];
case {'southamerica'}, xlim = [ -85 -30]; ylim = [ -60 15];
case {'southatlantic'}, xlim = [ -50 10]; ylim = [ -70 0];
case {'africa'}, xlim = [ -20 52]; ylim = [ -40 38];
case {'indianocean'}, xlim = [ 40 100]; ylim = [ -40 10];
case {'australia'}, xlim = [ 110 160]; ylim = [ -45 -10];
case {'indonesia'}, xlim = [ 90 130]; ylim = [ -10 10];
case {'antarctica'}, xlim = [-180 180]; ylim = [ -90 -60];
case {'amazon'}, xlim = [ -75 -45]; ylim = [ -12 6];
case {'loweramazonbasin'}, xlim = [ -68 -57]; ylim = [ -22 -5];
otherwise, xlim = [-180 180]; ylim = [ -90 90];
end
ods = get(hFig,'Userdata'); % get ods stored with the map
ods.sslon = xlim;
ods.sslat = ylim;
if xlim(1)<xlim(2),
odss = odssubset(ods, xlim(1)<=ods.lon&ods.lon<=xlim(2) &ylim(1)<=ods.lat&ods.lat<=ylim(2));
else
odss = odssubset(ods,(xlim(1)<=ods.lon|ods.lon<=xlim(2))&ylim(1)<=ods.lat&ods.lat<=ylim(2));
end
obsplot(odss)
case 'pointer'
[h,hFig] = gcbo; % handles to cbo (h) and figure (hFig)
% get current pointer position in normalized units:
xy = get(hFig,'CurrentPoint');
p = get(hFig,'Position');
x = xy(1)/p(3);
y = xy(2)/p(4);
% see if the pointer is over the legend, if one is visible:
hLeg = findobj(hFig,'Type','axes','Tag','legend');
if ishandle(hLeg) & strcmp(get(hLeg,'Visible'),'on')
p = get(hLeg,'Position');
xl = (x-p(1))/p(3);
yl = (y-p(2))/p(4);
if (0<xl && xl<1 && 0<yl && yl<1),
hLegTxt = findobj(hLeg,'Type','text');
np = length(hLegTxt);
ip = min(np,max(1,round(np*yl)));
set(hLegTxt,'color','k')
set(hLegTxt(ip),'color','r')
end
end
% see if the pointer is over the map:
hAxes = findobj(hFig,'Type','axes','Tag','map'); % handle to map axes
hPloc = findobj(hAxes,'Type','text','Tag','pcoord'); % text object showing pointer position
p = get(hAxes,'Position');
xm = (x-p(1))/p(3);
ym = (y-p(2))/p(4);
if (0<xm && xm<1 && 0<ym && ym<1),
% get lat-lon coordinates at pointer location
xlim = get(hAxes,'XLim'); lon = xlim(1) + xm*(xlim(2)-xlim(1));
ylim = get(hAxes,'YLim'); lat = ylim(1) + ym*(ylim(2)-ylim(1));
str = [lonstr(lon) ', ' latstr(lat)];
% modify or create text object showing pointer position
if ishandle(hPloc),
set(hPloc,'string',str)
else
text(xlim(1),ylim(2),str,'Parent',hAxes,'Tag','pcoord',...
'HorizontalAlignment','left','VerticalAlignment','bottom',...
'Color','r','Fontsize',0.04);
end
set(hFig,'Pointer','crosshair')
else
delete(hPloc)
set(hFig,'Pointer','arrow')
end
end
%-------------------------------------------------------------------------
function plegend(action,varargin)
switch action
case 'create'
hAxes = varargin{1};
cinfo = varargin{2};
loc = varargin{3};
hLine = findobj(hAxes,'Type','line','Tag','obsloc'); % want legends for these objects
nl = length(hLine);
for il = 1:nl
ix = get(hLine(il),'UserData'); % color index
legtxt{il} = cinfo(ix).txt; % legend for this color
end
hLeg = legend(hAxes,hLine,legtxt,'Location',loc); % create the legend axes
set(hLeg,'Color','w','UiContextMenu',[])
hLegTxt = findobj(hLeg,'Type','text'); % context menu for each legend
np = length(hLegTxt);
for ip = 1:np
ipstr = int2str(np-ip+1);
visible = strcmp(get(hLine(np-ip+1),'Visible'),'on');
hmenu = uicontextmenu;
uimenu(hmenu,'Label','Show only','Tag','showonly',...
'Callback',['obsplot plegend showonly ' ipstr])
if visible, label = 'Hide'; else, label = 'Show'; end
uimenu(hmenu,'Label',label,'Tag','showorhide',...
'Callback',['obsplot plegend showorhide ' ipstr])
uimenu(hmenu,'Separator','on','Label','Move to top',...
'Callback',['obsplot plegend top ' ipstr])
uimenu(hmenu,'Label','Move to bottom',...
'Callback',['obsplot plegend bottom ' ipstr])
uimenu(hmenu,'Separator','on','Label','Show all',...
'Callback','obsplot plegend showorhide all')
uimenu(hmenu,'Label','Hide all',...
'Callback','obsplot plegend showorhide all')
set(hLegTxt(ip),'UiContextMenu',hmenu,'UserData',hLine(ip))
end
hMenu = findobj(get(hLeg,'Parent'),'Type','uimenu','Tag','showlegend'); % handle to menu item
on = strcmp(get(hMenu,'Checked'),'on');
if ~on, legend(hAxes,'hide'); end
case 'showonly'
ip = eval(varargin{1});
[h,hFig] = gcbo;
hLeg = findobj(hFig,'Type','axes','Tag','legend'); % handle to legend axes
hLegTxt = findobj(hLeg,'Type','text'); % legend text handles
np = length(hLegTxt);
for i = 1:np
hp = get(hLegTxt(i),'UserData'); % line to be shown or hidden
hm = findobj(get(hLegTxt(np-i+1),'UiContextMenu'),'Tag','showorhide');
if i==ip,
set(hp,'Visible','on')
set(hm,'Label','Hide')
else
set(hp,'Visible','off')
set(hm,'Label','Show')
end
end
case 'showorhide'
[h,hFig] = gcbo;
hLeg = findobj(hFig,'Type','axes','Tag','legend'); % handle to legend axes
hLegTxt = findobj(hLeg,'Type','text'); % legend text handles
np = length(hLegTxt);
if strcmp(varargin{1},'all')
ip = 1:np; % all items
else
ip = eval(varargin{1}); % single item
end
show = strncmp(get(h,'Label'),'Show',4);
for i = ip
hp = get(hLegTxt(i),'UserData'); % line to be shown or hidden
hm = findobj(get(hLegTxt(np-i+1),'UiContextMenu'),'Tag','showorhide');
if show,
set(hp,'Visible','on')
set(hm,'Label','Hide')
else
set(hp,'Visible','off')
set(hm,'Label','Show')
end
end
case 'showlegend'
[h,hFig] = gcbo;
hAxes = findobj(hFig,'Type','axes','Tag','map'); % handle to map axes
hMenu = findobj(hFig,'Type','uimenu','Tag','showlegend'); % handle to menu item
show = ~strcmp(get(hMenu,'Checked'),'on');
if show
legend(hAxes,'show')
set(hMenu,'Checked','on')
else
legend(hAxes,'hide')
set(hMenu,'Checked','off')
end
case {'top','bottom'}
ip = eval(varargin{1}); % sequence number of item to be moved
[h,hFig] = gcbo;
hAxes = findobj(hFig,'Type','axes','Tag','map'); % handle to map axes
hLeg = findobj(hFig,'Type','axes','Tag','legend'); % handle to legend axes
hLegTxt = findobj(hLeg,'Type','text'); % legend text handles
hp = get(hLegTxt(ip),'UserData'); % line to be moved
zp = get(hp,'ZData'); zp = zp(1);
np = length(hLegTxt);
if strcmp(action,'top'),
for i = 1:np
h = get(hLegTxt(i),'UserData');
z = get(h,'ZData');
if z(1)>zp, set(h,'ZData',z-1); end
end
set(hp,'ZData',np*ones(size(get(hp,'ZData'))))
else
for i = 1:np
h = get(hLegTxt(i),'UserData');
z = get(h,'ZData');
if z(1)<zp, set(h,'ZData',z+1); end
end
set(hp,'ZData',ones(size(get(hp,'ZData'))))
end
% ods = get(hFig,'UserData');
% for i = 1:np
% h = get(hLegTxt(i),'UserData');
% z = get(h,'ZData');
% ix = get(h,'UserData');
% disp([int2str(z(1)) ': ' ods.cinfo(ix).txt])
% end
end
%-------------------------------------------------------------------------
function pcoast(hAxes)
xlim = get(hAxes,'XLim');
load coastlines
i = [0; find(isnan(coastlon)); length(coastlon)];
for j = 2:length(i)-1,
is = i(j)+1:i(j+1)-1;
patch(coastlon(is),coastlat(is),[0.6 0.7 0.5])
end
for j = 1, % this is a hack to fix Antartica
is = i(j)+1:i(j+1)-1;
patch([-180; coastlon(is); 180],[-90; coastlat(is); -90],[0.6 0.7 0.5])
end
if xlim(1)<-180, % this is a crude way to handle dateline crossing
coastlon = coastlon - 360;
for j = 2:length(i)-1,
is = i(j)+1:i(j+1)-1;
patch(coastlon(is),coastlat(is),[0.6 0.7 0.5])
end
for j = 1,
is = i(j)+1:i(j+1)-1;
patch([xlim(1); coastlon(is); -180],[-90; coastlat(is); -90],[0.6 0.7 0.5])
end
end
if xlim(2)>180, % this is a crude way to handle dateline crossing
coastlon = coastlon + 360;
for j = 2:length(i)-1,
is = i(j)+1:i(j+1)-1;
patch(coastlon(is),coastlat(is),[0.6 0.7 0.5])
end
for j = 1,
is = i(j)+1:i(j+1)-1;
patch([180; coastlon(is); xlim(2)],[-90; coastlat(is); -90],[0.6 0.7 0.5])
end
end
%-------------------------------------------------------------------------
function plev(action,varargin)
switch action
case 'create'
hAxes = varargin{1};
ods = varargin{2};
hFig = get(hAxes,'Parent');
figure(hFig)
KTPRS = dconfig('KTPRS');
ipr = ismember(ods.kt,KTPRS);
npmax = 35;
p = sort(unique(ods.lev(ipr)));
np = length(p);
if np<=1, delete(hAxes); return; end % single level; forget it.
logp = log(ods.lev(ipr));
cidx = ods.cidx(ipr);
% define bin centers z
if np<npmax, % discrete, irregularly spaced bins (in log(p))
z = log(p); % bin centers
pbins = [p' Inf]; % bin edges [ )
else, % continuous, uniformly spaced bins (in log(p))
[n,z] = hist(logp,npmax); % bin centers
maxlogp = max(logp); minlogp = min(logp);
dz = (maxlogp-minlogp)/npmax;
zz = minlogp + dz*(0:npmax);
zz(end) = maxlogp;
zbins = zz + max(eps,eps*abs(zz));
pbins = exp(zbins);
pbins(1) = 0; pbins(end) = Inf; % bin edges [ )
end
nz = length(z);
% count, by color
cinfo = ods.cinfo;
nc = length(cinfo);
ncidx = zeros(nc,nz);
for ix = 1:nc,
ncidx(ix,:) = hist(logp(cidx==ix),z);
crgb{ix} = cinfo(ix).rgb;
end
% plot
hp = barh(ncidx','stack');
set(hp,{'FaceColor'},crgb')
set(hAxes,'Box','on','YDir','reverse','YLim',[0 nz+1])
% ticks
ytick = 1:nz;
if nz>20, ytick = 1:2:nz; end
yticklabel = [];
if np<npmax,
for i = 1:length(ytick),
yticklabel = strvcat(yticklabel,[num2str(exp(z(ytick(i))),4) 'hPa']);
end
else
for i = 1:length(ytick),
yticklabel = strvcat(yticklabel,[num2str(round(exp(z(ytick(i))))) 'hPa']);
end
end
set(hAxes,'YTick',ytick,'YTickLabel',yticklabel,'YAxisLocation','right')
set(hAxes,'XTick',[])
% prepare callback
set(hAxes,'Userdata',pbins) % store bin edges with axes object
set(hp,'ButtonDownFcn','obsplot plev barclick')
case 'barclick'
[hp,hFig] = gcbo; % handles to patch (hp) and figure (hFig)
if strcmp(get(hFig,'SelectionType'),'alt'), return, end % if right-click, do nothing
hAxes = get(hp,'Parent'); % handle to axes
v = get(hAxes,'CurrentPoint');
y = v(1,2); % y-coordinate of mouse click
ods = get(hFig,'Userdata'); % original data
pbins = get(hAxes,'Userdata'); % edges of pressure bins
i = max(1,min(round(y),length(pbins)-1)); % bar index
KTPRS = dconfig('KTPRS');
s.kt = KTPRS(ismember(KTPRS,ods.kt));
s.lev = pbins([i i+1]);
odss = odssubset(ods,s);
odss.sskt = s.kt;
minlev = min(odss.lev); maxlev = max(odss.lev);
if diff([minlev maxlev]),
odss.sslev = s.lev; % selected bin edges
else
odss.sslev = minlev; % single level
end
obsplot(odss)
end
%-------------------------------------------------------------------------
function pchn(action,varargin)
switch action
case 'create'
hAxes = varargin{1};
ods = varargin{2};
hFig = get(hAxes,'Parent');
figure(hFig)
ncmax = 35;
ch = sort(unique(ods.lev));
nc = length(ch);
if nc<=1, delete(hAxes); return; end % single channel; forget it.
% define bin centers z
if nc<ncmax, % discrete, irregularly spaced bins
z = ch; % bin centers
chbins = [ch' Inf]; % bin edges [ )
else, % continuous, uniformly spaced bins
[n,z] = hist(ch,ncmax); % bin centers
maxch = max(ch); minch = min(ch);
dz = (maxch-minch)/ncmax;
zz = minch + dz*(0:ncmax);
zz(end) = maxch;
chbins = zz;
chbins(1) = 0; chbins(end) = Inf; % bin edges [ )
end
nz = length(z);
% count, by color
cinfo = ods.cinfo;
nc = length(cinfo);
ncidx = zeros(nc,nz);
for ix = 1:nc,
ncidx(ix,:) = hist(ods.lev(ods.cidx==ix),z);
crgb{ix} = cinfo(ix).rgb;
end
% plot
hp = barh(ncidx','stack');
set(hp,{'FaceColor'},crgb')
set(hAxes,'Box','on','YLim',[0 nz+1])
% ticks
ytick = 1:nz;
if nz>20, ytick = 1:2:nz; end
yticklabel = [];
if nc<ncmax,
for i = 1:length(ytick),
yticklabel = strvcat(yticklabel,num2str(z(ytick(i))));
end
else
for i = 1:length(ytick),
yticklabel = strvcat(yticklabel,num2str(round(z(ytick(i)))));
end
end
set(hAxes,'YTick',ytick,'YTickLabel',yticklabel,'YAxisLocation','right')
set(hAxes,'XTick',[])
% prepare callback
set(hAxes,'Userdata',chbins) % store bin edges with axes object
set(hp,'ButtonDownFcn','obsplot pchn barclick')
case 'barclick'
[hp,hFig] = gcbo; % handles to patch (hp) and figure (hFig)
if strcmp(get(hFig,'SelectionType'),'alt'), return, end % if right-click, do nothing
hAxes = get(hp,'Parent'); % handle to axes
v = get(hAxes,'CurrentPoint');
y = v(1,2); % y-coordinate of mouse click
ods = get(hFig,'Userdata'); % original data
pbins = get(hAxes,'Userdata'); % edges of pressure bins
i = max(1,min(round(y),length(pbins)-1)); % bar index
odss = odssubset(ods,pbins(i)<=ods.lev & ods.lev<pbins(i+1));
minlev = min(odss.lev); maxlev = max(odss.lev);
if diff([minlev maxlev]),
odss.sslev = pbins([i i+1]);
else,
odss.sslev = minlev; % single channel
end
obsplot(odss)
end
%-------------------------------------------------------------------------
function pkts(action,varargin)
switch action
case 'create'
hAxes = varargin{1};
ods = varargin{2};
hFig = get(hAxes,'Parent');
figure(hFig)
kts = unique(ods.kt);
nkt = length(kts);
% count, by color
cinfo = ods.cinfo;
nc = length(cinfo);
ncidx = zeros(nc,nkt);
if nkt==0,
delete(hAxes), return
elseif nkt==1,
for ix = 1:nc,
ncidx(ix,:) = sum(ods.cidx==ix);
crgb{ix} = cinfo(ix).rgb;
end
else
for ix = 1:nc,
ncidx(ix,:) = hist(single(ods.kt(ods.cidx==ix)),single(kts));
crgb{ix} = cinfo(ix).rgb;
end
end
n = sum(ncidx,1);
% plot
hp = barh([ncidx';zeros(1,nc)],'stack');
set(hp,{'FaceColor'},crgb')
hcb = hp;
set(hAxes,'YLim',[0 nkt+1],'YTick',[])
xtick = [0.50 1.00 1.50]*max(n);
factor = max(1,10^floor(log10(max(n))));
for i = 1:length(xtick),
xt = xtick(i)/factor;
xticklabel{i} = num2str(xt,2);
end
if factor>1,
xticklabel{end} = ['(x ' int2str(factor) ')'];
end
set(hAxes,'XLim',[0 1.5*max(n)],'XTick',xtick,'XTickLabel',xticklabel)
KTS = dconfig('KTS');
fs = min([0.17 max([0.07 0.7/nkt])]);
for i = 1:nkt,
j = find(kts(i)==[KTS.value]);
if any(j),
hcb = [hcb text(n(i),i,[' ' KTS(j).id],'FontSize',fs)];
end
end
set(hAxes,'YTick',1:nkt,'YTickLabel',kts)
% prepare callback
if nkt>1,
set(hAxes,'Userdata',kts) % store kts with axes object
set(hcb,'ButtonDownFcn','obsplot pkts barclick');
end
case 'barclick'
[hp,hFig] = gcbo; % handles to patch (hp) and figure (hFig)
if strcmp(get(hFig,'SelectionType'),'alt'), return, end % if right-click, do nothing
hAxes = get(hp,'Parent'); % handle to axes
v = get(hAxes,'CurrentPoint');
y = v(1,2); % y-coordinate of mouse click
ods = get(hFig,'Userdata'); % original data
kts = get(hAxes,'Userdata'); % kts associated with bars
i = max(1,min(round(y),length(kts))); % bar index
ods.sskt = kts(i);
obsplot(odssubset(ods,ods.kt==kts(i)))
end
%-------------------------------------------------------------------------
function pkxs(action,varargin)
switch action
case 'create'
hAxes = varargin{1};
ods = varargin{2};
hFig = get(hAxes,'Parent');
figure(hFig)
kxs = unique(ods.kx);
nkx = length(kxs);
% count, by color
cinfo = ods.cinfo;
nc = length(cinfo);
ncidx = zeros(nc,nkx);
if nkx==0,
delete(hAxes), return
elseif nkx==1,
for ix = 1:nc,
ncidx(ix,:) = sum(ods.cidx==ix);
crgb{ix} = cinfo(ix).rgb;
end
else
for ix = 1:nc,
ncidx(ix,:) = hist(single(ods.kx(ods.cidx==ix)),single(kxs));
crgb{ix} = cinfo(ix).rgb;
end
end
n = sum(ncidx,1);
% plot
hp = barh([ncidx';zeros(1,nc)],'stack');
set(hp,{'FaceColor'},crgb')
hcb = hp;
set(hAxes,'YLim',[0 nkx+1],'YTick',[])
xtick = [0.50 1.00 1.50]*max(n);
factor = max(1,10^floor(log10(max(n))));
for i = 1:length(xtick),
xt = xtick(i)/factor;
xticklabel{i} = num2str(xt,2);
end
if factor>1,
xticklabel{end} = ['(x ' int2str(factor) ')'];
end
set(hAxes,'XLim',[0 1.5*max(n)],'XTick',xtick,'XTickLabel',xticklabel)
KXS = dconfig('KXS');
fs = min([0.17 max([0.07 0.7/nkx])]);
for i = 1:nkx,
j = find(kxs(i)==[KXS.value]);
if any(j),
hcb = [hcb text(n(i),i,[' ' KXS(j).id],'FontSize',fs)];
end
end
set(hAxes,'YTick',1:nkx,'YTickLabel',kxs)
% prepare callback
if nkx>1,
set(hAxes,'Userdata',kxs) % store kxs with axes object
set(hcb,'ButtonDownFcn','obsplot pkxs barclick');
end
case 'barclick'
[hp,hFig] = gcbo; % handles to patch (hp) and figure (hFig)
if strcmp(get(hFig,'SelectionType'),'alt'), return, end % if right-click, do nothing
hAxes = get(hp,'Parent'); % handle to axes
v = get(hAxes,'CurrentPoint');
y = v(1,2); % y-coordinate of mouse click
ods = get(hFig,'Userdata'); % original data
kxs = get(hAxes,'Userdata'); % kxs associated with bars
i = max(1,min(round(y),length(kxs))); % bar index
ods.sskx = kxs(i);
obsplot(odssubset(ods,ods.kx==kxs(i)))
end
%-------------------------------------------------------------------------