Home > reduc > flag > flagData.m

flagData

PURPOSE ^

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

SYNOPSIS ^

function d = flagData(d, bitmask, flagTime)

DESCRIPTION ^

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
  function d = flagData(d, [bitmask], [flagTime])

   flags the data (from output of flagMask.m) according to the bitmask
   passed as input.  You may also pass a timerange of the data to be
   flagged.  [ ] indicates optional arguments.  if none are passed, will
   default to a set value.
  
   1st step is to flag on the bitmask (where bits are defined in flagMask.m)
   2nd step is to flag on the flagTime (if specified)
   RFI flagging occurs in deglitch module

   on exiting, you will now have a field that is
   d.flags.slow, d.flags.medium, d.flags.fast, with another field called
   d.flags.bit.(slow/medium/fast), which will list the reason why the data was flagged.

    in the .bit fields, the bits correspond
    to the following:
    bit 0 - flagged by bitmask  (antenna diagnostics flag)
    bit 1 - user flag
    bit 2 - time flag
    bit 3 - deglitch
    bit 4 - rfi
    bit 5 - position  
    bit 6 - alpha     
    bit 7 - tsys      
    bit 8 - noise     
    bit 9 - gain      
    bit 10 - tau       
    bit 11- astro     
    bit 12- rfactor   

    in the d.flags.(slow/medium/fast), the vectors will be booleans, with
    it set to high if the data is flagged for any reason.

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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function d = flagData(d, bitmask, flagTime)
0002 
0003 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0004 %
0005 %  function d = flagData(d, [bitmask], [flagTime])
0006 %
0007 %   flags the data (from output of flagMask.m) according to the bitmask
0008 %   passed as input.  You may also pass a timerange of the data to be
0009 %   flagged.  [ ] indicates optional arguments.  if none are passed, will
0010 %   default to a set value.
0011 %
0012 %   1st step is to flag on the bitmask (where bits are defined in flagMask.m)
0013 %   2nd step is to flag on the flagTime (if specified)
0014 %   RFI flagging occurs in deglitch module
0015 %
0016 %   on exiting, you will now have a field that is
0017 %   d.flags.slow, d.flags.medium, d.flags.fast, with another field called
0018 %   d.flags.bit.(slow/medium/fast), which will list the reason why the data was flagged.
0019 %
0020 %    in the .bit fields, the bits correspond
0021 %    to the following:
0022 %    bit 0 - flagged by bitmask  (antenna diagnostics flag)
0023 %    bit 1 - user flag
0024 %    bit 2 - time flag
0025 %    bit 3 - deglitch
0026 %    bit 4 - rfi
0027 %    bit 5 - position
0028 %    bit 6 - alpha
0029 %    bit 7 - tsys
0030 %    bit 8 - noise
0031 %    bit 9 - gain
0032 %    bit 10 - tau
0033 %    bit 11- astro
0034 %    bit 12- rfactor
0035 %
0036 %    in the d.flags.(slow/medium/fast), the vectors will be booleans, with
0037 %    it set to high if the data is flagged for any reason.
0038 %
0039 %    sjcm
0040 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0041 
0042 % check inputs
0043 if nargin==1
0044   bitmask = [0 1 5 6 7 8 10 12 13 14];
0045   flagTime = [];
0046 elseif nargin==2
0047   flagTime = [];
0048 end
0049 
0050 % set the flags.
0051 d = dataFilter(d, bitmask, flagTime);
0052 
0053 % report back what flags got set.
0054 reportFlags(d, bitmask);
0055 
0056 return;
0057 
0058 
0059 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0060 function d = dataFilter(d, bitmask, flagTime)
0061 
0062 % first we flag on the bitmask
0063 remSlow  = (bitand(d.flags.mask.slow, sum(2.^bitmask))) & 1;
0064 remMed   = (bitand(d.flags.mask.medium, sum(2.^bitmask))) & 1;
0065 remFast  = (bitand(repmat(d.flags.mask.fast, [1 3]), sum(2.^bitmask))) & 1;
0066 
0067 f = find(remSlow);
0068 d.flags.bit.slow(f) = bitset(d.flags.bit.slow(f),1);
0069 f = find(remMed);
0070 d.flags.bit.medium(f) = bitset(d.flags.bit.medium(f),1);
0071 f = find(remFast);
0072 d.flags.bit.fast(f) = bitset(d.flags.bit.fast(f),1);
0073 
0074 % next we do the time flagging
0075 if(~isempty(flagTime))
0076   flagTime = flagTime*6.944444444e-4;
0077   t = flagTime(:,2) - flagTime(:,1);
0078   if any(t<0)
0079     error('stop time should be after start time');
0080   end
0081   s = size(flagTime, 1);
0082 
0083   for m=1:s
0084     d = userTimeFlag(d, flagTime(m,:));
0085   end
0086 end
0087 
0088 % set the boolean flags
0089 d.flags.slow   = d.flags.bit.slow>0;
0090 d.flags.medium = d.flags.bit.medium>0;
0091 d.flags.fast   = d.flags.bit.fast>0;
0092 
0093 return;
0094 
0095 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0096 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0097 function d = userTimeFlag(d, flagTime)
0098 
0099 if flagTime(1,2) < d.array.frame.utc(1)
0100   error('time not within actual data range');
0101 elseif flagTime(1,1) > last(d.array.frame.utc)
0102   error('time outside actual data time');
0103 elseif (flagTime(1,1) < d.array.frame.utc(1)) & (flagTime(1,2) > ...
0104       d.array.frame.utc(1))
0105   flagTime(1,1) = d.array.frame.utc(1);
0106   warning('first time before data begins');
0107 elseif (flagTime(1,2) > last(d.array.frame.utc)) & ...
0108       (flagTime(1,1) < last(d.array.frame.utc))
0109   flagTime(1,2) = last(d.array.frame.utc);
0110   warning('end time after data ends');
0111 end
0112 
0113 badSlow = find( (d.array.frame.utc > flagTime(1,1)) & (d.array.frame.utc < flagTime(1,2)) );
0114 
0115 badMed = find( (d.antenna.servo.utc> flagTime(1,1)) & (d.antenna0.servo.utc < flagTime(1,2)) );
0116 
0117 badFast = find( (d.antenna0.receiver.utc > flagTime(1,1)) & (d.antenna0.receiver.utc < flagTime(1,2)) );
0118 
0119 
0120 f = find(badSlow);
0121 d.flags.bit.slow(f) = bitset(d.flags.bit.slow(f),3);
0122 f = find(badMed);
0123 d.flags.bit.medium(f) = bitset(d.flags.bit.medium(f),3);
0124 f = find(repmat(badFast, [1 3]));
0125 d.flags.bit.fast(f) = bitset(d.flags.bit.fast(f),3);
0126 
0127 return;
0128 
0129 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0130 function reportFlags(d, bitmask)
0131                                                      
0132 numFrames = length(d.flags.mask.fast);
0133 bitlist = [
0134   '                             FRAME:     ';
0135   '                           RX COLD:     ';
0136   '                     TRACKER STATE:     ';
0137   '                      TRACKER LACK:     ';
0138   '                         ELEVATION:     ';
0139   '                           WEATHER:     ';
0140   '                        CONTINUOUS:     ';
0141   '                      DATA BACKLOG:     ';
0142   '                     BACKEND CLOCK:     ';
0143   '                      BACKEND 1PPS:     ';
0144   '                   SERVO/CRYO 1PPS:     ';
0145   '                     BACKEND COMMS:     ';
0146   '             INTEGRATION SHORTFALL:     ';
0147   '                     SUN PROXIMITY:     ';
0148   '                    MOON PROXIMITY:     ';
0149   '                  CONTROL BUILDING:     '];
0150 
0151 last = ['                             TOTAL:     '];
0152 
0153 for m=1:length(bitmask)
0154   rem(m) = sum(bitand(d.flags.mask.fast, 2^bitmask(m)) & 1);
0155 end
0156 total = sum(d.flags.fast(:,1));
0157 
0158 
0159 display(sprintf('               -----------------------------------------------------'))
0160 display(sprintf('               ------------------ FLAGGING REPORT ------------------'));
0161 display(sprintf('               -----------------------------------------------------\n'))
0162 
0163 
0164 
0165 display(sprintf('               Out of %6d frames, the number flagged follows:\n', numFrames));
0166 display(sprintf('               ------------------- ANTENNA FLAGS ----------------'));
0167 for m=1:length(bitmask)
0168   display(sprintf('%s %6d ', bitlist(bitmask(m)+1,:), rem(m)));
0169 end
0170 display(sprintf('\n%s %6d \n\n', last(:), total));
0171 
0172 return;

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