0001 function [d LL RR L1 L2 QQ UU mask] = cbassS2N(d,chan,bad_chan_array)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
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
0034
0035
0036
0037
0038
0039 flagging=input('Do you want to flag the timestream data interactively (y/n) ', 's');
0040
0041 if (flagging=='y')
0042
0043
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
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
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
0091
0092
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
0114 dodgyU=(UU<=-6e4);
0115 UU(dodgyU)=NaN;
0116 dodgyQ=(QQ<=-6e4);
0117 QQ(dodgyQ)=NaN;
0118
0119 close all
0120
0121
0122
0123
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
0134
0135
0136
0137
0138
0139
0140
0141
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
0203 end
0204 end
0205 end
0206
0207
0208
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))');
0217 d.antenna0.receiver.data(:,6)= nanmean((RR(:,mask)-L1(:,mask))');
0218 d.antenna0.receiver.data(:,2)= nanmean(QQ(:,mask)');
0219 d.antenna0.receiver.data(:,3)= nanmean(UU(:,mask)');
0220 d.antenna0.receiver.data(:,4) = d.antenna0.receiver.data(:,2);
0221 d.antenna0.receiver.data(:,5) = d.antenna0.receiver.data(:,3);
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
0230
0231
0232
0233
0234
0235
0236
0237
0238
0239
0240
0241
0242
0243
0244
0245
0246
0247
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
0254 d.antenna0.receiver.flags=zeros(fast_length,1);
0255 d.antenna0.receiver.utc=d.antenna0.servo.utcFast;
0256
0257
0258
0259
0260
0261
0262
0263
0264
0265
0266
0267
0268
0269
0270
0271
0272 d.antenna0.frame.utc=d.antenna0.servo.utc;
0273
0274
0275 d.antenna0.frame.received=2*ones(slow_length,1);
0276
0277
0278
0279 d.array.weather.status=zeros(slow_length,1);
0280
0281
0282
0283 d.flags.interpFlags.fast = zeros(fast_length,1);
0284 d.flags.interpFlags.medium = zeros(medium_length,1);
0285
0286
0287
0288 d.antenna0.receiver.diagnostics = zeros(fast_length,4);
0289 d.antenna0.receiver.diagnostics(:,2)=1;
0290
0291
0292
0293
0294
0295
0296
0297
0298
0299
0300
0301
0302
0303
0304
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