Home > reduc > plotting > genfig.m

genfig

PURPOSE ^

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

SYNOPSIS ^

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

DESCRIPTION ^

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

  function that generates figures for a webpage.

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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function genfig(d,flags,xc,txt,ax,type, p, field, saveplot, maindir)
0002 
0003 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0004 %
0005 %  function genfig(d,flags,xc,txt,ax,type, p, field, saveplot)
0006 %
0007 %  function that generates figures for a webpage.
0008 %
0009 %  sjcm
0010 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0011 
0012 if(nargin<9)
0013   saveplot = 1;
0014   maindir = [];
0015 end
0016 if(nargin<10)
0017   maindir = [];
0018 end
0019 
0020   
0021 
0022 % check for axis setting
0023 if (~exist('ax'))
0024   ax=[];
0025 end
0026 
0027 if(saveplot)
0028   % get the directory to write to
0029   if(isempty(maindir))
0030     maindir=getMainDir(d, field);
0031   end
0032 end
0033 
0034   
0035 % num is the number of pages to be displayed.
0036 % matrix is the size of each of the pages to be displayed.
0037 if(~p.swap)
0038   num = size(xc,2);
0039   plotsPerPage = size(xc{2,1},2);
0040   if(plotsPerPage==6)
0041     matrix = [2 3];
0042   elseif(plotsPerPage==1)
0043     matrix = [1 1];
0044   elseif(plotsPerPage==24)
0045     matrix = [2 3];
0046     plotsPerPage = 6;
0047   elseif(plotsPerPage==2)
0048     % opacity plots
0049     matrix = [2 1];
0050     plotsPerPage = 2;
0051   else
0052     error('Unrecognized number of plots');
0053   end
0054 else
0055   num = size(xc{2,1},2);
0056   plotsPerPage = size(xc,2);
0057   matrix = ceil(sqrt(size(xc,2)));
0058   matrix = [matrix; matrix];
0059 end
0060 
0061 %close all
0062 
0063 for pageNum=1:num
0064 
0065   if(plotsPerPage==2)
0066     setwinsize(gcf, 1000, 400);
0067   else
0068     setwinsize(gcf, 1000, 750); 
0069   end
0070   for plotNum=1:plotsPerPage
0071     subplot(matrix(1), matrix(2), plotNum);
0072     
0073     [m,n]=swapIndex(p.swap,pageNum,plotNum);
0074     switch p.style
0075       case 'flag'
0076     h(pageNum,plotNum)=plotflag(xc,flags,ax,m,n,txt,num,matrix,p.swap);
0077     
0078       case 'feature'
0079     [h(pageNum,plotNum),leg]=plotfeat(xc,flags,ax,m,n,txt,num, ...
0080         matrix,p.swap, p.type);
0081     
0082     end
0083   end
0084   if (strcmp(p.style,'feature') & ~isempty(leg))
0085     legend(leg,'Location','Best');
0086     leg=[];
0087   end
0088   if(length(txt)==5)
0089     eval(sprintf('legend(''%s'', ''%s'', ''Location'',''Best'');', ...
0090     txt{5}{1}, txt{5}{2}));    
0091   end    
0092   
0093   if (length(txt)>3)
0094     gtitle(txt{4});
0095   end
0096 
0097 
0098   if(saveplot==1)
0099     dbclear if error
0100     set(gcf,'paperposition',[0 0 6.0 6.0])
0101     eval(sprintf('print -dpng -r200 %s/%s/fig%u.png;', ...
0102     maindir,type,pageNum));
0103     dbstop if error
0104   else
0105     pause(1);
0106   end
0107   
0108   pageNum=pageNum+1;
0109 end
0110 
0111 
0112 return;
0113 
0114 
0115 %%%%%%%%%%%%%%%%%%%%%%%%%
0116 function [h, leg] = plotfeat(x,allflags,ax,pageNum,plotNum,txt,num,matrix,swap, type)
0117 
0118 % get the features to plot
0119 % we only have {source, calibrator, abscal, blank, skydip, noise_event, and noise}
0120 
0121 % get the color and legend
0122 [clr, legall] = getcolor(type,x);
0123 
0124 % we only need to plot the ones with legall
0125 switch type
0126   case 'allflags'
0127     % first we just plot the data
0128     h = plot(x{1,pageNum}, x{2,pageNum}(:,plotNum), 'k.');  hold on
0129     index = 2;
0130     leg{1} = 'data';
0131     
0132   case 'feature'
0133     index = 1;
0134     leg = [];
0135     h = [];
0136 end
0137 
0138 for m=1:length(legall)
0139   switch type
0140     case 'allflags'
0141       txt1 = sprintf('a = x{1,pageNum}(x{3,pageNum}.%s(:,plotNum));', legall{m});
0142       txt2 = sprintf('b = x{2,pageNum}(x{3,pageNum}.%s(:,plotNum), plotNum);', legall{m});
0143       
0144     case 'feature'
0145       txt1 = sprintf('a = x{1,pageNum}(x{3,pageNum}.%s);', legall{m});
0146       txt2 = sprintf('b = x{2,pageNum}(x{3,pageNum}.%s, plotNum);', legall{m});
0147   end
0148 
0149   eval(txt1); eval(txt2);
0150 
0151   % do not plot if there are no data points to plot
0152   if(sum(a)>0)
0153     txtPlot = sprintf('h = plot(a, b, ''.'', ''markerfacecolor'', clr(m,:), ''markeredgecolor'', clr(m,:), ''MarkerSize'',5);');
0154     eval(txtPlot);
0155     hold on;
0156     leg{index} = legall{m};
0157     index = index+1;
0158   end
0159 end  
0160 
0161 if(isempty(h))
0162   % no data to plot in this section
0163   a = x{1,pageNum};
0164   b = zeros(size(a));
0165   h = plot(a,b,'w');
0166   text(a(1), b(1), 'DATA HAS NO INTENT', 'FontSize', 18);
0167   text(a(1), -0.25, 'FOR THIS TIME PERIOD', 'FontSize', 18);
0168 end
0169 
0170 ax(1) = min(x{1,pageNum});
0171 ax(2) = max(x{1,pageNum});
0172 ax(3) = min(x{2,pageNum}(:,plotNum));
0173 ax(4) = max(x{2,pageNum}(:,plotNum));
0174 manaxis(ax,x{2,pageNum}(:,plotNum))
0175 plotdescription(txt,plotNum,pageNum,num,matrix,swap);
0176 
0177 hold off
0178     
0179 return;
0180 
0181 
0182 %%%%%%%%%%%%%%%%%%%%%%%%%
0183 function h=plotflag(x,allflags,ax,pageNum,plotNum,txt,num,matrix,swap, multLinesPerPlot)
0184 
0185 % if x has a fourth dimension, plot that first
0186 if(size(x,1)==4)
0187   if(size(x{1,pageNum},1) == size(x{4,pageNum},1))
0188     plot(x{1,pageNum},x{4,pageNum}(:,plotNum),'c.','MarkerSize',5);
0189     hold on;
0190     ymin = min([min(x{4,pageNum}(:,plotNum)) min(x{2,pageNum}(:,plotNum))]);
0191     ymax = max([max(x{4,pageNum}(:,plotNum)) max(x{4,pageNum}(:,plotNum))]);
0192     yvals = [x{4,pageNum}(:,plotNum); x{2,pageNum}(:,plotNum)];
0193   else
0194     plot(x{3,pageNum},x{4,pageNum}(:,plotNum),'c.','MarkerSize',5);
0195     ymin = min([min(x{4,pageNum}(:,plotNum)) min(x{2,pageNum}(:,plotNum))]);
0196     ymax = max([max(x{4,pageNum}(:,plotNum)) max(x{4,pageNum}(:,plotNum))]);
0197     yvals = [x{4,pageNum}(:,plotNum); x{2,pageNum}(:,plotNum)];
0198     hold on;
0199   end
0200 else
0201   ymin = min(x{2,pageNum}(:,plotNum));
0202   ymax = max(x{2,pageNum}(:,plotNum));
0203   yvals = [x{2,pageNum}(:,plotNum)];
0204 end
0205 if(ymin < 0)
0206   ymin = 1.05*ymin;
0207 else
0208   ymin = 0.95*ymin;
0209 end
0210 if(ymax < 0)
0211   ymax = 0.95*ymax;
0212 else
0213   ymax = 1.05*ymax;
0214 end
0215 
0216 % plot data
0217 h=plot(x{1,pageNum},x{2,pageNum}(:,plotNum),'b.','MarkerSize',5);
0218 hold on
0219 plot(x{1,pageNum},x{2,pageNum}(:,plotNum),'b.','MarkerSize',5);
0220 ax(1) = min(x{1,pageNum});
0221 ax(2) = max(x{1,pageNum});
0222 ax(3) = ymin;
0223 ax(4) = ymax;
0224 
0225 if(ax(1) == ax(2))
0226   ax(1) = ax(1) - 0.05;
0227   ax(2) = ax(1) + 0.1;
0228 end
0229 
0230 manaxis(ax,yvals);
0231 hold on;
0232 
0233 plotdescription(txt,plotNum,pageNum,num,matrix,swap);
0234 
0235 
0236 % check for manual axis settings
0237 manaxis(ax,yvals);
0238 
0239 % plot order is IMPORTANT!
0240 numpts = size(x{1,pageNum},1);
0241   
0242 % plot old flags
0243 if (~isempty(allflags{2,pageNum}))
0244   f = find(allflags{2,pageNum}(:,plotNum));
0245   if (~isempty(f))
0246     h=plot(x{1,pageNum}(f),x{2,pageNum}(f,plotNum),'g.','MarkerSize',5);
0247   end
0248 end           
0249 
0250 % plot new
0251 if (~isempty(allflags{1,pageNum}))
0252   % always plotting fast sampled data.
0253   f = find(allflags{1,pageNum}(:,plotNum));
0254   if (~isempty(f))
0255     h=plot(x{1,pageNum}(f),x{2,pageNum}(f,plotNum),'r.','MarkerSize',5);
0256   end
0257 end
0258 if(min(x{1,pageNum}) ~= max(x{1,pageNum}))
0259   xlim([min(x{1,pageNum}) max(x{1,pageNum})]);
0260 end
0261 
0262 hold off
0263 
0264 return;
0265 
0266 %%%%%%%%%%%%%%%%%%%%%%%%%
0267 function plotdescription(txt,n,m,num,matrix,swap)
0268 
0269 if(length(txt{1})>1)
0270   title(txt{1}{n});
0271   xlabel(char(txt{2}));
0272   ylabel(char(txt{3}));
0273   return;
0274 end
0275 
0276 
0277 if (matrix(1)==2 & matrix(2)==3)
0278   % plot of channels
0279   title(sprintf('Channel: %u', n));
0280 elseif (matrix(1)==4 & matrix(2)==6)
0281   % plot of switch states
0282   title(sprintf('Switch State Number: %u Ant: %u',n));
0283 elseif (num==6)
0284   % channels plotted in time
0285   title(sprintf('Channel Number: %u', m));
0286 elseif(num==24)
0287   % phase switch in time
0288   title(sprintf('Switch State Number: %u', m));
0289 elseif(matrix(1) == 1 & matrix(2)==2)
0290   % opacity plots
0291   title(sprintf('Total Intensity Channel: %u', n));
0292 end
0293 
0294 if(~isempty(txt))
0295   xlabel(char(txt{2}));
0296   ylabel(char(txt{3}));
0297 end
0298 
0299 return;
0300 
0301 
0302 %%%%%%%%%%%%%%%%%%%%%%%%%
0303 function manaxis(ax,y)
0304 
0305 if (~isempty(ax))
0306   ax4orig = ax(4);
0307   ymax=max(y)*1.1;
0308   if (max(y)>ax(4))
0309     % if max y is larger than mean
0310     ax(4)=ymax;
0311   elseif (8*nanmean(y)<ax(4) & ax(3)>=0)
0312     % if global mean (ax(4)) is much greater than the
0313     % local y data, rescale
0314     % but if ax(3)<0, that means we're looking at phase
0315     % so don't do anything.
0316     ax(4)=ymax;
0317   elseif (isnan(ax(4)) | isnan(ax(3)))
0318     if (isnan(ax(4)))
0319       ax(4)=1;
0320     end
0321     if (isnan(ax(3)))
0322       ax(3)=0;
0323     end
0324   end
0325   % this is in place until mike comes up with a better way to do
0326   % this - all the previous stuff at times resets the value of
0327   % ax(4) so that it is below that of ax(3) - i don't feel like
0328   % trying to figure out mike's logic, so here's a fix;
0329   if(ax(3) >= ax(4))
0330     if(ax4orig>ax(3))
0331           ax(4) = ax4orig;
0332     else
0333       ax(4) = ax(3)+1;
0334     end
0335   end
0336   axis(ax);
0337 end
0338 
0339 return;
0340 
0341 %%%%%%%%%%%%%%%%%%%%%%%%%
0342 function [clr,leg]=getcolor(type,x)
0343 
0344 clr=[ 0.2     0         0;
0345     1         0.66      0;
0346     1         0         1;
0347     0.5       0.2       1;
0348     0.2       0.2       0.8;
0349     1         0.5       0.12;
0350     0.1       0.5       0.9;
0351     0.75      1         1;
0352     0.2       0.5       0.66;
0353     0.9       0.8       0.7;
0354     0.6       0         0.1;
0355     0         0         1
0356     0.5869    0.1909    0.3461
0357     0.0576    0.8439    0.1660
0358     0.3676    0.1739    0.1556
0359     0.6315    0.1708    0.1911
0360     0.7176    0.9943    0.4225
0361     0.6927    0.4398    0.8560
0362     0.0841    0.3400    0.4902
0363     0.4544    0.3142    0.8159
0364     0.4418    0.3651    0.4608
0365     0.3533    0.3932    0.4574
0366     0.1536    0.5915    0.4507
0367     0.6756    0.1197    0.4122
0368     0.6992    0.0381    0.9016
0369     0.7275    0.4586    0.0056
0370     0.4784    0.8699    0.2974
0371     0.5548    0.9342    0.0492
0372     0.1210    0.2644    0.6932
0373     0.4508    0.1603    0.6501
0374     0.7159    0.8729    0.9830
0375     0         0         0];
0376 
0377 
0378 switch type
0379   case 'feature'
0380     leg = fieldnames(x{3});
0381 
0382   case 'allflags'
0383     leg = getFlagNames;
0384 
0385   case 'bitmask'
0386     leg={'frame','receiver', 'tracking', 'tracker', 'elevation', ...
0387     'continuous', 'fifo', 'clock', '1pps', 'cryo/servo', 'backend time', 'shortfall', 'sun', 'moon'};
0388 end
0389 
0390 return;
0391 
0392 
0393 
0394 %%%%%%%%%%%%%%%%%%%%%%%%%
0395 function [m,n]=swapIndex(swap,i,j)
0396 
0397 if (swap)
0398   m=j; n=i;
0399 else
0400   m=i; n=j;
0401 end

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