Home > reduc > plotting > genfigMainsSwitch.m

genfigMainsSwitch

PURPOSE ^

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

SYNOPSIS ^

function genfigMainsSwitch(d,flags,xc,txt,ax,type, p, field)

DESCRIPTION ^

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   
  function genfig(d,flags,xc,txt,ax,type, p, field)

  function that generates figures for a webpage.

  sjcm
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function genfigMainsSwitch(d,flags,xc,txt,ax,type, p, field)
0002 
0003 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0004 %
0005 %  function genfig(d,flags,xc,txt,ax,type, p, field)
0006 %
0007 %  function that generates figures for a webpage.
0008 %
0009 %  sjcm
0010 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0011 
0012 % check for axis setting
0013 if (~exist('ax'))
0014   ax=[];
0015 end
0016 
0017 % get the directory to write to
0018 maindir=getMainDir(d, field);
0019 
0020 % num is the number of pages to be displayed.
0021 % matrix is the size of each of the pages to be displayed.
0022 num = 6;
0023 plotsPerPage = 4;
0024 matrix = [2 2];
0025 
0026 plotoptions = {'b', 'g', 'r', 'c', 'm', 'y', 'k', ...
0027     'b.', 'g.', 'r.', 'c.', 'm.', 'y.', 'k.', ...    
0028     'bo', 'go', 'ro', 'co', 'mo', 'yo', 'ko', ...    
0029     'bx', 'gx', 'rx', 'cx', 'mx', 'yx', 'kx'};
0030 
0031 switchData = d.antenna0.receiver.switchData;
0032 switchData(d.flags.switch) = nan;
0033 timeVal = d.antenna0.receiver.utc*24*60*60;
0034 
0035 pageNum=1;
0036 fmode=logical(0);
0037 
0038 
0039 
0040 
0041 
0042 for pageNum=1:num
0043   dataIndex = (pageNum-1)*4;
0044 
0045   for plotNum=1:plotsPerPage
0046     indices = d.correction.mains.indices(chanIndex,:);
0047     subplot(matrix(1),matrix(2),plotNum)
0048     % plot data
0049     optionIndex = 1;
0050     for mm=1:size(d.correction.mains.factors,2)
0051       chanIndex = dataIndex+plotNum;
0052       if(mm==1)
0053     % plot uncorrected data
0054     [boo, coo, h(pageNum, plotNum,optionIndex)] = plot_powerspec(d, ...
0055         switchData(:,dataIndex+plotNum), indices(1), indices(2), ...
0056         0, plotoptions{optionIndex});
0057     hold on;
0058     leg{optionIndex} = 'Orig';
0059     optionIndex = optionIndex+1;
0060       end
0061       clear boo;
0062       clear coo;
0063       
0064       
0065       % remove the harmonic of hte mains
0066       best_freq = d.correction.mains.factors(chanIndex,mm,1);
0067       best_phase= d.correction.mains.factors(chanIndex,mm,2);
0068       best_amp  = d.correction.mains.factors(chanIndex,mm,3);
0069       best_fit_sin = sin(timeVal*2*pi*best_freq + ...
0070       best_phase)*best_amp;
0071       switchData(:,chanIndex) = switchData(:,chanIndex)-best_fit_sin;
0072       
0073       
0074       % plot the one with it removed
0075       [boo, coo, h(pageNum, plotNum, optionIndex)] = plot_powerspec(d, ...
0076       switchData(:,chanIndex), indices(1), indices(2), ...
0077       0, plotoptions{optionIndex});
0078       hold on;
0079       leg{optionIndex} = sprintf('Harmonic %u', mm);
0080       optionIndex = optionIndex+1;    
0081     end
0082     xlabel(txt{2});
0083     ylabel(txt{3});
0084     title(txt{1});
0085   end
0086     
0087   legend(leg,'Location','Best');
0088   
0089   gtitle(sprintf('Channel %u', pageNum));    
0090   
0091     
0092   dbclear if error
0093   set(gcf,'paperposition',[0 0 6.0 6.0])
0094   eval(sprintf('print -dpng -r200 %s/%s/fig%u.png;', ...
0095       maindir,type,pageNum));
0096   dbstop if error
0097   pageNum=pageNum+1;
0098 end
0099 
0100 % num is the number of pages to be displayed.
0101 % matrix is the size of each of the pages to be displayed.
0102 num = 6;
0103 plotsPerPage = 4;
0104 matrix = [2 2];
0105 
0106 plotoptions = {'b', 'g', 'r', 'c', 'm', 'y', 'k', ...
0107     'b.', 'g.', 'r.', 'c.', 'm.', 'y.', 'k.', ...    
0108     'bo', 'go', 'ro', 'co', 'mo', 'yo', 'ko', ...    
0109     'bx', 'gx', 'rx', 'cx', 'mx', 'yx', 'kx'};
0110 
0111 switchData = d.antenna0.receiver.switchData;
0112 switchData(d.flags.switch) = nan;
0113 timeVal = d.antenna0.receiver.utc*24*60*60;
0114 
0115 pageNum=1;
0116 fmode=logical(0);
0117 
0118 while(1)
0119   dataIndex = (pageNum-1)*4;
0120   if (w~=0 & w~=1)
0121     figure(1)
0122     setwinsize(gcf, 1000, 750); 
0123     clear leg;
0124     for plotNum=1:plotsPerPage
0125       indices = d.correction.mains.indices(chanIndex,:);
0126       subplot(matrix(1),matrix(2),plotNum)
0127       % plot data
0128       optionIndex = 1;
0129       for mm=1:size(d.correction.mains.factors,2)
0130     chanIndex = dataIndex+plotNum;
0131     if(mm==1)
0132       % plot uncorrected data
0133       [boo, coo, h(pageNum, plotNum,optionIndex)] = plot_powerspec(d, ...
0134           switchData(:,dataIndex+plotNum), indices(1), indices(2), ...
0135           0, plotoptions{optionIndex});
0136       hold on;
0137       leg{optionIndex} = 'Orig';
0138       optionIndex = optionIndex+1;
0139     end
0140     clear boo;
0141     clear coo;
0142     
0143     
0144     % remove the harmonic of hte mains
0145     best_freq = d.correction.mains.factors(chanIndex,mm,1);
0146     best_phase= d.correction.mains.factors(chanIndex,mm,2);
0147     best_amp  = d.correction.mains.factors(chanIndex,mm,3);
0148     best_fit_sin = sin(timeVal*2*pi*best_freq + ...
0149         best_phase)*best_amp;
0150     switchData(:,chanIndex) = switchData(:,chanIndex)-best_fit_sin;
0151     
0152     
0153     % plot the one with it removed
0154     [boo, coo, h(pageNum, plotNum, optionIndex)] = plot_powerspec(d, ...
0155         switchData(:,chanIndex), indices(1), indices(2), ...
0156         0, plotoptions{optionIndex});
0157     hold on;
0158     leg{optionIndex} = sprintf('Harmonic %u', mm);
0159     optionIndex = optionIndex+1;    
0160       end
0161       xlabel(txt{2});
0162       ylabel(txt{3});
0163       title(txt{1});
0164     end
0165     
0166     legend(leg,'Location','Best');
0167 
0168     gtitle(sprintf('Channel %u', pageNum));
0169     
0170     w=waitforbuttonpress;
0171     if (~w)
0172       % mouse click -> zooming
0173 %      flags = plotd(d,flags,xc,txt,ax,p,w,[],h,pageNum);
0174     else
0175       % evaluate key stroke
0176       % and get next plotting index
0177       [pageNum,format,p]=evalkey(d,pageNum,plotsPerPage,'matrix',p,num);
0178       % negative index means exit
0179       if(pageNum<0)
0180     return
0181       end
0182       if (strcmp(format,'swap'))
0183     numbuf=num;
0184     num=matrix;
0185     matrix=numbuf;
0186     pageNum=1;
0187     p.swap=~p.swap;
0188     clear h;
0189     close(1)
0190       end
0191     end
0192     % set w so we enter this statement again
0193     w=2;
0194   end
0195 end
0196 
0197     
0198 
0199 
0200 %%%%%%%%%%%%%%%%%%%%%%%%%
0201 function p=setProperties(p)
0202 
0203 if (isempty(p))
0204   p.style='flag';
0205   p.swap=0;
0206   p.featflag=0;
0207   return
0208 end
0209   
0210 if (isfield(p,'style'))
0211 
0212 else
0213   p.style='flag';  
0214   p.featflag=0;
0215 end
0216 
0217 if (~isfield(p,'swap'))
0218   p.swap=0;
0219 end
0220 
0221 return;
0222 
0223 
0224 
0225 
0226 %%%%%%%%%%%%%%%%%%%%%%%%%
0227 function [m,n]=swapIndex(swap,i,j)
0228 
0229 if (swap)
0230   m=j; n=i;
0231 else
0232   m=i; n=j;
0233 end
0234 
0235 
0236 %%%%%%%%%%%%%%%%%%%%%%%%%
0237 function h=plotflag(x,allflags,ax,pageNum,plotNum,txt,w,num,matrix,swap, multLinesPerPlot)
0238 % get auto flags and user flags
0239 [flag,autoflag,scriptflag]=cloneflag(allflags);
0240 
0241 % if x has a fourth dimension, plot that first
0242 if(size(x,1)==4)
0243   plot(x{1,pageNum},x{4,pageNum}(:,plotNum),'c.','MarkerSize',10);
0244   hold on;
0245 end
0246 
0247 
0248 % plot data
0249 h=plot(x{1,pageNum},x{2,pageNum}(:,plotNum),'b.','MarkerSize',10);
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 auto flags
0263 if (~isempty(autoflag))
0264   f = find(autoflag{1,pageNum}(:,plotNum));
0265   if (~isempty(f))
0266     h=plot(x{1,pageNum}(f),x{2,pageNum}(f,plotNum),'m.','MarkerSize',10);
0267   end
0268 end           
0269 
0270 % plot script flags
0271 if (~isempty(scriptflag))
0272   f = find(scriptflag{1,pageNum}(:,plotNum));
0273   if (~isempty(f))
0274     h=plot(x{1,pageNum}(f),x{2,pageNum}(f,plotNum),'g.','MarkerSize',10);
0275   end
0276 end           
0277 
0278 % plot flags
0279 if (~isempty(flag)) 
0280   % always plotting fast sampled data.
0281   f = find(flag{1,pageNum}(:,plotNum));
0282   if (~isempty(f))
0283     h=plot(x{1,pageNum}(f),x{2,pageNum}(f,plotNum),'r.','MarkerSize',10);
0284   end
0285 end
0286 
0287 hold off
0288     
0289 return;
0290 
0291 
0292 %%%%%%%%%%%%%%%%%%%%%%%%%
0293 function [h, leg] = plotfeat(x,allflags,ax,pageNum,plotNum,txt,w,num,matrix,swap)
0294 
0295 % get the features to plot
0296 % we only have {source, calibrator, abscal, blank, skydip, noise_event, and noise}
0297 
0298 % get auto flags and user flags
0299 [flag,autoflag,scriptflag]=cloneflag(allflags);
0300 
0301 % get the color and legend
0302 [clr, legall] = getcolor('feature');
0303 
0304 % we only need to plot the ones with legall
0305 index = 1;
0306 leg = [];
0307 for m=1:length(legall)
0308   txt1 = sprintf('a = x{1,pageNum}(x{3,pageNum}.%s);', legall{m});
0309   txt2 = sprintf('b = x{2,pageNum}(x{3,pageNum}.%s, plotNum);', legall{m});
0310   eval(txt1); eval(txt2);
0311   
0312   % do not plot if there are no data points to plot
0313   if(sum(a)>0)
0314     txtPlot = sprintf('h = plot(a, b, ''.'', ''markerfacecolor'', clr(m,:), ''markeredgecolor'', clr(m,:), ''MarkerSize'',10);');
0315     eval(txtPlot);
0316     hold on;
0317     leg{index} = legall{m};
0318     index = index+1;
0319   end
0320 end  
0321 
0322 
0323 % plot auto flags
0324 if (~isempty(autoflag))
0325   f = find(autoflag{1,pageNum}(:,plotNum));
0326   if (~isempty(f))
0327     h=plot(x{1,pageNum}(f),x{2,pageNum}(f,plotNum),'m.','MarkerSize',10);
0328     leg{index} = 'auto flag';
0329     index = index+1;
0330   end
0331 end           
0332 
0333 % plot script flags
0334 if (~isempty(scriptflag))
0335   f = find(scriptflag{1,pageNum}(:,plotNum));
0336   if (~isempty(f))
0337     h=plot(x{1,pageNum}(f),x{2,pageNum}(f,plotNum),'g.','MarkerSize',10);
0338     leg{index} = 'script flag';
0339     index = index+1;
0340   end
0341 end           
0342 
0343 % plot flags
0344 if (~isempty(flag)) 
0345   % always plotting fast sampled data.
0346   f = find(flag{1,pageNum}(:,plotNum));
0347   if (~isempty(f))
0348     h=plot(x{1,pageNum}(f),x{2,pageNum}(f,plotNum),'r.','MarkerSize',10);
0349     leg{index} = 'user flag';
0350     index = index+1;
0351   end
0352 end
0353       
0354 
0355 
0356 manaxis(ax,x{2,pageNum}(:,plotNum))
0357 plotdescription(txt,plotNum,pageNum,num,matrix,swap);
0358 
0359 hold off
0360     
0361 return;
0362 
0363 
0364 %%%%%%%%%%%%%%%%%%%%%%%%%
0365 function plotdescription(txt,n,m,num,matrix,swap)
0366 
0367 if (matrix(1)==2 & matrix(2)==3)
0368   % plot of channels
0369   title(sprintf('Channel: %u', n));
0370 elseif (matrix(1)==4 & matrix(2)==6)
0371   % plot of switch states
0372   title(sprintf('Switch State Number: %u Ant: %u',n));
0373 elseif (num==6)
0374   % channels plotted in time
0375   title(sprintf('Channel Number: %u', m));
0376 elseif(num==24)
0377   % phase switch in time
0378   title(sprintf('Switch State Number: %u', m));
0379 elseif(matrix(1) == 1 & matrix(2)==2)
0380   % opacity plots
0381   title(sprintf('Opacity for Channel: %u', m));
0382 end
0383 
0384 if(~isempty(txt))
0385   xlabel(char(txt{2}));
0386   ylabel(char(txt{3}));
0387 end
0388 
0389 return;
0390 
0391 
0392 %%%%%%%%%%%%%%%%%%%%%%%%%
0393 function manaxis(ax,y)
0394 
0395 if (~isempty(ax))
0396   ax4orig = ax(4);
0397   ymax=max(y)*1.1;
0398   if (max(y)>ax(4))
0399     % if max y is larger than mean
0400     ax(4)=ymax;
0401   elseif (8*nanmean(y)<ax(4) & ax(3)>=0)
0402     % if global mean (ax(4)) is much greater than the
0403     % local y data, rescale
0404     % but if ax(3)<0, that means we're looking at phase
0405     % so don't do anything.
0406     ax(4)=ymax;
0407   elseif (isnan(ax(4)) | isnan(ax(3)))
0408     if (isnan(ax(4)))
0409       ax(4)=1;
0410     end
0411     if (isnan(ax(3)))
0412       ax(3)=0;
0413     end
0414   end
0415   % this is in place until mike comes up with a better way to do
0416   % this - all the previous stuff at times resets the value of
0417   % ax(4) so that it is below that of ax(3) - i don't feel like
0418   % trying to figure out mike's logic, so here's a fix;
0419   if(ax(3) >= ax(4))
0420     if(ax4orig>ax(3))
0421           ax(4) = ax4orig;
0422     else
0423       ax(4) = ax(3)+1;
0424     end
0425   end
0426   axis(ax);
0427 end
0428 
0429 return;
0430 
0431 
0432 %%%%%%%%%%%%%%%%%%%%%%%%%
0433 function [clr,leg]=getcolor(type)
0434 
0435 clr=[ 0.2     0         0;
0436     1         0.66      0;
0437     1         0         1;
0438     0.5       0.2       1;
0439     0.2       0.2       0.8;
0440     1         0.5       0.12;
0441     0.1       0.5       0.9;
0442     0.75      1         1;
0443     0.2       0.5       0.66;
0444     0.9       0.8       0.7;
0445     0.6       0         0.1;
0446     0         0         1
0447     0.5869    0.1909    0.3461
0448     0.0576    0.8439    0.1660
0449     0.3676    0.1739    0.1556
0450     0.6315    0.1708    0.1911
0451     0.7176    0.9943    0.4225
0452     0.6927    0.4398    0.8560
0453     0.0841    0.3400    0.4902
0454     0.4544    0.3142    0.8159
0455     0.4418    0.3651    0.4608
0456     0.3533    0.3932    0.4574
0457     0.1536    0.5915    0.4507
0458     0.6756    0.1197    0.4122
0459     0.6992    0.0381    0.9016
0460     0.7275    0.4586    0.0056
0461     0.4784    0.8699    0.2974
0462     0.5548    0.9342    0.0492
0463     0.1210    0.2644    0.6932
0464     0.4508    0.1603    0.6501
0465     0.7159    0.8729    0.9830
0466     0         0         0];
0467 
0468 
0469 switch type
0470   case 'feature'
0471     leg = {'source', 'calibrator', 'abscal', 'blank', 'skydip', ...
0472     'noise_event', 'noise'};
0473     
0474   case 'bitmask'
0475     leg={'frame','receiver', 'tracking', 'tracker', 'elevation', ...
0476     'continuous', 'fifo', 'clock', '1pps', 'cryo/servo', 'backend time', 'shortfall', 'sun', 'moon'};
0477 end
0478 
0479 return;
0480 
0481 
0482 
0483 %%%%%%%%%%%%%%%%%%%%%%%%%
0484 function [m,n]=swapIndex(swap,i,j)
0485 
0486 if (swap)
0487   m=j; n=i;
0488 else
0489   m=i; n=j;
0490 end

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