0001
0002 MJD = [];
0003 Ivals = [];
0004 Iupper = [];
0005 Ilower =[];
0006 Irms = [];
0007
0008 Qvals = [];
0009 Qupper = [];
0010 Qlower =[];
0011 Qrms = [];
0012
0013 Uvals = [];
0014 Uupper = [];
0015 Ulower =[];
0016 Urms = [];
0017
0018
0019
0020 arcDir = '/elephant/CBASS_ARC/arc'
0021 date_start = '01-Oct-2012'
0022 date_end = '19-Jan-2014'
0023 path_to_redscript='reduc/redScript.red';
0024 sched_to_reduce = 'stare';
0025
0026 start_date_num = datenum(date_start);
0027 end_date_num = datenum(date_end);
0028
0029 display( 'Selecting correct date range' )
0030 [home,installeddir]=where_am_i();
0031 location = [home,'/',installeddir];
0032
0033
0034 file = '/elephant/cbass_analysis/log/obs_log.html'
0035 fid = fopen(file,'r');
0036
0037 if fid < 0
0038 disp(['File failed to open: ',file]);
0039 end
0040
0041 start_dates = {};
0042 end_dates = {};
0043 schedule = {};
0044 source_name = {};
0045 temp = 0;
0046
0047 for j=0:(end_date_num - start_date_num)
0048 d_string = datestr(start_date_num + j);
0049 date = d_string;
0050 disp( date )
0051 fid = fopen(file,'r');
0052 i=0;
0053 while 1
0054 tline = fgetl(fid);
0055 if(~ischar(tline))
0056
0057 ST = fclose(fid);
0058 break;
0059 end;
0060
0061 dloc = regexp(tline,date);
0062 if isempty(dloc)
0063 continue
0064 end
0065
0066 if (dloc(1) < 10)
0067 if ( length(regexp(tline,date)) ~=0)
0068 i=i+1;
0069
0070 splitline = regexp(tline, '\s+', 'split');
0071
0072
0073 if (~isempty(strfind(char(splitline(2)), '/')) )
0074 start_dates(end+1) = {'Error'};
0075 end_dates(end+1) = {'Error'};
0076 schedule(end+1) = {'Error'};
0077 source_name(end+1)={'Error'};
0078 else
0079 start_dates(end+1) = splitline(1);
0080 end_dates(end+1) = splitline(2);
0081 schedule(end+1) = splitline(3);
0082
0083
0084
0085
0086
0087
0088 temp = i+1;
0089 end
0090 end
0091 end
0092 end
0093 end
0094
0095
0096 emptyCells = cellfun(@isempty,schedule);
0097
0098 schedule(emptyCells) = [];
0099 start_dates(emptyCells) = [];
0100 end_dates(emptyCells) = [];
0101
0102
0103 display( 'Selecting correct schedules' )
0104
0105 start_string = {};
0106 end_string = {};
0107 sched_string = {};
0108
0109 for i=1:length(start_dates)
0110
0111 sched_bits = regexp(char(schedule(i)), '/', 'split');
0112 sched_name = char(sched_bits(length(sched_bits)));
0113
0114 sched_name = strrep(sched_name, '(','');
0115
0116
0117 if strcmp(char(start_dates(i)),'Error')
0118 continue
0119 end
0120
0121 if (exist('sched_to_reduce','var'))
0122 stripped_sched_to_reduce=sched_to_reduce;
0123 if (~isempty(regexp(sched_to_reduce,'^~')))
0124 stripped_sched_to_reduce = regexprep(sched_to_reduce,'^~','');
0125 end
0126
0127 does_sched_match = ~isempty(regexp(sched_name,stripped_sched_to_reduce,'match'));
0128 if (does_sched_match)
0129 start_string{end+1} = strrep(char(start_dates(i)),'/','');
0130 end_string{end+1} = strrep(char(end_dates(i)),'/','');
0131 sched_string{end+1} = char(schedule(i));
0132 continue;
0133 end;
0134 end;
0135
0136 end
0137
0138 start_string
0139
0140
0141
0142
0143
0144
0145
0146
0147 jmax = length( start_string );
0148 for j=1:jmax
0149
0150 if ( tstr2mjd(char(end_string(j))) - tstr2mjd(char(start_string(j))) )<0.4
0151 a = char( [start_string(j),end_string(j)] )
0152 d = read_arc( a(1,:),a(2,:));
0153 d = reduceData( d, './reduc/redScript_Luke.red' );
0154 d = determineIndices( d );
0155
0156 BLANK = d.index.blank.fast;
0157 len = length( BLANK );
0158 sIND = [];
0159 eIND = [];
0160 for i=1:len;
0161 if (i<len) & (BLANK(i)==0) & (BLANK(i+1)==1)
0162 sIND(end+1)=i;
0163 end
0164 if (i>1) & (BLANK(i)==0) & (BLANK(i-1)==1)
0165 eIND(end+1)=i;
0166 end
0167 end
0168 numOfStares = length(sIND)
0169
0170 for i=1:numOfStares
0171 if length(eIND)~=length(sIND);
0172 display( 'length(eIND) ~= length(sIND)' )
0173 continue
0174 end
0175 idx = 1:(eIND(i)-sIND(i)+1);
0176
0177 I1 = d.antenna0.receiver.data(sIND(i):eIND(i),1);
0178 I1 = I1 - polyval(polyfit( idx', I1, 1 ),idx)';
0179 Q1 = d.antenna0.receiver.data(sIND(i):eIND(i),2);
0180 Q1 = Q1 - polyval(polyfit( idx', Q1, 1 ),idx)';
0181 U1 = d.antenna0.receiver.data(sIND(i):eIND(i),3);
0182 U1 = U1 - polyval(polyfit( idx', U1, 1 ),idx)';
0183
0184 Fs = 100;
0185 L = eIND(i)-sIND(i)+1;
0186 NFFT = 2^nextpow2(L);
0187 x = Fs/2*linspace(0,1,NFFT/2+1);
0188
0189 y= fft(I1,NFFT);
0190 y = y.*conj(y)/(L*Fs);
0191 I1p = (y(1:NFFT/2+1));
0192
0193 y= fft(Q1,NFFT);
0194 y = y.*conj(y)/(L*Fs);
0195 Q1p = (y(1:NFFT/2+1));
0196
0197 y= fft(U1,NFFT);
0198 y = y.*conj(y)/(L*Fs);
0199 U1p = (y(1:NFFT/2+1));
0200
0201 fitLength = 4.;
0202 ft = fittype( 'noiseModel( x, sigma_w, f_knee, alpha )' );
0203 x_ = x(2:end/fitLength);
0204 I1p_ = I1p(2:end/fitLength);
0205 Q1p_ = Q1p(2:end/fitLength);
0206 U1p_ = U1p(2:end/fitLength);
0207
0208 Iguess = [std(I1p(end/fitLength:end)),0.1,1];
0209 [Iparams, Igof, output] = fit( x_', real(log(I1p_)), ft, 'StartPoint', Iguess, 'Lower', [0.,0.,0.], 'Exclude', (x_<1.3)&(x_>1.1) ,'TolFun', 1e-20, 'TolX',1e-10 );
0210 Iconf = confint(Iparams,0.95);
0211
0212 Qguess = [std(Q1p(end/fitLength:end)),0.01,1];
0213 [Qparams, Qgof, output] = fit( x_', real(log(Q1p_)), ft, 'StartPoint', Qguess, 'Lower', [0.,0.,0.], 'Exclude', (x_<1.3)&(x_>1.1) ,'TolFun', 1e-20, 'TolX',1e-10 );
0214 Qconf = confint(Qparams,0.95);
0215
0216 Uguess = [std(U1p(end/fitLength:end)),0.01,1];
0217 [Uparams, Ugof, output] = fit( x_', real(log(U1p_)), ft, 'StartPoint', Uguess, 'Lower', [0.,0.,0.], 'Exclude', (x_<1.3)&(x_>1.1) ,'TolFun', 1e-20, 'TolX',1e-10 );
0218 Uconf = confint(Uparams,0.95);
0219
0220 Ivals(end+1,1:3) = [Iparams.alpha, Iparams.f_knee, Iparams.sigma_w];
0221 Ilower(end+1,1:3) = [Iconf(1,1),Iconf(1,2),Iconf(1,3)];
0222 Iupper(end+1,1:3) = [Iconf(2,1),Iconf(2,2),Iconf(2,3)];
0223 Irms(end+1) = Igof.rmse;
0224 Qvals(end+1,1:3) = [Qparams.alpha, Qparams.f_knee, Qparams.sigma_w];
0225 Qlower(end+1,1:3) = [Qconf(1,1),Qconf(1,2),Qconf(1,3)];
0226 Qupper(end+1,1:3) = [Qconf(2,1),Qconf(2,2),Qconf(2,3)];
0227 Qrms(end+1) = Qgof.rmse;
0228 Uvals(end+1,1:3) = [Uparams.alpha, Uparams.f_knee, Uparams.sigma_w];
0229 Ulower(end+1,1:3) = [Uconf(1,1),Uconf(1,2),Uconf(1,3)];
0230 Uupper(end+1,1:3) = [Uconf(2,1),Uconf(2,2),Uconf(2,3)];
0231 Urms(end+1) = Ugof.rmse;
0232 MJD(end+1) = d.antenna0.receiver.utc(sIND(i));
0233 end
0234 end
0235 end
0236
0237
0238 save( ['skyStareNoiseStats_' date_start '_' date_end '.mat'] , 'Ivals', 'Qvals', 'Uvals', 'Irms', 'Qrms', 'Urms', 'Ilower', 'Qlower', 'Ulower', 'Iupper', 'Qupper', 'Uupper', 'MJD' )
0239 display( 'Saved' )
0240
0241
0242 [year month day] = mjd2date(MJD);
0243 dateno = datenum( year, month, day );
0244
0245
0246
0247
0248
0249
0250
0251
0252
0253
0254
0255
0256
0257
0258
0259
0260
0261
0262
0263
0264
0265
0266
0267
0268
0269
0270
0271
0272
0273
0274
0275
0276
0277
0278
0279
0280
0281
0282
0283
0284
0285
0286
0287
0288
0289
0290
0291
0292
0293
0294
0295
0296
0297
0298
0299
0300
0301
0302
0303
0304
0305
0306
0307
0308
0309
0310
0311
0312
0313
0314
0315
0316
0317
0318
0319
0320
0321
0322
0323
0324
0325
0326
0327
0328
0329
0330
0331
0332
0333
0334
0335
0336
0337
0338
0339
0340
0341
0342
0343
0344
0345
0346
0347
0348
0349
0350
0351
0352
0353
0354
0355
0356
0357
0358
0359
0360
0361
0362
0363
0364
0365
0366
0367
0368
0369
0370
0371
0372
0373
0374
0375
0376
0377
0378
0379
0380
0381
0382
0383
0384
0385
0386
0387
0388
0389
0390
0391
0392
0393
0394
0395
0396
0397
0398
0399
0400
0401
0402
0403
0404
0405
0406
0407
0408
0409
0410
0411
0412
0413
0414
0415
0416
0417
0418
0419
0420
0421
0422
0423
0424
0425
0426
0427
0428
0429
0430
0431
0432
0433
0434