Browse Source

Improving the speed of plotting of subsequent graphs by not doing a hard clear at each call to plot.

tags/1.6.1
Trevor Irons 5 years ago
parent
commit
3f9d8d98f5
3 changed files with 120 additions and 75 deletions
  1. 9
    3
      akvo/gui/mydynamicmplcanvas.py
  2. 26
    4
      akvo/tressel/harmonic.py
  3. 85
    68
      akvo/tressel/mrsurvey.py

+ 9
- 3
akvo/gui/mydynamicmplcanvas.py View File

17
     """Ultimately, this is a QWidget (as well as a FigureCanvasAgg, etc.)."""
17
     """Ultimately, this is a QWidget (as well as a FigureCanvasAgg, etc.)."""
18
     def __init__(self, parent=None, width=3, height=4, dpi=100):
18
     def __init__(self, parent=None, width=3, height=4, dpi=100):
19
         
19
         
20
-        self.fig = Figure(figsize=(width, height), dpi=dpi, facecolor='darkgrey') # this fucking works...why?
20
+        self.fig = Figure(figsize=(width, height), dpi=dpi, facecolor='darkgrey') 
21
         #self.fig.patch.set_facecolor('blue')
21
         #self.fig.patch.set_facecolor('blue')
22
         FigureCanvas.__init__(self, self.fig)
22
         FigureCanvas.__init__(self, self.fig)
23
 
23
 
198
         self.ax1.tick_params(axis='both', which='major', labelsize=8)
198
         self.ax1.tick_params(axis='both', which='major', labelsize=8)
199
         self.ax2.tick_params(axis='both', which='major', labelsize=8)
199
         self.ax2.tick_params(axis='both', which='major', labelsize=8)
200
 
200
 
201
-        self.ax1.ticklabel_format(style='sci', scilimits=(0,0), axis='y')  
202
-        self.ax2.ticklabel_format(style='sci', scilimits=(0,0), axis='y')  
201
+        self.ax1.ticklabel_format(style='scientific', scilimits=(0,0), axis='y')  
202
+        self.ax2.ticklabel_format(style='scientific', scilimits=(0,0), axis='y')  
203
 
203
 
204
         self.ax1.yaxis.get_offset_text().set_size(8) 
204
         self.ax1.yaxis.get_offset_text().set_size(8) 
205
         self.ax2.yaxis.get_offset_text().set_size(8) 
205
         self.ax2.yaxis.get_offset_text().set_size(8) 
206
+    
207
+    def softClear(self):
208
+        for ax in self.fig.get_axes():
209
+            for artist in ax.lines + ax.collections:
210
+                artist.remove()
211
+            ax.set_prop_cycle(None)
206
 
212
 
207
     def reAx3(self, shx=True, shy=True):
213
     def reAx3(self, shx=True, shy=True):
208
 
214
 

+ 26
- 4
akvo/tressel/harmonic.py View File

38
     return np.linalg.norm( harmonicEuler(sN, fs, t, f0, k1, kN, ks)[ii] ) 
38
     return np.linalg.norm( harmonicEuler(sN, fs, t, f0, k1, kN, ks)[ii] ) 
39
 
39
 
40
 def minHarmonic(sN, fs, t, f0, k1, kN, ks):
40
 def minHarmonic(sN, fs, t, f0, k1, kN, ks):
41
+    
41
     # CG, BFGS, Newton-CG, L-BFGS-B, TNC, SLSQP, dogleg, trust-ncg, trust-krylov, trust-exact and trust-constr
42
     # CG, BFGS, Newton-CG, L-BFGS-B, TNC, SLSQP, dogleg, trust-ncg, trust-krylov, trust-exact and trust-constr
42
-    res = minimize(harmonicNorm, np.array((f0)), args=(sN, fs, t, k1, kN, ks), jac='2-point', method='BFGS') # hess=None, bounds=None )
43
+    #res = minimize(harmonicNorm, np.array((f0)), args=(sN, fs, t, k1, kN, ks), jac='2-point', method='BFGS') # hess=None, bounds=None )
44
+    
45
+    #############
46
+    # Reduced N #
47
+    #############
48
+    #print("min 10")
49
+    #res = minimize(harmonicNorm, np.array((f0)), args=(sN, fs, t, k1, 10, ks), jac='2-point', method='BFGS') # hess=None, bounds=None )
50
+    
51
+    ########## 
52
+    # Bounds #
53
+    ##########
54
+    print("bounded search for f0", f0)
55
+    bnds = ( (f0-0.125, f0+0.125), )
56
+    #print("len f0", len( [f0,] ))
57
+    #print("len bnds", len(bnds) )
58
+    res = minimize(harmonicNorm, (f0,), args=(sN, fs, t, k1, kN, ks), jac='2-point', method='L-BFGS-B', bounds=bnds ) # hess=None, bounds=None )
59
+    
43
     #print(res)
