0001 function FitsRADECMap(fitsfilepath,listoffiles,do_pa_rot)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 [home,installeddir] = where_am_i();
0015 addpath([home,'/',installeddir,'/Angelas_Raster_Code/']);
0016
0017
0018
0019
0020 maindir= [home,'/',installeddir,'/'];
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051 fitsfilepath='/reduc/RasterAug2014_rfi20_detrend/';
0052
0053 source_name = 'TauA'
0054 listoffiles='files.txt'
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067 formatSpec = '%s%[^\n\r]';
0068 delimiter = ' ';
0069
0070 fileID = fopen([maindir,'/',fitsfilepath,'/',listoffiles],'r');
0071
0072
0073
0074
0075
0076 dataArray = textscan(fileID, formatSpec, 'Delimiter', delimiter, 'ReturnOnError', false);
0077
0078
0079 fclose(fileID);
0080
0081
0082
0083 filenames = dataArray{:, 1};
0084
0085
0086 clearvars listoffiles delimiter formatSpec fileID dataArray ans;
0087
0088
0089
0090
0091 MJD = [];
0092 RA = [];
0093 DEC = [];
0094 EL_D = [];
0095 AZ_D = [];
0096 I1 = [];
0097 Q1 = [];
0098 U1 = [];
0099 I2 = [];
0100 Q2 = [];
0101 U2 = [];
0102
0103
0104
0105 DAYFLAG = logical([]);
0106 FLAG = logical([]);
0107
0108
0109 figure
0110 hold all
0111 for i=1:length(filenames)
0112 data_labels = { 'MJD', 'RA', 'DEC', 'AZ', 'EL', 'I1', 'Q1', 'U1','I2', 'Q2', 'U2','DAYFLAG','FLAG'};
0113 info =fitsinfo([maindir,'/',fitsfilepath,cell2mat(filenames(i))]);
0114 data = fitsread([maindir,'/',fitsfilepath,cell2mat(filenames(i))],'bintable',1);
0115 values = info.BinaryTable(1).Keywords(:,2);
0116 names = info.BinaryTable(1).Keywords(:,1);
0117 pinfo = info.PrimaryData.Keywords(:,1:2) ;
0118
0119
0120
0121 for ilab=1:length(data_labels);
0122 ilab;
0123 pos = (names(strcmp(data_labels{ilab},values)));
0124 pos = regexp(pos{1},'\d','match');
0125 pos = cell2mat(pos);
0126 data_pos{ilab}=pos;
0127 end
0128
0129
0130
0131
0132
0133
0134 tMJD= (data{str2num(cell2mat(data_pos(strcmp(data_labels,'MJD'))))});
0135 tRA= (data{str2num(cell2mat(data_pos(strcmp(data_labels,'RA'))))});
0136 tDEC = (data{str2num(cell2mat(data_pos(strcmp(data_labels,'DEC'))))});
0137 tEL_D = (data{str2num(cell2mat(data_pos(strcmp(data_labels,'EL'))))});
0138 tAZ_D = (data{str2num(cell2mat(data_pos(strcmp(data_labels,'AZ'))))});
0139 tI1 = ((data{str2num(cell2mat(data_pos(strcmp(data_labels,'I1'))))}));
0140 tQ1 = ((data{str2num(cell2mat(data_pos(strcmp(data_labels,'Q1'))))}));
0141 tU1 = ((data{str2num(cell2mat(data_pos(strcmp(data_labels,'U1'))))}));
0142 tI2 = ((data{str2num(cell2mat(data_pos(strcmp(data_labels,'I2'))))}));
0143 tQ2 = ((data{str2num(cell2mat(data_pos(strcmp(data_labels,'Q2'))))}));
0144 tU2 = ((data{str2num(cell2mat(data_pos(strcmp(data_labels,'U2'))))}));
0145
0146
0147
0148 tDAYFLAG = logical(data{str2num(cell2mat(data_pos(strcmp(data_labels,'DAYFLAG'))))});
0149 tFLAG = logical(data{str2num(cell2mat(data_pos(strcmp(data_labels,'FLAG'))))});
0150
0151
0152
0153
0154
0155
0156
0157
0158
0159
0160
0161
0162 MJD = [MJD;tMJD];
0163 RA = [RA;tRA];
0164 DEC = [DEC;tDEC];
0165 EL_D = [EL_D;tEL_D];
0166 AZ_D = [AZ_D;tAZ_D];
0167 I1 = [I1;tI1];
0168 Q1 = [Q1;tQ1];
0169 U1 = [U1;tU1];
0170 I2 = [I2;tI2];
0171 Q2 = [Q2;tQ2];
0172 U2 = [U2;tU2];
0173
0174
0175
0176 DAYFLAG = logical([DAYFLAG;tDAYFLAG]);
0177 FLAG = logical([FLAG;tFLAG]);
0178
0179
0180
0181 DEC = rad2deg(DEC);
0182 RA = rad2deg(RA);
0183
0184
0185
0186
0187 end
0188
0189
0190 Iall = [I1,I2,(I1+I2)/2];
0191 Qall = [Q1,Q2,(Q1+Q2)/2];
0192 Uall = [U1,U2,(U1+U2)/2];
0193 Pall = [sqrt(Qall(:,1).^2 + Uall(:,1).^2),sqrt(Qall(:,2).^2 + Uall(:,2).^2),sqrt(Qall(:,3).^2 + Uall(:,3).^2)];
0194 allIQUP = {Iall,Qall,Uall,Pall};
0195 allIQUP_labels={'I','Q','U','P'};
0196 figure(2)
0197 for i=1:4
0198 subplot(4,1,i)
0199 for j=1:3
0200 plot(allIQUP{1,i}(:,j))
0201 hold all
0202 end
0203 xlabel('MJD')
0204 ylabel('Kelvin')
0205 title(allIQUP_labels{i})
0206 end
0207 gtitle('Timestream data for I,Q,U,P - no PA rotation')
0208
0209
0210
0211
0212
0213 if(exist('calmat'))
0214 calmat
0215
0216 calmat1=calmat(:,[1,3,5]);
0217 calmat2=calmat(:,[2,4,6]);
0218
0219 invcalmat1 = inv(calmat1);
0220 invcalmat2 = inv(calmat2);
0221
0222 data1 = [Iall(:,1),Qall(:,1),Uall(:,1)];
0223 data2 = [Iall(:,2),Qall(:,2),Uall(:,2)];
0224
0225
0226
0227 for i=1:length(data1(:,1));
0228 data1(i,[1,2,3])=data1(i,[1,2,3])*invcalmat1;
0229 data2(i,[1,2,3])=data2(i,[1,2,3])*invcalmat2;
0230 end
0231
0232 disp('Calibration now applied')
0233
0234 Qall = [data1(:,2),data2(:,2),(data1(:,2)+data2(:,2))/2];
0235 Uall = [data1(:,3),data2(:,3),(data1(:,3)+data2(:,3))/2] ;
0236 Pall = [sqrt(Qall(:,1).^2 + Uall(:,1).^2),sqrt(Qall(:,2).^2 + Uall(:,2).^2),sqrt(Qall(:,3).^2 + Uall(:,3).^2)];
0237
0238 else
0239 disp('No calibration applied')
0240 end
0241
0242
0243
0244
0245
0246
0247
0248
0249
0250
0251
0252
0253
0254
0255
0256
0257
0258 LAT_D = cell2mat(pinfo(strcmp(pinfo(:,1),'LAT-OBS'),2))
0259 LON_D = cell2mat(pinfo(strcmp(pinfo(:,1),'LONG-OBS'),2))
0260
0261 LAT = deg2rad(LAT_D);
0262 LON = deg2rad(LON_D);
0263
0264 JD = mjd2jd(MJD);
0265 LST=lst(JD,deg2rad(LON_D),'m');
0266
0267
0268 sinPA = -((sind(AZ_D).*cosd(LAT_D))./cosd(DEC));
0269 sinPA(abs(sinPA)>=1)=1;
0270 PA_D = asind(sinPA);
0271
0272
0273
0274
0275 for i=1:3
0276 Qall_pa(:,i) = Qall(:,i).*cosd(2*PA_D) - Uall(:,i).*sind(2*PA_D) ;
0277 Uall_pa(:,i) = Uall(:,i).*cosd(2*PA_D) + Qall(:,i).*sind(2*PA_D) ;
0278 Pall_pa(:,i) = (sqrt(Qall_pa(:,i).^2 + Uall_pa(:,i).^2));
0279 end
0280
0281
0282
0283
0284 close all
0285 flagdodgyQ=interactive_flag(Q1);
0286 nanflag = isnan(I1);
0287 flagvector2 = (~nanflag & ~FLAG & ~flagdodgyQ(1:size(Q1,1)));
0288
0289
0290 if(do_pa_rot==1)
0291 allIQUP_pa = {Iall,Qall_pa,Uall_pa,Pall_pa};
0292 else
0293 disp('No parallactic angle rotation applied')
0294 allIQUP_pa = {Iall,Qall,Uall,Pall};
0295 end
0296
0297 figure
0298 for i=1:4
0299 subplot(4,1,i)
0300 for j=1:3
0301 plot(allIQUP_pa{1,i}(flagvector2,j))
0302
0303 hold all
0304 end
0305 xlabel('MJD')
0306 ylabel('Kelvin')
0307 title(allIQUP_labels{i})
0308 end
0309 if(exist('calmat'))
0310 gtitle('Calibrated timestream data for I,Q,U,P - with PA rotation')
0311 else
0312 gtitle('Timestream data for I,Q,U,P - with PA rotation')
0313 end
0314
0315 raster_flags = input('List the rasters you wish to flag e.g. [1 2 3]: ');
0316 if isempty(raster_flags)
0317 raster_flags = [];
0318 end
0319
0320
0321 tsig =(abs(diff(EL_D)));
0322 dsig=(tsig<=1);
0323 [s e]=findStartStop(dsig);
0324
0325
0326 n=0
0327 for m=raster_flags
0328 for i=1:4
0329 n = n+1;
0330 ind = zeros(size(FLAG));
0331 ind(s(m):e(m)) = 1;
0332 ind = logical(ind);
0333 nanflag(ind)=1;
0334 end
0335
0336 end
0337
0338 flagvector2 = (~nanflag & ~FLAG );
0339 figure
0340 for i=1:4
0341 subplot(4,1,i)
0342 for j=1:3
0343 plot(allIQUP_pa{1,i}(flagvector2,j),'.')
0344 hold all
0345 end
0346 xlabel('MJD')
0347 ylabel('Kelvin')
0348 title(allIQUP_labels{i})
0349 end
0350
0351
0352 figure;
0353 plot_labels={'I1','Q1','U1','P1','I2','Q2','U2','P2'};
0354 plot_lims=[-0.5 3.6; -0.08 0.08; -0.05 0.3; 0 0.25];
0355 k=1;
0356 tdate=(mjd2date_v2(MJD));
0357 aa = datenum(tdate.year,tdate.month,tdate.day,tdate.hour,tdate.minute,tdate.second);
0358
0359 for j=1:2
0360
0361 for i=1:4
0362 subplot(2,4,k)
0363
0364 plot(smooth(allIQUP_pa{1,i}(flagvector2,j),10))
0365 xlabel('Time hours')
0366 ylabel('Kelvin')
0367 xlim([min(aa) max(aa)]);
0368 ylim([plot_lims(i,1) plot_lims(i,2)])
0369 datetick('x','hh','keeplimits','keepticks');
0370 title(plot_labels(k));
0371 k=k+1;
0372 end
0373 end
0374
0375
0376
0377
0378
0379 [RA_tau DEC_tau] = sourcePos(source_name)
0380 RA_off = RA-RA_tau;
0381 DEC_off = DEC-DEC_tau;
0382 RA_off = RA_off.*(cosd(DEC));
0383 pixel_size = 0.1;
0384
0385
0386
0387
0388
0389
0390 ramin = - 2;
0391 ramax = + 2;
0392 decmin = - 2;
0393 decmax = + 2;
0394
0395 figure
0396 map_labels={'I','Q','U','P'};
0397 for i=1:4
0398 [TauAmap{i}, xidx, yidx, TauAmapIdx{i}] = bin_quickly2d(ramin, ramax, decmin, decmax, pixel_size,...
0399 RA_off(flagvector2), DEC_off(flagvector2),allIQUP_pa{1,i}(flagvector2,3));
0400 subplot(2,2,i)
0401 imagesc(fliplr(xidx),yidx,TauAmap{i})
0402 title([source_name,' :',map_labels(i)])
0403 xlabel('RA offset, deg')
0404 ylabel('DEC offset, deg')
0405 colormap('default')
0406 colorbar
0407 axis square
0408 end
0409
0410
0411
0412
0413 tsig =(abs(diff(EL_D)));
0414 dsig=(tsig<=1);
0415 [s e]=findStartStop(dsig);
0416
0417
0418
0419 close all
0420
0421 [RA_tau DEC_tau] = sourcePos(source_name);
0422
0423 RA_off = RA-RA_tau;
0424 DEC_off = DEC-DEC_tau;
0425 RA_off = RA_off.*(cosd(DEC));
0426
0427 pixel_size = 0.1;
0428
0429 ramin = - 5;
0430 ramax = + 5;
0431 decmin = - 5;
0432 decmax = + 5;
0433
0434
0435 clim = [0 3.5;-0.02 0.02;-0.02 0.02;0 0.02]
0436
0437 for m= 1:length(s)
0438 n = n+1;
0439 ind = zeros(size(FLAG));
0440 ind(s(m):e(m)) = 1;
0441 ind = logical(ind);
0442 flagvector3 = (~nanflag & ~FLAG & ind & ~flagdodgyQ(1:size(Q1,1)));
0443
0444 for i=1:4
0445 [TauAmap{i}, xidx, yidx, TauAmapIdx{i}] = bin_quickly2d(ramin, ramax, decmin, decmax, pixel_size,...
0446 RA_off(flagvector3), DEC_off(flagvector3),allIQUP_pa{1,i}(flagvector3,3));
0447 figure(m)
0448 subplot(2,2,i)
0449
0450
0451 imagesc(fliplr(xidx),yidx,TauAmap{i})
0452 title([source_name,' map:', num2str(i)])
0453 colormap('default')
0454 colorbar
0455 axis square
0456 end
0457
0458
0459
0460 end
0461
0462
0463
0464
0465
0466
0467
0468
0469
0470 gfit=[];
0471
0472 [RA_tau DEC_tau] = sourcePos(source_name);
0473 JD = mjd2jd(MJD);
0474
0475
0476 LST=lst(JD,deg2rad(LON_D),'m');
0477
0478
0479
0480
0481
0482 LST_hr = LST*24;
0483
0484 ha_deg = ra2ha(RA_tau,LST_hr)*15;
0485 ha_rad = deg2rad(ha_deg);
0486
0487 [A,E]=hdl2ae(ha_rad,deg2rad(DEC_tau),deg2rad(LAT_D)) ;
0488
0489
0490
0491 Az_source = rad2deg(A);
0492 Az_source = wrap360(Az_source);
0493 El_source = rad2deg(E);
0494
0495
0496
0497
0498
0499
0500
0501 Azoff = AZ_D - Az_source;
0502 Eloff = EL_D - El_source;
0503
0504
0505
0506 Azoff = Azoff.*cosd(EL_D);
0507
0508
0509
0510 tsig =(abs(diff(EL_D)));
0511 dsig=(tsig<=1);
0512 [s e]=findStartStop(dsig);
0513
0514 pixel_size = 0.1;
0515
0516 azmin = - 5;
0517 azmax = + 5;
0518 elmin = - 5;
0519 elmax = + 5;
0520
0521
0522 clim = [0 3.5;-0.02 0.02;-0.02 0.02;0 0.04]
0523 n=0
0524 map_labels={'I','Q','U','P'};
0525
0526 for m= 1:length(s)
0527 n = n+1;
0528 ind = zeros(size(FLAG));
0529 ind(s(m):e(m)) = 1;
0530 ind = logical(ind);
0531 flagvector3 = (~nanflag & ~FLAG & ind & ~flagdodgyQ(1:size(Q1,1)));
0532
0533 for i=1:4
0534 for j=1:3
0535 [TauAmap{i,j}, xidx, yidx, TauAmapIdx{i,j}] = bin_quickly2d(azmin, azmax, elmin, elmax, pixel_size,...
0536 Azoff(flagvector3), Eloff(flagvector3),allIQUP_pa{1,i}(flagvector3,j));
0537 figure(m)
0538 subplot(2,2,i)
0539
0540
0541 imagesc(fliplr(xidx),yidx,TauAmap{i})
0542 title([source_name,' :',map_labels(i)])
0543 xlabel('AZ offset, deg')
0544 ylabel('EL offset, deg')
0545 colormap('default')
0546 colorbar
0547 axis square
0548
0549
0550
0551
0552
0553
0554 [sf gof t] = Egauss2D_fit_act(XI,YI,TauAmap{i,j},[],i,gfit,m);
0555 gfit{m,i,j} = sf;
0556 end
0557 end
0558 end
0559
0560
0561 figure
0562 for i=1:4
0563 [TauAmap{i}, xidx, yidx, TauAmapIdx{i}] = bin_quickly2d(azmin, azmax, elmin, elmax, pixel_size,...
0564 Azoff(~flagvector3), Eloff(~flagvector3),allIQUP_pa{1,i}(~flagvector3,3));
0565 figure(m)
0566 subplot(2,2,i)
0567
0568
0569 imagesc(fliplr(xidx),yidx,TauAmap{i})
0570 title([source_name,' :',map_labels(i)])
0571 xlabel('AZ offset, deg')
0572 ylabel('EL offset, deg')
0573 colormap('default')
0574 colorbar
0575 axis square
0576 end