-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfg_main.m
569 lines (427 loc) · 22 KB
/
fg_main.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
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
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
function varargout = fg_main(varargin)
% FG_MAIN MATLAB code for fg_main.fig
% FG_MAIN, by itself, creates a new FG_MAIN or raises the existing
% singleton*.
%
% H = FG_MAIN returns the handle to a new FG_MAIN or the handle to
% the existing singleton*.
%
% FG_MAIN('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in FG_MAIN.M with the given input arguments.
%
% FG_MAIN('Property','Value',...) creates a new FG_MAIN or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before fg_main_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to fg_main_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_main
% Last Modified by GUIDE v2.5 29-Sep-2020 18:49:09
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @fg_main_OpeningFcn, ...
'gui_OutputFcn', @fg_main_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_main is made visible.
function fg_main_OpeningFcn(hObject, eventdata, handles, varargin)
% Center the figure on the top of the screen
movegui(hObject, 'center');
% 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_main (see VARARGIN)
% Choose default command line output for fg_main
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes fg_main wait for user response (see UIRESUME)
% uiwait(handles.fg_main);
% disable all menus until user sets working path
set(handles.mnuIntruments,'Enable', 'off');
set(handles.mnuLines,'Enable', 'off');
set(handles.mnuGravity,'Enable', 'off');
set(handles.mnuCreateFolderStruct,'Enable','off');
set(handles.mnuCheckFolderStruct,'Enable','off');
% --- Outputs from this function are returned to the command line.
function varargout = fg_main_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;
% --------------------------------------------------------------------
function mnuIntruments_Callback(hObject, eventdata, handles)
% hObject handle to mnuIntruments (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function mnuAddInstrument_Callback(hObject, eventdata, handles)
% hObject handle to mnuAddInstrument (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
hfg_instruments = fg_instruments();
% --------------------------------------------------------------------
function mnuInstStatistics_Callback(hObject, eventdata, handles)
% hObject handle to mnuInstStatistics (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% bring up a couple statistic windows for a particular instrument
hObj = guidata(hObject);
project = CssProject(hObj.working_folder);
instruments = project.LoadInstruments();
[inst, sel] = listdlg('PromptString', 'Select an instrument', 'SelectionMode','single','ListString',{instruments.name});
if sel
% an instrument was selected
lines = project.LoadLines();
residuals = [];
% make a histogram of the residuals of this instrument
for i = 1:length(lines)
[~,r] = lines(i).GetDeltasResiduals(instruments(inst).name);
residuals = [residuals; r];
end
figure('Name', ['Delta residuals for instrument ' instruments(inst).name]);
histfit(residuals,100);
grid on
title(['Standard deviation: ' sprintf('%5.2f', nanstd(residuals)) ' mGal'])
xlabel('Residual [mGal]')
ylabel('Count')
end
% --------------------------------------------------------------------
function mnuFolders_Callback(hObject, eventdata, handles)
% hObject handle to mnuFolders (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function mnuLines_Callback(hObject, eventdata, handles)
% hObject handle to mnuLines (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function mnuGravity_Callback(hObject, eventdata, handles)
% hObject handle to mnuGravity (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function mnuAbsoluteGravity_Callback(hObject, eventdata, handles)
% hObject handle to mnuAbsoluteGravity (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
hfg_absolute = fg_absolute();
% --------------------------------------------------------------------
function mnuAdjustment_Callback(hObject, eventdata, handles)
% hObject handle to mnuAdjustment (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function mnuBenchmarks_Callback(hObject, eventdata, handles)
% hObject handle to mnuBenchmarks (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function mnuGravityLine_Callback(hObject, eventdata, handles)
% hObject handle to mnuGravityLine (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
hfg_edit_line = fg_edit_line();
% --------------------------------------------------------------------
function mnuEditGravityLine_Callback(hObject, eventdata, handles)
% hObject handle to mnuEditGravityLine (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function mnuRemoveGravityLine_Callback(hObject, eventdata, handles)
% hObject handle to mnuRemoveGravityLine (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function mnuSetWorkingFolder_Callback(hObject, eventdata, handles)
% hObject handle to mnuSetWorkingFolder (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.working_folder = uigetdir('~','Select the working folder:');
hObj.valid_folder_struct = -1;
if hObj.working_folder ~= 0
% trigger the check structure functions
result = check_folder_struct(hObj.working_folder, handles);
if result ~= 0
choice = questdlg('The folder structure of a gravity project was not detected. Would you like to create it?', ...
'Folder structure check not passed!', ...
'Yes','No','No');
if choice == 'Yes'
create_folder_structure(hObj.working_folder)
hObj.valid_folder_struct = 0;
end
else
hObj.valid_folder_struct = 0;
end
if hObj.valid_folder_struct == 0
set(handles.mnuIntruments,'Enable', 'on');
set(handles.mnuLines,'Enable', 'on');
set(handles.mnuGravity,'Enable', 'on');
set(handles.mnuCreateFolderStruct,'Enable','off');
set(handles.mnuCheckFolderStruct,'Enable','on');
% load the database
load(fullfile(hObj.working_folder, 'database.mat'))
set(handles.lblFolder, 'String', [hObj.working_folder ' (' database.proj_description ')' ]);
else
set(handles.mnuCreateFolderStruct,'Enable','on');
end
guidata(hObject, hObj);
end
% --------------------------------------------------------------------
function mnuCreateFolderStruct_Callback(hObject, eventdata, handles)
% hObject handle to mnuCreateFolderStruct (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function mnuCheckFolderStruct_Callback(hObject, eventdata, handles)
% hObject handle to mnuCheckFolderStruct (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function mnuAddBenchmark_Callback(hObject, eventdata, handles)
% hObject handle to mnuAddBenchmark (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function mnuAddEditRemoveBenchmark_Callback(hObject, eventdata, handles)
% hObject handle to mnuAddEditRemoveBenchmark (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% call fg_find_benchmark
fg_find_benchmark();
% --------------------------------------------------------------------
function mnuAdjust_Callback(hObject, eventdata, handles)
% hObject handle to mnuAdjust (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
fg_adjust();
% --------------------------------------------------------------------
function mnuStats_Callback(hObject, eventdata, handles)
% hObject handle to mnuStats (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% section for user defined functions
function value = check_folder_struct(working_folder, handles)
% this function check the existance of all the necessary folders and
% structures.
value = -1;
if ~exist(fullfile(working_folder, 'lines'),'dir')
set(handles.lblFolder, 'String', 'checking lines folder...');
return
end
if ~exist(fullfile(working_folder, 'instruments'),'dir')
set(handles.lblFolder, 'String', 'checking instruments...');
return
end
% if ~exist(fullfile(working_folder, 'absolute'),'dir')
% set(handles.lblFolder, 'String', 'checking absolute gravity data...');
% return
% end
if ~exist(fullfile(working_folder, 'database.mat'),'file')
set(handles.lblFolder, 'String', 'checking database mat file...');
return
end
value = 0;
function create_folder_structure(working_folder)
% this function creates all the necessary folders and
% structures.
if ~exist([working_folder '/lines'],'dir')
mkdir([working_folder '/lines'])
end
if ~exist([working_folder '/instruments'],'dir')
mkdir([working_folder '/instruments'])
end
% if ~exist([working_folder '/absolute'],'dir')
% mkdir([working_folder '/absolute'])
% end
if ~exist([working_folder '/database.mat'],'file')
% no basic information in the folder! bring up the config window
hfg_project = fg_project();
hfg_project_data = guidata(hfg_project);
hfg_project_data.working_folder = working_folder;
guidata(hfg_project, hfg_project_data);
waitfor(hfg_project);
end
% end section
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% --------------------------------------------------------------------
function cmdLineStats_Callback(hObject, eventdata, handles)
% hObject handle to cmdLineStats (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
hfg_linestats = fg_linestats();
% --------------------------------------------------------------------
function mnuRejected_Callback(hObject, eventdata, handles)
% hObject handle to mnuRejected (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% output a KML file with all
vars = guidata(hObject);
project = CssProject(vars.working_folder);
lines = project.LoadLines();
database = project.LoadDatabase();
benchmarks = database.benchmarks;
network = CssNetwork(lines, benchmarks);
k = kml('Gravity Lines') ;
colors = {'FF0000FF', 'FF00FFFF', 'FF00FF00'};
icons = {'http://maps.google.com/mapfiles/kml/shapes/donut.png', 'http://maps.google.com/mapfiles/kml/shapes/square.png'};
f = k.createFolder('Rejected benchmarks/lines');
r = {};
g = {};
for i = 1:length(lines)
if any(sum(lines(i).status) < 2) % the purpose of this if sentence is to check benchmark redundancy
% if less than 2 positive status (i.e. positive = 1) then no redundancy.
% this line has to go into the KML
% get the number of observations available
cc = sum(lines(i).status);
% if more than 3, then assign 3
cc(cc > 2) = 2;
% convert to index from 1-4
cc = cc + 1;
folder = f.createFolder(lines(i).line_name);
% circle or square depending on node or point
nodes = ismember({lines(i).benchmarks.name}', {network.nodes.name});
nodes = nodes + 1;
folder.plot3([lines(i).benchmarks.lon], [lines(i).benchmarks.lat], [lines(i).benchmarks.height], 'lineWidth', 3, 'name', 'gravity line', 'lineColor', colors{min(cc)}, 'altitudeMode', 'clampToGround');
folder.point([lines(i).benchmarks.lon], [lines(i).benchmarks.lat], [lines(i).benchmarks.height], ...
'iconScale', 0.5, ...
'name', {lines(i).benchmarks.name}', ...
'iconURL', icons(nodes), ...
'iconColor', colors(cc)', 'altitudeMode', 'clampToGround');
r{i,1} = {[lines(i).benchmarks.lon]', [lines(i).benchmarks.lat]', [lines(i).benchmarks.height]', {lines(i).benchmarks.name}', colors(cc)'};
end
end
f = k.createFolder('Good benchmarks/lines');
for i = 1:length(lines)
if all(sum(lines(i).status) >= 2)
% get the number of observations available
cc = sum(lines(i).status);
% if more than 3, then assign 3
cc(cc > 2) = 2;
% convert to index from 1-4
cc = cc + 1;
folder = f.createFolder(lines(i).line_name);
% circle or square depending on node or point
nodes = ismember({lines(i).benchmarks.name}', {network.nodes.name});
nodes = nodes + 1;
folder.plot3([lines(i).benchmarks.lon], [lines(i).benchmarks.lat], [lines(i).benchmarks.height], 'lineWidth', 3, 'name', 'gravity line', 'lineColor', 'FFFF0000', 'altitudeMode', 'clampToGround');
folder.point([lines(i).benchmarks.lon], [lines(i).benchmarks.lat], [lines(i).benchmarks.height], ...
'iconScale', 0.5, ...
'name', {lines(i).benchmarks.name}', ...
'iconURL', icons(nodes), ...
'altitudeMode', 'clampToGround');
end
g{i,1} = {[lines(i).benchmarks.lon]', [lines(i).benchmarks.lat]', [lines(i).benchmarks.height]', {lines(i).benchmarks.name}', colors(cc)'};
end
g = g(~cellfun('isempty',g));
r = r(~cellfun('isempty',r));
k.save('test.kml')
save('good.mat', 'g')
save('bad.mat', 'r')
% --------------------------------------------------------------------
function mnuInstDrifts_Callback(hObject, eventdata, handles)
% hObject handle to mnuInstDrifts (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% bring up a couple statistic windows for a particular instrument
hObj = guidata(hObject);
project = CssProject(hObj.working_folder);
instruments = project.LoadInstruments();
[inst, sel] = listdlg('PromptString', 'Select an instrument', 'SelectionMode','single','ListString',{instruments.name});
if sel
% an instrument was selected
lines = project.LoadLines();
drifts = [];
% make a histogram of the residuals of this instrument
for i = 1:length(lines)
d = lines(i).GetDrifts(instruments(inst).name);
drifts = [drifts; d];
end
figure('Name', ['Drifts for instrument ' instruments(inst).name]);
histfit(drifts,100);
grid on
title(['Standard deviation: ' sprintf('%5.2f', nanstd(drifts)) ' mGal/h'])
xlabel('[mGal/h]')
ylabel('Count')
end
% --------------------------------------------------------------------
function mnuExportDatabase_Callback(hObject, eventdata, handles)
% hObject handle to mnuExportDatabase (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% this menu creates a database file (Excel) with all the instruments
% and points to syncronize the tablet software
hObj = guidata(hObject);
[file, path] = uiputfile('*.xls','Export database for tablet');
if ~isempty(file)
filename = fullfile(path,file);
project = CssProject(hObj.working_folder);
database = project.LoadDatabase();
benchmarks = database.benchmarks;
t = table({benchmarks.name}', [benchmarks.lat]', [benchmarks.lon]',...
[benchmarks.height]', [benchmarks.offset]', [benchmarks.x]',...
[benchmarks.y]', [benchmarks.z]', ...
zeros(size([benchmarks.z]')), zeros(size([benchmarks.z]')), ...
'VariableNames', {'name', 'lat', 'lon', 'height', 'offset', ...
'x', 'y', 'z', 'absolute_g', 'uncertainty'});
writetable(t, filename, 'Sheet', 'Sheet1')
instruments = project.LoadInstruments();
for i = 1:size(instruments, 1)
writetable(table(instruments(i).calibration), filename, 'Sheet', instruments(i).name, 'WriteVariableNames', false)
end
msgbox(['Successfully exported the database to ' filename]);
end
% --------------------------------------------------------------------
function mnuZeroHeight_Callback(hObject, eventdata, handles)
% hObject handle to mnuZeroHeight (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);
[file, path] = uiputfile('*.kmz','Output KML with benchmarks with zero height');
if ~isempty(file)
k = kml('Benchmarks') ;
project = CssProject(hObj.working_folder);
icons = {'http://maps.google.com/mapfiles/kml/shapes/donut.png'};
colors = {'FF0000FF', 'FF00FFFF', 'FF00FF00'};
database = project.LoadDatabase();
benchmarks = database.benchmarks([database.benchmarks.height] == 0);
c = ones(size(benchmarks,1),1);
for i = 1:size(benchmarks,1)
lon(i) = benchmarks(i).lon;
lat(i) = benchmarks(i).lat;
h(i) = benchmarks(i).height;
name{i} = benchmarks(i).name;
if ~isempty(benchmarks(i).absolute_g)
c(i) = 3;
end
end
folder = k.createFolder('Benchmarks with zero height');
folder.point(lon, lat, h, ...
'iconScale', 0.5, ...
'name', name, ...
'iconURL', icons(ones(size(benchmarks,1),1)), ...
'iconColor', colors(c), 'altitudeMode', 'clampToGround');
k.save(fullfile(path,file))
msgbox(['Successfully exported benchmarks without height to ' fullfile(path,file)]);
end