-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdataTimesCB.m
More file actions
505 lines (484 loc) · 17.3 KB
/
dataTimesCB.m
File metadata and controls
505 lines (484 loc) · 17.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
action = get(gcbo,'Tag');
hfig = get(gcbo,'Parent');
UD = get(hfig,'UserData');
DataFiles = UD.DataFiles;
NIMSinfo = UD.NIMSinfo;
Sites = UD.Sites;
maxSites = UD.MaxSites;
HZ = UD.HZ;
getOS;
dataHome = [ getenv('MTdata') filesep DataFiles{1}.surveyName ];
dataDir = [ dataHome filesep 'data' filesep];
binDir = getenv('MTbin');
header = '';
switch action
case 'Segment'
v = get(gcbo,'Value');
UD = get(gcbo,'UserData');
if ~isempty(UD.hSeg)
if v
set(gcbo,'ForeGroundColor',[1,0,0]);
if isfield(UD.hSeg,'Color') || isprop(UD.hSeg,'Color')
set(UD.hSeg,'Color',[1,0,0]);
end
else
set(gcbo,'ForeGroundColor',UD.defClr);
if isfield(UD.hSeg,'Color') || isprop(UD.hSeg,'Color')
set(UD.hSeg,'Color',UD.defClr);
end
end
end
H = findobj('Parent',hfig,'Tag','Segment');
SelectedDataFiles = {};
FileNames = {};
nFiles = 0;
allFiles = [];
for l = 1:length(H)
if get(H(l),'value')
UD = get(H(l),'UserData');
nFiles = nFiles+1;
SelectedDataFiles{nFiles} = DataFiles{UD.iFile};
if length(UD.Name) == 7
sName = [UD.Name(3) UD.Name(5:7)];
else
sName = UD.Name;
end
FileNames{nFiles} = UD.Name;
allFiles = [allFiles sName ';'];
end
end
% set text window
if(length(allFiles) > 0)
allFiles = allFiles(1:end-1);
end
set(findobj('Parent',hfig,'Tag','FileNames'),...
'String',allFiles,'UserData',SelectedDataFiles);
% Enable buttons checks number of files in selected group,
% enables shift, proecessing buttons accordingly
SelectedSites = uniqueSites(SelectedDataFiles);
EnableButtons
case 'decimated'
% no need to do anything for this case ... just
% check value before loading files
case 'Load'
set(hfig,'Pointer','Watch')
% make list of selected file names
H = findobj('Parent',hfig,'Tag','Segment');
LDF = {};
nFiles = 0;
scaleFac = [];
rescaleData = 1;
for l = 1:length(H)
if get(H(l),'value')
UD = get(H(l),'UserData');
nFiles = nFiles+1;
LDF{nFiles} = DataFiles{UD.iFile};
LDF{nFiles}.FileName = UD.Name;
if length(LDF{nFiles}.scaleFactors)>0
scaleFac = [scaleFac LDF{nFiles}.scaleFactors];
else
rescaleData = 0;
end
end
end
plotStart = get(findobj('Tag','Plot','Parent',hfig),'UserData');
DEC = get(findobj('Tag','decimated','Parent',hfig),'value') ;
if(DEC)
for k = 1:length(LDF)
FileNames{k} = [LDF{k}.FileName '.dbn'];
LDF{k}.FileName = FileNames{k};
end
else
for k = 1:length(LDF)
FileNames{k} = [LDF{k}.FileName '.bin'];
LDF{k}.FileName = FileNames{k};
end
end
% add list of selected file names to list of LOADED
LOADED = get(gcbo,'UserData');
nLoaded = length(LOADED);
if nLoaded > 0
LOADEDnames = get(findobj('Tag','Plot List','Parent',hfig),'String');
else
LOADEDnames = {};
end
iA = nLoaded+1 ;
LOADEDnames{iA} = get(findobj('Parent',hfig,'Tag','FileNames'),...
'String');
set(findobj('Tag','Plot List','Parent',hfig),...
'String',LOADEDnames,'Enable','on','Value',iA);
set(findobj('Tag','Plot','Parent',hfig),'Enable','on')
% load NIMS data ... no decimation, scale data to nT, mV
% (NOT mV/km)
decFac = 1;
SCALE = 1;
currentDir = pwd;
eval(['cd ''' dataDir '''']);
[y,SysTF,dt,t0,dataZero,ch,sta,error] = readTSnims(FileNames,decFac,SCALE);
eval(['cd ''' currentDir '''']);
% rescale data channels to physical units
if rescaleData
[nch,npts] = size(y);
for k = 1:nch
y(k,:) = scaleFac(k)*y(k,:);
end
end
% set up TSd
TSd1 = setTSd(y,t0,dt,ch,sta,SysTF,dataZero);
TSd1.sta = char(TSd1.sta);
data0 = (TSd1.range(:,1)+TSd1.range(:,2))/2;
rng = (TSd1.range(:,2)-TSd1.range(:,1))/2;
rng = plotStart.rangeScale*rng;
TSd1.range(:,1:2) = [ data0-rng data0+rng];
TSd1.DataDir = dataDir;
TSd1.arrayID = LDF{1}.Name;
% copy into cell arrays
if iA == 1
TSdata = {};
TSd = {};
end
TSdata{iA} = y;
clear y
TSd{iA} = TSd1;
clear TSd1
LDF{1}.dt = dt;
LOADED{iA}=LDF;
set(gcbo,'UserData',LOADED);
set(hfig,'Pointer','Arrow')
% Enable buttons checks number of files in selected group,
% enables shift, proecessing buttons accordingly
EnableButtons
% now set based on what is in selction window
% need sampling rate for shifting ... we are assuming that
% the same sampling rate is used for all files loaded
case 'Plot List'
iA = get(gcbo,'Value');
% Enable buttons checks number of files in selected group,
% enables shift, proecessing buttons accordingly
EnableButtons
case 'Plot'
iA = get(findobj('Tag','Plot List','Parent',hfig),'Value');
plotStart = get(gcbo,'UserData');
% reset nPw (# of points to plot initially on one page) now
% that dt has been read from data file (NOTE: dt returned
% by readTSnims accounts for subsampling by a factor of decFac)
dt = TSd{iA}.dt;
nPw = fix(plotStart.tFac*plotStart.nTunits/dt);
plotStart.nPw = nPw;
rect = plotStart.rect;
[hTSw,TSw1] = plotTSwin(TSd{iA},plotStart);
TSfigInd(hTSw.Number) = iA;
% set(hTSw,'Name',DataArrays{iA});
i0 = TSw1.i0; i1 = TSw1.i1; di = TSw1.di;
yFac = TSw1.yFac;
ddt = TSd{iA}.dt/TSw1.tFac;
t0 = (TSd{iA}.t0)*(1-TSw1.t0Eq0)/TSw1.tFac;
I = i0:di:min(i1,size(TSdata{iA},2));
[TSw1] = plotPage(ddt*I+t0,...
yFac*TSdata{iA}(:,I),...
TSw1,TSd{iA},1);
TSw{iA} = TSw1;
TSc = {};
TSp= {};
% LOADED = get(findobj('Tag','Load','Parent',hfig),'UserData');
% FileNames = LOADED{iPlot};
case 'Map'
nSites = length(SelectedSites);
if nSites==1
% do nothing
else
Lats = zeros(nSites,1);Lons = Lats;
for k = 1:nSites
Lats(k) = SelectedSites{k}.lat;
Lons(k) = SelectedSites{k}.lon;
end
minLat = min(Lats);
minLon = min(Lons);
maxLat = max(Lats);
maxLon = max(Lons);
midLat = (maxLat+minLat)/2;
midLon = (maxLon+minLon)/2;
X = 111*cos(pi*midLat/180)*(Lons-midLon);
Y = 111*(Lats-midLat);
xR = max(X)-min(X);
yR = max(Y)-min(Y);
asp = yR/xR;
if(asp < 1)
Rect = [100,100,400,400*asp];
orient = 'LandScape';
else
Rect = [100,100,400/asp,400];
orient = 'Portrait';
end
figure('Position',Rect,'PaperOrientation',orient,...
'PaperPosition',Rect/100,'Name','Site Map');
plot(X,Y,'r+','MarkerSize',14,'LineWidth',2)
set(gca,'FontWeight','demi','FontSize',12)
xlabel('km E')
ylabel('km N')
for k = 1:nSites
ShortName = SelectedSites{k}.Name([3 end-1:end]);
text(X(k)+5,Y(k)-5,ShortName,'FontWeight','demi');
end
end
case 'Shift'
iA = get(findobj('Tag','Plot List','Parent',hfig),'Value');
LDF = LOADED{iA};
set(hfig,'Pointer','watch')
shiftPlotStart(TSdata{iA},LDF)
set(hfig,'Pointer','arrow')
case 'xmledit'
SelectedDataFiles = get(findobj('Parent',hfig,'Tag','FileNames'),...
'UserData');
xmleditfig = checkHeaderGUI(SelectedDataFiles{1}.metaData,'xmlEdit');
%disp(SelectedDataFiles{1}.metaData);
case 'dnff'
SelectedDataFiles = get(findobj('Parent',hfig,'Tag','FileNames'),...
'UserData');
currentDir = pwd;
eval(['cd ''' dataHome ''''])
binFile = [SelectedDataFiles{1}.Name '.bin'];
dnffRunFile = ['tmp' filesep SelectedDataFiles{1}.Name 'FT.cfg'];
logFile = ['tmp' filesep SelectedDataFiles{1}.Name 'FT.log'];
fid = fopen(dnffRunFile,'w');
fprintf(fid,'%s\n',binFile);
fprintf(fid,'%s\n','n');
fclose(fid);
if exist(['FC' filesep SelectedDataFiles{1}.Name '.f5'],'file')
system(['rm FC' filesep SelectedDataFiles{1}.Name '.f5']);
end
system([binDir 'dnff -B < ' dnffRunFile '>! ' logFile ' &'])
eval(['cd ''' currentDir '''']);
case 'RR'
SelectedDataFiles = get(findobj('Parent',hfig,'Tag','FileNames'),...
'UserData');
optionsFile = get(gcbo,'UserData');
ComputeTF(SelectedDataFiles,'RR',optionsFile);
case 'SS'
SelectedDataFiles = get(findobj('Parent',hfig,'Tag','FileNames'),...
'UserData');
optionsFile = get(gcbo,'UserData');
ComputeTF(SelectedDataFiles,'SS',optionsFile);
case 'MMT'
SelectedDataFiles = get(findobj('Parent',hfig,'Tag','FileNames'),...
'UserData');
optionsFile = get(gcbo,'UserData');
ComputeTF(SelectedDataFiles,'MMT',optionsFile);
case 'MaxTimeString'
hMax = gcbo;
hMin = findobj('Parent',hfig,'Tag','MinTimeString');
tL2 = round(str2num(get(hMax,'String')));
tL1 = round(str2num(get(hMin,'String')));
Tdata = get(hMax,'UserData');
% check that tL2 is in range, adjust if not
if tL2 > Tdata(2)
tL2 = Tdata(2);
set(hMax,'String',num2str(tL2));
elseif tL2 < Tdata(1) + Tdata(3)
tL2 = round(Tdata(1) + Tdata(3));
set(hMax,'String',num2str(tL2));
end
% set slider to adjusted tL2 value
set(findobj('Parent',hfig,'Tag','MaxTimeSlider'),'Value',tL2);
% Then check to see if lower limit should be adjusted
if tL1 > tL2 - Tdata(3)
tL1 = round(tL2-Tdata(3));
% set text window, slider to adjusted tL1 value
set(hMin,'String',num2str(tL1));
set(findobj('Parent',hfig,'Tag','MinTimeSlider'),'Value',tL1);
end
case 'MinTimeString'
hMin = gcbo;
hMax = findobj('Parent',hfig,'Tag','MaxTimeString');
tL2 = str2num(get(hMax,'String'));
tL1 = round(str2num(get(hMin,'String')));
Tdata = get(hMin,'UserData');
% check that tL1 is in range, adjust if not
if tL1 < Tdata(1)
tL1 = Tdata(1);
set(hMin,'String',num2str(tL1));
elseif tL1 > Tdata(2) - Tdata(3)
tL1 = Tdata(2) - round(Tdata(3));
set(hMin,'String',num2str(tL1));
end
% set slider to adjusted tL2 value
set(findobj('Parent',hfig,'Tag','MinTimeSlider'),'Value',tL1);
% Then check to see if upper limit should be adjusted
if tL2 < tL1 + Tdata(3)
tL2 = tL1+round(Tdata(3));
% set text window, slider to adjusted tL2 value
set(hMax,'String',num2str(tL2));
set(findobj('Parent',hfig,'Tag','MaxTimeSlider'),'Value',tL2);
end
case 'MaxTimeSlider'
hMax = gcbo;
hMin = findobj('Parent',hfig,'Tag','MinTimeSlider');
tL2 = round(get(hMax,'Value'));
tL1 = round(get(hMin,'Value'));
Tdata = get(hMax,'UserData');
% set edit window to new tL2 value
set(findobj('Parent',hfig,'Tag','MaxTimeString'),...
'String',num2str(tL2));
% Then check to see if lower limit should be adjusted
if tL1 > tL2 - Tdata(3)
tL1 = tL2-round(Tdata(3));
% set text window, slider to adjusted tL1 value
set(hMin,'Value',tL1);
set(findobj('Parent',hfig,'Tag','MinTimeString'),...
'String',num2str(tL1));
end
case 'MinTimeSlider'
hMin = gcbo;
hMax = findobj('Parent',hfig,'Tag','MaxTimeSlider');
tL2 = round(get(hMax,'Value'));
tL1 = round(get(hMin,'Value'));
Tdata = get(hMin,'UserData');
% set edit window to new tL1 value
set(findobj('Parent',hfig,'Tag','MinTimeString'),...
'String',num2str(tL1));
% Then check to see if upper limit should be adjusted
if tL2 < tL1 + Tdata(3)
tL2 = tL1+round(Tdata(3));
% set text window, slider to adjusted tL2 value
set(hMax,'Value',tL2);
set(findobj('Parent',hfig,'Tag','MaxTimeString'),...
'String',num2str(tL2));
end
case 'Replot Data Times'
tL1 = str2num(get(findobj('Parent',hfig,...
'Tag','MinTimeString'),'String'));
tL2 = str2num(get(findobj('Parent',hfig,...
'Tag','MaxTimeString'),'String'));
plotStart = get(findobj('Tag','Plot','Parent',hfig),'UserData');
delete(hfig)
clear TSd
clear TSw
clear TSdata
dataTimes(DataFiles,NIMSinfo,Sites,plotStart,[tL1,tL2],HZ)
case 'Sort Alph'
tL1 = get(findobj('Parent',hfig,...
'Tag','MinTimeSlider'),'Value');
tL2 = get(findobj('Parent',hfig,...
'Tag','MaxTimeSlider'),'Value');
plotStart = get(findobj('Tag','Plot','Parent',hfig),'UserData');
delete(hfig)
clear TSd
clear TSw
clear TSdata
dataQC(DataFiles,NIMSinfo,Sites,plotStart,[round(tL1),round(tL2)],HZ,1)
case 'All Data Times'
plotStart = get(findobj('Tag','Plot','Parent',hfig),'UserData');
clear TSd
clear TSw
clear TSdata
delete(hfig)
dataTimes(DataFiles,NIMSinfo,Sites,plotStart,maxSites,HZ)
case 'Replot QC'
tL1 = str2num(get(findobj('Parent',hfig,...
'Tag','MinTimeString'),'String'))
tL2 = str2num(get(findobj('Parent',hfig,...
'Tag','MaxTimeString'),'String'))
plotStart = get(findobj('Tag','Plot','Parent',hfig),'UserData');
delete(hfig)
clear TSd
clear TSw
clear TSdata
dataQC(DataFiles,NIMSinfo,Sites,plotStart,[tL1,tL2],HZ)
case 'QC'
plotStart = get(findobj('Tag','Plot','Parent',hfig),'UserData');
clear TSd
clear TSw
clear TSdata
delete(hfig)
dataQC(DataFiles,NIMSinfo,Sites,plotStart,maxSites,HZ)
case 'Site Name'
siteName = get(gcbo,'String');
MTdir = [dataHome filesep 'MT'];
cd(MTdir);
zid = [ siteName '*.z*; ' lower(siteName) '*.z*; *.zmm' ];
apresplt
% Callbacks for the Summary function
case 'Best TF'
l = get(gcbo,'UserData');
options = get(gcbo,'String');
Sites{l}.bestTF = char(options(get(gcbo,'Value')));
UD.Sites = Sites;
set(hfig,'UserData',UD);
case 'Good From'
l = get(gcbo,'UserData');
Sites{l}.period(1) = str2double(get(gcbo,'String'));
UD.Sites = Sites;
set(hfig,'UserData',UD);
case 'Good To'
l = get(gcbo,'UserData');
Sites{l}.period(2) = str2double(get(gcbo,'String'));
UD.Sites = Sites;
set(hfig,'UserData',UD);
case 'Data Quality'
l = get(gcbo,'UserData');
options = get(gcbo,'String');
Sites{l}.quality = str2double(options(get(gcbo,'Value')));
UD.Sites = Sites;
set(hfig,'UserData',UD);
case 'Load From File'
[qcfile,qcdir] = uigetfile('*.qc');
fid = fopen([qcdir filesep qcfile],'r');
header = fgetl(fid);
%qcinfo = textscan(fid,'%s %f %f %s %f %s %f %f %f %f %q\n',[11 inf]);
qcinfo = textscan(fid,'%s %f %f %s %f %s %f %f %f %f %q\n',inf);
fclose(fid);
for l = 1:length(Sites)
k = strmatch(Sites{l}.Name,qcinfo{1});
if ~isempty(k)
Sites{l}.lat = qcinfo{2}(k);
Sites{l}.lon = qcinfo{3}(k);
%Sites{l}.suffix = char(qcinfo{4}(k)); % skip suffix array
%Sites{l}.days = qcinfo{5}(k);
Sites{l}.bestTF = char(qcinfo{6}(k));
Sites{l}.period(1) = qcinfo{7}(k);
Sites{l}.period(2) = qcinfo{8}(k);
Sites{l}.quality = qcinfo{9}(k);
Sites{l}.flag = qcinfo{10}(k);
Sites{l}.comments = char(qcinfo{11}(k));
end
end
plotStart = get(findobj('Tag','Plot','Parent',hfig),'UserData');
clear TSd
clear TSw
clear TSdata
delete(hfig)
dataQC(DataFiles,NIMSinfo,Sites,plotStart,maxSites)
case 'Save To File'
[qcfile,qcdir] = uiputfile('*.qc');
fid = fopen([qcdir filesep qcfile],'wt');
fprintf(fid,['Site ID\tLatitude\tLongitude\tRuns\tTime (days)\t' ...
'Best TF\tGood From Period (secs)\tGood To Period (secs)\t' ...
'Quality Rating\tWarning Flag\tComments\n'],header);
for l = 1:length(Sites)
id = Sites{l}.Name;
lat = Sites{l}.lat;
lon = Sites{l}.lon;
suffix = Sites{l}.suffix;
days = sum(Sites{l}.days);
quality = Sites{l}.quality;
bestTF = char(Sites{l}.bestTF);
goodfrom = round(Sites{l}.period(1));
goodto = round(Sites{l}.period(2));
flag = Sites{l}.flag;
comments = char(Sites{l}.comments);
fprintf(fid,'%s\t%f\t%f\t%s\t%.1f\t%s\t%d\t%d\t%d',...
id,lat,lon,suffix,days,bestTF,goodfrom,goodto,quality);
if ~isnan(flag)
fprintf(fid,'\t%d\t"%s"',flag,comments);
end
fprintf(fid,'\n');
end
fclose(fid);
case 'Copy TFs'
outdir = uigetdir(dataHome,'Copy TFs to this directory:');
MTdir = [dataHome filesep 'MT'];
for l = 1:length(Sites)
zfile = [ MTdir filesep char(Sites{l}.bestTF) ];
system(['cp ' zfile ' ' outdir]);
end
end