0001 function data=plotMainsReg(d, flags, xc, txt, ax, prop, w, chunk, h, ind1)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031 if(exist('w')~=1)
0032 w = 2;
0033 end
0034
0035
0036 if (~exist('ax'))
0037 ax=[];
0038 end
0039
0040
0041 if (exist('prop'))
0042 p=setProperties(prop);
0043 else
0044 p=setProperties([]);
0045 end
0046
0047
0048
0049 num = 1;
0050 plotsPerPage = 6;
0051 matrix = [3 2];
0052
0053 plotoptions = {'b', 'g', 'r', 'c', 'm', 'y', 'k', ...
0054 'b.', 'g.', 'r.', 'c.', 'm.', 'y.', 'k.', ...
0055 'bo', 'go', 'ro', 'co', 'mo', 'yo', 'ko', ...
0056 'bx', 'gx', 'rx', 'cx', 'mx', 'yx', 'kx'};
0057
0058 data = d.antenna0.receiver.dataT;
0059 data(d.flags.fast) = nan;
0060 timeVal = d.antenna0.receiver.utc*24*60*60;
0061 timeVal_1 = circshift(timeVal,1);
0062
0063 pageNum=1;
0064 fmode=logical(0);
0065
0066 while(1)
0067 if (w~=0 & w~=1)
0068 figure(1)
0069 setwinsize(gcf, 1000, 750);
0070 clear leg;
0071 for plotNum=1:plotsPerPage
0072 indices = d.correction.mains.indices(plotNum,:);
0073 subplot(matrix(1),matrix(2),plotNum)
0074
0075 optionIndex = 1;
0076 for mm=1:size(d.correction.mains.factors,2)
0077 if(mm==1)
0078
0079 [boo, coo, h(pageNum, plotNum,optionIndex)] = plot_powerspec(d, ...
0080 data(:,plotNum), indices(1), indices(2), ...
0081 0, plotoptions{optionIndex});
0082 hold on;
0083 leg{optionIndex} = 'Orig';
0084 optionIndex = optionIndex+1;
0085 end
0086 clear boo;
0087 clear coo;
0088
0089
0090
0091 best_freq = d.correction.mains.factors(plotNum,mm,1);
0092 best_phase= d.correction.mains.factors(plotNum,mm,2);
0093 best_amp = d.correction.mains.factors(plotNum,mm,3);
0094
0095 best_fit_sin = cos((timeVal*2*pi*(best_freq))+best_phase) ...
0096 - cos((timeVal_1*2*pi*(best_freq))+best_phase);
0097
0098 best_fit_sin = best_fit_sin * best_amp;
0099
0100
0101
0102
0103
0104
0105 data(:,plotNum) = data(:,plotNum)-best_fit_sin;
0106
0107
0108 [boo, coo, h(pageNum, plotNum,optionIndex)] = plot_powerspec(d, ...
0109 data(:,plotNum), indices(1), indices(2), ...
0110 0, plotoptions{optionIndex});
0111 hold on;
0112 leg{optionIndex} = sprintf('Harmonic %u', mm);
0113 optionIndex = optionIndex+1;
0114 end
0115 xlabel(txt{2});
0116 ylabel(txt{3});
0117 thisTitle = sprintf('%s %u', txt{1}{1}, plotNum);
0118 title(thisTitle);
0119 end
0120
0121 legend(leg,'Location','Best');
0122 gtitle('Mains Hum Removal');
0123 w=waitforbuttonpress;
0124 if (~w)
0125
0126
0127 else
0128
0129
0130 [pageNum,format,p]=evalkey(d,pageNum,plotsPerPage,'matrix',p,num);
0131
0132 if(pageNum<0)
0133 return
0134 end
0135 if (strcmp(format,'swap'))
0136 numbuf=num;
0137 num=matrix;
0138 matrix=numbuf;
0139 pageNum=1;
0140 p.swap=~p.swap;
0141 clear h;
0142 close(1)
0143 end
0144 end
0145
0146 w=2;
0147 else
0148
0149
0150
0151
0152
0153
0154
0155
0156
0157
0158
0159
0160
0161
0162
0163
0164
0165
0166
0167
0168
0169
0170
0171
0172
0173
0174
0175 end
0176 end
0177
0178
0179
0180
0181
0182 function p=setProperties(p)
0183
0184 if (isempty(p))
0185 p.style='flag';
0186 p.swap=0;
0187 p.featflag=0;
0188 return
0189 end
0190
0191 if (isfield(p,'style'))
0192
0193 else
0194 p.style='flag';
0195 p.featflag=0;
0196 end
0197
0198 if (~isfield(p,'swap'))
0199 p.swap=0;
0200 end
0201
0202 return;
0203
0204
0205
0206
0207
0208 function [m,n]=swapIndex(swap,i,j)
0209
0210 if (swap)
0211 m=j; n=i;
0212 else
0213 m=i; n=j;
0214 end
0215
0216
0217
0218 function h=plotflag(x,allflags,ax,pageNum,plotNum,txt,w,num,matrix,swap, multLinesPerPlot)
0219
0220 [flag,autoflag,scriptflag]=cloneflag(allflags);
0221
0222
0223 if(size(x,1)==4)
0224 plot(x{1,pageNum},x{4,pageNum}(:,plotNum),'c.','MarkerSize',10);
0225 hold on;
0226 end
0227
0228
0229
0230 h=plot(x{1,pageNum},x{2,pageNum}(:,plotNum),'b.','MarkerSize',10);
0231 manaxis(ax,x{2,pageNum}(:,plotNum))
0232 hold on;
0233
0234 plotdescription(txt,plotNum,pageNum,num,matrix,swap);
0235
0236
0237
0238 manaxis(ax,x{2,pageNum}(:,plotNum));
0239
0240
0241 numpts = size(x{1,pageNum},1);
0242
0243
0244 if (~isempty(autoflag))
0245 f = find(autoflag{1,pageNum}(:,plotNum));
0246 if (~isempty(f))
0247 h=plot(x{1,pageNum}(f),x{2,pageNum}(f,plotNum),'m.','MarkerSize',10);
0248 end
0249 end
0250
0251
0252 if (~isempty(scriptflag))
0253 f = find(scriptflag{1,pageNum}(:,plotNum));
0254 if (~isempty(f))
0255 h=plot(x{1,pageNum}(f),x{2,pageNum}(f,plotNum),'g.','MarkerSize',10);
0256 end
0257 end
0258
0259
0260 if (~isempty(flag))
0261
0262 f = find(flag{1,pageNum}(:,plotNum));
0263 if (~isempty(f))
0264 h=plot(x{1,pageNum}(f),x{2,pageNum}(f,plotNum),'r.','MarkerSize',10);
0265 end
0266 end
0267
0268 hold off
0269
0270 return;
0271
0272
0273
0274 function [h, leg] = plotfeat(x,allflags,ax,pageNum,plotNum,txt,w,num,matrix,swap)
0275
0276
0277
0278
0279
0280 [flag,autoflag,scriptflag]=cloneflag(allflags);
0281
0282
0283 [clr, legall] = getcolor('feature');
0284
0285
0286 index = 1;
0287 leg = [];
0288 for m=1:length(legall)
0289 txt1 = sprintf('a = x{1,pageNum}(x{3,pageNum}.%s);', legall{m});
0290 txt2 = sprintf('b = x{2,pageNum}(x{3,pageNum}.%s, plotNum);', legall{m});
0291 eval(txt1); eval(txt2);
0292
0293
0294 if(sum(a)>0)
0295 txtPlot = sprintf('h = plot(a, b, ''.'', ''markerfacecolor'', clr(m,:), ''markeredgecolor'', clr(m,:), ''MarkerSize'',10);');
0296 eval(txtPlot);
0297 hold on;
0298 leg{index} = legall{m};
0299 index = index+1;
0300 end
0301 end
0302
0303
0304
0305 if (~isempty(autoflag))
0306 f = find(autoflag{1,pageNum}(:,plotNum));
0307 if (~isempty(f))
0308 h=plot(x{1,pageNum}(f),x{2,pageNum}(f,plotNum),'m.','MarkerSize',10);
0309 leg{index} = 'auto flag';
0310 index = index+1;
0311 end
0312 end
0313
0314
0315 if (~isempty(scriptflag))
0316 f = find(scriptflag{1,pageNum}(:,plotNum));
0317 if (~isempty(f))
0318 h=plot(x{1,pageNum}(f),x{2,pageNum}(f,plotNum),'g.','MarkerSize',10);
0319 leg{index} = 'script flag';
0320 index = index+1;
0321 end
0322 end
0323
0324
0325 if (~isempty(flag))
0326
0327 f = find(flag{1,pageNum}(:,plotNum));
0328 if (~isempty(f))
0329 h=plot(x{1,pageNum}(f),x{2,pageNum}(f,plotNum),'r.','MarkerSize',10);
0330 leg{index} = 'user flag';
0331 index = index+1;
0332 end
0333 end
0334
0335
0336
0337 manaxis(ax,x{2,pageNum}(:,plotNum))
0338 plotdescription(txt,plotNum,pageNum,num,matrix,swap);
0339
0340 hold off
0341
0342 return;
0343
0344
0345
0346 function plotdescription(txt,n,m,num,matrix,swap)
0347
0348 if (matrix(1)==2 & matrix(2)==3)
0349
0350 title(sprintf('Channel: %u', n));
0351 elseif (matrix(1)==4 & matrix(2)==6)
0352
0353 title(sprintf('Switch State Number: %u Ant: %u',n));
0354 elseif (num==6)
0355
0356 title(sprintf('Channel Number: %u', m));
0357 elseif(num==24)
0358
0359 title(sprintf('Switch State Number: %u', m));
0360 elseif(matrix(1) == 1 & matrix(2)==2)
0361
0362 title(sprintf('Opacity for Channel: %u', m));
0363 end
0364
0365 if(~isempty(txt))
0366 xlabel(char(txt{2}));
0367 ylabel(char(txt{3}));
0368 end
0369
0370 return;
0371
0372
0373
0374 function manaxis(ax,y)
0375
0376 if (~isempty(ax))
0377 ax4orig = ax(4);
0378 ymax=max(y)*1.1;
0379 if (max(y)>ax(4))
0380
0381 ax(4)=ymax;
0382 elseif (8*nanmean(y)<ax(4) & ax(3)>=0)
0383
0384
0385
0386
0387 ax(4)=ymax;
0388 elseif (isnan(ax(4)) | isnan(ax(3)))
0389 if (isnan(ax(4)))
0390 ax(4)=1;
0391 end
0392 if (isnan(ax(3)))
0393 ax(3)=0;
0394 end
0395 end
0396
0397
0398
0399
0400 if(ax(3) >= ax(4))
0401 if(ax4orig>ax(3))
0402 ax(4) = ax4orig;
0403 else
0404 ax(4) = ax(3)+1;
0405 end
0406 end
0407 axis(ax);
0408 end
0409
0410 return;
0411
0412
0413 function [inc,format,p]=evalkey(d,inc,num,type,p,numPages)
0414
0415 format='default';
0416 ch=get(gcf,'CurrentCharacter');
0417 switch ch
0418 case 'p'
0419 inc=inc-1;
0420
0421 case 'n'
0422 inc=inc+1;
0423
0424 case 'q'
0425 if (strcmp(type,'zoom'))
0426 close(2)
0427 else
0428 close(1)
0429 end
0430 inc=-1;
0431
0432 otherwise
0433 inc=inc;
0434 end
0435
0436 if (strcmp(type,'matrix'))
0437 if(inc>numPages)
0438 inc = 1;
0439 elseif(inc==0)
0440 inc=numPages;
0441 end
0442 else
0443 if (inc>num)
0444 inc=1;
0445 elseif (inc==0)
0446 inc=num;
0447 end
0448 end
0449
0450
0451
0452 return;
0453
0454
0455 function printhelp()
0456
0457 disp(' ')
0458 disp('******************************')
0459 disp(' Plotting Help ')
0460 disp('******************************')
0461 disp(' ');
0462 disp('IN PLOT WINDOW (MATRIX and ZOOM)')
0463 disp(' ')
0464 disp('h - command menu')
0465 disp('p - Previous plots')
0466 disp('n - Next plots')
0467 disp('q - exit plot')
0468 disp(' ')
0469 disp(' ')
0470 disp('*******************WARNING*********************')
0471 disp('*******************WARNING*********************')
0472 disp('*******************WARNING*********************')
0473 disp('*******************WARNING*********************')
0474 disp('*******************WARNING*********************')
0475 disp('Do not exit plot by manually killing the window.')
0476 disp('This will cause the program to crash!')
0477 disp('***********************************************')
0478 disp(' ')
0479
0480
0481 return;
0482
0483
0484
0485 function [clr,leg]=getcolor(type)
0486
0487 clr=[ 0.2 0 0;
0488 1 0.66 0;
0489 1 0 1;
0490 0.5 0.2 1;
0491 0.2 0.2 0.8;
0492 1 0.5 0.12;
0493 0.1 0.5 0.9;
0494 0.75 1 1;
0495 0.2 0.5 0.66;
0496 0.9 0.8 0.7;
0497 0.6 0 0.1;
0498 0 0 1
0499 0.5869 0.1909 0.3461
0500 0.0576 0.8439 0.1660
0501 0.3676 0.1739 0.1556
0502 0.6315 0.1708 0.1911
0503 0.7176 0.9943 0.4225
0504 0.6927 0.4398 0.8560
0505 0.0841 0.3400 0.4902
0506 0.4544 0.3142 0.8159
0507 0.4418 0.3651 0.4608
0508 0.3533 0.3932 0.4574
0509 0.1536 0.5915 0.4507
0510 0.6756 0.1197 0.4122
0511 0.6992 0.0381 0.9016
0512 0.7275 0.4586 0.0056
0513 0.4784 0.8699 0.2974
0514 0.5548 0.9342 0.0492
0515 0.1210 0.2644 0.6932
0516 0.4508 0.1603 0.6501
0517 0.7159 0.8729 0.9830
0518 0 0 0];
0519
0520
0521 switch type
0522 case 'feature'
0523 leg = {'source', 'calibrator', 'abscal', 'blank', 'skydip', ...
0524 'noise_event', 'noise'};
0525
0526 case 'bitmask'
0527 leg={'frame','receiver', 'tracking', 'tracker', 'elevation', ...
0528 'continuous', 'fifo', 'clock', '1pps', 'cryo/servo', 'backend time', 'shortfall', 'sun', 'moon'};
0529 end
0530
0531 return;
0532
0533