Home > reduc > cbassS2N.m

cbassS2N

PURPOSE ^

Put data into Cbass-N style

SYNOPSIS ^

function [d LL RR L1 L2 QQ UU mask] = cbassS2N(d,chan,bad_chan_array)

DESCRIPTION ^

 Put data into Cbass-N style
 Either use just one channel - useful for beam mapping with arificial source
 or average all data channels together
 Inputs:  d
          chan (optional, leave blank if you want to average all data
          across the band), 
          -- or use 1 to pick a 'good channel' mask interactively. 
          -- use 2 to list a fixed set of bad channels use e.g.:
           cbassS2N(d,2,[1 2 3 4])

 Load 1 is RR, Load 2 is LL

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [d LL RR L1 L2 QQ UU mask] = cbassS2N(d,chan,bad_chan_array)
0002 
0003 % Put data into Cbass-N style
0004 % Either use just one channel - useful for beam mapping with arificial source
0005 % or average all data channels together
0006 % Inputs:  d
0007 %          chan (optional, leave blank if you want to average all data
0008 %          across the band),
0009 %          -- or use 1 to pick a 'good channel' mask interactively.
0010 %          -- use 2 to list a fixed set of bad channels use e.g.:
0011 %           cbassS2N(d,2,[1 2 3 4])
0012 %
0013 % Load 1 is RR, Load 2 is LL
0014 
0015 % Make a data structure d.antenna0.recevier.data(:,1:6)
0016 % [ (LL-load2),Q,U,Q,U,(RR-load1) ]
0017 % averaged over frequency (using the selected channel mask)
0018 %
0019 %  ACT & JL
0020 
0021 %%
0022 
0023 %  Order the data into channels run from 4.5-5.5GHz. 128 Channels in total.
0024 LL = [d.antenna0.roach1.LL,fliplr(d.antenna0.roach2.LL)]; 
0025 RR = [d.antenna0.roach1.RR,fliplr(d.antenna0.roach2.RR)]; 
0026 L1 = [d.antenna0.roach1.load1,fliplr(d.antenna0.roach2.load1)]; 
0027 L2 = [d.antenna0.roach1.load2,fliplr(d.antenna0.roach2.load2)]; 
0028 
0029 QQ = [d.antenna0.roach1.Q,fliplr(d.antenna0.roach2.Q)];
0030 UU = [d.antenna0.roach1.U,fliplr(d.antenna0.roach2.U)];
0031 
0032 %%
0033 % Quick deglitcher - pick out time regions from plot
0034 % Use cursor to identify ranges of data to flag. Pick points in pairs.Press
0035 % return when done. It will then plot the unflagged data to see if you are
0036 % happy.
0037 
0038 % Get rid of this once we have full pipeline functionality
0039 flagging=input('Do you want to flag the timestream data interactively (y/n) ', 's');
0040 
0041 if (flagging=='y')
0042 
0043 % Set up a temporary array to keep track of the user flagged data
0044 flagDodgy = logical((LL(:,1))*0);
0045 
0046 
0047 happy='n';
0048 while(happy=='n')
0049 
0050  figure
0051 plot(mean(LL'))
0052 hold all
0053 plot(mean(RR'))
0054 disp('cbassS2N:: Plotting LL & RR. Pick time ranges that you want to exclude from the data. Press return when done')
0055 
0056 [x,y]=ginput
0057 
0058 % Make that data NaNs
0059 for i=1:2:length(x)
0060     if x(i+1)>size(LL,1)
0061         x(i+1)=size(LL,1)
0062     end
0063     LL(x(i):x(i+1),:)=NaN;
0064     RR(x(i):x(i+1),:)=NaN;
0065     QQ(x(i):x(i+1),:)=NaN;
0066     UU(x(i):x(i+1),:)=NaN;
0067     L1(x(i):x(i+1),:)=NaN;
0068     L2(x(i):x(i+1),:)=NaN;
0069     flagDodgy(x(i):x(i+1),:)=1;
0070 end
0071 figure
0072 plot(mean(LL'))
0073 hold all
0074 plot(mean(RR'))
0075 happy = input('Happy? (y/n) ', 's');
0076 
0077 end
0078 
0079 % Now check Q and U
0080 happy='n'
0081 while(happy=='n')
0082 
0083 figure
0084 plot(mean(QQ'))
0085 hold all
0086 plot(mean(UU'))
0087 disp('cbassS2N:: Plotting Q and U. Again, pick time ranges that you want to exclude from the data. Press return when done')
0088 
0089 [x,y]=ginput
0090 % Keep track of what we are flagging
0091 
0092 % Make that data NaNs
0093 for i=1:2:length(x)
0094     LL(x(i):x(i+1),:)=NaN;
0095     RR(x(i):x(i+1),:)=NaN;
0096     QQ(x(i):x(i+1),:)=NaN;
0097     UU(x(i):x(i+1),:)=NaN;
0098     L1(x(i):x(i+1),:)=NaN;
0099     L2(x(i):x(i+1),:)=NaN;
0100     flagDodgy(x(i):x(i+1),:)=1;
0101 end
0102 close all
0103 figure
0104 plot(mean(QQ'))
0105 hold all
0106 plot(mean(UU'))
0107 happy = input('Happy? (y/n) ', 's');
0108 end
0109 close all
0110 
0111 end
0112 %%
0113 % Also flag very bad Q,U values which are less than -6.5e4
0114 dodgyU=(UU<=-6e4);
0115 UU(dodgyU)=NaN;
0116 dodgyQ=(QQ<=-6e4);
0117 QQ(dodgyQ)=NaN;
0118 
0119 close all
0120 
0121 %%
0122 % Now apply a mask to the channels
0123 % Flag out end channels as default
0124 goodchans = [8:61,68:125]; 
0125 mask=ones(1,128);
0126 mask(goodchans) = 0;
0127 mask=logical(mask);
0128 mask = ~mask;
0129 
0130 
0131 
0132 %%
0133 % Plot out std and imagesc of remaining good data - ask for more bad
0134 % channels to mask
0135 % Identify the channels to flag from the plots then enter them as e.g. [1 2 3]
0136 % You will be asked if happy - if you aren't then it will store your current mask
0137 % and then plot things again, allowing you to addmore channels to the mask.
0138 
0139 % At a later date we should streamline this to allow you to enter directly
0140 % a pre-determined mask. For now it will always do at least one cycle of
0141 % plotting the data and then ask for a set of channels
0142 if exist('chan')
0143     if(chan==1)
0144         disp('cbassS2N:: You will now be able to select which channels to flag from the data')
0145         disp('cbassS2N:: Please wait while I plot the rms of each data channel...')
0146         disp('cbassS2N:: Use the plots to identify which channels you want to flag.')
0147         addpath('./Angelas_Raster_Code')
0148         happy='n';
0149         while(happy=='n')
0150             
0151             LL(:,~mask)=NaN;
0152             RR(:,~mask)=NaN;
0153             QQ(:,~mask)=NaN;
0154             UU(:,~mask)=NaN;
0155             close all
0156             figure
0157             subplot(2,2,1)
0158             plot(nanstd2(RR))
0159             title('RR')
0160             subplot(2,2,2)
0161             plot(nanstd2(LL))
0162             title('LL')
0163             subplot(2,2,3)
0164             plot(nanstd2(UU))
0165             title('UU')
0166             subplot(2,2,4)
0167             plot(nanstd2(QQ))
0168             title('QQ')
0169             badchans = input('identify other bad chans: e.g.[75 96 24] ');
0170             mask(badchans)=0;
0171             
0172             LL(:,~mask)=NaN;
0173             RR(:,~mask)=NaN;
0174             QQ(:,~mask)=NaN;
0175             UU(:,~mask)=NaN;
0176             close all
0177             figure
0178             subplot(2,2,1)
0179             plot(nanstd2(RR))
0180             title('RR')
0181             subplot(2,2,2)
0182             plot(nanstd2(LL))
0183             title('LL')
0184             subplot(2,2,3)
0185             plot(nanstd2(UU))
0186             title('UU')
0187             subplot(2,2,4)
0188             plot(nanstd2(QQ))
0189             title('QQ')
0190             happy = input('Happy? (y/n) ', 's');
0191             close all
0192         end
0193     else
0194         if (chan==2)
0195             disp(['Will flag channels ', num2str(bad_chan_array)])
0196             badchans = bad_chan_array;
0197             mask(badchans)=0;
0198             LL(:,~mask)=NaN;
0199             RR(:,~mask)=NaN;
0200             QQ(:,~mask)=NaN;
0201             UU(:,~mask)=NaN;
0202             %plot(nanstd2(LL(:,mask)))
0203         end
0204     end
0205 end
0206 
0207 %%
0208 % Gets the data into North format
0209 disp(' ')
0210 disp('cbassS2N:: Now averaging across your masked channels')
0211 disp('cbassS2N:: and writing out to d.antenna0.receiver.data')
0212 if ~exist('chan')
0213     disp('cbassS2N:: Just using a basic channel mask which removes the edge channels [1:8, 61:68, 125:128]')
0214     disp(' ')
0215 end
0216 d.antenna0.receiver.data(:,1)=  nanmean((LL(:,mask)-L2(:,mask))'); %LL - load2
0217 d.antenna0.receiver.data(:,6)=  nanmean((RR(:,mask)-L1(:,mask))'); %RR - load1
0218 d.antenna0.receiver.data(:,2)=  nanmean(QQ(:,mask)'); % Q
0219 d.antenna0.receiver.data(:,3)=  nanmean(UU(:,mask)'); % U
0220 d.antenna0.receiver.data(:,4) = d.antenna0.receiver.data(:,2);  % Q (copy)
0221 d.antenna0.receiver.data(:,5) = d.antenna0.receiver.data(:,3);  % U (copy)
0222 d.antenna0.receiver.utc=d.antenna0.roach1.utc;
0223 disp(' ')
0224 disp('cbassS2N:: d.antenna0.receiver.data now contains:')
0225 disp('cbassS2N:: [ (LL-load2)  Q  U  Q  U (RR-load2) ]')
0226 
0227 %%
0228 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0229 % JL
0230 % Now set up the rest of d.antenna0.receiver according to
0231 %ans =
0232 %
0233 %           flags: [267500x1 double]
0234 %             utc: [267500x1 double]
0235 %            data: [267500x6 double]
0236 %      switchData: [267500x24 double]
0237 %     diagnostics: [267500x4 double]
0238 %    drainCurrent: [2675x4x3 double]
0239 %    drainVoltage: [2675x4x3 double]
0240 %     gateVoltage: [2675x4x3 double]
0241 %       avgSecond: [267500x1 double]
0242 
0243 % Get length for "fast" arrays
0244 % d.antenna0.roach2.LLfreq
0245 % the rations should be
0246 % slow:medium:fast
0247 % 1:5:100 Hz
0248    
0249 fast_length = length(d.antenna0.roach2.LLfreq);
0250 medium_length=length(d.antenna0.servo.utc);
0251 slow_length = length(d.antenna0.roach2.intCount);
0252 
0253 % Not sure of meaning of these
0254 d.antenna0.receiver.flags=zeros(fast_length,1);
0255 d.antenna0.receiver.utc=d.antenna0.servo.utcFast;
0256 %d.antenna0.receiver.data has been set above.
0257 
0258 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0259 % switchData no longer used so will not make
0260 % not
0261 %
0262 % Not sure that are ever used, so will not create.
0263 %
0264 %     diagnostics: [267500x4 double]
0265 %    drainCurrent: [2675x4x3 double]
0266 %    drainVoltage: [2675x4x3 double]
0267 %     gateVoltage: [2675x4x3 double]
0268 %       avgSecond: [267500x1 double]
0269 
0270 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0271 % Medium length, it seems
0272   d.antenna0.frame.utc=d.antenna0.servo.utc;
0273 
0274 % !!! Do not know what this is meant to be - CHECK.
0275   d.antenna0.frame.received=2*ones(slow_length,1);
0276 
0277 
0278 % Weather array, zeros are good presumably
0279   d.array.weather.status=zeros(slow_length,1);
0280 
0281 % Should be all zero apparently
0282 % !!! Check
0283   d.flags.interpFlags.fast = zeros(fast_length,1);
0284   d.flags.interpFlags.medium = zeros(medium_length,1);
0285 
0286 % Diagnostics, a 4 column array , col2 should be all 1's apparently.
0287 % !!! Check
0288 d.antenna0.receiver.diagnostics = zeros(fast_length,4);
0289 d.antenna0.receiver.diagnostics(:,2)=1; 
0290 
0291 
0292 % Get IV is doing this
0293 
0294 %  I1 = d.antenna0.receiver.data(:,1);
0295 %  I2 = d.antenna0.receiver.data(:,8);
0296 %  Q1 = d.antenna0.receiver.data(:,2);
0297 %  Q2 = d.antenna0.receiver.data(:,4);
0298 %  %Q3 = d.antenna0.receiver.data(:,6);
0299 %  U1 = d.antenna0.receiver.data(:,3);
0300 %  U2 = d.antenna0.receiver.data(:,5);
0301 %  %U3 = d.antenna0.receiver.data(:,7);
0302 %  d.antenna0.receiver.data = [I1 Q1 U1 Q2 U2 I2];
0303 
0304 % So we need to do this.
0305 
0306 d.antenna0.receiver.data(:,8)=d.antenna0.receiver.data(:,6);
0307 
0308 
0309 
0310 clear badchans dodgyQ dodgyU flagDodgy flagging happy goodchans  medium_length slow_length fast_length x y chan
0311 end

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