-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathERT_AdvancedEditor_v1.36.py
2114 lines (1754 loc) · 94.4 KB
/
ERT_AdvancedEditor_v1.36.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
import math
import pandas as pd
import csv
import pathlib
import wx
import matplotlib
import matplotlib.pylab as pL
import matplotlib.pyplot as plt
import matplotlib.backends.backend_wxagg as wxagg
import re
import numpy as np
import scipy
import scipy.interpolate
import sys
#from mpl_toolkits.mplot3d import Axes3D
#import wx.lib.inspection as wxli
class ERTAPP(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, wx.ID_ANY, title='ERT Editing',pos=(100,100),size=(500,500))
#Built from template here: https://wiki.wxpython.org/GridSizerTutorial
#Set up Panels
def setUpPanels(self):
self.topPanel = wx.Panel(self, wx.ID_ANY,size = (1000,10),name='Top Panel')
self.infoPanel = wx.Panel(self, wx.ID_ANY,size = (1000,50),name='Info Panel')
self.chartPanel = wx.Panel(self, wx.ID_ANY,size = (1000,500),name='Chart Panel')
self.bottomPanel= wx.Panel(self, wx.ID_ANY,size = (1000,130),name='Bottom Panel')
#need to create more panels, see here: https://stackoverflow.com/questions/31286082/matplotlib-in-wxpython-with-multiple-panels
def titleSetup(self):
bmp = wx.ArtProvider.GetBitmap(wx.ART_INFORMATION, wx.ART_OTHER, (4, 4))
self.titleIco = wx.StaticBitmap(self.topPanel, wx.ID_ANY, bmp)
self.title = wx.StaticText(self.topPanel, wx.ID_ANY, 'Advanced ERT Editing')
#Declare inputs for first row
def inputSetup(self):
bmp = wx.ArtProvider.GetBitmap(wx.ART_TIP, wx.ART_OTHER, (4, 4))
self.inputOneIco = wx.StaticBitmap(self.topPanel, wx.ID_ANY, bmp)
self.labelOne = wx.StaticText(self.topPanel, wx.ID_ANY, 'Input ERT Data')
self.inputTxtOne = wx.TextCtrl(self.topPanel, wx.ID_ANY, '')
self.inputTxtOne.SetHint('Enter data file path here')
self.inputBrowseBtn = wx.Button(self.topPanel, wx.ID_ANY, 'Browse')
self.Bind(wx.EVT_BUTTON, self.onBrowse, self.inputBrowseBtn)
self.readInFileBtn = wx.Button(self.topPanel, wx.ID_ANY, 'Read Data')
self.Bind(wx.EVT_BUTTON, self.onReadIn, self.readInFileBtn)
self.inputDataType = wx.Choice(self.topPanel, id=wx.ID_ANY,choices=['.DAT (LS)','.TXT (LS)','.DAT (SAS)', '.VTK', '.XYZ'],name='.TXT (LS)')
self.Bind(wx.EVT_CHOICE,self.onDataType,self.inputDataType)
self.autoShiftBx = wx.CheckBox(self.topPanel,wx.ID_ANY, 'Auto Shift?')
self.autoShiftBx.SetValue(True)
#Row 3 item(s)
self.TxtProfileName = wx.StaticText(self.infoPanel, wx.ID_ANY, 'Profile Name: ')
self.TxtProfileRange = wx.StaticText(self.infoPanel, wx.ID_ANY, 'Profile Length: ')
self.TxtDataPts = wx.StaticText(self.infoPanel, wx.ID_ANY, 'Data Points: ')
self.TxtBlank = wx.StaticText(self.infoPanel, wx.ID_ANY, '')
self.TxtBlank2 = wx.StaticText(self.infoPanel, wx.ID_ANY, '')
self.TxtMinElectSpcng = wx.StaticText(self.infoPanel, wx.ID_ANY, 'Min. Electrode Spacing: ')
self.TxtProjectName = wx.StaticText(self.infoPanel, wx.ID_ANY, 'Project Name: ')
self.TxtArray = wx.StaticText(self.infoPanel, wx.ID_ANY, 'Array: ')
self.msgProfileName = wx.StaticText(self.infoPanel, wx.ID_ANY, '')
self.msgProfileRange = wx.StaticText(self.infoPanel, wx.ID_ANY, '')
self.msgDataPts = wx.StaticText(self.infoPanel, wx.ID_ANY, '')
self.msgMinElectSpcng = wx.StaticText(self.infoPanel, wx.ID_ANY, '')
self.msgProjectName = wx.StaticText(self.infoPanel, wx.ID_ANY, '')
self.msgArray = wx.StaticText(self.infoPanel, wx.ID_ANY, '')
# DataViz Area item(s)
def dataVizSetup(self):
self.editSlider = wx.Slider(self.chartPanel, pos=(200,0), id=wx.ID_ANY, style=wx.SL_TOP | wx.SL_AUTOTICKS | wx.SL_LABELS, name='Edit Data')
self.Bind(wx.EVT_SCROLL, self.onSliderEditEVENT, self.editSlider)
self.dataVizMsg1 = wx.StaticText(self.chartPanel, wx.ID_ANY, '')
self.dataVizMsg2 = wx.StaticText(self.chartPanel, wx.ID_ANY, '')
self.dataVizInput = wx.TextCtrl(self.chartPanel, wx.ID_ANY, '')
self.dataVizInputBtn = wx.Button(self.chartPanel, -1, "Use Value")
self.dataVizInputBtn.Bind(wx.EVT_BUTTON, self.ONdataVizInput)
self.saveEditsBtn = wx.Button(self.chartPanel, -1, "Save Edits")
self.saveEditsBtn.Bind(wx.EVT_BUTTON, self.ONSaveEdits)
self.saveEditsBtn.SetBackgroundColour((100,175,100))
self.currentChart = 'Graph'
self.editDataChoiceList = ['AppResist','Resistance','Electrode x-Dists','Variance','PctErr','PseudoX','PseudoZ']
self.editDataChoiceBool = [False]*len(self.editDataChoiceList)
self.editDataValues = []
for i in self.editDataChoiceList:
self.editDataValues.append([0,0])
self.editDataType = wx.Choice(self.chartPanel, id=wx.ID_ANY,choices=self.editDataChoiceList,name='Edit Data')
self.editDataType.Bind(wx.EVT_CHOICE, self.onSelectEditDataType)
self.setEditToggleBtn = wx.ToggleButton(self.chartPanel,wx.ID_ANY,'Unused',size=(25,30))
self.setEditToggleBtn.Bind(wx.EVT_TOGGLEBUTTON, self.onSetEditToggle)
self.labelMinRem = wx.StaticText(self.chartPanel, wx.ID_ANY, 'Min.')
self.inputTxtMinRem = wx.TextCtrl(self.chartPanel, wx.ID_ANY,style=wx.TE_PROCESS_ENTER, name='')
self.inputTxtMinRem.Bind(wx.EVT_TEXT_ENTER, self.onEditDataValueChangeEvent)
self.labelMaxRem = wx.StaticText(self.chartPanel, wx.ID_ANY,'Max.')
self.inputTxtMaxRem = wx.TextCtrl(self.chartPanel, wx.ID_ANY,style=wx.TE_PROCESS_ENTER,name= '')
self.inputTxtMaxRem.Bind(wx.EVT_TEXT_ENTER, self.onEditDataValueChangeEvent)
self.editTypeToggleBtn = wx.ToggleButton(self.chartPanel,wx.ID_ANY,'Remove',size=(25,50))
self.editTypeToggleBtn.Bind(wx.EVT_TOGGLEBUTTON, self.onEditTypeToggle)
self.editLogicToggleBtn = wx.ToggleButton(self.chartPanel,wx.ID_ANY,'OR',size=(25,25))
self.editLogicToggleBtn.Bind(wx.EVT_TOGGLEBUTTON, self.onLogicToggle)
self.removePtsBtn = wx.Button(self.chartPanel, -1, "Edit Points")
self.removePtsBtn.Bind(wx.EVT_BUTTON, self.onRemovePts)
self.electrodeToggleBtn = wx.ToggleButton(self.chartPanel,wx.ID_ANY,'On',size=(25,25))
self.electrodeToggleBtn.Bind(wx.EVT_TOGGLEBUTTON, self.ONtoggle)
self.GraphEditBtn = wx.Button(self.chartPanel, -1, "Graphic Editor", size=(100, 30))
self.GraphEditBtn.Bind(wx.EVT_BUTTON, self.graphChartEvent)
self.StatEditBtn = wx.Button(self.chartPanel, -1, "Statistical Editor", size=(100, 30))
self.Bind(wx.EVT_BUTTON, self.statChartEvent, self.StatEditBtn)
self.addGPSBtn = wx.Button(self.chartPanel, -1, "GPS Data", size=(100, 30))
self.addGPSBtn.Bind(wx.EVT_BUTTON, self.GPSChartEvent)
self.addTopoBtn = wx.Button(self.chartPanel, -1, "Topography Data", size=(100, 30))
self.addTopoBtn.Bind(wx.EVT_BUTTON, self.topoChartEvent)
self.reviewBtn = wx.Button(self.chartPanel, -1, "Review Edits", size=(100, 15))
self.reviewBtn.Bind(wx.EVT_BUTTON, self.reviewEvent)
def bottomAreaSetup(self):
# Row 4 items
self.reverseBx = wx.CheckBox(self.bottomPanel,wx.ID_ANY, 'Reverse Profile')
self.labelGPSIN = wx.StaticText(self.bottomPanel, wx.ID_ANY, 'GPS Data')
self.inputTxtGPS = wx.TextCtrl(self.bottomPanel, wx.ID_ANY, 'Enter GPS Filepath Here')
self.inputGPSBtn = wx.Button(self.bottomPanel, wx.ID_ANY, 'Browse')
self.Bind(wx.EVT_BUTTON, self.onGPSBrowse, self.inputGPSBtn)
self.Bind(wx.EVT_CHECKBOX, self.onReverse, self.reverseBx)
self.dataEditMsg = wx.StaticText(self.bottomPanel, wx.ID_ANY, '')
self.labelTopoIN = wx.StaticText(self.bottomPanel, wx.ID_ANY, 'Topo Data')
self.inputTxtTopo = wx.TextCtrl(self.bottomPanel, wx.ID_ANY, 'Enter Topo Filepath Here')
self.inputTopoBtn = wx.Button(self.bottomPanel, wx.ID_ANY, 'Browse')
self.includeTopoBx = wx.CheckBox(self.bottomPanel,wx.ID_ANY, 'Include Topography')
self.Bind(wx.EVT_BUTTON, self.onTopoBrowse, self.inputTopoBtn)
self.Bind(wx.EVT_CHECKBOX, self.onIncludeTopo, self.includeTopoBx)
#Bottom Row items
self.saveBtn = wx.Button(self.bottomPanel, wx.ID_ANY, 'Export and Save Data')
self.cancelBtn = wx.Button(self.bottomPanel, wx.ID_ANY, 'Cancel')
self.Bind(wx.EVT_BUTTON, self.onExport, self.saveBtn)
self.Bind(wx.EVT_BUTTON, self.onCancel, self.cancelBtn)
self.labelExport = wx.StaticText(self.bottomPanel, wx.ID_ANY, 'Export Data')
self.exportTXT = wx.TextCtrl(self.bottomPanel, wx.ID_ANY, 'Enter Export Filepath Here')
self.exportDataBtn = wx.Button(self.bottomPanel, wx.ID_ANY, 'Browse')
self.Bind(wx.EVT_BUTTON, self.onExportBrowse, self.exportDataBtn)
#Set up chart
def chartSetup(self):
self.chartSizer = wx.BoxSizer(wx.VERTICAL)
self.figure = matplotlib.figure.Figure()
self.canvas = wxagg.FigureCanvasWxAgg(self.chartPanel, -1, self.figure)
self.axes = self.figure.add_subplot(111)
self.axes.set_xlabel('X-Distance (m)')
self.axes.set_ylabel('Depth (m)')
self.toolbar = wxagg.NavigationToolbar2WxAgg(self.canvas)
def sizersSetup(self):
#Set up sizers
self.baseSizer = wx.BoxSizer(wx.VERTICAL)
self.topSizer = wx.BoxSizer(wx.VERTICAL)
self.titleSizer = wx.BoxSizer(wx.HORIZONTAL)
self.inputSizer = wx.BoxSizer(wx.HORIZONTAL)
#self.readMsgSizer = wx.BoxSizer(wx.HORIZONTAL)
self.profileInfoSizer = wx.BoxSizer(wx.HORIZONTAL)
self.profileTxtSizer1 = wx.BoxSizer(wx.VERTICAL)
self.profileTxtSizer2 = wx.BoxSizer(wx.VERTICAL)
self.profileMsgSizer1 = wx.BoxSizer(wx.VERTICAL)
self.profileMsgSizer2 = wx.BoxSizer(wx.VERTICAL)
self.profileInfoSizer = wx.BoxSizer(wx.HORIZONTAL)
self.ctrlSizer = wx.BoxSizer(wx.VERTICAL)
self.chartSizer = wx.BoxSizer(wx.VERTICAL)
self.dataVizSizer = wx.BoxSizer(wx.HORIZONTAL)
self.vizInfoSizer = wx.BoxSizer(wx.HORIZONTAL)
self.dataEditSizer = wx.BoxSizer(wx.HORIZONTAL)
self.bottomSizer = wx.BoxSizer(wx.VERTICAL)
self.GPSSizer = wx.BoxSizer(wx.HORIZONTAL)
self.TopoSizer = wx.BoxSizer(wx.HORIZONTAL)
self.botSizer = wx.BoxSizer(wx.HORIZONTAL)
def addtoSizers(self):
#Add items to sizers
self.titleSizer.Add(self.title, 0, wx.ALIGN_CENTER)
self.inputSizer.Add(self.labelOne, 1,wx.ALIGN_CENTER,5)
self.inputSizer.Add(self.inputTxtOne, 8,wx.EXPAND,5)
self.inputSizer.Add(self.inputBrowseBtn,1,wx.ALIGN_CENTER,5)
self.inputSizer.Add(self.inputDataType,1,wx.ALIGN_CENTER,5)
self.inputSizer.Add(self.readInFileBtn,1,wx.ALIGN_CENTER,5)
self.inputSizer.Add(self.autoShiftBx, 1, wx.ALIGN_CENTER, 5)
#self.readMsgSizer.Add(self.msgLabelOne, 0, wx.ALL,5)
self.profileTxtSizer1.Add(self.TxtProfileName, 0, wx.ALIGN_LEFT,5)
self.profileTxtSizer1.Add(self.TxtProfileRange, 0, wx.ALIGN_LEFT,5)
self.profileTxtSizer1.Add(self.TxtDataPts, 0, wx.ALIGN_LEFT,5)
self.profileTxtSizer2.Add(self.TxtMinElectSpcng, 0, wx.ALIGN_LEFT,5)
self.profileTxtSizer2.Add(self.TxtArray, 0, wx.ALIGN_LEFT,5)
self.profileTxtSizer2.Add(self.TxtProjectName, 0, wx.ALIGN_LEFT,5)
self.profileMsgSizer1.Add(self.msgProfileName, 0, wx.ALIGN_LEFT,5)
self.profileMsgSizer1.Add(self.msgProfileRange, 0, wx.ALIGN_LEFT,5)
self.profileMsgSizer1.Add(self.msgDataPts, 0, wx.ALIGN_LEFT,5)
self.profileMsgSizer2.Add(self.msgMinElectSpcng, 0, wx.ALIGN_LEFT,5)
self.profileMsgSizer2.Add(self.msgArray, 0, wx.ALIGN_LEFT,5)
self.profileMsgSizer2.Add(self.msgProjectName, 0, wx.ALIGN_LEFT,5)
self.profileInfoSizer.Add(self.profileTxtSizer1, 1,wx.ALL,5)
self.profileInfoSizer.Add(self.profileMsgSizer1,3,wx.ALL,5)
self.profileInfoSizer.Add(self.profileTxtSizer2, 1, wx.ALL, 5)
self.profileInfoSizer.Add(self.profileMsgSizer2, 3, wx.ALL, 5)
self.topSizer.Add(self.titleSizer,1,wx.ALL,5)
self.topSizer.Add(self.inputSizer, 2, wx.ALL, 5)
#self.topSizer.Add(self.readMsgSizer, 1, wx.ALL, 5)
self.vizInfoSizer.Add(self.dataVizMsg1,16,wx.ALL,5)
self.vizInfoSizer.Add(self.dataVizMsg2, 24, wx.ALL, 5)
self.vizInfoSizer.Add(self.electrodeToggleBtn,1,wx.ALL,5)
self.vizInfoSizer.Add(self.dataVizInput, 1, wx.ALL, 5)
self.vizInfoSizer.Add(self.dataVizInputBtn,3,wx.ALL,5)
self.vizInfoSizer.Add(self.saveEditsBtn,3,wx.ALL,5)
self.ctrlSizer.Add(self.GraphEditBtn, 2, wx.ALL, 5)
self.ctrlSizer.Add(self.StatEditBtn, 2, wx.ALL, 5)
self.ctrlSizer.Add(self.addGPSBtn, 2, wx.ALL, 5)
self.ctrlSizer.Add(self.addTopoBtn, 2, wx.ALL, 5)
self.ctrlSizer.Add(self.reviewBtn,1,wx.ALL,5)
self.dataEditSizer.Add(self.editDataType,5, wx.ALL, 5)
self.dataEditSizer.Add(self.setEditToggleBtn,2,wx.ALL,5)
self.dataEditSizer.Add(self.labelMinRem, 2, wx.ALL, 5)
self.dataEditSizer.Add(self.inputTxtMinRem, 3, wx.ALL, 5)
self.dataEditSizer.Add(self.inputTxtMaxRem, 3, wx.ALL, 5)
self.dataEditSizer.Add(self.labelMaxRem, 2, wx.ALL, 5)
self.dataEditSizer.Add(self.editTypeToggleBtn,3,wx.ALL,5)
self.dataEditSizer.Add(self.editLogicToggleBtn,2,wx.ALL,5)
self.dataEditSizer.Add(self.removePtsBtn, 3, wx.ALL, 5)
self.chartSizer.Add(self.vizInfoSizer, 1, wx.ALL, 5)
self.chartSizer.Add(self.editSlider,1, wx.LEFT | wx.RIGHT | wx.EXPAND,94)
self.chartSizer.Add(self.canvas, 12, wx.EXPAND)
self.chartSizer.Add(self.toolbar, 1, wx.EXPAND)
self.chartSizer.Add(self.dataEditSizer,1,wx.EXPAND)
self.dataVizSizer.Add(self.ctrlSizer,1,wx.EXPAND)
self.dataVizSizer.Add(self.chartSizer,6,wx.EXPAND)
self.GPSSizer.Add(self.dataEditMsg, 2, wx.ALL, 5)
self.GPSSizer.Add(self.reverseBx, 1, wx.ALL, 5)
self.GPSSizer.Add(self.labelGPSIN, 1, wx.ALIGN_CENTER_VERTICAL | wx.ALL, 5)
self.GPSSizer.Add(self.inputTxtGPS, 8, wx.ALIGN_CENTER_VERTICAL | wx.ALL, 5)
self.GPSSizer.Add(self.inputGPSBtn, 1, wx.ALIGN_CENTER_VERTICAL | wx.ALL, 5)
self.TopoSizer.Add(self.includeTopoBx, 2, wx.ALIGN_CENTER_VERTICAL | wx.ALL, 5)
self.TopoSizer.Add(self.labelTopoIN, 1, wx.ALIGN_CENTER_VERTICAL| wx.ALL, 5)
self.TopoSizer.Add(self.inputTxtTopo, 8, wx.ALIGN_CENTER_VERTICAL| wx.ALL, 5)
self.TopoSizer.Add(self.inputTopoBtn, 1, wx.ALIGN_CENTER_VERTICAL| wx.ALL, 5)
self.botSizer.Add(self.labelExport, 1, wx.ALL, 5)
self.botSizer.Add(self.exportTXT,6, wx.ALL, 5)
self.botSizer.Add(self.exportDataBtn,1, wx.ALL, 5)
self.botSizer.Add(self.cancelBtn, 1, wx.ALL, 5)
self.botSizer.Add(self.saveBtn, 1, wx.ALL, 5)
#btnSizer.Add(saveEditsBtn,0,wx.ALL,5)
self.bottomSizer.Add(self.GPSSizer,0, wx.ALIGN_RIGHT | wx.ALL, 5)
self.bottomSizer.Add(self.TopoSizer,0, wx.ALIGN_RIGHT | wx.ALL, 5)
self.bottomSizer.Add(self.botSizer,0, wx.ALIGN_RIGHT | wx.ALL, 5)
def addtoPanels(self):
self.topPanel.SetSizer(self.topSizer)
self.infoPanel.SetSizer(self.profileInfoSizer)
self.chartPanel.SetSizer(self.dataVizSizer)
self.bottomPanel.SetSizer(self.bottomSizer)
self.topPanel.Layout()
self.baseSizer.Add(self.topPanel,1, wx.EXPAND,1)
self.baseSizer.Add(self.infoPanel,1,wx.EXPAND,1)
self.baseSizer.Add(self.chartPanel, 10, wx.EXPAND | wx.ALL, 5)
self.baseSizer.Add(self.bottomPanel, 1, wx.EXPAND | wx.ALL, 1)
self.SetSizer(self.baseSizer)
self.SetSize(1100,950)
def variableInfo(): #To see what the 'global' variables are
pass
#self.electxDataIN: list of all electrode xdistances
#self.xCols: list with numbers of columns with x-values, from initial read-in table. varies with datatype
#self.xData: list with all x-values of data points
#self.zData: list with all z-values of data points (depth)
#self.values: list with all resist. values of data points
#self.inputDataExt: extension of file read in, selected from initial drop-down (default = .dat (LS))
#self.xDF : dataframe with only x-dist of electrodes, and all of them
#self.dataHeaders: headers from original file read in, used for column names for dataframeIN
#self.dataListIN: nested list that will be used to create dataframe, with all read-in data
#self.dataframeIN: initial dataframe from data that is read in
#self.df: dataframe formatted for editing, but remaining static as initial input data
#self.dataframeEDIT: dataframe that is manipulated during editing
#self.electrodes: sorted list of all electrode xdistances
#self.electrodesShifted: shifted, sorted list of all electrode xdistances
#self.electState:list of booleans giving status of electrode (True = in use, False = edited out)
#self.electrodeElevs: surface elevation values at each electrode
#self.dataLengthIN: number of measurements in file/length of dataframes
#self.dataframeEDITColHeaders
#self.dataShifted: indicates whether data has been shifted
setUpPanels(self)
titleSetup(self)
inputSetup(self)
dataVizSetup(self)
bottomAreaSetup(self)
chartSetup(self)
sizersSetup(self)
addtoSizers(self)
addtoPanels(self)
#wxli.InspectionTool().Show(self)
#Initial Plot
def nullFunction(self,event):
pass
def onBrowse(self,event):
with wx.FileDialog(self,"Open Data File", style= wx.FD_OPEN | wx.FD_FILE_MUST_EXIST) as fileDialog:
if fileDialog.ShowModal() == wx.ID_CANCEL:
return
self.dataPath = pathlib.Path(fileDialog.GetPath())
fName = str(self.dataPath.parent) + '\\' + self.dataPath.name
self.inputDataExt = self.dataPath.suffix
try:
with open(self.dataPath,'r') as datafile:
self.inputTxtOne.SetValue(fName)
except IOError:
wx.LogError("Cannot Open File")
if self.inputDataExt.lower() == '.txt':
self.inputDataExt = '.TXT (LS)'
n = 1
elif self.inputDataExt.lower() == '.dat':
if self.dataPath.stem.startswith('lr'):
self.inputDataExt = '.DAT (SAS)'
n = 2
else:
self.inputDataExt = '.DAT (LS)'
n = 0
elif self.inputDataExt.lower() == '.vtk':
self.inputDataExt = '.VTK'
n=3
elif self.inputDataExt.lower() == '.xyz':
self.inputDataExt = '.XYZ'
n=4
else:
wx.LogError("Cannot Open File")
if self.inputDataExt == '.DAT (LS)' or self.inputDataExt == '.TXT (LS)':
outPath = self.dataPath.stem.split('-')[0]
else:
outPath = self.dataPath.stem.split('.')[0]
if outPath.startswith('lr'):
outPath = outPath[2:]
outPath = outPath +'_pyEdit.dat'
if self.includeTopoBx.GetValue():
outPath = outPath[:-4]
outPath = outPath + "_topo.dat"
self.exportTXT.SetValue(str(self.dataPath.with_name(outPath)))
self.inputDataType.SetSelection(n)
self.readInFileBtn.SetLabelText('Read Data')
def onGPSBrowse(self,event):
with wx.FileDialog(self,"Open GPS File", style= wx.FD_OPEN | wx.FD_FILE_MUST_EXIST) as fileDialog:
if fileDialog.ShowModal() == wx.ID_CANCEL:
return
self.GPSpath = pathlib.Path(fileDialog.GetPath())
gpsFName = str(self.GPSpath.parent) + '\\' + self.GPSpath.name
self.inputTxtGPS.SetValue(gpsFName)
self.getGPSVals()
def getGPSVals(self):
with open(self.GPSpath) as GPSFile:
data = csv.reader(GPSFile)
self.gpsXData = []
self.gpsYData = []
self.gpsLabels = []
for row in enumerate(data):
if row[0] == 0:
pass #headerline
else:
r = re.split('\t+', str(row[1][0]))
if row[0] == '':
pass
else:
self.gpsLabels.append(r[2])
self.gpsXData.append(float(r[3]))
self.gpsYData.append(float(r[4]))
def onTopoBrowse(self,event):
with wx.FileDialog(self,"Open Topo File", style= wx.FD_OPEN | wx.FD_FILE_MUST_EXIST) as fileDialog:
if fileDialog.ShowModal() == wx.ID_CANCEL:
return
self.topoPath = pathlib.Path(fileDialog.GetPath())
topoFName = str(self.topoPath.parent) + '\\' + self.topoPath.name
self.inputTxtTopo.SetValue(topoFName)
self.includeTopoBx.SetValue(True)
self.getTopoVals()
self.topoText()
def onIncludeTopo(self,event):
self.topoText()
def topoText(self):
if self.includeTopoBx.GetValue() == True:
#print('topo' not in self.exportTXT.GetValue())
if 'topo' not in self.exportTXT.GetValue():
#print("It's Not in")
if len(self.exportTXT.GetValue())>0:
outPath = self.exportTXT.GetValue()
outPath = outPath[:int(len(outPath)-4)]
outPath = outPath + "_topo.dat"
self.exportTXT.SetValue(outPath)
elif self.includeTopoBx.GetValue() == False:
if '_topo' in self.exportTXT.GetValue():
outPath = self.exportTXT.GetValue()
#print(outPath)
strInd = int(outPath.find("_topo"))
strInd2 = strInd + 5
outPath = outPath[:strInd]+outPath[strInd2:]
self.exportTXT.SetValue(outPath)
def onReverse(self,event):
self.reverseText()
def reverseText(self):
if self.reverseBx.GetValue() == True:
if '_rev' not in self.exportTXT.GetValue():
if len(self.exportTXT.GetValue())>0:
outPath = self.exportTXT.GetValue()
outPath = outPath[:int(len(outPath)-4)]
outPath = outPath + "_rev.dat"
self.exportTXT.SetValue(outPath)
elif self.reverseBx.GetValue() == False:
if '_rev' in self.exportTXT.GetValue():
outPath = self.exportTXT.GetValue()
#print(outPath)
strInd = int(outPath.find("_rev"))
strInd2 = strInd + 4
outPath = outPath[:strInd]+outPath[strInd2:]
self.exportTXT.SetValue(outPath)
def getTopoVals(self):
with open(self.topoPath) as topoFile:
data = csv.reader(topoFile)
topoXData = []
topoYData = []
topoLabels = []
for row in enumerate(data):
if row[0] == 0:
pass
else:
r = re.split('\t+', str(row[1][0]))
if r[0] == '':
pass
else:
topoLabels.append(r[0])
topoXData.append(float(r[1]))
topoYData.append(float(r[2]))
self.topoDF = pd.DataFrame([topoXData, topoYData]).transpose()
self.topoDF.columns = ["xDist", "Elev"]
def onDataType(self,event):
self.inputDataExt = self.inputDataType.GetString(self.inputDataType.GetSelection())
if self.inputDataExt == '.DAT (LS)':
self.headerlines = 8
elif self.inputDataExt == '.DAT (SAS)':
self.headerlines = 5
elif self.inputDataExt == '.VTK':
self.headerlines = 5 #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
elif self.inputDataExt == '.XYZ':
self.header = 5 #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
elif self.inputDataExt =='':
self.headerlines = 8
else:
if len(self.inputTxtOne.GetValue()) > 0:
try:
with open(self.dataPath, 'r') as datafile:
filereader = csv.reader(datafile)
start = 0
for row in enumerate(filereader):
if start == 0:
if 'N\\tTime' in str(row[1]):
start = 1
self.headerlines = row[0]
else:
continue
else:
continue
except:
self.headerlines = -1
wx.LogError('Data File not selected')
else:
self.headerlines = -1
def onReadIn(self, event):
self.onDataType(self) #initialize number of headerlines to use
self.dataHeader = []
filepath = pathlib.Path(self.inputTxtOne.GetValue())
self.ext = str(filepath.suffix)
filename = str(filepath.stem)
self.dataframeEDITColHeaders = ['MeasID','A(x)','A(z)','B(x)','B(z)','M(x)','M(z)','N(x)','N(z)', 'aVal', 'nFac','PseudoX','PseudoZ','Resistance','AppResist','Cycles','Variance','DataLevel','DtLvlMean','PctErr','Keep']
if self.ext.lower() == '.dat':
###############Need to update to fit .txt data format
dataLst = []
self.dataLead = []
self.dataTail = []
with open(filepath) as dataFile:
data = csv.reader(dataFile)
if self.inputDataExt == '.DAT (SAS)':
self.dataHeaders = ['M(x)','aVal','nFac','AppResist']
i = 0
dataList=[]
for row in enumerate(data):
if row[0]>self.headerlines: #Read in actual data
if row[0] > self.headerlines + datalength: #Read in data tail
self.dataTail.append(row[1])
else:
#It sometimes reads the lines differently. Sometimes as a list (as it should) other times as a long string
if len(row[1]) < 4:
#Entire row is read as string
dataList.append(re.split(' +', row[1][0]))
else:
#Row is read correctly as separate columns
dataList.append(row[1])
i+=1
else:
if row[0] == 3: #Read in data length
datalength = float(row[1][0])
self.dataLead.append(row[1])#Create data lead variable for later use
datalengthIN = i
self.fileHeaderDict = {}
self.dataListIN = dataList #Formatted global nested list is created of data read in
project = self.dataLead[0][0]
array = self.dataLead[2][0]
if float(array) == 3:
array = "Dipole-Dipole"
msrmtType = 'Apparent Resistivity'
self.fileHeaderDict['Filename'] = filename
self.fileHeaderDict['Project'] = project
self.fileHeaderDict['minElectSpcng'] = round(float(self.dataLead[1][0]),2)
self.fileHeaderDict['Array'] = array
self.fileHeaderDict["Type of Measurement"] = msrmtType
self.fileHeaderDict['DataPts'] = self.dataLead[3][0]
self.dataframeIN = pd.DataFrame(self.dataListIN)
#Sometimes the data is read in with an extra column at the beginning. This fixes that.
if len(self.dataframeIN.columns) > 4:
del self.dataframeIN[0]
self.dataframeIN.reindex([0, 1, 2, 3], axis='columns')
self.dataframeIN = self.dataframeIN.astype(float)
self.dataframeIN.columns = self.dataHeaders
self.dataframeCols = [-2, -3, -4, -5, -6, 0, -7, -8, -9, 1, 2, -10, -11, -12, 3, -1, -1, -13, -14, -15,-16] # neg val ind. colums that need to be calculated
self.dataframeEDIT = pd.DataFrame()
dataframelength = len(self.dataframeIN.index)
nullList = []
keepList = []
zeroList = []
for i in range(0, dataframelength):
nullList.append(-1)
zeroList.append(0.0)
keepList.append(True)
# Create dataframe that will be used in editing process (self.dataframeEDIT) one column at a time
for item in enumerate(self.dataframeEDITColHeaders):
if self.dataframeCols[
item[0]] > -1: # Columns from dataframeIN that are directly read to dataframeEDIT
self.dataframeEDIT[item[1]] = self.dataframeIN.iloc[:, self.dataframeCols[item[0]]]
self.dataframeEDIT[item[1]] = self.dataframeEDIT[item[1]].astype(float)
elif self.dataframeCols[item[0]] == -1: # Null list (can't calculate)
self.dataframeEDIT[item[1]] = nullList
elif self.dataframeCols[item[0]] == -2: # Measure ID
for i in range(0, dataframelength):
self.dataframeEDIT.loc[i, item[1]] = i
elif self.dataframeCols[item[0]] == -3: # A(x)
self.dataframeIN['A(x)'] = self.dataframeIN['M(x)'] + self.dataframeIN['aVal'] + (self.dataframeIN['aVal']*self.dataframeIN['nFac']) + self.dataframeIN['aVal']
self.dataframeEDIT['A(x)'] = self.dataframeIN['A(x)']
elif self.dataframeCols[item[0]] == -4: # A(z)
self.dataframeEDIT[item[1]] = zeroList
elif self.dataframeCols[item[0]] == -5: # B(x)
self.dataframeIN['B(x)'] = self.dataframeIN['M(x)'] + self.dataframeIN['aVal'] + (self.dataframeIN['aVal']*self.dataframeIN['nFac'])
self.dataframeEDIT['B(x)'] = self.dataframeIN['B(x)']
elif self.dataframeCols[item[0]] == -6: # B(z)
self.dataframeEDIT[item[1]] = zeroList
#elif self.dataframeCols[item[0]] == -6: # M(x)
#Reads in directly
elif self.dataframeCols[item[0]] == -7: # M(z)
self.dataframeEDIT[item[1]] = zeroList
elif self.dataframeCols[item[0]] == -8: #N(x)
self.dataframeIN['N(x)'] = self.dataframeIN['M(x)'] + self.dataframeIN['aVal']
self.dataframeEDIT['N(x)'] = self.dataframeIN['N(x)']
elif self.dataframeCols[item[0]] == -9: # N(z)
self.dataframeEDIT[item[1]] = zeroList
elif self.dataframeCols[item[0]] == -10: # PseudoX
self.dataframeEDIT['PseudoX'] = (((self.dataframeEDIT['A(x)'] + self.dataframeEDIT[
'B(x)']) / 2) + ((self.dataframeEDIT['M(x)'] + self.dataframeEDIT['N(x)']) / 2)) / 2
elif self.dataframeCols[item[0]] == -11: # PseudoZ
n = self.dataframeEDIT['nFac']
a = self.dataframeEDIT['aVal']
self.dataframeEDIT['PseudoZ'] = round((((n ** 2) * -0.0018) + 0.2752 * n + 0.1483) * a, 1)
elif self.dataframeCols[item[0]] == -12: #Resistance
PI = math.pi
n = self.dataframeEDIT['nFac']
a = self.dataframeEDIT['aVal']
appR = self.dataframeIN['AppResist']
if self.fileHeaderDict['Array'] == 'Dipole-Dipole':
self.dataframeEDIT['Resistance'] = appR/(PI * n * (n + 1) * (n + 2) * a)
else:
print(
'Array is not Dipole-Dipole, but Dipole-Dipole k-factor used to calculate App. Resistivity')
elif self.dataframeCols[item[0]] == -13: #DataLevel
self.dataframeEDIT['DataLevel'] = nullList
uniqueDepths = self.dataframeEDIT['PseudoZ'].unique()
uniqueDepths = list(set(uniqueDepths.flatten()))
self.dataLevels = len(uniqueDepths)
dataLength = len(self.dataframeEDIT['PseudoZ'])
for i in range(0, dataLength):
self.dataframeEDIT.loc[i, 'DataLevel'] = uniqueDepths.index(
self.dataframeEDIT.loc[i, 'PseudoZ'])
elif self.dataframeCols[item[0]] == -14: #DtLvlMean
for i in uniqueDepths:
df = self.dataframeEDIT[self.dataframeEDIT.iloc[:, 12] == i]
dtLvlMean = df['AppResist'].mean()
indexList = df.index.values.tolist()
for ind in indexList:
self.dataframeEDIT.loc[ind, 'DtLvlMean'] = dtLvlMean
elif self.dataframeCols[item[0]] == -15: #PctErr
self.dataframeEDIT['PctErr'] = (abs(
self.dataframeEDIT['DtLvlMean'] - self.dataframeEDIT['AppResist'])) / \
self.dataframeEDIT['DtLvlMean']
elif self.dataframeCols[item[0]] == -16: #Keep
self.dataframeEDIT[item[1]] = keepList
else:
self.dataframeEDIT[item[1]] = nullList
elif self.inputDataExt == '.DAT (LS)': # If it's .DAT (LS)
self.dataHeaders = ["NoElectrodes",'A(x)', 'A(z)', 'B(x)', 'B(z)', 'M(x)', 'M(z)', 'N(x)', 'N(z)', 'Resistance']
datalength=12
dataList = []
for row in enumerate(data):
if row[0]>int(self.headerlines) and row[0] <= float(self.headerlines + datalength):
strrow = str(row[1])
strrow = strrow[2:-2]
splitrow = strrow.split('\\t')
if len(splitrow) != 10:
newrow = []
for i in splitrow:
val = i.strip()
newrow.append(val)
if len(newrow) < 9:
newrow = re.split(' +',newrow[0])
row = [float(i) for i in newrow]
dataList.append(row)
else:
dataList.append(splitrow)
elif row[0] <= int(self.headerlines):
if isinstance(row[1], list):
val = str(row[1])[2:-2]
else:
val = row[1]
self.dataLead.append(val)
if row[0] == 6:
datalength = float(row[1][0])
else:
self.dataTail.append(row[1])
self.dataListIN = dataList
self.fileHeaderDict = {}
project = self.dataLead[0]
dataFrmt = self.dataLead[2]
array = int(self.dataLead[3])
if array == 3:
array = "Dipole-Dipole"
msrmtType = str(self.dataLead[5])
if msrmtType.strip() == '0':
msrmtType = "Apparent Resistivity"
else:
msrmtType = 'Resistance'
self.fileHeaderDict['Filename'] = filename
self.fileHeaderDict['Project'] = project
self.fileHeaderDict['minElectSpcng'] = str(round(float(self.dataLead[1]),2))
self.fileHeaderDict['Array'] = array
self.fileHeaderDict["Type of Measurement"] = msrmtType
self.fileHeaderDict['DataPts'] = str(self.dataLead[6])
self.fileHeaderDict['DistType'] = str(self.dataLead[7])
self.dataframeIN = pd.DataFrame(self.dataListIN)
self.dataframeIN.columns = self.dataHeaders
self.dataframeCols = [-2, 1, 2, 3, 4, 5, 6, 7, 8, -3, -4, -5, -6, 9, -7, -1, -1, -8, -9, -10, -11] # neg val ind. colums that need to be calculated
self.dataframeEDIT = pd.DataFrame()
dataframelength = len(self.dataframeIN.index)
nullList = []
keepList = []
for i in range(0, dataframelength):
nullList.append(-1)
keepList.append(True)
# Create dataframe that will be used in editing process (self.dataframeEDIT) one column at a time
for item in enumerate(self.dataframeEDITColHeaders):
if self.dataframeCols[item[0]] > -1: #Columns from dataframeIN that are directly read to dataframeEDIT
self.dataframeEDIT[item[1]] = self.dataframeIN.iloc[:, self.dataframeCols[item[0]]]
self.dataframeEDIT[item[1]] = self.dataframeEDIT[item[1]].astype(float)
elif self.dataframeCols[item[0]] == -1: #Null list (can't calculate)
self.dataframeEDIT[item[1]] = nullList
elif self.dataframeCols[item[0]] == -2:#Measure ID
for i in range(0,dataframelength):
self.dataframeEDIT.loc[i,item[1]] = i
elif self.dataframeCols[item[0]] == -3: #A spacing
self.dataframeEDIT[item[1]] = abs(self.dataframeEDIT['A(x)'] - self.dataframeEDIT['B(x)'])
elif self.dataframeCols[item[0]] == -4: #N-factor
self.dataframeEDIT[item[1]] = abs(self.dataframeEDIT['B(x)'] - self.dataframeEDIT['N(x)']) / self.dataframeEDIT['aVal']
elif self.dataframeCols[item[0]] == -5:#PseduoX
self.dataframeEDIT['PseudoX'] = (((self.dataframeEDIT['A(x)']+self.dataframeEDIT['B(x)'])/2)+((self.dataframeEDIT['M(x)']+self.dataframeEDIT['N(x)'])/2))/2
elif self.dataframeCols[item[0]] == -6: #PseduoZ
n = self.dataframeEDIT['nFac']
a = self.dataframeEDIT['aVal']
self.dataframeEDIT['PseudoZ'] = round((((n**2)*-0.0018)+0.2752*n+0.1483)*a,1)
elif self.dataframeCols[item[0]] == -7:#AppResistivity
PI = math.pi
n = self.dataframeEDIT['nFac']
a = self.dataframeEDIT['aVal']
R = self.dataframeEDIT['Resistance']
if self.fileHeaderDict['Array'] == 'Dipole-Dipole':
self.dataframeEDIT['AppResist'] = PI*n*(n+1)*(n+2)*a*R
else:
print('Array is not Dipole-Dipole, but Dipole-Dipole k-factor used to calculate App. Resistivity')
elif self.dataframeCols[item[0]] == -8: #DataLevel
self.dataframeEDIT['DataLevel'] = nullList
uniqueDepths = self.dataframeEDIT['PseudoZ'].unique()
uniqueDepths = list(set(uniqueDepths.flatten()))
self.dataLevels = len(uniqueDepths)
dataLength = len(self.dataframeEDIT['PseudoZ'])
for i in range(0, dataLength):
self.dataframeEDIT.loc[i, 'DataLevel'] = uniqueDepths.index(self.dataframeEDIT.loc[i, 'PseudoZ'])
elif self.dataframeCols[item[0]] == -9: # DtLvlMean
for i in uniqueDepths:
df = self.dataframeEDIT[self.dataframeEDIT.iloc[:, 12] == i]
dtLvlMean = df['AppResist'].mean()
indexList = df.index.values.tolist()
for ind in indexList:
self.dataframeEDIT.loc[ind, 'DtLvlMean'] = dtLvlMean
elif self.dataframeCols[item[0]] == -10: #PctErr
self.dataframeEDIT['PctErr'] = (abs(
self.dataframeEDIT['DtLvlMean'] - self.dataframeEDIT['AppResist'])) / \
self.dataframeEDIT['DtLvlMean']
elif self.dataframeCols[item[0]] == -11: #Keep
self.dataframeEDIT[item[1]] = keepList
else:
self.dataframeEDIT[item[1]] = nullList
self.readInFileBtn.SetLabelText("Reset Data")
elif self.ext.lower() == '.txt':
with open(filepath, 'r') as datafile:
filereader = csv.reader(datafile)
start = 0
end = 0
fileHeader = []
data = []
for row in enumerate(filereader):
if start == 0:
if row[0] <= 13:
fileHeader.append(row[1])
fileHeader[row[0]] = fileHeader[row[0]][:]
if 'N\\tTime' in str(row[1]):
start = 1
self.headerlines = row[0]
dataHdrTemp = str(row[1])
self.dataHeaders = dataHdrTemp[2:-2].split('\\t')
self.dataHeaders[1] = dataHdrTemp[1].strip()
self.fileHeaderDict = {}
for item in fileHeader:
if len(item) > 0:
self.fileHeaderDict[str(item[0]).split(":", 1)[0]] = str(item[0]).split(":", 1)[1].strip()
elif start == 1 and end == 0:
if len(row[1]) > 0:
data.append(str(row[1])[2:-1].split('\\t'))
else:
end = 1
else:
continue
self.dataListIN = data
self.dataframeIN = pd.DataFrame(self.dataListIN)
self.dataframeCols = [0, 6, 8, 9, 11, 12, 14, 15, 17, -2, -3, 18, 20, 26, 28, 29, 27, -4, -5, -6, -7] #neg val ind. colums that need to be calculated
self.dataframeEDIT = pd.DataFrame()
dataframelength = len(self.dataframeIN.index)
nullList = []
keepList = []
for i in range(0, dataframelength):
nullList.append(-1)
keepList.append(True)
# Create dataframe that will be used in editing process (self.dataframeEDIT) one column at a time
for item in enumerate(self.dataframeEDITColHeaders):
if self.dataframeCols[item[0]] > -1:
#print(item[1])
self.dataframeEDIT[item[1]] = self.dataframeIN.iloc[:, self.dataframeCols[item[0]]]
self.dataframeEDIT[item[1]] = self.dataframeEDIT[item[1]].astype(float)
elif self.dataframeCols[item[0]] == -2:
self.dataframeEDIT[item[1]] = abs(self.dataframeEDIT['A(x)'] - self.dataframeEDIT['B(x)'])
elif self.dataframeCols[item[0]] == -3:
self.dataframeEDIT[item[1]] = abs(self.dataframeEDIT['N(x)'] - self.dataframeEDIT['M(x)']) / self.dataframeEDIT['aVal']
elif self.dataframeCols[item[0]] == -4:
self.dataframeEDIT['DataLevel'] = nullList
uniqueDepths = self.dataframeEDIT['PseudoZ'].unique()
uniqueDepths = list(set(uniqueDepths.flatten()))
self.dataLevels = len(uniqueDepths)
dataLength = len(self.dataframeEDIT['PseudoZ'])
for i in range(0, dataLength):
self.dataframeEDIT.loc[i, 'DataLevel'] = uniqueDepths.index(self.dataframeEDIT.loc[i, 'PseudoZ'])
elif self.dataframeCols[item[0]] == -5:
for i in uniqueDepths:
df = self.dataframeEDIT[self.dataframeEDIT.iloc[:, 12] == i]
dtLvlMean = df['AppResist'].mean()
indexList = df.index.values.tolist()
for ind in indexList:
self.dataframeEDIT.loc[ind, 'DtLvlMean'] = dtLvlMean
elif self.dataframeCols[item[0]] == -6:
self.dataframeEDIT['PctErr'] = (abs(self.dataframeEDIT['DtLvlMean'] - self.dataframeEDIT['AppResist'])) / self.dataframeEDIT['DtLvlMean']
elif self.dataframeCols[item[0]] == -7:
self.dataframeEDIT[item[1]] = keepList
else:
self.dataframeEDIT[item[1]] = nullList
self.dataHeaders[1] = 'MeasTime'
if len(self.dataHeaders) > 37:
self.dataHeaders[37] = 'Extra'
self.dataTail = [0,0,0,0,0,0,0]
self.dataframeIN.columns = self.dataHeaders
self.readInFileBtn.SetLabelText("Reset Data")
self.fileHeaderDict['Filename'] = filename
self.fileHeaderDict['Project'] = self.fileHeaderDict['Project name']
self.fileHeaderDict['Array'] = self.fileHeaderDict['Protocol file'][21:-4]
self.fileHeaderDict['minElectSpcng'] = self.fileHeaderDict['Smallest electrode spacing']
self.fileHeaderDict['DataPts'] = len(self.dataframeIN)
self.dataLead = []
self.dataLead.append(self.fileHeaderDict['Project name'] + " " + self.fileHeaderDict['Filename'])
self.dataLead.append(self.fileHeaderDict['minElectSpcng'])
self.dataLead.append('11') #General Array format
self.dataLead.append(self.fileHeaderDict['Sub array code']) #tells what kind of array is used
self.dataLead.append('Type of measurement (0=app.resistivity,1=resistance)')
self.dataLead.append('0') #Col 26 in .txt (col 28 is app. resistivity)
self.dataLead.append(self.fileHeaderDict['DataPts'])
self.dataLead.append('2')
self.dataLead.append('0')
elif self.ext.lower() == '.vtk':
with open(filepath, 'r') as datafile:
filereader = csv.reader(datafile)
startLocs = 0
startData = 0
startLocInd = 'POINTS'
startDataInd = 'LOOKUP_TABLE'
endLocs = 0
endData = 0
endLocInd = []
endDataInd = []
fileLead = []
fileMid = []
fileTail = []
vtkdata = []
vtklocs = []
newrow = []
xLocPts = []
yLocPts = []
zLocPts = []
vPts = []
for row in enumerate(filereader):
if startLocs == 0:
fileLead.append(row[1])
fileLead[row[0]] = fileLead[row[0]][:]
if startLocInd in str(row[1]):
startLocs = 1
elif startLocs == 1 and endLocs == 0:
if endLocInd == row[1]:
endLocs = 1
else:
newrow = re.split(' +', str(row[1][0]))
newrow = newrow[1:]
vtklocs.append(newrow)
elif startData == 0:
fileMid.append(row[1])
if startDataInd in str(row[1]):
startData = 1
elif startData == 1 and endData == 0:
if row[1] == endDataInd:
endData == 1
else:
newrow = re.split(' +', str(row[1][0]))
newrow = newrow[1:]
vtkdata.append(newrow)
else:
fileTail.append(row[1])
fileTail[row[0]] = fileTail[row[0]][:]
xPtCols = [0,3,6,9]
yPtCols = [1,4,7,10]
zPtCols = [2,5,8,11]
for r in vtklocs:
Xs = 0.0
for x in xPtCols:
Xs = Xs + float(r[x])
xLocPts.append(Xs/4.0)
Ys = 0.0
for y in yPtCols:
Ys = Ys + float(r[y])
yLocPts.append(Ys/4.0)
Zs = 0.0
for z in zPtCols:
Zs = Zs + float(r[z])
zLocPts.append(Zs/4)