Browse Source

currently broken, but refactoring to enable processing of legacy data

add-license-1
Trevor Irons 7 years ago
parent
commit
885c7fa494
2 changed files with 86 additions and 97 deletions
  1. 7
    4
      akvo/gui/akvoGUI.py
  2. 79
    93
      akvo/tressel/mrsurvey.py

+ 7
- 4
akvo/gui/akvoGUI.py View File

192
         #self.ui.loopTableWidget.cellPressed.connect(self.loopCellClicked) 
192
         #self.ui.loopTableWidget.cellPressed.connect(self.loopCellClicked) 
193
 
193
 
194
         self.ui.loopTableWidget.setDragDropOverwriteMode(False)
194
         self.ui.loopTableWidget.setDragDropOverwriteMode(False)
195
-        self.ui.loopTableWidget.setDragEnabled(True)
196
-        self.ui.loopTableWidget.setDragDropMode(QtWidgets.QAbstractItemView.InternalMove)
195
+        self.ui.loopTableWidget.setDragEnabled(False)
196
+        #self.ui.loopTableWidget.setDragDropMode(QtWidgets.QAbstractItemView.InternalMove)
197
 
197
 
198
         self.loops = {}        
198
         self.loops = {}        
199
 
199
 
203
         self.ui.layerTableWidget.setColumnCount(3)      
203
         self.ui.layerTableWidget.setColumnCount(3)      
204
         self.ui.layerTableWidget.setHorizontalHeaderLabels( [r"top [m]", r"bottom [m]", "σ [ Ωm]" ] )
204
         self.ui.layerTableWidget.setHorizontalHeaderLabels( [r"top [m]", r"bottom [m]", "σ [ Ωm]" ] )
205
 
205
 
206
+        # do we want this
206
         self.ui.layerTableWidget.setDragDropOverwriteMode(False)
207
         self.ui.layerTableWidget.setDragDropOverwriteMode(False)
207
         self.ui.layerTableWidget.setDragEnabled(True)
208
         self.ui.layerTableWidget.setDragEnabled(True)
208
         self.ui.layerTableWidget.setDragDropMode(QtWidgets.QAbstractItemView.InternalMove)
209
         self.ui.layerTableWidget.setDragDropMode(QtWidgets.QAbstractItemView.InternalMove)
422
         self.RAWDataProc.updateProcTrigger.connect(self.updateProc)
423
         self.RAWDataProc.updateProcTrigger.connect(self.updateProc)
423
 
424
 
424
     def openGMRRAWDataset(self):
425
     def openGMRRAWDataset(self):
425
-
426
+        """ Opens a GMR header file
427
+        """
426
         try:
428
         try:
427
             with open('.gmr.last.path') as f: 
429
             with open('.gmr.last.path') as f: 
428
                 fpath = f.readline()  
430
                 fpath = f.readline()  
612
 
614
 
613
     # Export XML file suitable for USGS ScienceBase Data Release
615
     # Export XML file suitable for USGS ScienceBase Data Release
614
     def ExportXML(self):
616
     def ExportXML(self):
615
-
617
+        """ This is a filler function for use by USGS collaborators 
618
+        """
616
         return 42
619
         return 42
617
 
620
 
618
     def OpenPreprocess(self):
621
     def OpenPreprocess(self):

+ 79
- 93
akvo/tressel/mrsurvey.py View File

5
 import sys
5
 import sys
6
 import scipy
6
 import scipy
7
 import copy
7
 import copy
8
+import struct
8
 from scipy.io.matlab import mio
9
 from scipy.io.matlab import mio
9
 from numpy import pi
10
 from numpy import pi
10
 from math import floor
11
 from math import floor
183
         self.transFreq       = HEADER[1]
184
         self.transFreq       = HEADER[1]
184
         self.maxBusV         = HEADER[2]
185
         self.maxBusV         = HEADER[2]
185
         self.pulseLength     = pulseLengthDict.get((int)(HEADER[0]))(1e-3*HEADER[3])
