-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfg_linestats.m
462 lines (349 loc) · 18 KB
/
fg_linestats.m
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
function varargout = fg_linestats(varargin)
% FG_LINESTATS MATLAB code for fg_linestats.fig
% FG_LINESTATS, by itself, creates a new FG_LINESTATS or raises the existing
% singleton*.
%
% H = FG_LINESTATS returns the handle to a new FG_LINESTATS or the handle to
% the existing singleton*.
%
% FG_LINESTATS('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in FG_LINESTATS.M with the given input arguments.
%
% FG_LINESTATS('Property','Value',...) creates a new FG_LINESTATS or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before fg_linestats_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to fg_linestats_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help fg_linestats
% Last Modified by GUIDE v2.5 26-Sep-2020 11:59:45
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @fg_linestats_OpeningFcn, ...
'gui_OutputFcn', @fg_linestats_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before fg_linestats is made visible.
function fg_linestats_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to fg_linestats (see VARARGIN)
% load the current directory project's database
h = findobj('Tag','fg_main');
vars = guidata(h);
project = CssProject(vars.working_folder);
database = project.LoadDatabase();
lines = project.LoadLines();
residual_std = EstimateStd(lines);
set(handles.lblStd,'String',[num2str(3*residual_std) ' mGal'])
set(handles.lblLines,'String',num2str(length(lines)))
set(handles.lblBenchmarks,'String',num2str(length(database.benchmarks)))
% Choose default command line output for fg_absolute
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% save the database to the local handle
hObj = guidata(hObject);
hObj.database = database;
hObj.working_folder = vars.working_folder;
hObj.Lines = lines;
hObj.changed_lines = [];
% visualization object
hObj.Visualization = CssVisualization(lines, database.benchmarks, handles.axMap, [.5,.5,.5], [1 0 1], [.2,.2,.2], [1 0 0]);
hObj.Visualization = hObj.Visualization.PlotLines(residual_std);
hObj.Visualization = hObj.Visualization.PlotNodes();
hObj.std = residual_std;
guidata(hObject, hObj);
% fill the listbox
set(handles.lstLines,'String', hObj.Visualization.LineNameList)
% UIWAIT makes fg_linestats wait for user response (see UIRESUME)
% uiwait(handles.fg_linestats);
function residual_std = EstimateStd(lines)
% calculate the residual standard deviation based on the line info
residual_std = [];
for i = 1:length(lines)
res = cell2mat(lines(i).residuals);
if any(isnan(res))
disp(['Line ' lines(i).line_name ' has residuals equal to NaN. Check the line to identify the problem.'])
else
residual_std = [residual_std; res];
end
end
residual_std = std(residual_std);
% --- Outputs from this function are returned to the command line.
function varargout = fg_linestats_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on selection change in lstLines.
function lstLines_Callback(hObject, eventdata, handles)
% hObject handle to lstLines (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns lstLines contents as cell array
% contents{get(hObject,'Value')} returns selected item from lstLines
vars = guidata(hObject);
selection = get(handles.lstLines,{'string','value'});
line_index = selection{2};
if strcmp(get(handles.fg_linestats,'SelectionType'),'open')
% double click on a line: open stats
if handles.optTime.Value ~= 0
vars.Visualization.PlotLineTime(vars.selected_line, true)
elseif handles.optDeltas.Value ~= 0
vars.Visualization.PlotLineInfo(vars.selected_line, true)
elseif handles.optCompare.Value ~= 0
vars.Visualization.PlotComparison(vars.selected_line, true)
end
else
% simple clic, show information about instruments
ShowInstruments(vars, line_index, handles)
end
hObj = guidata(hObject);
hObj.selected_line = line_index;
hObj.Visualization = hObj.Visualization.SelectLine(line_index);
guidata(hObject, hObj);
function ShowInstruments(vars, line_index, handles)
% check the state of this instrument (check the state of the
% benchmarks
for i = 1:length(vars.Lines(line_index).instruments)
if all(vars.Lines(line_index).status(i,:) == 0)
inst_names(i) = {sprintf('<HTML><strong><FONT color="%s">%s', 'blue', vars.Lines(line_index).instruments{i})};
else
inst_names(i) = vars.Lines(line_index).instruments(i);
end
end
set(handles.lstInstruments,'String', inst_names)
set(handles.lstInstruments,'Value', 1)
set(handles.lstBenchmarks,'String', {})
% --- Executes during object creation, after setting all properties.
function lstLines_CreateFcn(hObject, eventdata, handles)
% hObject handle to lstLines (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: listbox controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on selection change in lstInstruments.
function lstInstruments_Callback(hObject, eventdata, handles)
% hObject handle to lstInstruments (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns lstInstruments contents as cell array
% contents{get(hObject,'Value')} returns selected item from lstInstruments
vars = guidata(hObject);
selection = get(handles.lstInstruments,{'string','value'});
index = selection{2};
if strcmp(get(handles.fg_linestats,'SelectionType'),'open')
instrument = vars.Lines(vars.selected_line).instruments{index};
% double click: disable/enable instrument
if all(vars.Lines(vars.selected_line).status(index,:) == false)
% deactivated, activate
vars.Lines(vars.selected_line) = vars.Lines(vars.selected_line).ActivateObservationPair(instrument, vars.Lines(vars.selected_line).benchmarks);
else
% activated, deactivate
vars.Lines(vars.selected_line) = vars.Lines(vars.selected_line).DeactivateObservationPair(instrument, vars.Lines(vars.selected_line).benchmarks);
end
% repaint the item to show the current state
ShowInstruments(vars, vars.selected_line, handles)
residual_std = EstimateStd(vars.Lines);
set(handles.lblStd,'String',[num2str(3*residual_std) ' mGal'])
% update the standard deviation and lines
hObj = guidata(hObject);
hObj.std = residual_std;
hObj.Lines = vars.Lines;
hObj.Visualization.lines = vars.Lines;
hObj.Visualization = hObj.Visualization.UpdateStdMax(residual_std);
hObj.changed_lines = [hObj.changed_lines; vars.selected_line];
set(handles.lstLines,'String', hObj.Visualization.LineNameList)
% if plots for this line are open, refresh
if handles.optTime.Value ~= 0
vars.Visualization.PlotLineTime(vars.selected_line, false)
elseif handles.optDeltas.Value ~= 0
vars.Visualization.PlotLineInfo(vars.selected_line, false)
elseif handles.optCompare.Value ~= 0
vars.Visualization.PlotComparison(vars.selected_line, false)
end
guidata(hObject, hObj);
else
% simple click, show benchmarks
ShowBenchmarks(vars, index, handles)
end
hObj = guidata(hObject);
hObj.selected_inst = index;
guidata(hObject, hObj);
function ShowBenchmarks(vars, inst_index, handles)
for i = 1:size(vars.Lines(vars.selected_line).status(inst_index,:),2)
if vars.Lines(vars.selected_line).status(inst_index,i) == false
benchmarks(i) = {sprintf('<HTML><strong><FONT color="%s">%s', 'blue', vars.Lines(vars.selected_line).benchmarks(i).name)};
else
benchmarks(i) = {vars.Lines(vars.selected_line).benchmarks(i).name};
end
end
set(handles.lstBenchmarks,'String', benchmarks)
set(handles.lstBenchmarks,'Value', 1)
% --- Executes during object creation, after setting all properties.
function lstInstruments_CreateFcn(hObject, eventdata, handles)
% hObject handle to lstInstruments (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: listbox controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on selection change in lstBenchmarks.
function lstBenchmarks_Callback(hObject, eventdata, handles)
% hObject handle to lstBenchmarks (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns lstBenchmarks contents as cell array
% contents{get(hObject,'Value')} returns selected item from lstBenchmarks
vars = guidata(hObject);
selection = get(handles.lstBenchmarks,{'string','value'});
index = selection{2};
if strcmp(get(handles.fg_linestats,'SelectionType'),'open')
% deactivate/activate this benchmark
instrument = vars.Lines(vars.selected_line).instruments{vars.selected_inst};
% double click: disable/enable instrument
if vars.Lines(vars.selected_line).status(vars.selected_inst,index) == false
% deactivated, activate
vars.Lines(vars.selected_line) = vars.Lines(vars.selected_line).ActivateObservationPair(instrument, vars.Lines(vars.selected_line).benchmarks(index));
else
% activated, deactivate
vars.Lines(vars.selected_line) = vars.Lines(vars.selected_line).DeactivateObservationPair(instrument, vars.Lines(vars.selected_line).benchmarks(index));
end
% repaint the item to show the current state
ShowInstruments(vars, vars.selected_line, handles)
ShowBenchmarks (vars, vars.selected_inst, handles)
residual_std = EstimateStd(vars.Lines);
set(handles.lblStd,'String',[num2str(3*residual_std) ' mGal'])
% update the standard deviation and lines
hObj = guidata(hObject);
hObj.std = residual_std;
hObj.Lines = vars.Lines;
hObj.Visualization.lines = vars.Lines;
hObj.Visualization = hObj.Visualization.UpdateStdMax(residual_std);
hObj.changed_lines = [hObj.changed_lines; vars.selected_line];
set(handles.lstLines,'String', hObj.Visualization.LineNameList)
% if plots for this line are open, refresh
if handles.optTime.Value ~= 0
hObj.Visualization.PlotLineTime(vars.selected_line, false)
elseif handles.optDeltas.Value ~= 0
hObj.Visualization.PlotLineInfo(vars.selected_line, false)
elseif handles.optCompare.Value ~= 0
hObj.Visualization.PlotComparison(vars.selected_line, false)
end
guidata(hObject, hObj);
end
% --- Executes during object creation, after setting all properties.
function lstBenchmarks_CreateFcn(hObject, eventdata, handles)
% hObject handle to lstBenchmarks (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: listbox controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --------------------------------------------------------------------
function uipushtool1_ClickedCallback(hObject, eventdata, handles)
% hObject handle to uipushtool1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[FileName,PathName] = uiputfile({'*.png' ;'*.tif';'*.jpg'},'Save figure as...');
fr = getframe(handles.axMap);
imwrite(fr.cdata, fullfile(PathName,FileName))
% --- Executes on button press in cmdZoomIn.
function cmdZoomIn_Callback(hObject, eventdata, handles)
% hObject handle to cmdZoomIn (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
hObj = guidata(hObject);
hObj.Visualization.ZoomInLine();
% --- Executes on button press in optDeltas.
function optDeltas_Callback(hObject, eventdata, handles)
% hObject handle to optDeltas (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of optDeltas
% --- Executes on button press in optTimes.
function optTimes_Callback(hObject, eventdata, handles)
% hObject handle to optTimes (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of optTimes
% --- Executes on button press in cmdSave.
function cmdSave_Callback(hObject, eventdata, handles)
% hObject handle to cmdSave (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% loop through the lines and save them to disk
vars = guidata(hObject);
h = waitbar(0,'Saving lines to disk...');
vars.changed_lines = unique(vars.changed_lines);
for i = 1:length(vars.changed_lines)
vars.Lines(vars.changed_lines(i)).SaveGravityLine(fullfile(vars.working_folder,'lines'), true);
waitbar(i/length(vars.Lines))
end
close(h)
% --- Executes on button press in cmdSelectMap.
function cmdSelectMap_Callback(hObject, eventdata, handles)
% hObject handle to cmdSelectMap (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
vars = guidata(hObject);
% request user's input
[x, y] = ginput(1);
vars.Visualization = vars.Visualization.PickLine(x, y);
if ~isempty(vars.Visualization.selected_line)
set(handles.lstLines,'Value', vars.Visualization.selected_line)
end
% save data
guidata(hObject, vars);
% --- Executes on button press in cmdNetworkAnalysis.
function cmdNetworkAnalysis_Callback(hObject, eventdata, handles)
% hObject handle to cmdNetworkAnalysis (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
vars = guidata(hObject);
figure;
set(gcf, 'Name', ['Information for network of project ' vars.database.proj_description]);
vars.Visualization.network.PlotNetwork(vars.database.agravbench)
% --- Executes on button press in cmdFind.
function cmdFind_Callback(hObject, eventdata, handles)
% hObject handle to cmdFind (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
benchmark = inputdlg('Enter benchmark name','Find benchmark');
vars = guidata(hObject);
for i = 1:length(vars.Lines)
if ismember(benchmark, {vars.Lines(i).benchmarks.name})
disp(['found at ' num2str(i)])
% select the line
set(handles.lstLines, 'Value', i)
return
end
end
warndlg('Could not find specified benchmark name');