-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmog_ui.py
2612 lines (2154 loc) · 114 KB
/
mog_ui.py
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
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding: utf-8 -*-
"""
Copyright 2017 Bernard Giroux, Elie Dumas-Lefebvre, Jerome Simon
email: [email protected]
This file is part of BhTomoPy.
BhTomoPy is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
import os
import sys
import re
import unicodedata
from PyQt5 import QtGui, QtWidgets, QtCore
import numpy as np
from scipy.signal import filtfilt, welch, cheb1ord, cheby1
from scipy import interpolate
from matplotlib.axes import Axes
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg, NavigationToolbar2QT
from matplotlib.colorbar import Colorbar
from matplotlib.colors import LinearSegmentedColormap
from matplotlib.figure import Figure
from mpl_toolkits.axes_grid1 import make_axes_locatable
from mpl_toolkits.mplot3d import axes3d # @UnusedImport
from spectrum import arburg
from database import BhTomoDb
from mog import MogData, Mog, AirShots
from utils import compute_SNR, data_select
from utils_ui import MyQLabel, choose_mog
class MOGUI(QtWidgets.QWidget): # Multi Offset Gather User Interface
mogInfoSignal = QtCore.pyqtSignal(int)
ntraceSignal = QtCore.pyqtSignal(int)
databaseSignal = QtCore.pyqtSignal(str)
moglogSignal = QtCore.pyqtSignal(str)
def __init__(self, db, parent=None):
super(MOGUI, self).__init__(parent)
self.setWindowTitle("BhTomoPy/MOGs")
self.db = db
self.init_UI()
self.data_rep = ''
def add_MOG(self):
filename = QtWidgets.QFileDialog.getOpenFileName(self, 'Open File')[0]
if filename:
self.load_file_MOG(filename)
self.update_edits()
def load_file_MOG(self, filename):
# Conditions to get the path of the file itself in order to execute it
if ".rad" in filename.lower() or ".rd3" in filename.lower() or ".tlf" in filename.lower():
basename = filename[:-4]
else:
self.moglogSignal.emit("Error: MOG file must have either *.rad, *.rd3 or *.tlf extension")
return
try:
self.data_rep,rname = os.path.split(basename)
mogdata = MogData(rname)
try:
mogdata.readRAMAC(basename)
except IOError:
position_input = PositionInputDialog(mogdata)
ans = position_input.exec()
if ans == QtWidgets.QDialog.Rejected:
return
mog = Mog(rname, mogdata)
try:
self.db.mogs.append(mog)
except ValueError:
rname, ok = QtWidgets.QInputDialog.getText(self, 'Name already used', 'Enter name to store MOG :')
if ok:
mog.name = rname
try:
self.db.mogs.append(mog)
except ValueError:
QtWidgets.QMessageBox.warning(self, 'Error', 'Name already used: aborting',
buttons=QtWidgets.QMessageBox.Ok)
else:
return
self.update_list_widget()
self.MOG_list.setCurrentRow(len(self.db.mogs) - 1)
self.update_spectra_and_coverage_Tx_num_list()
self.update_spectra_and_coverage_Tx_elev_value_label()
self.update_edits()
self.update_prune_edits_info()
self.update_prune_info()
self.moglogSignal.emit("{} Multi Offset-Gather has been loaded successfully".format(rname))
except Exception as e:
QtWidgets.QMessageBox.warning(self, 'Warning', "MOG could not be opened : '" + str(e)[:42] + "...' [mog_ui 1]",
buttons=QtWidgets.QMessageBox.Ok)
def update_edits(self):
"""
Updates the info either in the MOG's edits or in the info's labels
"""
itemNo = self.MOG_list.currentRow()
if itemNo != -1:
mog = self.db.mogs[itemNo]
if mog is not None:
self.Rx_Offset_edit.clear()
self.Tx_Offset_edit.clear()
self.Correction_Factor_edit.clear()
self.Multiplication_Factor_edit.clear()
self.Nominal_Frequency_edit.clear()
self.Nominal_Frequency_edit.setText(str(mog.data.rnomfreq))
self.Rx_Offset_edit.setText(str(mog.data.RxOffset))
self.Tx_Offset_edit.setText(str(mog.data.TxOffset))
self.Correction_Factor_edit.setText(str(mog.user_fac_dt))
self.Multiplication_Factor_edit.setText(str(mog.f_et))
self.Date_edit.setText(mog.data.date)
if mog.av is not None:
self.Air_Shot_Before_edit.setText(mog.av.name)
else:
self.Air_Shot_Before_edit.setText('')
if mog.ap is not None:
self.Air_Shot_After_edit.setText(mog.ap.name)
else:
self.Air_Shot_After_edit.setText('')
if mog.useAirShots:
self.Air_shots_checkbox.setChecked(True)
else:
self.Air_shots_checkbox.setChecked(False)
if mog.Tx is None:
self.Tx_combo.setCurrentIndex(-1)
else:
self.Tx_combo.setCurrentIndex(self.Tx_combo.findText(mog.Tx.name))
if mog.Rx is None:
self.Rx_combo.setCurrentIndex(-1)
else:
self.Rx_combo.setCurrentIndex(self.Rx_combo.findText(mog.Rx.name))
tot_traces = 0
for mog in self.db.mogs:
tot_traces += mog.data.ntrace
self.ntraceSignal.emit(tot_traces)
updateHandlerMog = False # focus may be lost twice due to setFocus and/or the QMessageBox. 'updateHandlerMog' prevents that.
def update_mog_info(self):
if self.updateHandlerMog:
return
self.updateHandlerMog = True
expFloat = re.compile("^-?[0-9]+([\.,][0-9]+)?$") # float number, with or without decimals, and allowing negatives
for item in (self.Nominal_Frequency_edit, self.Rx_Offset_edit, self.Tx_Offset_edit,
self.Correction_Factor_edit, self.Multiplication_Factor_edit):
if item.text() != '' and not expFloat.match(item.text()):
self.moglogSignal.emit("Error: Some edited information is incorrect.")
item.setFocus()
QtWidgets.QMessageBox.warning(self, 'Warning', "Some edited information is incorrect. Edit fields cannot contain letters or special characters.",
buttons=QtWidgets.QMessageBox.Ok)
self.updateHandlerMog = False
return
item.setText(item.text().replace(',', '.'))
self.updateHandlerMog = False
itemNo = self.MOG_list.currentItem()
if itemNo != -1:
mog = self.db.mogs[itemNo]
mog.data.rnomfreq = float(self.Nominal_Frequency_edit.text())
mog.data.RxOffset = float(self.Rx_Offset_edit.text())
mog.data.TxOffset = float(self.Tx_Offset_edit.text())
mog.data.date = self.Date_edit.text()
mog.user_fac_dt = float(self.Correction_Factor_edit.text())
mog.f_et = float(self.Multiplication_Factor_edit.text())
def del_MOG(self):
itemNo = self.MOG_list.currentRow()
if itemNo != -1:
mog_ = self.db.mogs[itemNo]
for model in self.db.models:
if mog_ in model.mogs:
QtWidgets.QMessageBox.warning(self, 'Warning', 'MOG {0:s} used by Model {1:s}'.format(mog_.name, model.name),
buttons=QtWidgets.QMessageBox.Ok)
break
else:
self.db.mogs.remove(mog_)
if len(self.db.mogs) > 0:
self.MOG_list.setCurrentRow(0)
else:
self.MOG_list.setCurrentRow(-1)
self.update_list_widget()
self.update_edits()
def rename(self):
itemNo = self.MOG_list.currentRow()
if itemNo != -1:
new_name, ok = QtWidgets.QInputDialog.getText(self, "Rename", 'new MOG name')
if ok:
for mog in self.db.mogs:
if mog.name == new_name:
QtWidgets.QMessageBox.warning(self, 'Error', 'Name already used',
buttons=QtWidgets.QMessageBox.Ok)
return
mog_ = self.db.mogs[itemNo]
self.moglogSignal.emit("MOG {} is now {}".format(mog_.name, new_name))
mog_.name = new_name
self.update_list_widget()
self.update_edits()
mog_.modified = True
def use_air(self):
itemNo = self.MOG_list.currentRow()
if itemNo != -1:
mog = self.db.mogs[itemNo]
if self.Air_shots_checkbox.isChecked():
mog.useAirShots = 1
else:
mog.useAirShots = 0
mog.modified = True
def air_before(self):
# then we get the filename to process
filename = QtWidgets.QFileDialog.getOpenFileName(self, 'Open t0 air shot before survey')[0]
if not filename:
return
else:
# We get the selected index of MOG_list to then be able to get the mog instance from MOGS
itemNo = self.MOG_list.currentRow()
if itemNo != -1:
mog = self.db.mogs[itemNo]
# then we get only the real name of the file (i.e. not the path behind it)
basename = filename[:-4]
rname = os.path.basename(basename)
# # then we verify if we've already applied the airshots
# airshot = database.session.query(AirShots).filter(AirShots.name == basename).first()
# if airshot is not None:
# # then we associate the index of the air shot to the selected mog
# database.session.query(Mog).filter(Mog.name == item.text()).av = airshot
for airshot in self.db.air_shots:
if airshot.name == rname:
mog.av = airshot
self.Air_Shot_Before_edit.setText(airshot.name)
mog.modified = True
break
else:
# because of the fact that Airshots files are either rd3, tlf or rad, we apply the method read
# ramac to get the informations from these files
try:
data = MogData()
data.readRAMAC(basename)
except:
self.moglogSignal.emit('Error: AirShot File must have *.rad, *.tlf or *.rd3 extension')
return
# Then we ask if the airshots were done in a succession of positions or at a fixed position
distance, ok = QtWidgets.QInputDialog.getText(self, 'Airshots Before', 'Distance between Tx and Rx :')
# The getText method returns a tuple containing the entered data and a boolean factor
# (i.e. if the ok button is clicked, it returns True)
if ok:
if not distance:
self.moglogSignal.emit('Error: you must pick distances for the airshot')
return
distance_list = re.findall(r"[-+]?\d*\.\d+|\d+", distance)
distance_list = np.array([float(i) for i in distance_list])
if len(distance_list) > 1:
if len(distance_list) != data.ntrace:
self.moglogSignal.emit('Error: Number of positions inconsistent with number of traces')
return
airshot_before = AirShots(str(rname))
airshot_before.data = data
airshot_before.tt = -1 * np.ones(data.ntrace) # tt stands for the travel time vector
airshot_before.et = -1 * np.ones(data.ntrace) # to be defined
airshot_before.tt_done = np.zeros(data.ntrace, dtype=bool) # the tt_done is a zeros array and whenever a ray arrives, its value will be changed to one
airshot_before.d_TxRx = distance_list # Contains all the positions for which the airshots have been made
airshot_before.fac_dt = 1
airshot_before.in_vect = np.ones(data.ntrace, dtype=bool)
if len(distance_list) == 1:
airshot_before.method = 'fixed_antenna'
else:
airshot_before.method = 'walkaway'
self.Air_Shot_Before_edit.setText(airshot_before.name)
self.db.air_shots.append(airshot_before)
mog.av = airshot_before
mog.modified = True
def air_after(self):
# As you can see, the air_after method is almost the same as air_before (refer to air_before for any questions)
filename = QtWidgets.QFileDialog.getOpenFileName(self, 'Open t0 air shot after survey')[0]
if not filename:
return
else:
itemNo = self.MOG_list.currentRow()
if itemNo != -1:
mog = self.db.mogs[itemNo]
basename = filename[:-4]
rname = os.path.basename(basename)
for airshot in self.db.air_shots:
if airshot.name == rname:
mog.ap = airshot
self.Air_Shot_After_edit.setText(airshot.name)
mog.modified = True
break
else:
try:
data = MogData()
data.readRAMAC(basename)
except:
self.moglogSignal.emit('Error: AirShot File must have *.rad, *.tlf or *.rd3 extension')
return
distance, ok = QtWidgets.QInputDialog.getText(self, 'Airshots After', 'Distance between Tx and Rx :')
if ok:
if not distance:
self.moglogSignal.emit('Error: you must pick distances for the airshot')
return
distance_list = re.findall(r"[-+]?\d*\.\d+|\d+", distance)
distance_list = np.array([float(i) for i in distance_list])
if len(distance_list) > 1:
if len(distance_list) != data.ntrace:
self.moglogSignal.emit('Error: Number of positions inconsistent with number of traces')
return
airshot_after = AirShots(str(rname))
airshot_after.data = data
airshot_after.tt = -1 * np.ones(data.ntrace)
airshot_after.et = -1 * np.ones(data.ntrace)
airshot_after.tt_done = np.zeros(data.ntrace, dtype=bool)
airshot_after.d_TxRx = distance_list
airshot_after.fac_dt = 1
airshot_after.in_vect = np.ones(data.ntrace, dtype=bool)
if len(distance_list) == 1:
airshot_after.method = 'fixed_antenna'
else:
airshot_after.method = 'walkaway'
self.Air_Shot_After_edit.setText(airshot_after.name)
self.db.air_shots.append(airshot_after)
mog.ap = airshot_after
mog.modified = True
def update_spectra_and_coverage_Tx_num_list(self):
itemNo = self.MOG_list.currentRow()
self.Tx_num_list.clear()
if itemNo != -1:
mog = self.db.mogs[itemNo]
unique_Tx_z = np.unique(mog.data.Tx_z)
for Tx in range(len(unique_Tx_z)):
self.Tx_num_list.addItem(str(Tx))
self.trace_num_combo.addItem(str(Tx))
self.Tx_num_list.setCurrentRow(0)
self.trace_num_combo.setCurrentIndex(0)
def update_spectra_and_coverage_Tx_elev_value_label(self):
itemNo = self.MOG_list.currentRow()
if itemNo != -1:
mog = self.db.mogs[itemNo]
self.Tx_elev_value_label.clear()
ind1 = self.Tx_num_list.selectedIndexes()
ind2 = int(self.trace_num_edit.text())
unique_Tx_z = np.unique(mog.data.Tx_z)[::-1]
for i in ind1:
self.Tx_elev_value_label.setText(str((list(unique_Tx_z))[-i.row()]))
self.value_elev_label.setText(str((list(unique_Tx_z))[-ind2]))
def search_Tx_elev(self):
if self.search_combo.currentText() == 'Search with Elevation':
try:
item = float(self.search_elev_edit.text())
except:
pass
item_ = self.MOG_list.currentRow()
mog = self.db.mogs[item_]
for i in range(len(mog.data.Tx_z)):
if mog.data.Tx_z[i] == item:
self.Tx_num_list.setCurrentRow(i + 1)
elif item not in mog.data.Tx_z:
idx = np.argmin((np.abs(np.unique(mog.data.Tx_z) - item)))
self.Tx_num_list.setCurrentRow(idx + 1)
green = QtGui.QPalette()
green.setColor(QtGui.QPalette.Foreground, QtCore.Qt.darkCyan)
self.search_info_label.setText('{} is not a value in this data, {} is the closest'.format(item, np.unique(mog.data.Tx_z)[idx], decimals=1))
self.search_info_label.setPalette(green)
self.update_spectra_and_coverage_Tx_elev_value_label()
elif self.search_combo.currentText() == 'Search with Number':
item = float(self.search_elev_edit.text())
if item in range(len(self.Tx_num_list)):
self.Tx_num_list.setCurrentRow(item)
else:
red = QtGui.QPalette()
red.setColor(QtGui.QPalette.Foreground, QtCore.Qt.red)
self.search_info_label.setText('This data contains only {} traces, {} is out of range'.format(len(self.Tx_num_list) - 1, int(item)))
self.search_info_label.setPalette(red)
def update_list_widget(self):
self.MOG_list.clear()
for mog in self.db.mogs:
self.MOG_list.addItem(mog.name)
self.mogInfoSignal.emit(len(self.MOG_list))
def update_Tx_and_Rx_Widget(self, liste):
self.Tx_combo.clear()
self.Rx_combo.clear()
for bh in liste:
self.Tx_combo.addItem(bh.name)
self.Rx_combo.addItem(bh.name)
def update_coords(self):
itemNo = self.MOG_list.currentRow()
if itemNo != -1:
Tx_no = self.Tx_combo.currentIndex()
Rx_no = self.Rx_combo.currentIndex()
mog = self.db.mogs[itemNo]
mog.type = self.mog_type.currentIndex()
if Tx_no != -1:
mog.Tx = self.db.boreholes[Tx_no]
else:
mog.Tx = None
if Rx_no != -1:
mog.Rx = self.db.boreholes[Rx_no]
else:
mog.Rx = None
try:
mog.update_coords()
except Exception as e:
QtWidgets.QMessageBox.information(self, 'Warning', str(e),
buttons=QtWidgets.QMessageBox.Ok)
return
self.moglogSignal.emit("{}'s Tx and Rx are now {} and {}".format(mog.name, mog.Tx.name, mog.Rx.name))
def plot_rawdata(self):
if len(self.db.mogs) > 0:
itemNo = self.MOG_list.currentRow()
if itemNo != -1:
mog_ = self.db.mogs[itemNo]
self.rawdataFig.plot_raw_data(mog_.data)
self.moglogSignal.emit(" MOG {}'s Raw Data has been plotted ". format(mog_.name))
self.rawdatamanager.show()
else:
QtWidgets.QMessageBox.warning(self, 'Warning', "No MOGs in Database",
buttons=QtWidgets.QMessageBox.Ok)
def plot_spectra(self):
if len(self.db.mogs) > 0:
itemNo = self.MOG_list.currentRow()
if itemNo != -1:
n = self.Tx_num_list.currentIndex().row()
mog = self.db.mogs[itemNo]
Fmax = float(self.f_max_edit.text())
filter_state = self.filter_check.isChecked()
scale = self.snr_combo.currentText()
estimation_method = self.psd_combo.currentText()
self.spectraFig.plot_spectra(mog, n, Fmax, filter_state, scale, estimation_method)
# self.moglogSignal.emit(" MOG {}'s Spectra has been plotted ". format(mog.name))
self.spectramanager.show()
else:
QtWidgets.QMessageBox.warning(self, 'Warning', "No MOGs in Database",
buttons=QtWidgets.QMessageBox.Ok)
def plot_zop(self):
if len(self.db.mogs) > 0:
itemNo = self.MOG_list.currentRow()
if itemNo != -1:
self.zopFig.plot_zop()
# mog_ = self.db.mogs[itemNo]
# self.moglogSignal.emit(" MOG {}'s Zero-Offset Profile has been plotted ".format(mog_.name))
self.zopmanager.show()
else:
QtWidgets.QMessageBox.warning(self, 'Warning', "No MOGs in Database",
buttons=QtWidgets.QMessageBox.Ok)
def plot_zop_rays(self):
if len(self.db.mogs) > 0:
itemNo = self.MOG_list.currentRow()
if itemNo != -1:
mog_ = self.db.mogs[itemNo]
tol = float(self.tol_edit.text())
self.zopraysFig.plot_rays(mog_, tol)
self.zopraysmanager.show()
else:
QtWidgets.QMessageBox.warning(self, 'Warning', "No MOGs in Database",
buttons=QtWidgets.QMessageBox.Ok)
def plot_stats_tt(self):
if len(self.db.mogs) > 0:
itemNo = self.MOG_list.currentRow()
if itemNo != -1:
mog_ = self.db.mogs[itemNo]
done = (mog_.tt_done.astype(int) + mog_.in_vect.astype(int)) - 1
if len(np.nonzero(done == 1)[0]) == 0:
QtWidgets.QMessageBox.warning(self, 'Warning', "Data not processed",
buttons=QtWidgets.QMessageBox.Ok)
else:
self.statsttFig.plot_stats(mog_)
self.moglogSignal.emit("MOG {}'s Traveltime statistics have been plotted".format(mog_.name))
self.statsttmanager.show()
else:
QtWidgets.QMessageBox.warning(self, 'Warning', "No MOGs in Database",
buttons=QtWidgets.QMessageBox.Ok)
def plot_stats_amp(self):
if len(self.db.mogs) > 0:
itemNo = self.MOG_list.currentRow()
if itemNo != -1:
mog_ = self.db.mogs[itemNo]
self.statsampFig.plot_stats(mog_)
self.moglogSignal.emit("MOG {}'s Amplitude statistics have been plotted".format(mog_.name))
self.statsampmanager.show()
else:
QtWidgets.QMessageBox.warning(self, 'Warning', "No MOGs in Database",
buttons=QtWidgets.QMessageBox.Ok)
def plot_ray_coverage(self):
if len(self.db.mogs) > 0:
itemNo = self.MOG_list.currentRow()
if itemNo != -1:
coverage_ind = self.trace_num_combo.currentIndex()
show_type = self.show_type_combo.currentText()
entire_state = self.entire_coverage_check.isChecked()
n = int(self.trace_num_edit.text()) - 1
mog_ = self.db.mogs[itemNo]
self.raycoverageFig.plot_ray_coverage(mog_, n, show_type, entire_state)
# self.moglogSignal.emit("MOG {}'s Ray Coverage have been plotted".format(mog_.name))
self.raymanager.show()
else:
QtWidgets.QMessageBox.warning(self, 'Warning', "No MOGs in Database",
buttons=QtWidgets.QMessageBox.Ok)
def plot_prune(self):
if len(self.db.mogs) > 0:
itemNo = self.MOG_list.currentRow()
if itemNo != -1:
mog_ = self.db.mogs[itemNo]
if mog_.Tx != 1 and mog_.Tx != 1:
self.pruneFig.plot_prune(mog_, 0)
self.moglogSignal.emit("MOG {}'s Prune have been plotted".format(mog_.name))
self.prunemanager.show()
else:
QtWidgets.QMessageBox.warning(self, 'Warning', "Please select Tx and Rx for MOG",
buttons=QtWidgets.QMessageBox.Ok)
else:
QtWidgets.QMessageBox.warning(self, 'Warning', "No MOGs in Database",
buttons=QtWidgets.QMessageBox.Ok)
def next_trace(self):
n = int(self.trace_num_edit.text())
n += 1
self.trace_num_edit.setText(str(n))
self.update_spectra_and_coverage_Tx_elev_value_label()
self.plot_ray_coverage()
def prev_trace(self):
n = int(self.trace_num_edit.text())
n -= 1
self.trace_num_edit.setText(str(n))
self.update_spectra_and_coverage_Tx_elev_value_label()
self.plot_ray_coverage()
def export_tt(self):
if len(self.db.mogs) > 0:
itemNo = self.MOG_list.currentRow()
if itemNo != -1:
filename = QtWidgets.QFileDialog.getSaveFileName(self, 'Export tt')
self.moglogSignal.emit('Exporting Traveltime file ...')
mog = self.db.mogs[itemNo]
ind = np.not_equal(mog.tt, -1).astype(int) + np.equal(mog.in_vect, 1)
ind = np.where(ind == 2)[0]
export_file = open(filename, 'w')
data = np.array([ind, mog.tt[ind], mog.et[ind]]).T
np.savetxt(filename, data)
export_file.close()
self.moglogSignal.emit('File exported successfully ')
else:
QtWidgets.QMessageBox.warning(self, 'Warning', "No MOGs in Database",
buttons=QtWidgets.QMessageBox.Ok)
def export_tau(self):
if len(self.db.mogs) > 0:
filename = QtWidgets.QFileDialog.getOpenFileName(self, 'Export tau')[0]
self.moglogSignal.emit('Exporting tau file ...')
# TODO:
self.moglogSignal.emit('File exported successfully ')
else:
QtWidgets.QMessageBox.warning(self, 'Warning', "No MOGs in Database",
buttons=QtWidgets.QMessageBox.Ok)
updateHandlerPrune = False # focus may be lost twice due to setFocus and/or the QMessageBox. 'updateHandlerPrune' prevents that.
def update_prune(self):
"""
This method updates the figure containing the points of Tx and Rx
with the information which is in the different edits of the prune widget
"""
if self.updateHandlerPrune:
return
self.updateHandlerPrune = True
expFloat = re.compile("^-?[0-9]+([\.,][0-9]+)?$") # float number, with or without decimals, and allowing negatives
expInt = re.compile("^[0-9]+$") # positive integer
for item in (self.min_elev_edit, self.max_elev_edit,
self.round_fac_edit, self.thresh_edit,
self.min_ang_edit, self.max_ang_edit):
if item.text() != '' and not expFloat.match(item.text()):
item.setFocus()
QtWidgets.QMessageBox.warning(None, 'Warning', "Some edited information is incorrect. Edit fields cannot contain letters or special characters.",
buttons=QtWidgets.QMessageBox.Ok)
self.updateHandlerPrune = False
return
item.setText(item.text().replace(',', '.'))
for item in (self.skip_Rx_edit, self.skip_Tx_edit):
if item.text() != '' and not expInt.match(item.text()):
item.setFocus()
QtWidgets.QMessageBox.warning(None, 'Warning', "Some edited information is incorrect. Edit fields cannot contain letters or special characters.",
buttons=QtWidgets.QMessageBox.Ok)
self.updateHandlerPrune = False
return
self.updateHandlerPrune = False
# First, we get the mog instance's informations
itemNo = self.MOG_list.currentRow()
if itemNo != -1:
mog = self.db.mogs[itemNo]
# List which contain the indexes of the skipped Tx and Rx
inRx = []
inTx = []
# Reinitialisation of the boolean vectors before modification
mog.in_Rx_vect = np.ones(mog.data.ntrace, dtype=bool)
mog.in_Tx_vect = np.ones(mog.data.ntrace, dtype=bool)
# Information from all the edits of the prune widget
new_min = float(self.min_elev_edit.text())
new_max = float(self.max_elev_edit.text())
skip_len_Rx = int(self.skip_Rx_edit.text())
skip_len_Tx = int(self.skip_Tx_edit.text())
round_factor = float(self.round_fac_edit.text())
use_snr = self.thresh_check.isChecked()
threshold_snr = float(self.thresh_edit.text())
ang_min = float(self.min_ang_edit.text())
ang_max = float(self.max_ang_edit.text())
# -These steps are for the constraining of the Tx's ad Rx's elevation--------------------------------------------
# Because the truth of multiple values array is ambiguous, we have to do these steps
# We first create a boolean vector which will have a True value if the elevation is greater or equals the new min
# and will be False the other way
min_Tx = np.greater_equal(-np.unique(mog.data.Tx_z), new_min)
min_Rx = np.greater_equal(-np.unique(np.sort(mog.data.Rx_z)), new_min)
# Then we create another boolean vector which will have a True value if the elevation is less or equals the new max
# and will be false otherwise
max_Tx = np.less_equal(-np.unique(mog.data.Tx_z), new_max)
max_Rx = np.less_equal(-np.unique(np.sort(mog.data.Rx_z)), new_max + 0.0000000001) # TODO À voir avec bernard
# Finally, we add these two boolean vectors as integer type. The subsequent vector will have values of 1 and 2,
# but only the 2s are of interest because they mean that the value is true, either in the min vector than the
# max vector.we than substract 1 to this vector and transform it to a boolean type to have the right points
# plotted in the pruneFig
mog.in_Tx_vect = (min_Tx.astype(int) + max_Tx.astype(int) - 1).astype(bool)
mog.in_Rx_vect = (min_Rx.astype(int) + max_Rx.astype(int) - 1).astype(bool)
# We then append a False boolean vector to fit the lenght of ntrace
mog.in_Tx_vect = np.append(mog.in_Tx_vect, np.ones(mog.data.ntrace - len(min_Tx), dtype=bool))
mog.in_Rx_vect = np.append(mog.in_Rx_vect, np.ones(mog.data.ntrace - len(min_Rx), dtype=bool))
# -These steps are for the skipping of Txs and Rxs---------------------------------------------------------------
# We first get the unique version of Rx_z and Tx_z
unique_Rx_z = np.unique(mog.data.Rx_z)
unique_Tx_z = np.unique(mog.data.Tx_z)
# And then we apply the skip_len with proper matrix indexing
unique_Rx_z = unique_Rx_z[::skip_len_Rx + 1]
unique_Tx_z = unique_Tx_z[::skip_len_Tx + 1]
# Why the +1 ? its because skipping 0 would bring out an error. The initial skipping value is 1, which skips no values
# We then look for the indexes of the skipped values
for i in range(len(np.unique(mog.data.Rx_z))):
if np.unique(mog.data.Rx_z)[i] not in unique_Rx_z:
inRx.append(i)
# And the we assing and False to the skipped points, so the plotting can be successful
for value in inRx:
mog.in_Rx_vect[value] = False
# here its the same thig but for the Txs
for i in range(len(np.unique(mog.data.Tx_z))):
if np.unique(mog.data.Tx_z)[i] not in unique_Tx_z:
inTx.append(i)
for value in inTx:
mog.in_Tx_vect[value] = False
# For the angular restrictions, we first calculate the X-Y distance between the Tx's and Rx's
dr = np.sqrt((mog.data.Tx_x - mog.data.Rx_x)**2 + (mog.data.Tx_y - mog.data.Rx_y)**2)
# Then we call the arctan2 function from numpy which gives us the angle for every couple Tx-Rx
theta = np.arctan2(mog.data.Tx_z - mog.data.Rx_z, dr) * 180 / np.pi
# After finding all the angles of the Tx-Rx set, we do the same thing we did for the elevation
min_theta = np.greater_equal(theta, ang_min)
max_theta = np.less_equal(theta, ang_max)
intheta = (min_theta.astype(int) + max_theta.astype(int) - 1).astype(bool)
# We then look for the indexes of the angle values which don't fit in the restrictions
false_theta = np.where(not intheta)
# Then we associate a false value to these indexes in the in_Rx_vect so the plot will contain only the Rx points
# which fit the constraints values of the min_ang and max_ang edits
for false_index in false_theta[0]:
mog.in_Rx_vect[false_index] = False
if use_snr:
# TODO: Faire la fonction detrend_rad
SNR = compute_SNR(mog)
mog.in_vect = (mog.in_Rx_vect.astype(int) + mog.in_Tx_vect.astype(int) - 1).astype(bool)
# And then. when all of the steps have been done, we update the prune info subwidget and plot the graphic
self.update_prune_info()
self.pruneFig.plot_prune(mog, round_factor)
# Why wouldn't we apply the modification of the round factor in the update prune method?
# well it's because the update prune method modifies the boolean vector in_Tx_vect and in_Rx_vect
# and the applicatiomn of a round facotr modifies the data itself so we had to put it in the plotting
def update_prune_edits_info(self):
itemNo = self.MOG_list.currentRow()
if itemNo != -1:
try:
mog_ = self.db.mogs[itemNo]
self.min_ang_edit.setText(str(mog_.pruneParams.thetaMin))
self.max_ang_edit.setText(str(mog_.pruneParams.thetaMax))
if min(mog_.data.Tx_z) < min(mog_.data.Rx_z):
self.min_elev_edit.setText(str(-mog_.data.Tx_z[-1]))
self.max_elev_edit.setText(str(mog_.data.Tx_z[0]))
elif min(mog_.data.Rx_z) < min(mog_.data.Tx_z):
self.min_elev_edit.setText(str(-max(mog_.data.Rx_z)))
self.max_elev_edit.setText(str(-min(mog_.data.Rx_z)))
except Exception as e:
QtWidgets.QMessageBox.warning(self, 'Warning', "MOG could not be opened : '" + str(e)[:42] + "...' [mog_ui 2]",
buttons=QtWidgets.QMessageBox.Ok)
def update_prune_info(self):
itemNo = self.MOG_list.currentRow()
if itemNo != -1:
mog_ = self.db.mogs[itemNo]
selected_angle = float(self.max_ang_edit.text()) - float(self.min_ang_edit.text())
removed_Tx = mog_.data.ntrace - sum(mog_.in_Tx_vect)
removed_Rx = mog_.data.ntrace - sum(mog_.in_Rx_vect)
removed_Tx_and_Rx = (removed_Tx + removed_Rx) / mog_.data.ntrace * 100
tot_traces = mog_.data.ntrace
selec_traces = sum(mog_.in_vect)
kept_traces = (selec_traces / tot_traces) * 100
self.value_Tx_info_label.setText(str(len(np.unique(mog_.data.Tx_z))))
self.value_Rx_info_label.setText(str(len(np.unique(mog_.data.Rx_z))))
self.value_Tx_Rx_removed_label.setText(str(np.round(removed_Tx_and_Rx)))
self.value_ray_angle_removed_label.setText(str(np.round(((180 - selected_angle) / 180) * 100)))
self.value_traces_kept_label.setText(str(round(kept_traces, 2)))
# TODO: updater le label qui contient la valeur du S/M ratio lorsque la fonction computeSNR sera finie
def start_merge(self):
if len(self.MOG_list) == 0:
QtWidgets.QMessageBox.information(self, 'Warning', "No MOG in Database",
buttons=QtWidgets.QMessageBox.Ok)
return
if len(self.MOG_list) == 1:
QtWidgets.QMessageBox.information(self, 'Warning', "Only 1 MOG in Database",
buttons=QtWidgets.QMessageBox.Ok)
return
self.mergemog = MergeMog(self)
self.mergemog.ref_combo.clear()
for mog in self.db.mogs:
self.mergemog.ref_combo.addItem(str(mog.name))
self.mergemog.getCompat()
def start_delta_t(self):
if len(self.MOG_list) == 0:
QtWidgets.QMessageBox.information(self, 'Warning', "No MOG in Database",
buttons=QtWidgets.QMessageBox.Ok)
return
self.deltat = DeltaTMOG(self.db)
for mog in self.db.mogs:
self.deltat.min_combo.addItem(str(mog.name))
self.deltat.getCompat()
def import_mog(self):
item = choose_mog(self.db)
if item is not None:
self.db.mogs.append(item)
self.update_list_widget()
self.MOG_list.setCurrentRow(len(self.db.mogs) - 1)
self.update_spectra_and_coverage_Tx_num_list()
self.update_spectra_and_coverage_Tx_elev_value_label()
self.update_edits()
self.update_prune_edits_info()
self.update_prune_info()
self.moglogSignal.emit("Mog '{}' was imported successfully".format(item.name))
def update_color_scale(self):
if self.color_scale_combo.currentText() == 'Low':
self.color_scale_edit.setText('28000')
elif self.color_scale_combo.currentText() == 'Medium':
self.color_scale_edit.setText('7000')
elif self.color_scale_combo.currentText() == 'High':
self.color_scale_edit.setText('700')
def init_UI(self):
char1 = unicodedata.lookup("GREEK SMALL LETTER TAU")
char2 = unicodedata.lookup("GREEK CAPITAL LETTER DELTA")
# -------- Creation of the manager for the ZOPRay figure ------- #
self.zopraysFig = ZOPRaysFig()
self.zopraysmanager = QtWidgets.QDialog()
self.zopraystool = NavigationToolbar2QT(self.zopraysFig, self)
zopraysmanagergrid = QtWidgets.QGridLayout()
zopraysmanagergrid.addWidget(self.zopraystool, 0, 0)
zopraysmanagergrid.addWidget(self.zopraysFig, 1, 0)
self.zopraysmanager.setLayout(zopraysmanagergrid)
# -------- Creation of the manager for the Stats Amp figure ------- #
self.statsampFig = StatsAmpFig()
self.statsampmanager = QtWidgets.QDialog()
self.statsamptool = NavigationToolbar2QT(self.statsampFig, self)
statsampmanagergrid = QtWidgets.QGridLayout()
statsampmanagergrid.addWidget(self.statsamptool, 0, 0)
statsampmanagergrid.addWidget(self.statsampFig, 1, 0)
self.statsampmanager.setLayout(statsampmanagergrid)
# ------- Creation of the manager for the Stats tt figure ------- #
self.statsttFig = StatsttFig()
self.statsttmanager = QtWidgets.QDialog()
self.statstttool = NavigationToolbar2QT(self.statsttFig, self)
statsttmanagergrid = QtWidgets.QGridLayout()
statsttmanagergrid.addWidget(self.statstttool, 0, 0)
statsttmanagergrid.addWidget(self.statsttFig, 1, 0)
self.statsttmanager.setLayout(statsttmanagergrid)
# ------- Widgets in Prune ------- #
# --- Labels --- #
skip_Tx_label = MyQLabel('Number of stations to Skip - Tx', ha='center')
skip_Rx_label = MyQLabel('Number of stations to Skip - Rx', ha='center')
round_fac_label = MyQLabel('Rounding Factor', ha='center')
min_ang_label = MyQLabel('Minimum Ray Angle', ha='center')
max_ang_label = MyQLabel('Maximum Ray Angle', ha='center')
min_elev_label = MyQLabel('Minimum Elevation', ha='center')
max_elev_label = MyQLabel('Maximum Elevation', ha='center')
# - Labels in Info -#
Tx_info_label = MyQLabel('Tx', ha='left')
Rx_info_label = MyQLabel('Rx', ha='left')
Tx_Rx_removed_label = MyQLabel('% removed - Tx & Rx', ha='left')
sm_ratio_removed_label = MyQLabel('% removed - S/M ratio', ha='left')
ray_angle_removed_label = MyQLabel('% removed - Ray angle', ha='left')
traces_kept_label = MyQLabel('% of traces kept', ha='left')
self.value_Tx_info_label = MyQLabel('0', ha='right')
self.value_Rx_info_label = MyQLabel('0', ha='right')
self.value_Tx_Rx_removed_label = MyQLabel('0', ha='right')
self.value_sm_ratio_removed_label = MyQLabel('0', ha='right')
self.value_ray_angle_removed_label = MyQLabel('0', ha='right')
self.value_traces_kept_label = MyQLabel('100', ha='right')
# --- Edits --- #
self.skip_Tx_edit = QtWidgets.QLineEdit('0')
self.skip_Rx_edit = QtWidgets.QLineEdit('0')
self.round_fac_edit = QtWidgets.QLineEdit('0')
self.min_ang_edit = QtWidgets.QLineEdit()
self.max_ang_edit = QtWidgets.QLineEdit()
self.min_elev_edit = QtWidgets.QLineEdit()
self.max_elev_edit = QtWidgets.QLineEdit()
self.thresh_edit = QtWidgets.QLineEdit('0')
# - Edits Actions -#
self.skip_Tx_edit.editingFinished.connect(self.update_prune)
self.skip_Rx_edit.editingFinished.connect(self.update_prune)
self.min_ang_edit.editingFinished.connect(self.update_prune)
self.max_ang_edit.editingFinished.connect(self.update_prune)
self.min_elev_edit.editingFinished.connect(self.update_prune)
self.max_elev_edit.editingFinished.connect(self.update_prune)
self.round_fac_edit.editingFinished.connect(self.update_prune)
# - Edits Disposition -#
self.skip_Tx_edit.setAlignment(QtCore.Qt.AlignHCenter)
self.skip_Rx_edit.setAlignment(QtCore.Qt.AlignHCenter)
self.round_fac_edit.setAlignment(QtCore.Qt.AlignHCenter)
self.min_ang_edit.setAlignment(QtCore.Qt.AlignHCenter)
self.max_ang_edit.setAlignment(QtCore.Qt.AlignHCenter)
self.min_elev_edit.setAlignment(QtCore.Qt.AlignHCenter)
self.max_elev_edit.setAlignment(QtCore.Qt.AlignHCenter)
self.thresh_edit.setAlignment(QtCore.Qt.AlignHCenter)
# --- CheckBox --- #
self.thresh_check = QtWidgets.QCheckBox('Threshold - SNR')
# - CheckBox Action -#
self.thresh_check.stateChanged.connect(self.update_prune)
# --- Button --- #
btn_done = QtWidgets.QPushButton('Done')
# --- Info Frame --- #
info_frame = QtWidgets.QFrame()
info_frame_grid = QtWidgets.QGridLayout()
info_frame_grid.addWidget(self.value_Tx_info_label, 1, 0)
info_frame_grid.addWidget(Tx_info_label, 1, 1)
info_frame_grid.addWidget(self.value_Rx_info_label, 2, 0)
info_frame_grid.addWidget(Rx_info_label, 2, 1)
info_frame_grid.addWidget(self.value_Tx_Rx_removed_label, 3, 0)
info_frame_grid.addWidget(Tx_Rx_removed_label, 3, 1)
info_frame_grid.addWidget(self.value_sm_ratio_removed_label, 4, 0)
info_frame_grid.addWidget(sm_ratio_removed_label, 4, 1)
info_frame_grid.addWidget(self.value_ray_angle_removed_label, 5, 0)
info_frame_grid.addWidget(ray_angle_removed_label, 5, 1)
info_frame_grid.addWidget(self.value_traces_kept_label, 6, 0)
info_frame_grid.addWidget(traces_kept_label, 6, 1)
info_frame_grid.setAlignment(QtCore.Qt.AlignCenter)
info_frame.setLayout(info_frame_grid)
info_frame.setStyleSheet('background: white')
# --- Info GroupBox --- #
info_group = QtWidgets.QGroupBox('Informations')
info_grid = QtWidgets.QGridLayout()