Home > reduc > flag > massageDataSa.m

massageDataSa

PURPOSE ^

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

SYNOPSIS ^

function d = massageData(d)

DESCRIPTION ^

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  function d = massageData(d)
  
  this function should be used to massage any eccentricities we find with
  previous data.  one example is the weird azimuth offset in the encoder
  values in january 2010, or the timing error that was found.  please
  document whatever it is you are fixing.

  sjcm

%%%%%%%%%%
 Edit 1:
 Fixed it to not crash when only temperature sensor data is read in
 ogk
%%%%%%%%%%
 Edit 2:
 Fixed it to not crash when only frame data is read in
 ogk
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%
 Edit 3:
 Fixed it so that if Tracker Thread Timing Issue is really bad (i.e
 21-Jul-2010:13:02:25 Time End: 21-Jul-2010:15:18:08) then the process
 errors out
 CJC 23/8/2010
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function d = massageData(d)
0002 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0003 %  function d = massageData(d)
0004 %
0005 %  this function should be used to massage any eccentricities we find with
0006 %  previous data.  one example is the weird azimuth offset in the encoder
0007 %  values in january 2010, or the timing error that was found.  please
0008 %  document whatever it is you are fixing.
0009 %
0010 %  sjcm
0011 %
0012 %%%%%%%%%%%
0013 % Edit 1:
0014 % Fixed it to not crash when only temperature sensor data is read in
0015 % ogk
0016 %%%%%%%%%%%
0017 % Edit 2:
0018 % Fixed it to not crash when only frame data is read in
0019 % ogk
0020 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0021 %%%%%%%%%%%
0022 % Edit 3:
0023 % Fixed it so that if Tracker Thread Timing Issue is really bad (i.e
0024 % 21-Jul-2010:13:02:25 Time End: 21-Jul-2010:15:18:08) then the process
0025 % errors out
0026 % CJC 23/8/2010
0027 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0028 
0029 if(~isfield(d, 'array'))
0030   return;
0031 end
0032 
0033 %%%%%%%%%%%%%%%%
0034 % Added by ogk in edit 1
0035 if(~isfield(d.array, 'frame'))
0036   return;
0037 end
0038 %%%%%%%%%%%%%%%%
0039 
0040 
0041 % timing fix for times before feb , 2010
0042 if(d.array.frame.utc(1)<55230)
0043   if(isfield(d, 'antenna0'));
0044     if(isfield(d.antenna0, 'receiver'))
0045       d.antenna0.receiver.utc = ...
0046       d.antenna0.receiver.utc-0.3/24/60/60;
0047     end
0048     if(isfield(d.antenna0, 'servo'))
0049       d.antenna0.servo.utc = ...
0050       d.antenna0.servo.utc+0.5/24/60/60;
0051     end
0052   end
0053 elseif(d.array.frame.utc(1)>55230 & d.array.frame.utc(1)<55244)
0054   if(isfield(d, 'antenna0'));  
0055     if(isfield(d.antenna0, 'servo'))
0056       d.antenna0.servo.utc = d.antenna0.servo.utc+0.5/24/60/60;
0057     end
0058   end
0059 end
0060 
0061 
0062 % fix for az position offset from Jan 22 to Jan 27, 2010
0063 if(d.array.frame.utc(1)>55218 & d.array.frame.utc(1)<55223)
0064   if(isfield(d, 'antenna0'))
0065     if(isfield(d.antenna0, 'servo'))
0066       if(isfield(d.antenna0.servo, 'fast_az_pos'))
0067     d.antenna0.servo.fast_az_pos = ...
0068         d.antenna0.servo.fast_az_pos-22.42;
0069     d.antenna0.servo.slow_az_pos = ...
0070         d.antenna0.servo.slow_az_pos-22.42;
0071       end
0072     end
0073   end
0074 end
0075 
0076 % OGK edit 2: Added conditional nature of the call to fixTimingOrder
0077 % let's fix the order of the timing.
0078 if(isfield(d, 'antenna0'))
0079   if(isfield(d.antenna0, 'servo') && isfield(d.antenna0, 'receiver') && ...
0080     isfield(d.antenna0, 'thermal'))
0081         d = fixTimingOrder(d);
0082   end
0083 end
0084 % next we check that no times are doubled.
0085 
0086 % this one's weird:  the clock for the tracker thread sometimes doesn't
0087 % update -- it not only causes the problems with the control system that
0088 % matthew saw at the beginning of july, but it also makes the data have
0089 % issues being processed.  This fix only takes care of the data being
0090 % processed.
0091 
0092 if(isfield(d, 'antenna0'))
0093   if(isfield(d.antenna0, 'tracker'))
0094     dt = deriv(d.antenna0.tracker.utc)*24*60*60;
0095     ind = dt>1.1 | dt<0.9;
0096     if(~isempty(find(ind)))
0097       l = length(find(ind));
0098       display('Tracker Thread Timing Issue');
0099       display(sprintf('Issue affected %d out of %d data samples', l, length(ind)));
0100       display('Fixing data for postprocessing');
0101       P=polyfit([1:length(d.antenna0.tracker.utc)]',d.antenna0.tracker.utc,1);
0102       d.antenna0.tracker.utc = polyval(P,[1:length(d.antenna0.tracker.utc)]');
0103       %d.antenna0.tracker.utc(ind) = d.array.frame.utc(ind) + 1/24/60/60;
0104       display('Fixed data for postprocessing');
0105       %STUPID THING TO ADD
0106 %      if(l/length(ind)>0.01)%added by CJC for really bad data 23/8/2010
0107 %          error('massageData:Chk','Error massaging the data')%added by CJC for really bad data 23/8/2010
0108 %      end
0109     end
0110   end
0111 end
0112 
0113 
0114 %if(isfield(d, 'antenna0'))
0115 %  if(isfield(d.antenna0, 'receiver'))
0116 %    if(isfield(d.antenna0.receiver, 'gateVoltage'))
0117 %      d.antenna0.lna.drainCurrent = d.antenna0.receiver.drainCurrent;
0118 %      d.antenna0.lna.drainVoltage = d.antenna0.receiver.drainVoltage;
0119 %      d.antenna0.lna.gateVoltage  = d.antenna0.receiver.gateVoltage;
0120 %      d.antenna0.receiver = rmfield(d.antenna0.receiver, 'drainCurrent');
0121 %      d.antenna0.receiver = rmfield(d.antenna0.receiver, 'drainVoltage');
0122 %      d.antenna0.receiver = rmfield(d.antenna0.receiver, 'gateVoltage');
0123 %    end
0124 %  end
0125 %end
0126 
0127 
0128 return;
0129 
0130 
0131 function dfinal = fixTimingOrder(d)
0132 % basically the servo and the receiver data are from two seconds ago,
0133 % cryocon is from 1 second ago, and the data frame is current time
0134 
0135 if(isfield(d, 'antenna0'))
0136   if(~isfield(d.antenna0, 'servo') | ~isfield(d.antenna0, 'receiver') | ...
0137     ~isfield(d.antenna0, 'thermal'))
0138     dfinal = d;
0139     return;
0140   end
0141 end
0142 
0143 if(~isfield(d.antenna0.receiver, 'data'))
0144   dfinal = d;
0145   return;
0146 end
0147 
0148 
0149 dservo = d.antenna0.servo;
0150 dreceiver = d.antenna0.receiver;
0151 dthermal = d.antenna0.thermal;
0152 lengthOrig = size(d.array.frame.utc);
0153 
0154 % now from dfinal we cut out the last frame and from everything else we cut
0155 % out the first frame.
0156 indFinal = ones(lengthOrig);
0157 indFinal(length(indFinal)-1:length(indFinal)) = 0;
0158 
0159 indFinal = ones(lengthOrig);
0160 indFinal(1:2) = 0;
0161 dservo = framecutSub(dservo, logical(indFinal));
0162 dreceiver = framecutSub(dreceiver, logical(indFinal));
0163 
0164 indFinal = ones(lengthOrig);
0165 indFinal([1 length(indFinal)]) = 0;
0166 dthermal = framecutSub(dthermal, logical(indFinal));
0167 
0168 dfinal = framecutSub(d, logical(indFinal));
0169 clear d;
0170 dfinal.antenna0.receiver = dreceiver;
0171 dfinal.antenna0.servo.utc = dservo.utc;
0172 dfinal.antenna0.servo.fast_az_pos = dservo.fast_az_pos;
0173 dfinal.antenna0.servo.fast_el_pos = dservo.fast_el_pos;
0174 dfinal.antenna0.servo.fast_az_err = dservo.fast_az_err;
0175 dfinal.antenna0.servo.fast_el_err = dservo.fast_el_err;
0176 dfinal.antenna0.thermal.utc       = dthermal.utc;
0177 dfinal.antenna0.thermal.ccTemperatureLoad = dthermal.ccTemperatureLoad;
0178 
0179 % now all the data should be on the same timescale, which should make things
0180 % easier to cut/etc.
0181 
0182 return;
0183               
0184               
0185 
0186 function d = framecutSub(d, ind)
0187 
0188 names=fieldnames(d);
0189 for i=1:length(names)
0190   if(eval(sprintf('isstruct(d.%s)',names{i})))
0191     eval(sprintf('d.%s=framecutSub(d.%s,ind);',names{i},names{i}));
0192   else
0193     eval(sprintf('d.%s=regcut(d.%s,ind);',names{i},names{i}));            
0194   end
0195 end
0196 
0197 return
0198 
0199 %%%%%%%%%%%%%%%%%%%%%%%%
0200 function r=regcut(r,ind)
0201 
0202 switch(ndims(r))
0203   case 1
0204     r=r(ind);
0205   case 2
0206     r=r(ind,:);
0207   case 3
0208     r=r(ind,:,:);
0209   case 4
0210     r=r(ind,:,:,:);
0211 end
0212 
0213 return

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