Home > reduc > support > rfiWrapper.m

rfiWrapper

PURPOSE ^

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

SYNOPSIS ^

function d = rfiWrapper(d, plotparams, parm, field,thedate_day_portion);

DESCRIPTION ^

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

  function d = rfiWrapper(d, plotparams, parm, field)

    reduceData function that calls the rfi algorithm with
    parameters parm.


    sjcm

    Modified Oct 8, 2010 (MAS):  Switched in new RFI flagging for noise
    diode events.

    Modified Dec 20, 2010 (MAS):  Switched in generalized RFI flagging for
    all data.  Removed distinction and need for two rfi flagging sessions.

    Modified Jan 7, 2011 (MAS):  Got rid of the stageNum parameter.
    
    3/29/2011 (SJCM):  no plotting but saving plots

    Modified Apr 15, 2011 (MAS):  Updated to latest algorithm.  
    Added support for user parameters.  Added spatial flagging.

    Modified Sep 10, 2012 (MAS):  Updated to handle "aggressive"
    parameter, rather than the previous set of 11.

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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function d = rfiWrapper(d, plotparams, parm, field,thedate_day_portion);
0002 
0003 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0004 %
0005 %  function d = rfiWrapper(d, plotparams, parm, field)
0006 %
0007 %    reduceData function that calls the rfi algorithm with
0008 %    parameters parm.
0009 %
0010 %
0011 %    sjcm
0012 %
0013 %    Modified Oct 8, 2010 (MAS):  Switched in new RFI flagging for noise
0014 %    diode events.
0015 %
0016 %    Modified Dec 20, 2010 (MAS):  Switched in generalized RFI flagging for
0017 %    all data.  Removed distinction and need for two rfi flagging sessions.
0018 %
0019 %    Modified Jan 7, 2011 (MAS):  Got rid of the stageNum parameter.
0020 %
0021 %    3/29/2011 (SJCM):  no plotting but saving plots
0022 %
0023 %    Modified Apr 15, 2011 (MAS):  Updated to latest algorithm.
0024 %    Added support for user parameters.  Added spatial flagging.
0025 %
0026 %    Modified Sep 10, 2012 (MAS):  Updated to handle "aggressive"
0027 %    parameter, rather than the previous set of 11.
0028 %
0029 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0030 
0031 [d,q] = logcal(d, 'stokes');
0032 if (~q)
0033   disp('Stokes step not yet applied.  You need to do that first.');
0034   disp(' ')
0035 %  d=checkstatus(d);
0036   return
0037 end
0038 [d,q] = logcal(d, 'rfi');
0039 if (q)
0040   disp('RFI flagging has already been applied')
0041   disp(' ')
0042 %  d=checkstatus(d);
0043   return
0044 end
0045 
0046 
0047 % Check which type of data we're using.
0048 parFlag = checkpar(parm, 'alpha');
0049 if(parFlag)
0050   alphaType  = parm.alpha.type; % 0/1/2: filtered/classic/polonly
0051 else
0052   % check if we're running interactively so we can set what we want.
0053   if(plotparams.interactive==1)
0054     display('You are running in interactive mode');
0055     alphaType = 4;
0056     while(alphaType<0 || alphaType>3)
0057       alphaType = input('What type of correction did you apply?  [0-FILTERED, 1-CLASSIC, 2-POLONLY] ');
0058     end
0059   else
0060     display('No correction type specified, defaulting to classic data.');
0061     alphaType  = 1;
0062   end
0063 end
0064 
0065 
0066 
0067 % check if we have the flagging parameters
0068 parFlag = checkpar(parm, 'rfi');
0069 
0070 % check if we have the coord parameter.
0071 parFlag = checkpar(parm, 'coord');
0072 if(parFlag)
0073   flagParamsPositional = parm.coord.hemisphere;
0074 else
0075   display('Using Default Positional RFI flagging parameters');
0076   flagParamsPositional = 1;
0077 end
0078 
0079 
0080 %---------------------------------------------
0081 % Positional Flagging:
0082 %---------------------------------------------
0083 [horzFlag satFlag] = flagRFI_pos2(d,flagParamsPositional);
0084 
0085 preFlag = horzFlag | satFlag ;
0086 
0087 flags.old.bit = d.flags.bit;
0088 flags.new.bit.fast = repmat(preFlag, [1 3]);
0089 
0090 setPlotDisplay(plotparams.plot);
0091 % plot the positional flagging
0092 [d, outFlags] = packd(d, flags, 'none', 'positional', plotparams, ...
0093     'Positional Flagging Plots', field, []);
0094 
0095 % user positional flags
0096 userPosFlags = (outFlags.new.out>0) - (flags.new.bit.fast>0) ~= 0;
0097 userPosVec   = sum(userPosFlags,2)>0;
0098 
0099 % set all of these bits accordingly
0100 d = setNewFlag(d, repmat(horzFlag, [1 3]), 'horizon');
0101 d = updateFlags(d, 1);
0102 
0103 d = setNewFlag(d, repmat(satFlag, [1 3]), 'satellite');
0104 d = updateFlags(d, 1);
0105 
0106 d = setNewFlag(d, userPosFlags, 'pos_user');
0107 d = updateFlags(d, 1);
0108 
0109 % add user flags to preFlag
0110 preFlag = preFlag | userPosVec;
0111 
0112 %---------------------------------------------
0113 % Deglitching and new Statistical Flagging:
0114 %---------------------------------------------
0115 tic
0116 [flag bitFlag sky] = find_rfi(d, parm,thedate_day_portion);
0117 toc
0118 
0119 d.flags.rfi = bitFlag;
0120 d.flags.rfi.data.fast = logical(ones(size(d.flags.rfi.wings.fast)));
0121 flags.old.bit = d.flags.bit;
0122 flags.new.bit.fast = repmat(flag, [1 3]);
0123 
0124 % plot the data
0125 setPlotDisplay(plotparams.plot);
0126 [d, outFlags] = packd(d, flags, 'none', 'rfi2', plotparams, 'RFI Plots', field, []);
0127 d = setNewFlag(d, flag, 'rfi');
0128 d = updateFlags(d, 1);
0129 
0130 % add the simulated data to the data stream
0131 d.antenna0.receiver.sky = [sky.I.val sky.P.val];
0132 
0133 d = logcal(d, 'rfi');
0134 
0135 return;
0136 
0137 
0138 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0139 function d=checkstatus(d)
0140 
0141 disp('Would you like to view the plots?')
0142 
0143 if (query)
0144   d = packd(d, [], 'none', 'rfi', 0, 'RFI Plots', '');
0145 end
0146 
0147 disp(' ')
0148 
0149

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