186
         self.pulseLength     = pulseLengthDict.get((int)(HEADER[0]))(1e-3*HEADER[3])
186
-        self.interpulseDelay = 1e-3*HEADER[4]   # for T2, Spin Echo
187
-        self.repetitionDelay = HEADER[5]        # delay between first pulse
188
-        self.nPulseMoments   = (int)(HEADER[6]) # Number of pulse moments per stack
189
-        self.TuneCapacitance = HEADER[7]        # tuning capacitance in uF
190
-        self.nTransVersion   = HEADER[8]        # Transmitter version
191
-        self.nDAQVersion     = HEADER[9]        # DAQ software version 
192
-        self.nInterleaves    = HEADER[10]       # num interleaves
187
+        self.interpulseDelay = 1e-3*HEADER[4]      # for T2, Spin Echo
188
+        self.repetitionDelay = HEADER[5]           # delay between first pulse
189
+        self.nPulseMoments   = (int)(HEADER[6])    # Number of pulse moments per stack
190
+        self.TuneCapacitance = HEADER[7]           # tuning capacitance in uF
191
+        self.nTransVersion   = HEADER[8]           # Transmitter version
192
+        self.nDAQVersion     = HEADER[9]           # DAQ software version 
193
+        self.nInterleaves    = HEADER[10]          # num interleaves
194
+
193
         self.gain()
195
         self.gain()
194
         
196
         
195
         # default 
197
         # default 
198
 
200
 
199
         # newer header files contain 64 entries
201
         # newer header files contain 64 entries
200
         if self.nDAQVersion >= 2:
202
         if self.nDAQVersion >= 2:
201
-            #print "new file format"
203
+           #self.deadtime       = HEADER[11]
204
+           #self.unknown        = HEADER[12]
205
+           #self.PreAmpGain     = HEADER[13]
202
             self.samp           = HEADER[14]     # sampling frequency
206
             self.samp           = HEADER[14]     # sampling frequency
203
             self.dt             = 1./self.samp   # sampling rate 
207
             self.dt             = 1./self.samp   # sampling rate 
204
             self.deadTime       = .0055          # instrument dead time before measurement
208
             self.deadTime       = .0055          # instrument dead time before measurement
241
         # Current gain
245
         # Current gain
242
         if floor(self.nDAQVersion) == 1:
246
         if floor(self.nDAQVersion) == 1:
243
             self.CurrentGain = 150.
247
             self.CurrentGain = 150.
244
-        elif floor(self.nDAQVersion) ==2:
248
+        elif floor(self.nDAQVersion) == 2:
245
             self.CurrentGain = 180.
249
             self.CurrentGain = 180.
246
 
250
 
247
     def updateProgress(self):
251
     def updateProgress(self):
1754
         self.doneTrigger.emit() 
1758
         self.doneTrigger.emit() 
1755
         self.updateProcTrigger.emit()  
1759
         self.updateProcTrigger.emit()  
1756
 
1760
 