60
     #print(res)
44
     #print ( "guess", guessf0(  harmonicEuler(sN, fs, t, res.x[0], k1, kN, ks), fs  ) )
61
     #print ( "guess", guessf0(  harmonicEuler(sN, fs, t, res.x[0], k1, kN, ks), fs  ) )
45
-    return harmonicEuler(sN, fs, t, res.x[0], k1, kN, ks)#[0]
62
+    return harmonicEuler(sN, fs, t, res.x[0], k1, kN, ks), res.x[0]#[0]
46
 
63
 
47
 def harmonicEuler2 ( sN, fs, t, f0, f0k1, f0kN, f0ks, f1, f1k1, f1kN, f1ks ): 
64
 def harmonicEuler2 ( sN, fs, t, f0, f0k1, f0kN, f0ks, f1, f1k1, f1kN, f1ks ): 
48
     """
65
     """
91
     return np.linalg.norm( harmonicEuler2(sN, fs, t, f0[0], f0k1, f0kN, f0ks, f0[1], f1k1, f1kN, f1ks)[ii] ) 
108
     return np.linalg.norm( harmonicEuler2(sN, fs, t, f0[0], f0k1, f0kN, f0ks, f0[1], f1k1, f1kN, f1ks)[ii] ) 
92
 
109
 
93
 def minHarmonic2(sN, fs, t, f0, f0k1, f0kN, f0ks, f1, f1k1, f1kN, f1ks):
110
 def minHarmonic2(sN, fs, t, f0, f0k1, f0kN, f0ks, f1, f1k1, f1kN, f1ks):
111
+    
94
     # CG, BFGS, Newton-CG, L-BFGS-B, TNC, SLSQP, dogleg, trust-ncg, trust-krylov, trust-exact and trust-constr
112
     # CG, BFGS, Newton-CG, L-BFGS-B, TNC, SLSQP, dogleg, trust-ncg, trust-krylov, trust-exact and trust-constr
95
-    res = minimize(harmonic2Norm, np.array((f0, f1)), args=(sN, fs, t, f0k1, f0kN, f0ks, f1k1,f1kN, f1ks), jac='2-point', method='BFGS') # hess=None, bounds=None )
113
+    #res = minimize(harmonic2Norm, np.array((f0, f1)), args=(sN, fs, t, f0k1, f0kN, f0ks, f1k1,f1kN, f1ks), jac='2-point', method='BFGS') # hess=None, bounds=None )
114
+    
115
+    print("search 10")
116
+    res = minimize(harmonic2Norm, np.array((f0, f1)), args=(sN, fs, t, f0k1, 10, f0ks, f1k1, 10, f1ks), jac='2-point', method='BFGS') # hess=None, bounds=None )
117
+    
96
     #print(res)
118
     #print(res)
97
     #print ( "guess", guessf0(harmonicEuler2(sN, fs, t, res.x[0], f0k1, f0kN, f0ks, res.x[1], f1k1, f1kN, f1ks), fs)  )
119
     #print ( "guess", guessf0(harmonicEuler2(sN, fs, t, res.x[0], f0k1, f0kN, f0ks, res.x[1], f1k1, f1kN, f1ks), fs)  )
98
-    return harmonicEuler2(sN, fs, t, res.x[0], f0k1, f0kN, f0ks, res.x[1], f1k1, f1kN, f1ks)#[0]
120
+    return harmonicEuler2(sN, fs, t, res.x[0], f0k1, f0kN, f0ks, res.x[1], f1k1, f1kN, f1ks), res.x[0], res.x[1]#[0]
99
 
121
 
100
 def guessf0( sN, fs ):
122
 def guessf0( sN, fs ):
101
     S = np.fft.fft(sN)
123
     S = np.fft.fft(sN)

+ 85
- 68
akvo/tressel/mrsurvey.py View File

194
         self.RotatedAmplitude = False
194
         self.RotatedAmplitude = False
195
 #        self.DATA                   = np.zeros(1) # Numpy array to hold all data, dimensions resized based on experiment
195
 #        self.DATA                   = np.zeros(1) # Numpy array to hold all data, dimensions resized based on experiment
