Home > reduc > support > alphaWrapper.m

alphaWrapper

PURPOSE ^

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

SYNOPSIS ^

function d = alphaWrapper(d, plotparams, parm, field);

DESCRIPTION ^

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

  function d = alphaWrapper(d, plotparams, parm, field);

    reduceData function that calls the alpha calculation and flagging
    acording to parameters parm.

    sjcm

   3/30/2011 sjcm:  can now save plots without displaying them.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function d = alphaWrapper(d, plotparams, parm, field);
0002 
0003 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0004 %
0005 %  function d = alphaWrapper(d, plotparams, parm, field);
0006 %
0007 %    reduceData function that calls the alpha calculation and flagging
0008 %    acording to parameters parm.
0009 %
0010 %    sjcm
0011 %
0012 %   3/30/2011 sjcm:  can now save plots without displaying them.
0013 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0014 
0015 [d,q] = logcal(d, 'alpha');
0016 if (q)
0017   disp('Alpha correction has been applied');
0018   disp(' ')
0019   d=checkstatus(d);
0020   return
0021 end
0022 
0023 % check if we have the flagging parameters
0024 parFlag = checkpar(parm, 'alpha');
0025 if(parFlag)
0026   flagParams = [parm.alpha.jump parm.alpha.flat];
0027   alphaType  = parm.alpha.type;
0028   solveAlpha = parm.alpha.solve;
0029 else
0030   display('No flagging in alpha correction');
0031   flagParams = [1.5 0.004];
0032   % check if we're running interactively so we can set what we want.
0033   if(plotparams.interactive==1)
0034     display('You are running in interactive mode');
0035     alphaType = 4;
0036     solveAlpha = 0;
0037     while(alphaType<0 | alphaType>3)
0038       alphaType = input('What type of correction do you want?  [0-FILTERED, 1-CLASSIC, 2-POLONLY]');
0039     end
0040   else
0041     display('No alpha correction type specified, defaulting to 1 on un-filtered data');
0042     alphaType  = 1;
0043     solveAlpha = 0;
0044   end
0045 end
0046 
0047 % check if we're autoflagging
0048 autoFlag = checkpar(parm, 'autorun');
0049 if(autoFlag)
0050   autoFlag = parm.autorun.flag;
0051 else
0052   autoFlag = 0;
0053 end
0054 
0055 
0056 isup2date = checkAlphaDatabase((d.array.frame.utc(1)));
0057 if(~isup2date)
0058   % check if we're running it interactively
0059   if(plotparams.interactive==1)
0060     display('Your alpha database is not up to snuff');
0061     display('Would you like to solve it from the data in this track?');
0062     solveAlpha = query;
0063   end
0064 end
0065 
0066 
0067 % needed for plotting/flagging  -- even in other routines.
0068 [off1StartPos onEndPos off2EndPos onStartPos off1EndPos off2StartPos] = calcNoiseIndices(d);
0069 d.correction.alpha.indices = [off1StartPos onEndPos off2EndPos onStartPos];
0070 d.correction.alpha.indices2 = [off1StartPos onEndPos off2EndPos onStartPos ...
0071       off1EndPos off2StartPos];
0072 d.correction.alpha.type = alphaType;
0073 
0074 % This is done in calculateAlpha. Do not do it here.
0075 % % Calculating alpha seems to require that the .equa field has been calculated
0076 % if(~isfield(d.antenna0.servo, 'equa'))
0077 %   display('Calculating RA/DEC');
0078 %   long=-118.2822;
0079 %   lat=37.2339;
0080 %   az = d.antenna0.servo.apparent(:,1);
0081 %   el = d.antenna0.servo.apparent(:,2);
0082 %   jd=mjd2jd(d.antenna0.receiver.utc);
0083 %   [equa] = horiz_coo([pi/180*(az) pi/180*(el)],jd,[pi/180*(long) ...
0084 %     pi/180*(lat)],'e');
0085 %   d.antenna0.servo.equa=equa;
0086 %   clear az;
0087 %   clear el;
0088 %   clear equa;
0089 % end
0090     
0091 
0092 
0093 
0094 % need to assemble the streams so we can either correct it or not.
0095 % if we don't do this, the plotting will be messed up.
0096 switch(alphaType)
0097   case 1
0098     d = assembleAlphaStreams(d,'CLASSIC');
0099     % check if we want to solve it from this data set.
0100     if(solveAlpha)
0101       [tA,Ac,Gc] = calculateAlpha(d,'CLASSIC');
0102       d = applyAlpha(d, tA, Ac, Gc,'CLASSIC');
0103     else
0104       % oliver's alpha correction
0105       % alpha should be in the database at this point.
0106       d = applyAlpha(d,'CLASSIC');    
0107       printDisclaimer1;
0108     end
0109     flags.old.bit = d.flags.bit;
0110     flags.new.bit.fast = zeros(size(flags.old.bit.fast));
0111     
0112     
0113     % next we plot only the noise source events, and flag whichever ones are
0114     % bad.  After we're done flagging, we strike those values of alpha which are
0115     % offending, re-apply the alpha correction, and then save the resulting
0116     % stuff.
0117     setPlotDisplay(plotparams.plot);
0118     display('Plotting data');
0119     
0120     %d.history{length(d.history)+1}='Alpha Correct:: Data format is now TSKY_1 TLOAD_1 U Q U Q <U> <Q> TSKY_2 TLOAD_2';
0121     
0122     
0123     [d, outFlags] = packd(d, flags, 'none', 'alpha', plotparams, 'Alpha Plots', field);
0124     d = setNewFlag(d, outFlags.new.out, 'alpha');
0125     d = updateFlags(d, 1);
0126     % log that it has been applied
0127     d = logcal(d, 'alpha');
0128     
0129     
0130   case 2
0131     d = assembleAlphaStreams(d,'POLONLY');
0132     if(solveAlpha)
0133       [tA,Ac,Gc] = calculateAlpha(d,'POLONLY');
0134       d=applyAlpha(d, tA, Ac, Gc,'POLONLY');
0135     else
0136       % oliver filled this in
0137       d = applyAlpha(d,'POLONLY');
0138     end
0139     display('No plot for you');
0140     printDisclaimer2;
0141     
0142     
0143     %d.history{length(d.history)+1}= 'Alpha Correct:: Data format is now TSKY_1-TLOAD_1 U Q U Q <U> <Q> TSKY_2-TLOAD_2';
0144     
0145     d = logcal(d, 'alpha');
0146   
0147   otherwise
0148     
0149     d = assembleAlphaStreams(d,'FILTERED');
0150     if(solveAlpha)
0151       [tA,Af,Gf] = calculateAlpha(d,'FILTERED');
0152       d = applyAlpha(d, tA, Af, Gf,'FILTERED');
0153     else
0154       % apply the database
0155       d = applyAlpha(d,'FILTERED');
0156     end
0157     printDisclaimerFilter;
0158 
0159     d = logcal(d, 'alpha');
0160     
0161 end
0162 
0163 
0164 % and now, we remove the switchData field, which will never be used
0165 % again. -- NEEDED IN R-FACTOR PLOTS
0166 %d.antenna0.receiver = rmfield(d.antenna0.receiver, 'switchData');
0167 
0168 return;
0169 
0170 
0171 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0172 function d=checkstatus(d, flags)
0173 
0174 disp('Would you like to view the plots?')
0175 
0176 if (query)
0177     d = packd(d, d.flags, 'none', 'alpha', 0, 'Alpha Plots', '');
0178 end
0179 
0180 disp(' ')
0181 
0182 return;
0183 
0184 
0185 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0186 function printDisclaimer1()
0187 
0188 disp('====================ATTENTION=====================');
0189 disp('You have now alpha calibrated your data');
0190 disp('Your antenna0.receiver.data structure has changed');
0191 disp('If the calibration thus far has worked, your');
0192 disp('columns in antenna0.receiver.data now correspond to:');
0193 disp('[TSKY_1 TLOAD_1 U1 Q1 U2 Q2 <U> <Q> TSKY_2 TLOAD_2]');
0194 disp('i.e. 10 Column format'); 
0195 disp('====================ATTENTION=====================');
0196 
0197 return;
0198 
0199 
0200 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0201 function printDisclaimerFilter()
0202 
0203 disp('====================ATTENTION=====================');
0204 disp('You have now alpha calibrated your data');
0205 disp('Your antenna0.receiver.data structure has changed');
0206 disp('If the calibration thus far has worked, your');
0207 disp('columns in antenna0.receiver.data now correspond to:');
0208 disp('[ ((I+V)/2-TA) Q1 U2 (I-V)/2-TB]');
0209 disp('i.e. 4 Column format'); 
0210 disp('====================ATTENTION=====================');
0211 
0212 return;
0213 
0214 
0215 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0216 function printDisclaimer2()
0217 
0218 
0219 disp('====================ATTENTION=====================');
0220 disp('You have now alpha calibrated your data');
0221 disp('Your antenna0.receiver.data structure has changed');
0222 disp('If the calibration thus far has worked, your');
0223 disp('columns in antenna0.receiver.data now correspond to:');
0224 disp('[(TSKY_1-TLOAD_1) U1 Q1 U2 Q2 <U> <Q> (TSKY_2-TLOAD_2)]');
0225 disp('i.e. 8 Column format');
0226 disp('====================ATTENTION=====================');
0227 
0228 
0229 return;
0230

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