1761
+    def loadGMRBinaryFID( self, rawfname ):
1762
+        """ Reads a single binary GMR file and fills into DATADICT
1763
+        """
1764
+
1765
+        #################################################################################
1766
+        # figure out key data indices
1767
+        # Pulse        
1768
+        nps  = (int)((self.prePulseDelay)*self.samp)
1769
+        npul   = (int)(self.pulseLength[0]*self.samp) #+ 100 
1770
+
1771
+        # Data 
1772
+        nds  = nps+npul+(int)((self.deadTime)*self.samp);        # indice pulse 1 data starts 
1773
+        nd1 = (int)(1.*self.samp)                                # samples in first pulse
1774
+
1775
+        invGain = 1./self.RxGain        
1776
+        invCGain = self.CurrentGain        
1777
+
1778
+        pulse = "Pulse 1"
1779
+        chan = self.DATADICT[pulse]["chan"] 
1780
+        rchan = self.DATADICT[pulse]["rchan"] 
1781
+        
1782
+        rawFile = open( rawfname, 'rb')
1783
+
1784
+        buf1 = rawFile.read(4)
1785
+        buf2 = rawFile.read(4)
1786
+                
1787
+        N_chan = struct.unpack('>i', buf1 )[0]
1788
+        N_samp = struct.unpack('>i', buf2 )[0]
1789
+ 
1790
+        T = N_samp * self.dt 
1791
+        TIMES = np.arange(0, T, self.dt) - .0002 # small offset in GMR DAQ?
1792
+
1793
+        DATA = np.zeros([N_samp, N_chan+1])
1794
+        for ichan in range(N_chan):
1795
+            DATADUMP = rawFile.read(4*N_samp)
1796
+            for irec in range(N_samp):
1797
+                DATA[irec,ichan] = struct.unpack('>f', DATADUMP[irec*4:irec*4+4])[0]
1798
+                           
1799
+        # Save into Data Cube 
1800
+        for ichan in chan:
1801
+            self.DATADICT["Pulse 1"][ichan][ipm][istack] = DATA[:,eval(ichan)+3][nds:nds+nd1] * invGain 
1802
+            self.DATADICT["Pulse 1"]["TIMES"] = TIMES[nds:nds+nd1]
1803
+            self.DATADICT["Pulse 1"]["CURRENT"][ipm][istack] = DATA[:,1][nps:nps+npul] * invCGain
1804
+            self.DATADICT["Pulse 1"]["PULSE_TIMES"] = TIMES[nps:nps+npul] 
1805
+
1806
+        # plot reference channels?
1807
+        for ichan in rchan:
1808
+            self.DATADICT["Pulse 1"][ichan][ipm][istack] = DATA[:,eval(ichan)+3][nds:nds+nd1] * invGain 
1809
+            self.DATADICT["Pulse 1"]["TIMES"] = TIMES[nds:nds+nd1]
1810
+
1757
     def loadFIDData(self, base, procStacks, chanin, rchanin, FIDProc, canvas, deadTime, plot):
1811
     def loadFIDData(self, base, procStacks, chanin, rchanin, FIDProc, canvas, deadTime, plot):
1758
         '''
1812
         '''
1759
-            Loads a GMR FID dataset, reads OLD ASCII files
1813
+            Loads a GMR FID dataset, reads binary format files 
1760
         '''
1814
         '''
1761
-        import struct
1815
+
1762
         canvas.reAx3(True,False)
1816
         canvas.reAx3(True,False)
1763
 
1817
 
1764
         chan = []
1818
         chan = []
1774
         self.deadTime       = deadTime       # instrument dead time before measurement
1828
         self.deadTime       = deadTime       # instrument dead time before measurement
1775
         self.samp = 50000.                   # in case this is a reproc, these might have 
1829
         self.samp = 50000.                   # in case this is a reproc, these might have 
1776
         self.dt   = 1./self.samp             # changed
1830
         self.dt   = 1./self.samp             # changed
1777
-        invGain = 1./self.RxGain        
1778
-        invCGain = self.CurrentGain        
1779
-
1780
-        #################################################################################
1781
-        # figure out key data indices
1782
-        # Pulse        
1783
-        nps  = (int)((self.prePulseDelay)*self.samp)
1784
-        npul   = (int)(self.pulseLength[0]*self.samp) #+ 100 
1785
 
1831
 
1786
-        # Data 
1787
-        nds  = nps+npul+(int)((self.deadTime)*self.samp);        # indice pulse 1 data starts 
1788
-        nd1 = (int)(1.*self.samp)                              # samples in first pulse
1789
 
1832
 
1790
         #################################################################################
1833
         #################################################################################
1791
         # Data structures     
1834
         # Data structures     
1813
         ##############################################
1856
         ##############################################
1814
         # Read in binary (.lvm) data
1857
         # Read in binary (.lvm) data
1815
         iistack = 0
1858
         iistack = 0
1816
-        hack = False
1817
         for istack in procStacks:
1859
         for istack in procStacks:
1818
-            rawFile = open(base + "_" + str(istack) + ".lvm", 'rb')
1819
-            if hack:
1820
-                subFile = open(base + "sub" + "_" + str(istack) + ".lvm", 'wb')
1821
-            for ipm in range(self.nPulseMoments):
1822
-                
1823
-                # frequency cycing modulation
1824
-                #mod = (-1)**(ipm%2) * (-1)**(istack%2)
1825
-                
1826
-                buf1 = rawFile.read(4)
1827
-                buf2 = rawFile.read(4)
1828
-                
1829
-                if hack:
1830
-                    # hack to do some data analysis
1831
-                    subFile.write(buf1)
1832
-                    subFile.write(buf2)
1833
-                    # end hack
1834
-                
1835
-                #N_chan = struct.unpack('>i', rawFile.read(4))[0]
1836
-                #N_samp = struct.unpack('>i', rawFile.read(4))[0]
1837
-                
1838
-                N_chan = struct.unpack('>i', buf1 )[0]
1839
-                N_samp = struct.unpack('>i', buf2 )[0]
1840
-        
1841
- 
1842
-                T = N_samp * self.dt 
1843
-                TIMES = np.arange(0, T, self.dt) - .0002 # small offset in GMR DAQ?
1844
-
1845
-                DATA = np.zeros([N_samp, N_chan+1])
1846
-                for ichan in range(N_chan):
1847
-                    DATADUMP = rawFile.read(4*N_samp)
1848
-                    #subFile.write(DATADUMP)
1849
-                    for irec in range(N_samp):
1850
-                        DATA[irec,ichan] = struct.unpack('>f', DATADUMP[irec*4:irec*4+4])[0]
1860
+            
1861
+            if self.nDAQVersion < 2.3:
1862
+                rawfname = base + "_" + str(istack) 
1863
+            else:
1864
+                self.loadGMRBinaryFID( base + "_" + str(istack) + ".lvm" )
1851
 
1865
 
1852
-                if hack:                       
1853
-                    # hack to do some data analysis (array survey)
1854
-                    for ichan in range(5):
1855
-                        for irec in range(N_samp): 
1856
-                            bdata = struct.pack( '>f', DATA[irec,ichan] )               
1857
-                            subFile.write(bdata)
1858
-                    for ichan in range(5,6):
1859
-                        for irec in range(N_samp): 
1860
-                            bdata = struct.pack( '>f', DATA[irec,ichan] + DATA[irec,ichan+2] )               
1861
-                            #bdata = struct.pack( '>f', .23 )               
1862
-                            subFile.write(bdata)
1863
-                    for ichan in range(6,N_chan):
1864
-                        for irec in range(N_samp): 
1865
-                            bdata = struct.pack( '>f', DATA[irec,ichan] )               
1866
-                            subFile.write(bdata)
1866
+            # Plotting
1867
+            if plot: 
1868
+                canvas.ax1.clear()
1869
+                canvas.ax2.clear()
1870
+                canvas.ax3.clear()
1867
 
1871
 
1868
-                if plot: 
1869
-                    canvas.ax1.clear()
1870
-                    canvas.ax2.clear()
1871
-                    canvas.ax3.clear()
1872
+                for ipm in range(self.nPulseMoments):
1872
                            
1873
                            
1873
-                # Save into Data Cube 
1874
-                for ichan in chan:
1875
-                    self.DATADICT["Pulse 1"][ichan][ipm][istack] = DATA[:,eval(ichan)+3][nds:nds+nd1] * invGain 
1876
-                    self.DATADICT["Pulse 1"]["TIMES"] = TIMES[nds:nds+nd1]
1877
-                    self.DATADICT["Pulse 1"]["CURRENT"][ipm][istack] = DATA[:,1][nps:nps+npul] * invCGain
1878
-                    self.DATADICT["Pulse 1"]["PULSE_TIMES"] = TIMES[nps:nps+npul] 
1879
-                    if plot:
1880
-                        #canvas.ax2.plot(self.DATADICT["Pulse 1"]["TIMES"],       self.DATADICT["Pulse 1"][ichan][ipm][istack], label="Pulse 1 FID data ch. "+str(ichan)) #, color='blue')
1874
+                    for ichan in chan:
1881
                         canvas.ax1.plot(self.DATADICT["Pulse 1"]["PULSE_TIMES"], self.DATADICT["Pulse 1"]["CURRENT"][ipm][istack] , color='black')