196
 #        self.PULSES                 = np.zeros(1) # Numpy array to hold all data, dimensions resized based on experiment
196
 #        self.PULSES                 = np.zeros(1) # Numpy array to hold all data, dimensions resized based on experiment
197
-
197
+ 
198
     def Print(self):
198
     def Print(self):
199
         print ("pulse type", self.pulseType)
199
         print ("pulse type", self.pulseType)
200
         print ("maxBusV", self.maxBusV)
200
         print ("maxBusV", self.maxBusV)
560
         #plot = True
560
         #plot = True
561
         if plot:
561
         if plot:
562
             canvas.reAx2()
562
             canvas.reAx2()
563
-            canvas.ax1.tick_params(axis='both', which='major', labelsize=8)
564
-            canvas.ax1.ticklabel_format(style='sci', scilimits=(0,0), axis='y')  
565
-            canvas.ax2.tick_params(axis='both', which='major', labelsize=8)
566
-            canvas.ax2.ticklabel_format(style='sci', scilimits=(0,0), axis='y')  
563
+            #canvas.ax1.tick_params(axis='both', which='major', labelsize=8)
564
+            #canvas.ax1.ticklabel_format(style='sci', axis='y') #, scilimits=(0,0))
565
+            #canvas.ax2.tick_params(axis='both', which='major', labelsize=8)
566
+            #canvas.ax2.ticklabel_format(style='sci', axis='y') #, scilimits=(0,0)) 
567
+            canvas.ax1.set_ylabel(r"signal [nV]", fontsize=8)
568
+            canvas.ax2.set_xlabel(r"time [s]", fontsize=8)
569
+            canvas.ax2.set_ylabel(r"signal [nV]", fontsize=8)
570
+            #canvas.ax1.tick_params(axis='both', which='major', labelsize=8)
571
+            #canvas.ax2.tick_params(axis='both', which='major', labelsize=8)
567
 
572
 
568
         # Data
573
         # Data
569
         iFID = 0
574
         iFID = 0
570
 
575
 
576
+        # stores previous f0 as starting point in non-linear search 
577
+        f0p = {} 
578
+        f1p = {} 
579
+        for pulse in self.DATADICT["PULSES"]:
580
+            for rchan in self.DATADICT[pulse]["rchan"]:
581
+                f0p[rchan] = f0
582
+                f1p[rchan] = f1+1e-1 
583
+            for chan in self.DATADICT[pulse]["chan"]:
584
+                f0p[chan] = f0
585
+                f1p[chan] = f1+1e-1
586
+
571
         for pulse in self.DATADICT["PULSES"]:
587
         for pulse in self.DATADICT["PULSES"]:
572
             self.DATADICT[pulse]["TIMES"] =  self.DATADICT[pulse]["TIMES"]
588
             self.DATADICT[pulse]["TIMES"] =  self.DATADICT[pulse]["TIMES"]
573
             Nseg = int( np.floor(len( self.DATADICT[pulse]["TIMES"] ) / f0ns) )
589
             Nseg = int( np.floor(len( self.DATADICT[pulse]["TIMES"] ) / f0ns) )
574
-            for ipm in range(self.DATADICT["nPulseMoments"]):
575
-                for istack in self.DATADICT["stacks"]:
576
-                    canvas.ax1.clear()
577
-                    canvas.ax2.clear()
578
-                    #for ichan in np.append(self.DATADICT[pulse]["chan"], self.DATADICT[pulse]["rchan"]):
590
+            for istack in self.DATADICT["stacks"]:
591
+                for ipm in range(self.DATADICT["nPulseMoments"]):
592
+                    if plot:
593
+                        #canvas.ax1.clear()
594
+                        #canvas.ax2.clear()
595
+                        #for artist in canvas.ax1.lines + canvas.ax1.collections:
596
+                        #    artist.remove()
597
+                        #canvas.ax1.set_prop_cycle(None)
598
+                        #for artist in canvas.ax2.lines + canvas.ax2.collections:
599
+                        #    artist.remove()
600
+                        #canvas.ax2.set_prop_cycle(None)
601
+                        canvas.softClear()
602
+                        for ichan in self.DATADICT[pulse]["rchan"]:
603
+                            canvas.ax1.plot( self.DATADICT[pulse]["TIMES"], 1e9*self.DATADICT[pulse][ichan][ipm][istack], alpha=.5) 
604
+                            #, label = "orig " +  pulse + " ipm=" + str(ipm) + " istack=" + str(istack) + " rchan="  + str(ichan))
605
+                            
606
+                        for ichan in self.DATADICT[pulse]["chan"]:
607
+                            canvas.ax2.plot( self.DATADICT[pulse]["TIMES"], 1e9*self.DATADICT[pulse][ichan][ipm][istack], alpha=.5) 
608
+                            #, label = "orig " +  pulse + " ipm=" + str(ipm) + " istack=" + str(istack) + " chan="  + str(ichan))
609
+                        canvas.ax1.set_prop_cycle(None)
610
+                        canvas.ax2.set_prop_cycle(None)
579
                     for ichan in self.DATADICT[pulse]["rchan"]:
