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