Home > reduc > plotting > plot_alpha.m

plot_alpha

PURPOSE ^

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

SYNOPSIS ^

function [flags, final_flags] = plot_alpha(d, flags, xc, txt, ax, prop, w, chunk, h, ind1)

DESCRIPTION ^

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 function [flags, finalFlags] = plot_alpha(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 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'}
           p.featmask= [bitmask for style='feature']


 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 [flags, final_flags] = plot_alpha(d, flags, xc, txt, ax, prop, w, chunk, h, ind1)
0002 
0003 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0004 % function [flags, finalFlags] = plot_alpha(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 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'}
0020 %           p.featmask= [bitmask for style='feature']
0021 %
0022 %
0023 % internal inputs for recursive calling
0024 % w       - waitforbuttonpress result
0025 % chunk   - time chunk to start on
0026 % h       - plot handle
0027 % ind1    - indices
0028 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0029 
0030 if(exist('w')~=1)
0031   w = 2;
0032 end
0033 
0034 % check for axis setting
0035 if (~exist('ax'))
0036   ax=[];
0037 end
0038 
0039 % set the plot properties.
0040 if (exist('prop'))
0041   p=setProperties(prop);
0042 else
0043   p=setProperties([]);
0044 end
0045 
0046 % num is the number of pages to be displayed.
0047 % matrix is the size of each of the pages to be displayed.
0048 if(size(xc{2,1},2)~=2)
0049   error('Should not be using plot_alpha');
0050 end
0051 
0052 % each page will have noise diode events for a single intensity channel.
0053 % There will be at most 16 plots per page, and the number of pages will be
0054 % doubled due to the next intensity channel.
0055 
0056 
0057 numPlots = length(xc)/2;
0058 matrix = [4 4];
0059 linesPerPlot = 2;
0060 p.swap = 0;
0061 num = 2*ceil(numPlots/16);   % number of pages
0062 
0063 
0064 % need to calculate the number of plots for each page.
0065 nPlots = numPlots;
0066 m=1;
0067 while(nPlots >0)
0068   if(nPlots>=16)
0069     plotsPerPage(m) = 16;
0070     nPlots = nPlots - 16;
0071   else
0072     plotsPerPage(m) = nPlots;
0073     nPlots = 0;
0074   end
0075   m = m+1;
0076 end
0077 % repeat it
0078 plotsPerPage = [plotsPerPage plotsPerPage];
0079 final_flags = zeros(1,numPlots);
0080 
0081 
0082 pageNum=1;
0083 fmode=logical(0);
0084 while(1)
0085   if (w~=0 & w~=1)
0086     figure(1)
0087     setwinsize(gcf, 1000, 750); 
0088     clf;
0089     for plotNum=1:plotsPerPage(pageNum)
0090       subplot(matrix(1),matrix(2),plotNum)
0091       % plot data
0092       [m,n]=swapIndex(p.swap,pageNum,plotNum);
0093       switch p.style
0094     case 'flag'
0095       h(pageNum,plotNum,1:linesPerPlot)=plotflag(xc,flags,ax,m,n,txt,w,num,matrix,plotsPerPage);
0096       end
0097     end
0098     
0099     if (length(txt)>3)
0100       if(pageNum > (num/2))
0101     bigTitle = sprintf('Channel 6 %s', txt{4}{1});
0102       else
0103     bigTitle = sprintf('Channel 1 %s', txt{4}{1});
0104       end
0105       gtitle(bigTitle);
0106     end
0107     
0108     w=waitforbuttonpress;
0109     if (~w)
0110       % mouse click on bad time.
0111       % first you get the handle for the plot clicked on
0112       child = get(gca,'Children');
0113       % next we compare it to the original  handles to find out which one it
0114       % is
0115       aa = zeros(size(h));
0116       aa(:,:,2) = child(1);
0117       aa(:,:,1) = child(2);
0118       a = h == aa;
0119       a = sum(a,3) > 0;
0120 
0121       clear child;
0122       % where a is nonzero, we've flagged that data.
0123       if(size(a,1)>1)
0124     [flagPage flagPlot] = find(a);
0125     flagIndex = sum(plotsPerPage(1:flagPage-1)) + flagPlot;
0126     if(flagIndex > numPlots)
0127       flagIndex = flagIndex-numPlots;
0128     end
0129       else
0130     f = find(a);
0131     flagPage = 1;
0132     flagPlot = f;
0133     flagIndex = flagPlot;
0134       end
0135       final_flags(flagIndex) = 1;
0136 
0137       
0138       % set the flags for when the plots re-appear.
0139       flags{1, flagIndex}(:) = 1;
0140       flags{1, flagIndex+numPlots}(:) = 1;
0141 
0142     else
0143       % evaluate key stroke
0144       % and get next plotting index
0145       [pageNum,format,p]=evalkey(d,pageNum,plotsPerPage(pageNum),'matrix',p,num);
0146       % negative index means exit
0147       if(pageNum<0)
0148     return
0149       end
0150       if (strcmp(format,'swap'))
0151     numbuf=num;
0152     num=matrix;
0153     matrix=numbuf;
0154     pageNum=1;
0155     p.swap=~p.swap;
0156     clear h;
0157     close(1)
0158       end
0159     end
0160     % set w so we enter this statement again
0161     w=2;
0162   end
0163   
0164 end
0165 
0166 keyboard;
0167 
0168 
0169 return;
0170 
0171 
0172 %%%%%%%%%%%%%%%%%%%%%%%%%
0173 function p=setProperties(p)
0174 
0175 if (isempty(p))
0176   p.style='flag';
0177   p.swap=0;
0178   p.featflag=0;
0179   return
0180 end
0181   
0182 if (isfield(p,'style'))
0183 
0184 else
0185   p.style='flag';  
0186   p.featflag=0;
0187 end
0188 
0189 if (~isfield(p,'swap'))
0190   p.swap=0;
0191 end
0192 
0193 return;
0194 
0195 
0196 
0197 
0198 %%%%%%%%%%%%%%%%%%%%%%%%%
0199 function [m,n]=swapIndex(swap,i,j)
0200 
0201 if (swap)
0202   m=j; n=i;
0203 else
0204   m=i; n=j;
0205 end
0206 
0207 
0208 %%%%%%%%%%%%%%%%%%%%%%%%%
0209 function h=plotflag(x,allflags,ax,pageNum,plotNum,txt,w,num,matrix,plotsPerPage)
0210 
0211 % plot data
0212 if(pageNum==1)
0213   dataIndex = plotNum;
0214 else
0215   dataIndex = sum(plotsPerPage(1:pageNum-1)) + plotNum;
0216 end
0217 
0218 % dataIndex = (pageNum-1)*plotsPerPage+plotNum;
0219 h=plot(x{1,dataIndex},x{2,dataIndex}(:,1:2),'MarkerSize',10);
0220 manaxis(ax,x{2,dataIndex}(:,1:2));
0221 
0222 
0223 if(pageNum <= (num/2))
0224   plotdescription(txt,dataIndex);
0225   hold on
0226 else
0227   plotdescription(txt,dataIndex-(size(x,2)/2));
0228   hold on
0229 end
0230 
0231 
0232 % check for manual axis settings
0233 manaxis(ax,x{2,dataIndex}(:,1:2));
0234 
0235 % plot old flags
0236 if (~isempty(allflags{2, dataIndex}))
0237   for mm=1:2
0238     f = find(allflags{2, dataIndex}(:,mm));
0239     if (~isempty(f))
0240       h=plot(x{1, dataIndex}(f),x{2, dataIndex}(f,1:2),'g.','MarkerSize',10);
0241     end
0242   end
0243 end           
0244 
0245 % plot new flags
0246 if (~isempty(allflags{1, dataIndex}))
0247   for mm=1:2
0248     f = find(allflags{1, dataIndex}(:,mm));
0249     if (~isempty(f))
0250       h=plot(x{1, dataIndex}(f),x{2, dataIndex}(f,1:2),'r.','MarkerSize',10);
0251     end
0252   end           
0253 end
0254 
0255 
0256 hold off
0257     
0258 return;
0259 
0260 %%%%%%%%%%%%%%%%%%%%%%%%%
0261 function plotdescription(txt,dataIndex);
0262 
0263 % title is in
0264 titleTxt = sprintf('%s # %i', txt{1}{1}, dataIndex);
0265 title(titleTxt);
0266 
0267 
0268 if(~isempty(txt))
0269   xlabel(char(txt{2}));
0270   ylabel(char(txt{3}));
0271 end
0272 
0273 return;
0274 
0275 
0276 %%%%%%%%%%%%%%%%%%%%%%%%%
0277 function manaxis(ax,y)
0278 
0279 if (~isempty(ax))
0280   ax4orig = ax(4);
0281   ymax=max(y)*1.1;
0282   if (max(y)>ax(4))
0283     % if max y is larger than mean
0284     ax(4)=ymax;
0285   elseif (8*nanmean(y)<ax(4) & ax(3)>=0)
0286     % if global mean (ax(4)) is much greater than the
0287     % local y data, rescale
0288     % but if ax(3)<0, that means we're looking at phase
0289     % so don't do anything.
0290     ax(4)=ymax;
0291   elseif (isnan(ax(4)) | isnan(ax(3)))
0292     if (isnan(ax(4)))
0293       ax(4)=1;
0294     end
0295     if (isnan(ax(3)))
0296       ax(3)=0;
0297     end
0298   end
0299   % this is in place until mike comes up with a better way to do
0300   % this - all the previous stuff at times resets the value of
0301   % ax(4) so that it is below that of ax(3) - i don't feel like
0302   % trying to figure out mike's logic, so here's a fix;
0303   if(ax(3) >= ax(4))
0304     if(ax4orig>ax(3))
0305           ax(4) = ax4orig;
0306     else
0307       ax(4) = ax(3)+1;
0308     end
0309   end
0310   axis(ax);
0311 end
0312 
0313 return;
0314 
0315 %%%%%%%%%%%%%%%%%%%%%%%%%
0316 function [inc,format,p]=evalkey(d,inc,num,type,p,numPages)
0317 
0318 format='default';
0319 ch=get(gcf,'CurrentCharacter');
0320 switch ch
0321   case 'p'
0322     inc=inc-1;
0323     
0324   case 'n'
0325     inc=inc+1;
0326     
0327   case 'f'
0328     if (strcmp(type,'zoom'))
0329       % enter flag mode
0330       inc=-2;
0331     elseif (strcmp(type,'matrix'))
0332       inc=inc;
0333     end
0334     
0335   case 'q'
0336     if (strcmp(type,'zoom'))
0337       close(2)
0338     else
0339       close(1)
0340     end
0341     inc=-1;
0342     
0343   case 's'
0344     if (strcmp(type,'matrix'))
0345       format='swap';
0346     end
0347     
0348   case '1'
0349     if (strcmp(type,'matrix'))
0350       p.style='flag';
0351       disp('Highlighting auto and user flags')
0352     end
0353     
0354   case 'h'
0355     printhelp;
0356     inc=inc;
0357     
0358   case 'l'
0359     disp('Appending figure to prints.ps')
0360     %debugger must be turned off bc of bug noted in redrum.m
0361     dbclear if error
0362     print -dps -append prints.ps;
0363     dbstop if error
0364   
0365  otherwise
0366     inc=inc;
0367 end
0368 
0369 if (strcmp(type,'matrix'))
0370   if(inc>numPages)
0371     inc = 1;
0372   elseif(inc==0)
0373     inc=numPages;
0374   end
0375 else
0376   if (inc>num)
0377     inc=1;
0378   elseif (inc==0)
0379     inc=num;
0380   end
0381 end
0382 
0383   
0384 
0385 return;
0386 
0387 %%%%%%%%%%%%%%%%%%%%%%%%%
0388 function printhelp()
0389 
0390 disp(' ')
0391 disp('******************************')
0392 disp('        Plotting Help         ')
0393 disp('******************************')
0394 disp(' ');
0395 disp('ALPHA FLAGGING PLOTTING INFO');
0396 disp(' ')
0397 disp('To Flag a noise source event');
0398 disp('Simply CLICK on it');
0399 disp('h - command menu')
0400 disp('p - Previous plots')
0401 disp('n - Next plots')
0402 disp('q - exit plot')
0403 disp('l - append figure to prints.ps')
0404 disp(' ')
0405 disp('*******************WARNING*********************')
0406 disp('*******************WARNING*********************')
0407 disp('*******************WARNING*********************')
0408 disp('*******************WARNING*********************')
0409 disp('*******************WARNING*********************')
0410 disp('Do not exit plot by manually killing the window.')
0411 disp('This will cause the program to crash!')
0412 disp('***********************************************')
0413 disp(' ')
0414 
0415 
0416 return;
0417 
0418 
0419 %%%%%%%%%%%%%%%%%%%%%%%%%
0420 function [clr,leg]=getcolor(type)
0421 
0422 clr=[ 0.2     0         0;
0423     1         0.66      0;
0424     1         0         1;
0425     0.5       0.2       1;
0426     0.2       0.2       0.8;
0427     1         0.5       0.12;
0428     0.1       0.5       0.9;
0429     0.75      1         1;
0430     0.2       0.5       0.66;
0431     0.9       0.8       0.7;
0432     0.6       0         0.1;
0433     0         0         1
0434     0.5869    0.1909    0.3461
0435     0.0576    0.8439    0.1660
0436     0.3676    0.1739    0.1556
0437     0.6315    0.1708    0.1911
0438     0.7176    0.9943    0.4225
0439     0.6927    0.4398    0.8560
0440     0.0841    0.3400    0.4902
0441     0.4544    0.3142    0.8159
0442     0.4418    0.3651    0.4608
0443     0.3533    0.3932    0.4574
0444     0.1536    0.5915    0.4507
0445     0.6756    0.1197    0.4122
0446     0.6992    0.0381    0.9016
0447     0.7275    0.4586    0.0056
0448     0.4784    0.8699    0.2974
0449     0.5548    0.9342    0.0492
0450     0.1210    0.2644    0.6932
0451     0.4508    0.1603    0.6501
0452     0.7159    0.8729    0.9830
0453     0         0         0];
0454 
0455 
0456 switch type
0457   case 'feature'
0458     leg = {'source', 'calibrator', 'abscal', 'blank', 'skydip', ...
0459     'noise_event', 'noise'};
0460     
0461   case 'bitmask'
0462     leg={'frame','receiver', 'tracking', 'tracker', 'elevation', ...
0463     'continuous', 'fifo', 'clock', '1pps', 'cryo/servo', 'backend time', 'shortfall', 'sun', 'moon'};
0464 end
0465 
0466 return;
0467 
0468

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