Home > reduc > alpha > applyAlpha.m

applyAlpha

PURPOSE ^

function d = applyAlpha(d,t,A,G,selection)

SYNOPSIS ^

function d = applyAlpha(d,varargin)

DESCRIPTION ^

 function d = applyAlpha(d,t,A,G,selection)
   Apply the passed alpha values
 or
 function d = applyAlpha(d,selection)
   Use the database values
 
 This function applies the alpha corrections to the classic, polonly and
 filtered data chains.

 OGK, 12 Mar 2012

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function d = applyAlpha(d,varargin)
0002 % function d = applyAlpha(d,t,A,G,selection)
0003 %   Apply the passed alpha values
0004 % or
0005 % function d = applyAlpha(d,selection)
0006 %   Use the database values
0007 %
0008 % This function applies the alpha corrections to the classic, polonly and
0009 % filtered data chains.
0010 %
0011 % OGK, 12 Mar 2012
0012 %
0013 
0014 if nargin == 2
0015     selection = varargin{1};
0016 elseif nargin == 5
0017     selection = varargin{4};
0018 else
0019     disp('applyAlpha:: Wrong number of arguments passed to applyAlpha!')
0020     return
0021 end
0022 
0023 % Step 1: interpolate the values:
0024 [Ai,Gi] = interpolateAlpha(d.antenna0.receiver.utc,varargin{:});
0025 
0026 % Step 2: apply the interpolated values:
0027 if strcmp(selection,'CLASSIC')
0028     d = DD(d,Ai,Gi);
0029 end
0030 if strcmp(selection,'FILTERED') 
0031     if d.antenna0.receiver.utc(1) < tstr2mjd('01-oct-2011:00:00:00')
0032         disp('applyAlpha:: Cannot apply FILTERED option to data before October 2011')
0033     else
0034         d = filtered(d,Ai,Gi);
0035     end
0036 end
0037 if strcmp(selection,'POLONLY')
0038     d = PolOnly(d,Ai,Gi);
0039 end
0040 
0041 end
0042 
0043 function d = DD(d,Am,Gm)
0044 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0045 % d = DD(d,Am,Gm)
0046 %   This function applies the alpha leakage terms and G gain terms to the
0047 % data in d.
0048 %   After this step the columns in data have been properly separated
0049 % (i.e. into load and sky for total intensity) and their units have been
0050 % converted to a common scale. The scale is:
0051 %   (Antenna Temperature)/(Noise Diode Temperature)
0052 %   The polarization sets have been rotated to correct for the instrument
0053 % rotation.
0054 %
0055 % OGK, 13 Mar 2012
0056 %
0057 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0058 
0059 if size(d.antenna0.receiver.data,2) ~= 10
0060     error('applyAlpha:: Run assembleAlphaStreams first, with "CLASSIC" option!');
0061 end
0062 
0063 % the uncorrected data
0064 swd = d.antenna0.receiver.data;
0065 
0066 % And now form the corrected switchData products for total intensity:
0067 % Total intensity channel 1
0068 [Sky,Load] = separateI(swd(:,1),swd(:,2),Am(:,1),Gm(:,1));
0069 d.antenna0.receiver.data(:,1) = Sky;
0070 d.antenna0.receiver.data(:,2) = Load;
0071 
0072 % Polarization: apply the rotation matrix, with rotation angle -theta, to
0073 % the vector [Qmeasured;Umeasured]
0074 % Polarization set 1
0075 [Qr,Ur] = rotatePol(swd(:,3),swd(:,4),-Am(:,2),Gm(:,2));
0076 d.antenna0.receiver.data(:,3) = Qr;
0077 d.antenna0.receiver.data(:,4) = Ur;
0078 % Polarization set 2
0079 [Qr,Ur] = rotatePol(swd(:,5),swd(:,6),-Am(:,3),Gm(:,3));
0080 d.antenna0.receiver.data(:,5) = Qr;
0081 d.antenna0.receiver.data(:,6) = Ur;
0082 % Polarization set 3
0083 [Qr,Ur] = rotatePol(swd(:,7),swd(:,8),-Am(:,4),Gm(:,4));
0084 d.antenna0.receiver.data(:,7) = Qr;
0085 d.antenna0.receiver.data(:,8) = Ur;
0086 
0087 % Total intensity channel 2
0088 [Sky,Load] = separateI(swd(:,9),swd(:,10),Am(:,5),Gm(:,5));
0089 d.antenna0.receiver.data(:,9) = Sky;
0090 d.antenna0.receiver.data(:,10) = Load;
0091 
0092 end
0093 
0094 function d = filtered(d,Am,Gm)
0095 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0096 % d = filtered(d,Ai,Gi)
0097 %   This function applies the phase angles Ai and Gi gain terms to the
0098 % data in d.
0099 %   After this step the data are calibrated. The scale is:
0100 %   (Antenna Temperature)/(Noise Diode Temperature)
0101 %   The polarization sets have been rotated to correct for the instrument
0102 % rotation.
0103 %
0104 % OGK, 13 Mar 2012
0105 %
0106 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0107 
0108 if size(d.antenna0.receiver.data,2) ~= 8
0109     error('applyAlpha:: Run assembleAlphaStreams first with "FILTERED" option!');
0110 end
0111 
0112 % the data before the corrections are applied:
0113 data = d.antenna0.receiver.data;
0114 
0115 % Total intensity channel 1 (I+V)/2 - TA
0116 d.antenna0.receiver.data(:,1) = Gm(:,1).*data(:,1);
0117 % Polarization set 1:
0118 [Qr,Ur] = rotatePol(data(:,2),data(:,3),Am(:,1),Gm(:,2));
0119 d.antenna0.receiver.data(:,2) = Qr;
0120 d.antenna0.receiver.data(:,3) = Ur;
0121 % Polarization set 2:
0122 [Qr,Ur] = rotatePol(data(:,4),data(:,5),Am(:,2),Gm(:,3));
0123 d.antenna0.receiver.data(:,4) = Qr;
0124 d.antenna0.receiver.data(:,5) = Ur;
0125 % Polarization set 3:
0126 [Qr,Ur] = rotatePol(data(:,6),data(:,7),Am(:,3),Gm(:,4));
0127 d.antenna0.receiver.data(:,6) = Qr;
0128 d.antenna0.receiver.data(:,7) = Ur;
0129 % Total intensity channel 2 (I-V)/2 - TB
0130 d.antenna0.receiver.data(:,8) = Gm(:,5).*data(:,8);
0131 
0132 end
0133 
0134 function d = PolOnly(d,Am,Gm)
0135 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0136 % d = PolOnly(d,Am,Gm)
0137 %   This function applies the alpha leakage terms and G gain terms to the
0138 % data in d.
0139 %   This step applies the alpha value only to the polarization data. It
0140 % applies gain corrections to all the channels; their units have been
0141 % converted to a common scale. The scale is:
0142 %   (Antenna Temperature)/(Noise Diode Temperature)
0143 %   The polarization sets have been rotated to correct for the instrument
0144 % rotation.
0145 %
0146 % OGK, 13 Mar 2012
0147 %
0148 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0149 
0150 if size(d.antenna0.receiver.data,2) ~= 8
0151     error('applyAlpha:: Run assembleAlphaStreams first with "POLONLY" option!');
0152 end
0153 
0154 swd = d.antenna0.receiver.data;
0155 
0156 % And now form the corrected switchData products for total intensity:
0157 % Total intensity channel 1
0158 d.antenna0.receiver.data(:,1) = Gm(:,1).*swd(:,1); % propto ((I+V)/2 - Tload)
0159 
0160 % Polarization: apply the rotation matrix, with rotation angle -theta, to
0161 % the vector [Qmeasured;Umeasured]
0162 % Polarization set 1
0163 [Qr,Ur] = rotatePol(swd(:,2),swd(:,3),-Am(:,1),Gm(:,2));
0164 d.antenna0.receiver.data(:,2) = Qr;
0165 d.antenna0.receiver.data(:,3) = Ur;
0166 % Polarization set 2
0167 [Qr,Ur] = rotatePol(swd(:,4),swd(:,5),-Am(:,2),Gm(:,3));
0168 d.antenna0.receiver.data(:,4) = Qr;
0169 d.antenna0.receiver.data(:,5) = Ur;
0170 % Polarization set 3
0171 [Qr,Ur] = rotatePol(swd(:,6),swd(:,7),-Am(:,3),Gm(:,4));
0172 d.antenna0.receiver.data(:,6) = Qr;
0173 d.antenna0.receiver.data(:,7) = Ur;
0174 
0175 % Total intensity channel 2
0176 d.antenna0.receiver.data(:,8) = Gm(:,5).*swd(:,8); % propto ((I-V)/2 - Tload)
0177 
0178 end
0179 
0180 function [Qr,Ur] = rotatePol(Q,U,phi,G)
0181 % Rotate polarization vector Q and U by angle phi and scale by G.
0182 Qr = G.*( cos(phi).*Q + sin(phi).*U);
0183 Ur = G.*(-sin(phi).*Q + cos(phi).*U);
0184 end
0185 
0186 function [Sky,Load] = separateI(S,L,Am,Gm)
0187 % And now form the corrected switchData products for total intensity:
0188 % Total intensity channel 1
0189 A = S+L;
0190 B = S-L;
0191 Sky  = Gm.*(1/2*(A+B./Am));
0192 Load = Gm.*(1/2*(A-B./Am));
0193 end

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