Home > reduc > plotting > plotdnoflag.m

plotdnoflag

PURPOSE ^

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

SYNOPSIS ^

function plotdnoflag(d, flags, xc, txt, ax, prop, w, chunk, h, ind1)

DESCRIPTION ^

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 function plotdnoflag(d, flags, xc, txt, ax, prop, w, chunk, h, ind1)

 d       - data structure
 flag    - flag structure
 xc      - cell element of x and y data
           x{odd}  - x axis data
           x{even} - y axis data Nx1 or Nx6 or Nx24
 txt     - axis text
           txt{1} - title
           txt{2} - x axis
           txt{3} - y axis
           txt[4} - overall title
           txt{5} - legend
 ax         - manual axis settings.  [xmin xmax ymin ymax]
 prop    - initialize properties of plotting
           p.style = {'flag','feature'}
           p.swap  = swap to display plots in time.
           p.featmask= [bitmask for style='feature']
           p.type  = 'feature', 'allflags'

 internal inputs for recursive calling
 w       - waitforbuttonpress result
 chunk   - time chunk to start on
 h       - plot handle
 ind1    - indices
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

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

Generated on Sun 14-Jun-2015 17:12:45 by m2html © 2005