0001 function [flags newflag] =plotd(d, flags, xc, txt, ax, prop, w, chunk, h, ind1)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031 if(exist('w')~=1)
0032 w = 2;
0033 end
0034
0035
0036 newflag = [];
0037
0038
0039 if (~exist('ax'))
0040 ax=[];
0041 end
0042
0043
0044 if (exist('prop'))
0045 p=setProperties(prop);
0046 else
0047 p=setProperties([]);
0048 end
0049
0050
0051
0052 if(~p.swap)
0053 num = size(xc,2);
0054 plotsPerPage = size(xc{2,1},2);
0055 if(plotsPerPage==6)
0056 matrix = [2 3];
0057 elseif(plotsPerPage==1)
0058 matrix = [1 1];
0059 elseif(plotsPerPage==24)
0060 matrix = [2 3];
0061 plotsPerPage = 6;
0062 elseif(plotsPerPage==2)
0063
0064
0065 matrix = [2 1];
0066 plotsPerPage = 2;
0067 else
0068 error('Unrecognized number of plots');
0069 end
0070 else
0071 num = size(xc{2,1},2);
0072 plotsPerPage = size(xc,2);
0073 matrix = ceil(sqrt(size(xc,2)));
0074 matrix = [matrix; matrix];
0075 end
0076
0077 pageNum=1;
0078 fmode=logical(0);
0079 while(1)
0080 if (w~=0 & w~=1)
0081 figure(1)
0082 if(plotsPerPage==2)
0083 setwinsize(gcf, 1000, 400);
0084 else
0085 setwinsize(gcf, 1000, 750);
0086 end
0087
0088 for plotNum=1:plotsPerPage
0089 subplot(matrix(1),matrix(2),plotNum)
0090
0091 [m,n]=swapIndex(p.swap,pageNum,plotNum);
0092 switch p.style
0093 case 'flag'
0094 h(pageNum,plotNum)=plotflag(xc,flags,ax,m,n,txt,w,num,matrix,p.swap);
0095
0096 case 'feature'
0097 [h(pageNum,plotNum),leg]=plotfeat(xc,flags,ax,m,n,txt,w,num, ...
0098 matrix,p.swap);
0099
0100 end
0101 end
0102 if (strcmp(p.style,'feature') & ~isempty(leg))
0103 legend(leg,'Location','Best');
0104
0105 leg=[];
0106 end
0107 if(length(txt) == 5)
0108 eval(sprintf('legend(''%s'', ''%s'', ''Location'',''Best'');', ...
0109 txt{5}{1}, txt{5}{2}));
0110 end
0111 if (length(txt)>3)
0112 gtitle(txt{4});
0113 end
0114
0115 w=waitforbuttonpress;
0116 if (~w)
0117
0118 flags = plotd(d,flags,xc,txt,ax,p,w,[],h,pageNum);
0119 else
0120
0121
0122 [pageNum,format,p]=evalkey(d,pageNum,plotsPerPage,'matrix',p,num);
0123
0124 if(pageNum<0)
0125 return
0126 end
0127 if (strcmp(format,'swap'))
0128 numbuf=num;
0129 num=matrix;
0130 matrix=numbuf;
0131 pageNum=1;
0132 p.swap=~p.swap;
0133 clear h;
0134 close(1)
0135 end
0136 end
0137
0138 w=2;
0139 else
0140 if (~w)
0141
0142
0143 child=get(gca,'Children');
0144 ind2 = find(h(ind1,:)==child(1));
0145 if (isempty(ind2))
0146 if (isempty(chunk))
0147 disp(' Unknown plot. Default to channel 1');
0148 ind2=1;
0149 else
0150 ind2=chunk;
0151 end
0152 end
0153 else
0154
0155
0156 [ind2,format,p] = evalkey(d,chunk,plotsPerPage,'zoom',p,num);
0157
0158
0159 if(ind2==-1)
0160 break;
0161 elseif (ind2==-2)
0162 fmode = logical(1);
0163 ind2 = chunk;
0164 end
0165 end
0166
0167 figure(2)
0168 [m,n] = swapIndex(p.swap,ind1,ind2);
0169 switch p.style
0170 case 'flag'
0171 plotflag(xc,flags,ax,m,n,txt,w,num,matrix,p.swap);
0172
0173 case 'feature'
0174 plotfeat(xc,flags,ax,m,n,txt,w,num,matrix,p.swap);
0175
0176 end
0177
0178
0179 grid
0180
0181 if (fmode)
0182 [flags newflag] = flagplot(d,flags,xc,m,n);
0183 end
0184 hold off
0185 w = waitforbuttonpress;
0186 flags = plotd(d,flags,xc,txt,ax,p,w,ind2,h,ind1);
0187 break;
0188 end
0189 end
0190
0191
0192
0193
0194
0195 function p=setProperties(p)
0196
0197 if (isempty(p))
0198 p.style='flag';
0199 p.swap=0;
0200 p.featflag=0;
0201 return
0202 end
0203
0204 if (isfield(p,'style'))
0205
0206 else
0207 p.style='flag';
0208 p.featflag=0;
0209 end
0210
0211 if (~isfield(p,'swap'))
0212 p.swap=0;
0213 end
0214
0215 return;
0216
0217
0218
0219
0220
0221 function [m,n]=swapIndex(swap,i,j)
0222
0223 if (swap)
0224 m=j; n=i;
0225 else
0226 m=i; n=j;
0227 end
0228
0229
0230
0231 function h=plotflag(x,allflags,ax,pageNum,plotNum,txt,w,num,matrix,swap, multLinesPerPlot)
0232
0233
0234 if(size(x,1)==4)
0235 if(size(x{1,pageNum},1) == size(x{4,pageNum},1))
0236 plot(x{1,pageNum},x{4,pageNum}(:,plotNum),'c.','MarkerSize',5);
0237 hold on;
0238 else
0239 plot(x{3,pageNum},x{4,pageNum}(:,plotNum),'c.','MarkerSize',5);
0240 hold on;
0241 end
0242 end
0243
0244
0245 h=plot(x{1,pageNum},x{2,pageNum}(:,plotNum),'b.','MarkerSize',5);
0246 manaxis(ax,x{2,pageNum}(:,plotNum))
0247 hold on;
0248
0249 plotdescription(txt,plotNum,pageNum,num,matrix,swap);
0250
0251
0252
0253 manaxis(ax,x{2,pageNum}(:,plotNum));
0254
0255
0256 numpts = size(x{1,pageNum},1);
0257
0258
0259 if (~isempty(allflags{2,pageNum}))
0260 f = find(allflags{2,pageNum}(:,plotNum));
0261 if (~isempty(f))
0262 h=plot(x{1,pageNum}(f),x{2,pageNum}(f,plotNum),'g.','MarkerSize',5);
0263 end
0264 end
0265
0266
0267 if (~isempty(allflags{1,pageNum}))
0268
0269 f = find(allflags{1,pageNum}(:,plotNum));
0270 if (~isempty(f))
0271 h=plot(x{1,pageNum}(f),x{2,pageNum}(f,plotNum),'r.','MarkerSize',5);
0272 end
0273 end
0274
0275 hold off
0276
0277 return;
0278
0279
0280
0281 function [h, leg] = plotfeat(x,allflags,ax,pageNum,plotNum,txt,w,num,matrix,swap)
0282
0283
0284
0285
0286
0287 [flag,autoflag,scriptflag]=cloneflag(allflags);
0288
0289
0290 [clr, legall] = getcolor('feature');
0291
0292
0293 index = 1;
0294 leg = [];
0295 for m=1:length(legall)
0296 txt1 = sprintf('a = x{1,pageNum}(x{3,pageNum}.%s);', legall{m});
0297 txt2 = sprintf('b = x{2,pageNum}(x{3,pageNum}.%s, plotNum);', legall{m});
0298 eval(txt1); eval(txt2);
0299
0300
0301 if(sum(a)>0)
0302 txtPlot = sprintf('h = plot(a, b, ''.'', ''markerfacecolor'', clr(m,:), ''markeredgecolor'', clr(m,:), ''MarkerSize'',5);');
0303 eval(txtPlot);
0304 hold on;
0305 leg{index} = legall{m};
0306 index = index+1;
0307 end
0308 end
0309
0310
0311
0312 if (~isempty(autoflag))
0313 f = find(autoflag{1,pageNum}(:,plotNum));
0314 if (~isempty(f))
0315 h=plot(x{1,pageNum}(f),x{2,pageNum}(f,plotNum),'g.','MarkerSize',5);
0316 leg{index} = 'auto flag';
0317 index = index+1;
0318 end
0319 end
0320
0321
0322 if (~isempty(scriptflag))
0323 f = find(scriptflag{1,pageNum}(:,plotNum));
0324 if (~isempty(f))
0325 h=plot(x{1,pageNum}(f),x{2,pageNum}(f,plotNum),'g.','MarkerSize',5);
0326 leg{index} = 'script flag';
0327 index = index+1;
0328 end
0329 end
0330
0331
0332 if (~isempty(flag))
0333
0334 f = find(flag{1,pageNum}(:,plotNum));
0335 if (~isempty(f))
0336 h=plot(x{1,pageNum}(f),x{2,pageNum}(f,plotNum),'r.','MarkerSize',5);
0337 leg{index} = 'user flag';
0338 index = index+1;
0339 end
0340 end
0341
0342
0343
0344 manaxis(ax,x{2,pageNum}(:,plotNum))
0345 plotdescription(txt,plotNum,pageNum,num,matrix,swap);
0346
0347 hold off
0348
0349 return;
0350
0351
0352
0353 function plotdescription(txt,n,m,num,matrix,swap)
0354
0355 if(length(txt{1})>1)
0356 title(txt{1}{n})
0357 xlabel(char(txt{2}));
0358 ylabel(char(txt{3}));
0359 return;
0360 end
0361
0362
0363 if (matrix(1)==2 & matrix(2)==3)
0364
0365 title(sprintf('Channel: %u', n));
0366 elseif (matrix(1)==4 & matrix(2)==6)
0367
0368 title(sprintf('Switch State Number: %u Ant: %u',n));
0369 elseif (num==6)
0370
0371 title(sprintf('Channel Number: %u', m));
0372 elseif(num==24)
0373
0374 title(sprintf('Switch State Number: %u', m));
0375 elseif(matrix(1) == 1 & matrix(2)==2)
0376
0377 title(sprintf('Total Intensity Channel: %u', n));
0378 end
0379
0380 if(~isempty(txt))
0381 xlabel(char(txt{2}));
0382 ylabel(char(txt{3}));
0383 end
0384
0385 return;
0386
0387
0388
0389 function manaxis(ax,y)
0390
0391 if (~isempty(ax))
0392 ax4orig = ax(4);
0393 ymax=max(y)*1.1;
0394 if (max(y)>ax(4))
0395
0396 ax(4)=ymax;
0397 elseif (8*nanmean(y)<ax(4) & ax(3)>=0)
0398
0399
0400
0401
0402 ax(4)=ymax;
0403 elseif (isnan(ax(4)) | isnan(ax(3)))
0404 if (isnan(ax(4)))
0405 ax(4)=1;
0406 end
0407 if (isnan(ax(3)))
0408 ax(3)=0;
0409 end
0410 end
0411
0412
0413
0414
0415 if(ax(3) >= ax(4))
0416 if(ax4orig>ax(3))
0417 ax(4) = ax4orig;
0418 else
0419 ax(4) = ax(3)+1;
0420 end
0421 end
0422 axis(ax);
0423 end
0424
0425 return;
0426
0427
0428 function [inc,format,p]=evalkey(d,inc,num,type,p,numPages)
0429
0430 format='default';
0431 ch=get(gcf,'CurrentCharacter');
0432 switch ch
0433 case 'p'
0434 inc=inc-1;
0435
0436 case 'n'
0437 inc=inc+1;
0438
0439 case 'f'
0440 if (strcmp(type,'zoom'))
0441
0442 inc=-2;
0443 elseif (strcmp(type,'matrix'))
0444 inc=inc;
0445 end
0446
0447 case 'q'
0448 if (strcmp(type,'zoom'))
0449 close(2)
0450 else
0451 close(1)
0452 end
0453 inc=-1;
0454
0455 case 's'
0456 if (strcmp(type,'matrix'))
0457 format='swap';
0458 end
0459
0460 case '1'
0461 if (strcmp(type,'matrix'))
0462 p.style='flag';
0463 disp('Highlighting auto and user flags')
0464 end
0465
0466 case 'h'
0467 printhelp;
0468 inc=inc;
0469
0470 case 'l'
0471 disp('Appending figure to prints.ps')
0472
0473 dbclear if error
0474 print -dps -append prints.ps;
0475 dbstop if error
0476
0477 otherwise
0478 inc=inc;
0479 end
0480
0481 if (strcmp(type,'matrix'))
0482 if(inc>numPages)
0483 inc = 1;
0484 elseif(inc==0)
0485 inc=numPages;
0486 end
0487 else
0488 if (inc>num)
0489 inc=1;
0490 elseif (inc==0)
0491 inc=num;
0492 end
0493 end
0494
0495
0496
0497 return;
0498
0499
0500 function printhelp()
0501
0502 disp(' ')
0503 disp('******************************')
0504 disp(' Plotting Help ')
0505 disp('******************************')
0506 disp(' ');
0507 disp('IN PLOT WINDOW (MATRIX and ZOOM)')
0508 disp(' ')
0509 disp('h - command menu')
0510 disp('p - Previous plots')
0511 disp('n - Next plots')
0512 disp('q - exit plot')
0513 disp('l - append figure to prints.ps')
0514 disp(' ')
0515
0516
0517
0518
0519
0520
0521 disp(' ')
0522 disp(' ')
0523 disp('ZOOM ONLY')
0524 disp('click on plot to zoom and flag')
0525 disp(' ')
0526 disp('FLAGGING FROM ZOOM')
0527 disp(' ')
0528 disp('These commands are only available in flag mode')
0529 disp('Hit ''f''')
0530 disp(' ')
0531 disp('**Flagging**')
0532 disp(' ')
0533 disp('GLOBAL TYPE COMMANDS')
0534 disp('s - flag single channel');
0535 disp('a - all channels for this timestamp');
0536 disp(' ')
0537 disp('LOCAL TYPE COMMANDS')
0538 disp('c - chunk of data. click 2 corners of a rectangle')
0539 disp('t - time chunk. like ''c'' but only uses x-axis as constraint')
0540 disp('- - flags everything below y-value')
0541 disp('= - flags everything above y-value')
0542 disp('m - flags specific bands')
0543 disp('n - flags specific baselines/antennas')
0544 disp(' ')
0545 disp('EDIT TYPE COMMANDS')
0546 disp('f - flag mode')
0547 disp('u - unflag mode')
0548 disp('e - erases all new flags')
0549 disp(' ')
0550 disp('**Zoom**')
0551 disp('z - box zoom')
0552 disp('x - zoom x axis')
0553 disp('y - zoom y axis')
0554 disp('o - original plot (unzoom)')
0555 disp(' ')
0556 disp('**Misc Display**')
0557 disp('g - toggle grid on/off')
0558 disp('q - exit flag mode')
0559 disp('h - help')
0560 disp(' ')
0561 disp(' ')
0562 disp('In matrix mode, [p,n] will cycle through antennas/baselines.')
0563 disp('In zoom mode, these will cycle through bands')
0564 disp('Once in zoom mode, you must exit it to regain control')
0565 disp('of matrix mode. ''q'' in zoom mode returns to the matrix plot')
0566 disp('''q'' in matrix exits plot')
0567 disp(' ')
0568 disp('*******************WARNING*********************')
0569 disp('*******************WARNING*********************')
0570 disp('*******************WARNING*********************')
0571 disp('*******************WARNING*********************')
0572 disp('*******************WARNING*********************')
0573 disp('Do not exit plot by manually killing the window.')
0574 disp('This will cause the program to crash!')
0575 disp('***********************************************')
0576 disp(' ')
0577
0578
0579 return;
0580
0581
0582
0583 function [clr,leg]=getcolor(type)
0584
0585 clr=[ 0.2 0 0;
0586 1 0.66 0;
0587 1 0 1;
0588 0.5 0.2 1;
0589 0.2 0.2 0.8;
0590 1 0.5 0.12;
0591 0.1 0.5 0.9;
0592 0.75 1 1;
0593 0.2 0.5 0.66;
0594 0.9 0.8 0.7;
0595 0.6 0 0.1;
0596 0 0 1
0597 0.5869 0.1909 0.3461
0598 0.0576 0.8439 0.1660
0599 0.3676 0.1739 0.1556
0600 0.6315 0.1708 0.1911
0601 0.7176 0.9943 0.4225
0602 0.6927 0.4398 0.8560
0603 0.0841 0.3400 0.4902
0604 0.4544 0.3142 0.8159
0605 0.4418 0.3651 0.4608
0606 0.3533 0.3932 0.4574
0607 0.1536 0.5915 0.4507
0608 0.6756 0.1197 0.4122
0609 0.6992 0.0381 0.9016
0610 0.7275 0.4586 0.0056
0611 0.4784 0.8699 0.2974
0612 0.5548 0.9342 0.0492
0613 0.1210 0.2644 0.6932
0614 0.4508 0.1603 0.6501
0615 0.7159 0.8729 0.9830
0616 0 0 0];
0617
0618
0619 switch type
0620 case 'feature'
0621 leg = {'source', 'calibrator', 'abscal', 'blank', 'skydip', ...
0622 'noise_event', 'noise'};
0623
0624 case 'bitmask'
0625 leg={'frame','receiver', 'tracking', 'tracker', 'elevation', ...
0626 'continuous', 'fifo', 'clock', '1pps', 'cryo/servo', 'backend time', 'shortfall', 'sun', 'moon'};
0627 end
0628
0629 return;
0630
0631