611
                     for ichan in self.DATADICT[pulse]["rchan"]:
580
-                        if plot:
581
-                            canvas.ax1.plot( self.DATADICT[pulse]["TIMES"], 1e9*self.DATADICT[pulse][ichan][ipm][istack], \
582
-                                label = "orig " +  pulse + " ipm=" + str(ipm) + " istack=" + str(istack) + " rchan="  + str(ichan))
583
-
584
                         if nF == 1:
612
                         if nF == 1:
585
                             #self.DATADICT[pulse][ichan][ipm][istack] = harmonic.minHarmonic( f0, self.DATADICT[pulse][ichan][ipm][istack], self.samp, nK, self.DATADICT[pulse]["TIMES"] ) 
613
                             #self.DATADICT[pulse][ichan][ipm][istack] = harmonic.minHarmonic( f0, self.DATADICT[pulse][ichan][ipm][istack], self.samp, nK, self.DATADICT[pulse]["TIMES"] ) 
586
                             for iseg in range(f0ns):
614
                             for iseg in range(f0ns):
587
                                 if iseg < f0ns-1:
615
                                 if iseg < f0ns-1:
588
-                                    self.DATADICT[pulse][ichan][ipm][istack][iseg*Nseg:(iseg+1)*Nseg] = harmonic.minHarmonic( self.DATADICT[pulse][ichan][ipm][istack][iseg*Nseg:(iseg+1)*Nseg], \
616
+                                    self.DATADICT[pulse][ichan][ipm][istack][iseg*Nseg:(iseg+1)*Nseg], f0p[ichan] = harmonic.minHarmonic( self.DATADICT[pulse][ichan][ipm][istack][iseg*Nseg:(iseg+1)*Nseg], \
589
                                             self.samp,  self.DATADICT[pulse]["TIMES"][iseg*Nseg:(iseg+1)*Nseg], \
617
                                             self.samp,  self.DATADICT[pulse]["TIMES"][iseg*Nseg:(iseg+1)*Nseg], \
590
-                                            f0, f0K1, f0KN, f0Ks ) 
618
+                                            f0p[ichan], f0K1, f0KN, f0Ks ) 
591
                                 else:
619
                                 else:
592
-                                    self.DATADICT[pulse][ichan][ipm][istack][iseg*Nseg::] = harmonic.minHarmonic( self.DATADICT[pulse][ichan][ipm][istack][iseg*Nseg::], \
620
+                                    self.DATADICT[pulse][ichan][ipm][istack][iseg*Nseg::], f0p[ichan] = harmonic.minHarmonic( self.DATADICT[pulse][ichan][ipm][istack][iseg*Nseg::], \
593
                                             self.samp,  self.DATADICT[pulse]["TIMES"][iseg*Nseg::], \
621
                                             self.samp,  self.DATADICT[pulse]["TIMES"][iseg*Nseg::], \
594
-                                            f0, f0K1, f0KN, f0Ks ) 
595
-
622
+                                            f0p[ichan], f0K1, f0KN, f0Ks ) 
596
                             #self.DATADICT[pulse][ichan][ipm][istack] = harmonic.minHarmonic( self.DATADICT[pulse][ichan][ipm][istack], self.samp,  self.DATADICT[pulse]["TIMES"], \
623
                             #self.DATADICT[pulse][ichan][ipm][istack] = harmonic.minHarmonic( self.DATADICT[pulse][ichan][ipm][istack], self.samp,  self.DATADICT[pulse]["TIMES"], \
597
                             #    f0, f0K1, f0KN, f0Ks ) 
624
                             #    f0, f0K1, f0KN, f0Ks ) 
598
                         elif nF == 2:
625
                         elif nF == 2:
602
                             #    f1+1e-2, f1K1, f1KN, f1Ks ) 
629
                             #    f1+1e-2, f1K1, f1KN, f1Ks ) 
603
                             for iseg in range(f0ns):
630
                             for iseg in range(f0ns):
604
                                 if iseg < f0ns-1:
