Home > reduc > support > skim.m

skim

PURPOSE ^

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

SYNOPSIS ^

function info=skim(d,parm, printout,thedate_day_portion)

DESCRIPTION ^

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

 info=skim(d,parm)

 summary of data

 p = 1 prints output
     if p does not exist, defaults to true

 if no output (info) specified, there will be no output

  info.track.start (time)
  info.track.stop  (time)   
  info.track.intTime (minutes)
  info.track.perFlag (percentFlagged)
  info.track.numScans (number of scans)
  info.FIELDNAME.intTime (minutes)
  info.FIELDNAME.perFlag (percent Flagged)
  
  where FIELDNAME is all fields in index field, as well as one for the overall track
  sjcm
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function info=skim(d,parm, printout,thedate_day_portion)
0002 
0003 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0004 %
0005 % info=skim(d,parm)
0006 %
0007 % summary of data
0008 %
0009 % p = 1 prints output
0010 %     if p does not exist, defaults to true
0011 %
0012 % if no output (info) specified, there will be no output
0013 %
0014 %  info.track.start (time)
0015 %  info.track.stop  (time)
0016 %  info.track.intTime (minutes)
0017 %  info.track.perFlag (percentFlagged)
0018 %  info.track.numScans (number of scans)
0019 %  info.FIELDNAME.intTime (minutes)
0020 %  info.FIELDNAME.perFlag (percent Flagged)
0021 %
0022 %  where FIELDNAME is all fields in index field, as well as one for the overall track
0023 %  sjcm
0024 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0025 
0026 if (~exist('parm'))
0027   parm = [];
0028 end
0029 
0030 % setup month cell array
0031 month={'jan','feb','mar','apr','may','jun', ...
0032        'jul','aug','sep','oct','nov','dec'};
0033 
0034 flag=0;
0035 if (isfield(d,'flags'))
0036   if (isfield(d.flags,'fast'))
0037     flag=1;
0038   end
0039 end
0040 
0041 flag_intent_filename = ['flag_intent_',thedate_day_portion,'.txt'];
0042 flag_step_filename = ['flag_step_',thedate_day_portion,'.txt'];
0043 
0044 
0045 start=mjd2date_v2(d.array.frame.utc(1));
0046 stop=mjd2date_v2(last(d.array.frame.utc));
0047 info.track.start = start;
0048 info.track.stop  = stop;
0049 start=date2str(start);
0050 stop=date2str(stop);
0051 
0052 info.track.intTime = size(d.antenna0.receiver.data,1)/100/60;
0053 perFlag = length(find(d.flags.fast))./length(d.flags.fast(:))*100;
0054 info.track.perFlag = perFlag;
0055 
0056 % find the number of scans
0057 [junk ind] = cutObs(d, 'source', 'only');
0058 f = find(ind);
0059 ff = find(diff(f)>2);
0060 numScans = length(ff);
0061 info.track.numScans = numScans;
0062 
0063 % all we want is a measure of how much data is flagged for each of the separate fields.
0064 
0065 fieldList = fieldnames(d.index);
0066 for m=1:length(fieldList)
0067      eval(sprintf('dcut = cutObs(d, ''%s'', ''only'');', fieldList{m}));
0068      perFlag = length(find(dcut.flags.fast))./length(dcut.flags.fast(:))*100;
0069      intTime = size(dcut.antenna0.receiver.data,1)/100/60;
0070      if(isnan(perFlag))
0071        perFlag = 0;
0072      end
0073      
0074      eval(sprintf('info.%s.perFlag = perFlag;', fieldList{m}));
0075      eval(sprintf('info.%s.intTime = intTime;', fieldList{m}));
0076 end
0077 
0078 
0079 %  next we want to get how much was flagged at each stage.
0080 
0081 % get our flag indices in a parseable form
0082 fa = getFlagNames();
0083 prevSet = zeros(size(d.flags.fast));
0084 numPoints = size(d.flags.fast,1);
0085 for mm=1:length(fa)
0086   perFlag = [0 0 0];
0087   thisIndex = uint32(zeros(size(d.flags.fast)));
0088   [aa bb bitNum] = setNewFlag([],[],fa{mm});
0089   thisIndex = bitset(thisIndex, bitNum);
0090   isSet = bitand(thisIndex, d.flags.bit.fast) >0;
0091   
0092   thisSet = isSet - prevSet > 0;
0093   for mmm=1:3
0094     l = length(find(thisSet(:,mmm)));
0095     perFlag(1,mmm) = l./numPoints*100;
0096   end
0097   
0098   eval(sprintf('info.flag.%s = perFlag;', fa{mm}));
0099 end
0100 
0101 % total flags
0102 perFlag = [0 0 0];
0103 for mmm=1:3
0104   l = length(find(d.flags.fast(:,mmm)));
0105   perFlag(1,mmm) = l./numPoints*100;
0106 end
0107 
0108 info.flag.TOTAL = perFlag;
0109 
0110 
0111 if(0)
0112   
0113   % print all the crap out
0114   disp(' ')
0115   disp('                         Track Summary')
0116   disp('================================================================')
0117   disp(' ')
0118   disp('Observation schedule')
0119   disp(sprintf('  Start: %2s-%s-%4u:%2s:%2s:%5s',start.day,month{start.month},...
0120       start.year, start.hour, start.minute, start.second));
0121   disp(sprintf('  Stop:  %2s-%s-%4u:%2s:%2s:%5s',stop.day,month{stop.month},...
0122       stop.year, stop.hour, stop.minute, stop.second));
0123   disp(sprintf('  Number of Scans: %d', info.track.numScans));
0124   disp(sprintf('  Total time of Track: %2.2f', info.track.intTime));
0125   disp(sprintf('  Percent of total Data Flagged: %2.2f', info.track.perFlag));
0126   
0127   
0128   disp(' ');
0129   disp(' ');
0130   
0131   disp('   Intent          Integration [min]    Percent Flagged')
0132   disp('-------------      -----------------    ---------------')
0133 
0134   names = fieldnames(info);
0135   for m=1:length(names)
0136     thisName = names{m};
0137     eval(sprintf('thisData = info.%s;', thisName));
0138     
0139     if(m==1 | m==2 | m==4 | m==5 | m==6 | m==12)
0140       txt = sprintf('%s \t \t \t %8.2f \t    %8.2f', thisName, thisData.intTime, thisData.perFlag);
0141     elseif(m==3 | m==9 | m==10 |m==11)
0142     txt = sprintf('%s  \t \t %8.2f \t    %8.2f', thisName, ...
0143       thisData.intTime, thisData.perFlag);    
0144     elseif(m==14)
0145       % do nothing -- flags structure
0146     else
0147     txt = sprintf('%s  \t %8.2f \t    %8.2f', thisName, ...
0148       thisData.intTime, thisData.perFlag);          
0149     end
0150     disp(txt)
0151   end
0152   
0153   
0154   disp(' ');
0155   disp(' ');
0156   
0157   disp('   Routine         Flag Percent: [ I1, Pol, I2 ] ');
0158   disp('-------------      ------------------------------');
0159   names = fieldnames(info.flag);
0160   for m=1:length(names)
0161     if(strmatch(names{m}, 'tsys', 'exact'))
0162       txt = sprintf('tsys \t \t    %d of %d measurements', ...
0163       length(find(d.correction.tsys.flag)), ...
0164       length(find(d.correction.tsys.val)));
0165       disp(txt)
0166     elseif(strmatch(names{m}, 'noise', 'exact'))
0167       txt = sprintf('diode temp \t    %d of %d measurements', ...
0168       length(find(d.correction.tsys.flag)), ...
0169       length(find(d.correction.tsys.val)));
0170       disp(txt)      
0171     elseif(strmatch(names{m}, 'gain', 'exact'))
0172       txt = sprintf('gain \t  \t    %d of %d measurements', ...
0173       length(find(d.correction.gain.flag)), ...
0174       length(find(d.correction.gain.val)));
0175       disp(txt);
0176     elseif(strmatch(names{m}, 'tau', 'exact'))
0177       txt = sprintf('tau \t \t    %d of %d measurements', ...
0178       length(find(d.correction.tau.flag)), ...
0179       length(find(d.correction.tau.values(:,5:6))));
0180       disp(txt);
0181     else
0182       
0183       eval(sprintf('thisData = info.flag.%s;', names{m}));
0184       if(m==1 | m==4 | m==6 | m==7 | m==10 | m==17)
0185     txt = sprintf('%s \t    [ %4.2f, %4.2f, %4.2f ]', names{m}, thisData(:));
0186       else
0187     txt = sprintf('%s \t \t    [ %4.2f, %4.2f, %4.2f ]', names{m}, ...
0188         thisData(:));
0189       end
0190       disp(txt)
0191     end
0192   end
0193 end
0194 
0195 info = rmfield(info, 'ncp');
0196 
0197 
0198 % write out the summary data to two text files.
0199 % FILE 1 FORMAT -- flags per "source"
0200 % starttime stoptime numscans inttime perflag source.time source.flag
0201 % elscan.time elscan.flag cal.time cal.scan, .... noiseevent.time
0202 % noiseevent.flag
0203 thisFlag1 = [date2mjd_v2(info.track.start) date2mjd_v2(info.track.stop) ...
0204       info.track.numScans info.track.intTime info.track.perFlag];
0205 sa = fieldnames(info);
0206 for m=2:length(sa)-1
0207   eval(sprintf('thisEntry = [info.%s.intTime info.%s.perFlag];', sa{m}, ...
0208       sa{m}));
0209   thisFlag1 = [thisFlag1, thisEntry];
0210 end
0211 
0212 
0213 % FILE 2 FORMAT  -- flags per step
0214 % starttime stoptime numscans inttime perflag antennaflag userflag timeflag
0215 % deglitchflag .... rfactorflag totalflag
0216 thisFlag2 = [date2mjd_v2(info.track.start) date2mjd_v2(info.track.stop) ...
0217       info.track.numScans info.track.intTime info.track.perFlag];
0218 sa = fieldnames(info.flag);
0219 for m=1:length(sa)
0220   eval(sprintf('thisEntry = mean(info.flag.%s);', sa{m}));
0221   thisFlag2 = [thisFlag2, thisEntry];
0222 end
0223 
0224 % next, we save them.
0225 if(checkpar(parm, 'autosave'))
0226   [home,installeddir]=where_am_i();
0227   
0228   %allFlag1 = load([home,'/',installeddir,'/constants/flag_intent.txt']);
0229   %allFlag1 = [allFlag1; thisFlag1];
0230   save([home,'/',installeddir,'/constants/flag_intent.txt'], 'thisFlag1', '-ascii', '-single','-append')
0231   save([home,'/',installeddir,'/constants/',flag_intent_filename], 'thisFlag1', '-ascii', '-single','-append')
0232   % should add cvs update and commit to these.
0233   
0234   %allFlag2 = load([home,'/',installeddir,'/constants/flag_step.txt']);
0235   %allFlag2 = [allFlag2; thisFlag2];
0236   save([home,'/',installeddir,'/constants/flag_step.txt'], 'thisFlag2', '-ascii', '-single','-append')  
0237   save([home,'/',installeddir,'/constants/',flag_step_filename], 'thisFlag2', '-ascii', '-single','-append')
0238 
0239 end  
0240 
0241 return;
0242 
0243 
0244 
0245 
0246 %%%%%%%%%%%%%%%%%%%%%%%
0247 function s=date2str(s)
0248 
0249 month=s.month;
0250 sec=s.second;
0251 year=s.year;
0252 s=rmfield(s,'month');
0253 s=rmfield(s,'second');
0254 s=rmfield(s,'year');
0255 n=fieldnames(s);
0256 
0257 for i=1:length(n)
0258   eval(sprintf('s.%s=num2str(s.%s);',n{i},n{i}));
0259   if (eval(sprintf('length(s.%s)<2',n{i})))
0260     eval(sprintf('s.%s=strcat(''0'',s.%s);',n{i},n{i}));
0261   end
0262 end
0263 
0264 if (sec<10)
0265   sec=num2str(sec,3);
0266   sec=strcat('0',sec);
0267 else
0268   sec=num2str(sec,4);
0269 end
0270 
0271 s.year=year;
0272 s.second=sec;
0273 s.month=month;
0274 
0275 
0276     
0277   
0278   
0279

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