0001 function [mjdList changeList] = ...
0002 plotTemplateEstimates(mjdVec, estimateArray, mjdList)
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 polNames = {'I1'; 'Q3'; 'U3'; 'I2'};
0028
0029
0030
0031
0032 n_phase = size(estimateArray,1);
0033 n_pol = length(polNames);
0034 n_pad = round(12*(mjdVec(end) - mjdVec(1)))+1;
0035
0036 if n_pad > length(mjdVec)
0037
0038 mjdVec_pad = mjdVec(1) + (0:n_pad-1)/12;
0039
0040
0041 estimateArray_pad = zeros(n_phase,n_pad,n_pol);
0042
0043 j = 0;
0044 dt = round(diff(12*mjdVec));
0045 for k=1:length(mjdVec)
0046
0047 if k > 1 && dt(k-1) > 1
0048
0049 j = j + dt(k-1) - 1;
0050 end
0051 estimateArray_pad(:,k+j,:) = estimateArray(:,k,:);
0052 end
0053 else
0054
0055 mjdVec_pad = mjdVec;
0056 estimateArray_pad = estimateArray;
0057 end
0058
0059
0060
0061
0062 displayintro();
0063
0064
0065
0066 thetaVec = ((1:n_phase) - 0.5) / n_phase * 2 * pi;
0067
0068
0069
0070
0071
0072
0073
0074 scaleEstimate = 2.0 * median(abs(estimateArray_pad));
0075
0076 estimateArray_pad = estimateArray_pad ./ repmat(scaleEstimate, [n_phase 1 1]);
0077
0078
0079
0080 changeList = zeros(size(mjdList));
0081
0082
0083
0084
0085
0086 whichpol = 1;
0087 whichpol_last = 0;
0088 zoomrange = [min(mjdVec_pad) max(mjdVec_pad)];
0089 deletebound = 0;
0090 createbound = 0;
0091 nbound = length(mjdList);
0092
0093
0094
0095 loopval = 1;
0096 while loopval
0097
0098
0099 gcf;
0100 axis ij;
0101 hold on;
0102 ylabel('Phase (radians)');
0103 xlabel('MJD');
0104
0105
0106
0107
0108
0109
0110 if whichpol ~= whichpol_last
0111
0112
0113 title(polNames{whichpol});
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124
0125
0126
0127 imagesc(mjdVec_pad,thetaVec,estimateArray_pad(:,:,whichpol), [-1.0 1.0]);
0128
0129
0130
0131 handleVec = zeros(nbound,1);
0132 for k=1:nbound
0133 handleVec(k) = ...
0134 plot([mjdList(k) mjdList(k)], thetaVec([1 end]), 'm--', 'LineWidth', 4);
0135 end
0136
0137
0138 whichpol_last = whichpol;
0139
0140
0141
0142 elseif createbound ~= 0
0143
0144
0145 createbound = round(createbound * 12) / 12;
0146
0147
0148 disp(['Creating new boundary at ' mjd2string(createbound)]);
0149
0150
0151 mjdList(end+1) = createbound;
0152 changeList(end+1) = 1;
0153
0154 handleVec(end+1) = ...
0155 plot([createbound createbound], thetaVec([1 end]),'m--','LineWidth',4);
0156
0157
0158 nbound = nbound + 1;
0159
0160
0161 createbound = 0;
0162
0163
0164
0165
0166 elseif deletebound ~= 0 && nbound > 0
0167
0168
0169 [poo, delInd] = min(abs(mjdList - deletebound));
0170
0171 if min(abs(mjdList(delInd)-mjdVec(1)),abs(mjdList(delInd)-mjdVec(end))) <= 1/24
0172 disp('Sorry. Cannot delete boundary so close to plot edge.')
0173
0174 else
0175
0176 delQuery = ...
0177 input(['Delete boundary at ' mjd2string(mjdList(delInd)) ...
0178 '? (Y/N) '],'s');
0179
0180
0181 if strcmpi(delQuery,'y')
0182 delete(handleVec(delInd));
0183 handleVec(delInd) = [];
0184 mjdList(delInd) = [];
0185
0186
0187 if changeList(delInd) == 0 && delInd > 1
0188 changeList(delInd-1) = 2;
0189 end
0190 changeList(delInd) = [];
0191
0192 nbound = nbound - 1;
0193 end
0194 end
0195
0196 deletebound = 0;
0197 end
0198
0199
0200
0201 ylim([0 2*pi]);
0202 xlim(zoomrange);
0203
0204
0205 hold off;
0206
0207
0208
0209 [x, poo, button] = ginput(1);
0210
0211
0212
0213 if isempty(button)
0214 continue
0215 end
0216
0217
0218
0219 switch button
0220
0221
0222 case 113
0223 fprintf('\nYou have chosen to quit the interactive stage.\n');
0224 quitQuery = input( ...
0225 'Are you sure? (Y/N) ','s');
0226 if strcmpi(quitQuery,'y')
0227 loopval = 0;
0228 end
0229
0230
0231 case 122
0232 disp('Zooming...');
0233
0234 [x2, poo, button] = ginput(1);
0235
0236 if abs(x2-x) < 1/20.
0237 disp(' ... zero zoom range. Try again.');
0238
0239
0240 elseif button == 122 || button == 1
0241 zoomrange = sort([x x2]);
0242 end
0243
0244
0245 case 117
0246
0247
0248 zoomrange = [min(mjdVec_pad) max(mjdVec_pad)];
0249
0250
0251 case 100
0252
0253
0254 deletebound = x;
0255
0256
0257 case 99
0258
0259
0260 createbound = x;
0261
0262
0263 case 93
0264
0265
0266 if whichpol < 4
0267 whichpol = whichpol + 1;
0268 else
0269 whichpol = 1;
0270 end
0271
0272
0273 case 91
0274
0275
0276 if whichpol > 1
0277 whichpol = whichpol - 1;
0278 else
0279 whichpol = 4;
0280 end
0281
0282
0283 case 112
0284
0285 whichpolS = ...
0286 input('Which polarization? (1=I1, 2=Q3, 3=U3, 4=I2) ','s');
0287
0288
0289
0290 switch whichpolS
0291 case '1'
0292 whichpol = 1;
0293 case '2'
0294 whichpol = 2;
0295 case '3'
0296 whichpol = 3;
0297 case '4'
0298 whichpol = 4;
0299 otherwise
0300 disp('Invalid choice.');
0301 end
0302
0303
0304 case 116
0305
0306 disp(['Mouse position: ' mjd2string(x)]);
0307
0308
0309 case 104
0310
0311 displayhelp();
0312 end
0313 end
0314
0315
0316
0317
0318
0319 [mjdList,sortI,sortJ] = unique(mjdList,'last');
0320
0321 changeList = changeList(sortI);
0322
0323
0324 lenChange = find(changeList(1:end-1) == 0 & changeList(2:end) == 1);
0325 if ~isempty(lenChange)
0326 changeList(lenChange) = 2;
0327 end
0328
0329
0330
0331
0332 changeList(end) = 2 - changeList(end);
0333
0334 close(gcf);
0335
0336 end
0337
0338
0339
0340 function r = displayintro()
0341
0342 disp('====================================');
0343 disp('= Welcome to the Interactive =');
0344 disp('= Load Boundary Identification =');
0345 disp('====================================');
0346 disp(' ');
0347 disp('You are cordially requested to view the');
0348 disp('2-hour load templates for the filtered');
0349 disp('I1, Q3, U3, and I2 channels. Previously');
0350 disp('identified boundaries are denoted by');
0351 disp('magenta lines. Please use your judgement ');
0352 disp('to add or remove cold load boundaries.');
0353 disp(' ');
0354 disp('Fewer boundaries means higher SNR for');
0355 disp('the templates. Boundaries are necessary, ');
0356 disp('however, when changes in the ');
0357 disp('template structure occur.');
0358 disp(' ');
0359 disp('Press h for help.');
0360 disp(' ');
0361 disp('Take care.');
0362 disp(' ');
0363 disp('====================================');
0364 disp(' ');
0365
0366 r = 1;
0367 end
0368
0369
0370
0371 function r = displayhelp()
0372
0373 disp('====================================');
0374 disp('= Interactive Load Boundary Help =');
0375 disp('====================================');
0376 disp(' ');
0377 disp('Position your mouse pointer over the ');
0378 disp('plot window and use keyboard to input');
0379 disp('commands');
0380 disp(' ');
0381 disp('c -- Create a new load boundary at the');
0382 disp(' chosen location.');
0383 disp('d -- Delete the load boundary closest ');
0384 disp(' to the cursor.');
0385 disp('z -- Zoom in mjd. Press at the ');
0386 disp(' desired extrema.');
0387 disp('u -- Unzoom to full length.');
0388 disp('[ -- View the previous polarization.');
0389 disp('] -- View the next polarization.');
0390 disp('p -- Choose a polariation to view.');
0391 disp('t -- UTC at the current mouse position.');
0392 disp('h -- This help message.');
0393 disp('q -- Quit the interactive step and move on.');
0394 disp(' ');
0395 disp('====================================');
0396 disp(' ');
0397
0398 r = 1;
0399 end