631
                                 if iseg < f0ns-1:
605
-                                    self.DATADICT[pulse][ichan][ipm][istack][iseg*Nseg:(iseg+1)*Nseg] = harmonic.minHarmonic2( self.DATADICT[pulse][ichan][ipm][istack][iseg*Nseg:(iseg+1)*Nseg],\
632
+                                    self.DATADICT[pulse][ichan][ipm][istack][iseg*Nseg:(iseg+1)*Nseg], f0p[ichan], f1p[ichan] = harmonic.minHarmonic2( self.DATADICT[pulse][ichan][ipm][istack][iseg*Nseg:(iseg+1)*Nseg],\
606
                                      self.samp,  self.DATADICT[pulse]["TIMES"][iseg*Nseg:(iseg+1)*Nseg], \
633
                                      self.samp,  self.DATADICT[pulse]["TIMES"][iseg*Nseg:(iseg+1)*Nseg], \
607
-                                     f0-1e-2, f0K1, f0KN, f0Ks,  \
608
-                                     f1+1e-2, f1K1, f1KN, f1Ks ) 
634
+                                     f0p[ichan], f0K1, f0KN, f0Ks,  \
635
+                                     f1p[ichan], f1K1, f1KN, f1Ks ) 
609
                                 else:
636
                                 else:
610
-                                    self.DATADICT[pulse][ichan][ipm][istack][iseg*Nseg::] = harmonic.minHarmonic2( self.DATADICT[pulse][ichan][ipm][istack][iseg*Nseg::],\
637
+                                    self.DATADICT[pulse][ichan][ipm][istack][iseg*Nseg::], f0p[ichan], f1p[ichan] = harmonic.minHarmonic2( self.DATADICT[pulse][ichan][ipm][istack][iseg*Nseg::],\
611
                                      self.samp,  self.DATADICT[pulse]["TIMES"][iseg*Nseg::], \
638
                                      self.samp,  self.DATADICT[pulse]["TIMES"][iseg*Nseg::], \
612
-                                     f0-1e-2, f0K1, f0KN, f0Ks,  \
613
-                                     f1+1e-2, f1K1, f1KN, f1Ks ) 
639
+                                     f0p[ichan], f0K1, f0KN, f0Ks,  \
640
+                                     f1p[ichan], f1K1, f1KN, f1Ks ) 
614
                         # plot
641
                         # plot
615
                         if plot:
642
                         if plot:
616
                             canvas.ax1.plot( self.DATADICT[pulse]["TIMES"], 1e9*self.DATADICT[pulse][ichan][ipm][istack], \
643
                             canvas.ax1.plot( self.DATADICT[pulse]["TIMES"], 1e9*self.DATADICT[pulse][ichan][ipm][istack], \
618
 
645
 
619
                     for ichan in self.DATADICT[pulse]["chan"]:
646
                     for ichan in self.DATADICT[pulse]["chan"]:
620
                         
647
                         
621
-                        if plot:
622
-                            canvas.ax2.plot( self.DATADICT[pulse]["TIMES"], 1e9*self.DATADICT[pulse][ichan][ipm][istack], \
623
-                                label = "orig " +  pulse + " ipm=" + str(ipm) + " istack=" + str(istack) + " chan="  + str(ichan))
624
-                        
625
                         if nF == 1:
648
                         if nF == 1:
626
                             #self.DATADICT[pulse][ichan][ipm][istack] = harmonic.minHarmonic( f0, self.DATADICT[pulse][ichan][ipm][istack], self.samp, nK, self.DATADICT[pulse]["TIMES"] ) 
649
                             #self.DATADICT[pulse][ichan][ipm][istack] = harmonic.minHarmonic( f0, self.DATADICT[pulse][ichan][ipm][istack], self.samp, nK, self.DATADICT[pulse]["TIMES"] ) 
627
                             #self.DATADICT[pulse][ichan][ipm][istack] = harmonic.minHarmonic( self.DATADICT[pulse][ichan][ipm][istack], self.samp,  self.DATADICT[pulse]["TIMES"], \
650
                             #self.DATADICT[pulse][ichan][ipm][istack] = harmonic.minHarmonic( self.DATADICT[pulse][ichan][ipm][istack], self.samp,  self.DATADICT[pulse]["TIMES"], \
628
                             #    f0, f0K1, f0KN, f0Ks ) 
651
                             #    f0, f0K1, f0KN, f0Ks ) 
629
                             for iseg in range(f0ns):
652
                             for iseg in range(f0ns):
630
                                 if iseg < f0ns-1:
653
                                 if iseg < f0ns-1:
631
-                                    self.DATADICT[pulse][ichan][ipm][istack][iseg*Nseg:(iseg+1)*Nseg] = harmonic.minHarmonic( self.DATADICT[pulse][ichan][ipm][istack][iseg*Nseg:(iseg+1)*Nseg], 
654
+                                    self.DATADICT[pulse][ichan][ipm][istack][iseg*Nseg:(iseg+1)*Nseg], f0p[ichan] = harmonic.minHarmonic( self.DATADICT[pulse][ichan][ipm][istack][iseg*Nseg:(iseg+1)*Nseg], 
632
                                             self.samp,  self.DATADICT[pulse]["TIMES"][iseg*Nseg:(iseg+1)*Nseg], \
655
                                             self.samp,  self.DATADICT[pulse]["TIMES"][iseg*Nseg:(iseg+1)*Nseg], \
633
-                                            f0, f0K1, f0KN, f0Ks ) 
656
+                                            f0p[ichan], f0K1, f0KN, f0Ks ) 
634
                                 else:
657
                                 else:
635
-                                    self.DATADICT[pulse][ichan][ipm][istack][iseg*Nseg::] = harmonic.minHarmonic( self.DATADICT[pulse][ichan][ipm][istack][iseg*Nseg::], 
658
+                                    self.DATADICT[pulse][ichan][ipm][istack][iseg*Nseg::], f0p[ichan] = harmonic.minHarmonic( self.DATADICT[pulse][ichan][ipm][istack][iseg*Nseg::], 
636
                                             self.samp,  self.DATADICT[pulse]["TIMES"][iseg*Nseg::], \
659
                                             self.samp,  self.DATADICT[pulse]["TIMES"][iseg*Nseg::], \
637
-                                            f0, f0K1, f0KN, f0Ks ) 
660
+                                            f0p[ichan], f0K1, f0KN, f0Ks )
638
 
661
 
639
                         elif nF == 2:
662
                         elif nF == 2:
640
                             #self.DATADICT[pulse][ichan][ipm][istack] = harmonic.minHarmonic2( f0-1e-2, f1+1e-2, self.DATADICT[pulse][ichan][ipm][istack], self.samp, nK, self.DATADICT[pulse]["TIMES"] ) 
663
                             #self.DATADICT[pulse][ichan][ipm][istack] = harmonic.minHarmonic2( f0-1e-2, f1+1e-2, self.DATADICT[pulse][ichan][ipm][istack], self.samp, nK, self.DATADICT[pulse]["TIMES"] ) 
644
                             #    f1+1e-2, f1K1, f1KN, f1Ks ) 
667
                             #    f1+1e-2, f1K1, f1KN, f1Ks ) 
645
                             for iseg in range(f0ns):
668
                             for iseg in range(f0ns):
646
                                 if iseg < f0ns-1:
669
                                 if iseg < f0ns-1:
647
-                                    self.DATADICT[pulse][ichan][ipm][istack][iseg*Nseg:(iseg+1)*Nseg] = harmonic.minHarmonic2( self.DATADICT[pulse][ichan][ipm][istack][iseg*Nseg:(iseg+1)*Nseg],\
670
+                                    self.DATADICT[pulse][ichan][ipm][istack][iseg*Nseg:(iseg+1)*Nseg], f0p[ichan], f1p[ichan] = harmonic.minHarmonic2( self.DATADICT[pulse][ichan][ipm][istack][iseg*Nseg:(iseg+1)*Nseg],\
648
                                      self.samp,  self.DATADICT[pulse]["TIMES"][iseg*Nseg:(iseg+1)*Nseg], \
671
                                      self.samp,  self.DATADICT[pulse]["TIMES"][iseg*Nseg:(iseg+1)*Nseg], \
649
-                                     f0-1e-2, f0K1, f0KN, f0Ks,  \
650
-                                     f1+1e-2, f1K1, f1KN, f1Ks ) 
672
+                                     f0p[ichan], f0K1, f0KN, f0Ks,  \
673
+                                     f1p[ichan], f1K1, f1KN, f1Ks ) 
651
                                 else:
674
                                 else:
652
-                                    self.DATADICT[pulse][ichan][ipm][istack][iseg*Nseg::] = harmonic.minHarmonic2( self.DATADICT[pulse][ichan][ipm][istack][iseg*Nseg::],\
675
+                                    self.DATADICT[pulse][ichan][ipm][istack][iseg*Nseg::], f0p[ichan], f1p[ichan] = harmonic.minHarmonic2( self.DATADICT[pulse][ichan][ipm][istack][iseg*Nseg::],\
653
                                      self.samp,  self.DATADICT[pulse]["TIMES"][iseg*Nseg::], \
676
                                      self.samp,  self.DATADICT[pulse]["TIMES"][iseg*Nseg::], \
654
-                                     f0-1e-2, f0K1, f0KN, f0Ks,  \
655
-                                     f1+1e-2, f1K1, f1KN, f1Ks ) 
677
+                                     f0p[ichan], f0K1, f0KN, f0Ks,  \
678
+                                     f1p[ichan], f1K1, f1KN, f1Ks ) 
656
                
679
                
657
                         # plot
680
                         # plot
658
                         if plot:
681
                         if plot:
659
                             canvas.ax2.plot( self.DATADICT[pulse]["TIMES"], 1e9*self.DATADICT[pulse][ichan][ipm][istack], \
682
                             canvas.ax2.plot( self.DATADICT[pulse]["TIMES"], 1e9*self.DATADICT[pulse][ichan][ipm][istack], \
660
-                                label = "data " + pulse + " ipm=" + str(ipm) + " istack=" + str(istack) + " chan="  + str(ichan))
683
+                                label = pulse + " ipm=" + str(ipm) + " istack=" + str(istack) + " chan="  + str(ichan))
661
 
684
 
662
                     if plot:
685
                     if plot:
663
-                        canvas.ax1.set_xlabel(r"time [s]", fontsize=8)
664
-                        canvas.ax1.set_ylabel(r"signal [nV]", fontsize=8)
665
-                        canvas.ax2.set_xlabel(r"time [s]", fontsize=8)
666
-                        canvas.ax2.set_ylabel(r"signal [nV]", fontsize=8)
667
-                        canvas.ax1.legend(prop={'size':6})
668
-                        canvas.ax2.legend(prop={'size':6})
686
+                        canvas.ax1.legend(prop={'size':6}, loc='upper right')
687
+                        canvas.ax2.legend(prop={'size':6}, loc='upper right')
669
                         canvas.draw() 
688
                         canvas.draw() 
670
                     
689
                     
671
-                percent = (int)(1e2*((float)(iFID*self.DATADICT["nPulseMoments"]+(ipm))/(len(self.DATADICT["PULSES"])*self.nPulseMoments)))
690
+                #percent = (int)(1e2*((float)(iFID*self.DATADICT["nPulseMoments"]+(ipm))/(len(self.DATADICT["PULSES"])*self.nPulseMoments)))
691
+                percent = (int)(1e2*((ipm+istack*self.nPulseMoments)/(self.nPulseMoments*len(self.DATADICT["stacks"])))) 
672
                 self.progressTrigger.emit(percent)  
692
                 self.progressTrigger.emit(percent)  
673
             iFID += 1
693
             iFID += 1
694
+
674
         self.doneTrigger.emit() 
695
         self.doneTrigger.emit() 
675
         self.updateProcTrigger.emit()  
696
         self.updateProcTrigger.emit()  
676
 
697
 
1990
         canvas.draw() 
2011
         canvas.draw() 
1991
         return [bord, self.fe] 
2012
         return [bord, self.fe] 
1992
 
2013
 
1993
-    def downsample(self, truncate, dec, plot, canvas):
1994
-        """ Downsamples and truncates the raw signal. 
2014
+    def downsample(self, truncate, dec, plot=False, canvas=None):
2015
+        """ Downsamples and truncates the raw signal.
2016
+            Args 
2017
+                truncate (float) : the length of the signal to truncate to  
2018
+                dec (int) : the decimation factor, 1 results in no downsampling
2019
+                plot (bool) : perform plots
2020
+                canvas : MPL axis for plotting  
1995
         """
2021
         """
1996
-        canvas.reAx2()
1997
-
1998
-        canvas.ax1.tick_params(axis='both', which='major', labelsize=8)
1999
-        canvas.ax1.ticklabel_format(style='sci', scilimits=(0,0), axis='y')  
2000
-        canvas.ax2.tick_params(axis='both', which='major', labelsize=8)
2001
-        canvas.ax2.ticklabel_format(style='sci', scilimits=(0,0), axis='y')  
2022
+        
2023
+        if plot:
2024
+            canvas.reAx2()
2025
+            canvas.ax1.set_ylabel(r"signal [nV]", fontsize=8)
2026
+            canvas.ax2.set_xlabel(r"time [s]", fontsize=8)
2027
+            canvas.ax2.set_ylabel(r"signal [nV]", fontsize=8)
2002
 
2028
 
2003
         self.samp /= dec
2029
         self.samp /= dec
2004
         self.dt   = 1./self.samp       
2030
         self.dt   = 1./self.samp       
2009
         for pulse in self.DATADICT["PULSES"]:
2035
         for pulse in self.DATADICT["PULSES"]:
2010
             for ipm in range(self.DATADICT["nPulseMoments"]):
2036
             for ipm in range(self.DATADICT["nPulseMoments"]):
2011
                 for istack in self.DATADICT["stacks"]:
2037
                 for istack in self.DATADICT["stacks"]:
2012
-                    canvas.ax1.clear()
2013
-                    canvas.ax2.clear()
2038
+                    if plot:
2039
+                        canvas.softClear()
2014
                     for ichan in np.append(self.DATADICT[pulse]["chan"], self.DATADICT[pulse]["rchan"]):
2040
                     for ichan in np.append(self.DATADICT[pulse]["chan"], self.DATADICT[pulse]["rchan"]):
2015
                         # trim off indices that don't divide evenly
2041
                         # trim off indices that don't divide evenly
2016
                         ndi = np.shape(self.DATADICT[pulse][ichan][ipm][istack])[0]%dec
2042
                         ndi = np.shape(self.DATADICT[pulse][ichan][ipm][istack])[0]%dec
2025
                         if truncate:
2051
                         if truncate:
2026
                             self.DATADICT[pulse][ichan][ipm][istack] = self.DATADICT[pulse][ichan][ipm][istack][0:itrunc]
2052
                             self.DATADICT[pulse][ichan][ipm][istack] = self.DATADICT[pulse][ichan][ipm][istack][0:itrunc]
2027
                             RSTIMES = RSTIMES[0:itrunc]
2053
                             RSTIMES = RSTIMES[0:itrunc]
2028
-
2029
                     if plot:
2054
                     if plot:
2030
                         for ichan in self.DATADICT[pulse]["chan"]:
2055
                         for ichan in self.DATADICT[pulse]["chan"]:
2031
                             canvas.ax2.plot( RSTIMES, 1e9*self.DATADICT[pulse][ichan][ipm][istack], \
2056
                             canvas.ax2.plot( RSTIMES, 1e9*self.DATADICT[pulse][ichan][ipm][istack], \
2033
                         for ichan in self.DATADICT[pulse]["rchan"]:
2058
                         for ichan in self.DATADICT[pulse]["rchan"]:
2034
                             canvas.ax1.plot( RSTIMES, 1e9*self.DATADICT[pulse][ichan][ipm][istack], \
2059
                             canvas.ax1.plot( RSTIMES, 1e9*self.DATADICT[pulse][ichan][ipm][istack], \
2035
                                 label = pulse + " ipm=" + str(ipm) + " istack=" + str(istack) + " ichan="  + str(ichan))
2060
                                 label = pulse + " ipm=" + str(ipm) + " istack=" + str(istack) + " ichan="  + str(ichan))
2036
-                    
2037
-                        canvas.ax1.set_xlabel(r"time [s]", fontsize=8)
2038
-                        canvas.ax1.set_ylabel(r"signal [nV]", fontsize=8)
2039
-                        canvas.ax2.set_xlabel(r"time [s]", fontsize=8)
2040
-                        canvas.ax2.set_ylabel(r"signal [nV]", fontsize=8)
2041
-                    
2042
-                        canvas.ax1.legend(prop={'size':6})
2043
-                        canvas.ax2.legend(prop={'size':6})
2044
-                        canvas.ax1.ticklabel_format(style='sci', scilimits=(0,0), axis='y') 
2045
-                        canvas.ax2.ticklabel_format(style='sci', scilimits=(0,0), axis='y') 
2061
+                        canvas.ax1.legend(prop={'size':6}, loc='upper right')
2062
+                        canvas.ax2.legend(prop={'size':6}, loc='upper right')
2046
                         canvas.draw() 
2063
                         canvas.draw() 
2047
                 percent = (int)(1e2*((float)(iFID*self.DATADICT["nPulseMoments"]+(ipm))/( len(self.DATADICT["PULSES"])*self.nPulseMoments)))
2064
                 percent = (int)(1e2*((float)(iFID*self.DATADICT["nPulseMoments"]+(ipm))/( len(self.DATADICT["PULSES"])*self.nPulseMoments)))
2048
                 self.progressTrigger.emit(percent)
2065
                 self.progressTrigger.emit(percent)

Loading…
Cancel
Save