1875
                         canvas.ax1.plot(self.DATADICT["Pulse 1"]["PULSE_TIMES"], self.DATADICT["Pulse 1"]["CURRENT"][ipm][istack] , color='black')
1882
                         canvas.ax3.plot(self.DATADICT["Pulse 1"]["TIMES"],       self.DATADICT["Pulse 1"][ichan][ipm][istack], label="Pulse 1 FID data ch. "+str(ichan)) #, color='blue')
1876
                         canvas.ax3.plot(self.DATADICT["Pulse 1"]["TIMES"],       self.DATADICT["Pulse 1"][ichan][ipm][istack], label="Pulse 1 FID data ch. "+str(ichan)) #, color='blue')
1883
-                        #canvas.draw()
1884
 
1877
 
1885
-                # plot reference channels?
1886
-                for ichan in rchan:
1887
-                    self.DATADICT["Pulse 1"][ichan][ipm][istack] = DATA[:,eval(ichan)+3][nds:nds+nd1] * invGain 
1888
-                    self.DATADICT["Pulse 1"]["TIMES"] = TIMES[nds:nds+nd1]
1889
-                    if plot:
1878
+                    for ichan in rchan:
1890
                         canvas.ax2.plot(self.DATADICT["Pulse 1"]["TIMES"], self.DATADICT["Pulse 1"][ichan][ipm][istack], label="Pulse 1 FID ref ch. "+str(ichan)) #, color='blue')
1879
                         canvas.ax2.plot(self.DATADICT["Pulse 1"]["TIMES"], self.DATADICT["Pulse 1"][ichan][ipm][istack], label="Pulse 1 FID ref ch. "+str(ichan)) #, color='blue')
1891
 
1880
 
1892
-                if plot:
1893
                     canvas.ax3.legend(prop={'size':6})
1881
                     canvas.ax3.legend(prop={'size':6})
1894
                     canvas.ax2.legend(prop={'size':6})
1882
                     canvas.ax2.legend(prop={'size':6})
1895
                     
1883
                     
1906
                     canvas.ax3.ticklabel_format(style='sci', scilimits=(0,0), axis='y') 
1894
                     canvas.ax3.ticklabel_format(style='sci', scilimits=(0,0), axis='y') 
1907
 
1895
 
1908
                     canvas.draw()
1896
                     canvas.draw()
1897
+
1909
                 percent = (int) (1e2*((float)((iistack*self.nPulseMoments+ipm+1))  / (len(procStacks)*self.nPulseMoments)))
1898
                 percent = (int) (1e2*((float)((iistack*self.nPulseMoments+ipm+1))  / (len(procStacks)*self.nPulseMoments)))
1910
-                #self.progressTrigger.emit(percent) 
1911
                 self.progressTrigger.emit(percent) 
1899
                 self.progressTrigger.emit(percent) 
1912
 
1900
 
1913
             iistack += 1
1901
             iistack += 1
1914
 
1902
 
1915
-
1916
         self.enableDSP()    
1903
         self.enableDSP()    
1917
         self.doneTrigger.emit()
1904
         self.doneTrigger.emit()
1918
-
1919
     
1905
     
1920
     def load4PhaseT1Data(self, base, procStacks, chan, rchan, FIDProc, canvas, deadTime, plot): 
1906
     def load4PhaseT1Data(self, base, procStacks, chan, rchan, FIDProc, canvas, deadTime, plot): 
1921
 
1907
 

Loading…
Cancel
Save