Moved interesting old vclamp commands over into the curve plugin
authorW. Trevor King <wking@drexel.edu>
Sun, 8 Aug 2010 20:46:32 +0000 (16:46 -0400)
committerW. Trevor King <wking@drexel.edu>
Sun, 8 Aug 2010 20:46:32 +0000 (16:46 -0400)
hooke/plugin/curve.py
hooke/plugin/vclamp.py

index efa09f755701fef52d72ac7d8eea79e63edc5482..4877b5b0172a7472cdc85d10851875ca9dc49446 100644 (file)
@@ -430,3 +430,176 @@ Name of the new data block for storing the power spectrum (defaults to
         b[:,1] = power
         params['curve'].data.append(b)
         outqueue.put(b)
+
+
+class OldCruft (object):
+
+    def do_forcebase(self,args):
+        '''
+        FORCEBASE
+        (generalvclamp.py)
+        Measures the difference in force (in pN) between a point and a baseline
+        took as the average between two points.
+
+        The baseline is fixed once for a given curve and different force measurements,
+        unless the user wants it to be recalculated
+        ------------
+        Syntax: forcebase [rebase]
+                rebase: Forces forcebase to ask again the baseline
+                max: Instead of asking for a point to measure, asks for two points and use
+                     the maximum peak in between
+        '''
+        rebase=False #if true=we select rebase
+        maxpoint=False #if true=we measure the maximum peak
+
+        plot=self._get_displayed_plot()
+        whatset=1 #fixme: for all sets
+        if 'rebase' in args or (self.basecurrent != self.current.path):
+            rebase=True
+        if 'max' in args:
+            maxpoint=True
+
+        if rebase:
+            print 'Select baseline'
+            self.basepoints=self._measure_N_points(N=2, whatset=whatset)
+            self.basecurrent=self.current.path
+
+        if maxpoint:
+            print 'Select two points'
+            points=self._measure_N_points(N=2, whatset=whatset)
+            boundpoints=[points[0].index, points[1].index]
+            boundpoints.sort()
+            try:
+                y=min(plot.vectors[whatset][1][boundpoints[0]:boundpoints[1]])
+            except ValueError:
+                print 'Chosen interval not valid. Try picking it again. Did you pick the same point as begin and end of interval?'
+        else:
+            print 'Select point to measure'
+            points=self._measure_N_points(N=1, whatset=whatset)
+            #whatplot=points[0].dest
+            y=points[0].graph_coords[1]
+
+        #fixme: code duplication
+        boundaries=[self.basepoints[0].index, self.basepoints[1].index]
+        boundaries.sort()
+        to_average=plot.vectors[whatset][1][boundaries[0]:boundaries[1]] #y points to average
+
+        avg=np.mean(to_average)
+        forcebase=abs(y-avg)
+        print str(forcebase*(10**12))+' pN'
+        to_dump='forcebase '+self.current.path+' '+str(forcebase*(10**12))+' pN'
+        self.outlet.push(to_dump)
+
+    #---SLOPE---
+    def do_slope(self,args):
+        '''
+        SLOPE
+        (generalvclamp.py)
+        Measures the slope of a delimited chunk on the return trace.
+        The chunk can be delimited either by two manual clicks, or have
+        a fixed width, given as an argument.
+        ---------------
+        Syntax: slope [width]
+                The facultative [width] parameter specifies how many
+                points will be considered for the fit. If [width] is
+                specified, only one click will be required.
+        (c) Marco Brucale, Massimo Sandal 2008
+        '''
+
+        # Reads the facultative width argument
+        try:
+            fitspan=int(args)
+        except:
+            fitspan=0
+
+        # Decides between the two forms of user input, as per (args)
+        if fitspan == 0:
+            # Gets the Xs of two clicked points as indexes on the current curve vector
+            print 'Click twice to delimit chunk'
+            points=self._measure_N_points(N=2,whatset=1)
+        else:
+            print 'Click once on the leftmost point of the chunk (i.e.usually the peak)'
+            points=self._measure_N_points(N=1,whatset=1)
+            
+        slope=self._slope(points,fitspan)
+
+        # Outputs the relevant slope parameter
+        print 'Slope:'
+        print str(slope)
+        to_dump='slope '+self.current.path+' '+str(slope)
+        self.outlet.push(to_dump)
+
+    def _slope(self,points,fitspan):
+        # Calls the function linefit_between
+        parameters=[0,0,[],[]]
+        try:
+            clickedpoints=[points[0].index,points[1].index]
+            clickedpoints.sort()
+        except:
+            clickedpoints=[points[0].index-fitspan,points[0].index]        
+
+        try:
+            parameters=self.linefit_between(clickedpoints[0],clickedpoints[1])
+        except:
+            print 'Cannot fit. Did you click twice the same point?'
+            return
+             
+        # Outputs the relevant slope parameter
+        print 'Slope:'
+        print str(parameters[0])
+        to_dump='slope '+self.curve.path+' '+str(parameters[0])
+        self.outlet.push(to_dump)
+
+        # Makes a vector with the fitted parameters and sends it to the GUI
+        xtoplot=parameters[2]
+        ytoplot=[]
+        x=0
+        for x in xtoplot:
+            ytoplot.append((x*parameters[0])+parameters[1])
+
+        clickvector_x, clickvector_y=[], []
+        for item in points:
+            clickvector_x.append(item.graph_coords[0])
+            clickvector_y.append(item.graph_coords[1])
+
+        lineplot=self._get_displayed_plot(0) #get topmost displayed plot
+
+        lineplot.add_set(xtoplot,ytoplot)
+        lineplot.add_set(clickvector_x, clickvector_y)
+
+
+        if lineplot.styles==[]:
+            lineplot.styles=[None,None,None,'scatter']
+        else:
+            lineplot.styles+=[None,'scatter']
+        if lineplot.colors==[]:
+            lineplot.colors=[None,None,'black',None]
+        else:
+            lineplot.colors+=['black',None]
+        
+        
+        self._send_plot([lineplot])
+
+        return parameters[0]
+
+
+    def linefit_between(self,index1,index2,whatset=1):
+        '''
+        Creates two vectors (xtofit,ytofit) slicing out from the
+        current return trace a portion delimited by the two indexes
+        given as arguments.
+        Then does a least squares linear fit on that slice.
+        Finally returns [0]=the slope, [1]=the intercept of the
+        fitted 1st grade polynomial, and [2,3]=the actual (x,y) vectors
+        used for the fit.
+        (c) Marco Brucale, Massimo Sandal 2008
+        '''
+        # Translates the indexes into two vectors containing the x,y data to fit
+        xtofit=self.plots[0].vectors[whatset][0][index1:index2]
+        ytofit=self.plots[0].vectors[whatset][1][index1:index2]
+
+        # Does the actual linear fitting (simple least squares with numpy.polyfit)
+        linefit=[]
+        linefit=np.polyfit(xtofit,ytofit,1)
+
+        return (linefit[0],linefit[1],xtofit,ytofit)
index 64b5913ca6de275d46208c0c8e006b0205fbb29f..26fa4ff61194778cf413068b4e1d835b19fe8b8b 100644 (file)
@@ -581,62 +581,6 @@ Name of the spring constant in the `.info` dictionary.
 
 class generalvclampCommands(object):
 
-    def do_forcebase(self,args):
-        '''
-        FORCEBASE
-        (generalvclamp.py)
-        Measures the difference in force (in pN) between a point and a baseline
-        took as the average between two points.
-
-        The baseline is fixed once for a given curve and different force measurements,
-        unless the user wants it to be recalculated
-        ------------
-        Syntax: forcebase [rebase]
-                rebase: Forces forcebase to ask again the baseline
-                max: Instead of asking for a point to measure, asks for two points and use
-                     the maximum peak in between
-        '''
-        rebase=False #if true=we select rebase
-        maxpoint=False #if true=we measure the maximum peak
-
-        plot=self._get_displayed_plot()
-        whatset=1 #fixme: for all sets
-        if 'rebase' in args or (self.basecurrent != self.current.path):
-            rebase=True
-        if 'max' in args:
-            maxpoint=True
-
-        if rebase:
-            print 'Select baseline'
-            self.basepoints=self._measure_N_points(N=2, whatset=whatset)
-            self.basecurrent=self.current.path
-
-        if maxpoint:
-            print 'Select two points'
-            points=self._measure_N_points(N=2, whatset=whatset)
-            boundpoints=[points[0].index, points[1].index]
-            boundpoints.sort()
-            try:
-                y=min(plot.vectors[whatset][1][boundpoints[0]:boundpoints[1]])
-            except ValueError:
-                print 'Chosen interval not valid. Try picking it again. Did you pick the same point as begin and end of interval?'
-        else:
-            print 'Select point to measure'
-            points=self._measure_N_points(N=1, whatset=whatset)
-            #whatplot=points[0].dest
-            y=points[0].graph_coords[1]
-
-        #fixme: code duplication
-        boundaries=[self.basepoints[0].index, self.basepoints[1].index]
-        boundaries.sort()
-        to_average=plot.vectors[whatset][1][boundaries[0]:boundaries[1]] #y points to average
-
-        avg=np.mean(to_average)
-        forcebase=abs(y-avg)
-        print str(forcebase*(10**12))+' pN'
-        to_dump='forcebase '+self.current.path+' '+str(forcebase*(10**12))+' pN'
-        self.outlet.push(to_dump)
-
     def plotmanip_multiplier(self, plot, current):
         '''
         Multiplies all the Y values of an SMFS curve by a value stored in the 'force_multiplier'
@@ -742,192 +686,3 @@ class generalvclampCommands(object):
 
         return plot
 
-    #---SLOPE---
-    def do_slope(self,args):
-        '''
-        SLOPE
-        (generalvclamp.py)
-        Measures the slope of a delimited chunk on the return trace.
-        The chunk can be delimited either by two manual clicks, or have
-        a fixed width, given as an argument.
-        ---------------
-        Syntax: slope [width]
-                The facultative [width] parameter specifies how many
-                points will be considered for the fit. If [width] is
-                specified, only one click will be required.
-        (c) Marco Brucale, Massimo Sandal 2008
-        '''
-
-        # Reads the facultative width argument
-        try:
-            fitspan=int(args)
-        except:
-            fitspan=0
-
-        # Decides between the two forms of user input, as per (args)
-        if fitspan == 0:
-            # Gets the Xs of two clicked points as indexes on the current curve vector
-            print 'Click twice to delimit chunk'
-            points=self._measure_N_points(N=2,whatset=1)
-        else:
-            print 'Click once on the leftmost point of the chunk (i.e.usually the peak)'
-            points=self._measure_N_points(N=1,whatset=1)
-            
-        slope=self._slope(points,fitspan)
-
-        # Outputs the relevant slope parameter
-        print 'Slope:'
-        print str(slope)
-        to_dump='slope '+self.current.path+' '+str(slope)
-        self.outlet.push(to_dump)
-
-    def _slope(self,points,fitspan):
-        # Calls the function linefit_between
-        parameters=[0,0,[],[]]
-        try:
-            clickedpoints=[points[0].index,points[1].index]
-            clickedpoints.sort()
-        except:
-            clickedpoints=[points[0].index-fitspan,points[0].index]        
-
-        try:
-            parameters=self.linefit_between(clickedpoints[0],clickedpoints[1])
-        except:
-            print 'Cannot fit. Did you click twice the same point?'
-            return
-             
-        # Outputs the relevant slope parameter
-        print 'Slope:'
-        print str(parameters[0])
-        to_dump='slope '+self.curve.path+' '+str(parameters[0])
-        self.outlet.push(to_dump)
-
-        # Makes a vector with the fitted parameters and sends it to the GUI
-        xtoplot=parameters[2]
-        ytoplot=[]
-        x=0
-        for x in xtoplot:
-            ytoplot.append((x*parameters[0])+parameters[1])
-
-        clickvector_x, clickvector_y=[], []
-        for item in points:
-            clickvector_x.append(item.graph_coords[0])
-            clickvector_y.append(item.graph_coords[1])
-
-        lineplot=self._get_displayed_plot(0) #get topmost displayed plot
-
-        lineplot.add_set(xtoplot,ytoplot)
-        lineplot.add_set(clickvector_x, clickvector_y)
-
-
-        if lineplot.styles==[]:
-            lineplot.styles=[None,None,None,'scatter']
-        else:
-            lineplot.styles+=[None,'scatter']
-        if lineplot.colors==[]:
-            lineplot.colors=[None,None,'black',None]
-        else:
-            lineplot.colors+=['black',None]
-        
-        
-        self._send_plot([lineplot])
-
-        return parameters[0]
-
-
-    def linefit_between(self,index1,index2,whatset=1):
-        '''
-        Creates two vectors (xtofit,ytofit) slicing out from the
-        current return trace a portion delimited by the two indexes
-        given as arguments.
-        Then does a least squares linear fit on that slice.
-        Finally returns [0]=the slope, [1]=the intercept of the
-        fitted 1st grade polynomial, and [2,3]=the actual (x,y) vectors
-        used for the fit.
-        (c) Marco Brucale, Massimo Sandal 2008
-        '''
-        # Translates the indexes into two vectors containing the x,y data to fit
-        xtofit=self.plots[0].vectors[whatset][0][index1:index2]
-        ytofit=self.plots[0].vectors[whatset][1][index1:index2]
-
-        # Does the actual linear fitting (simple least squares with numpy.polyfit)
-        linefit=[]
-        linefit=np.polyfit(xtofit,ytofit,1)
-
-        return (linefit[0],linefit[1],xtofit,ytofit)
-
-
-    def fit_interval_nm(self,start_index,plot,nm,backwards):
-          '''
-          Calculates the number of points to fit, given a fit interval in nm
-          start_index: index of point
-          plot: plot to use
-          backwards: if true, finds a point backwards.
-          '''
-          whatset=1 #FIXME: should be decidable
-          x_vect=plot.vectors[1][0]
-          
-          c=0
-          i=start_index
-          start=x_vect[start_index]
-          maxlen=len(x_vect)
-          while abs(x_vect[i]-x_vect[start_index])*(10**9) < nm:
-              if i==0 or i==maxlen-1: #we reached boundaries of vector!
-                  return c
-              
-              if backwards:
-                  i-=1
-              else:
-                  i+=1
-              c+=1
-          return c
-
-
-
-    def find_current_peaks(self,noflatten, a=True, maxpeak=True):
-            #Find peaks.
-            if a==True:
-                  a=self.convfilt_config['mindeviation']
-            try:
-                  abs_devs=float(a)
-            except:
-                  print "Bad input, using default."
-                  abs_devs=self.convfilt_config['mindeviation']
-
-            defplot=self.current.curve.default_plots()[0]
-            if not noflatten:
-                flatten=self._find_plotmanip('flatten') #Extract flatten plotmanip
-                defplot=flatten(defplot, self.current, customvalue=1) #Flatten curve before feeding it to has_peaks
-            pk_location,peak_size=self.has_peaks(defplot, abs_devs, maxpeak)
-            return pk_location, peak_size
-
-
-    def pickup_contact_point(self,N=1,whatset=1):
-        '''macro to pick up the contact point by clicking'''
-        contact_point=self._measure_N_points(N=1, whatset=1)[0]
-        contact_point_index=contact_point.index
-        self.wlccontact_point=contact_point
-        self.wlccontact_index=contact_point.index
-        self.wlccurrent=self.current.path
-        return contact_point, contact_point_index
-
-
-    def baseline_points(self,peak_location, displayed_plot):
-        clicks=self.config['baseline_clicks']
-        if clicks==0:
-            self.basepoints=[]
-            base_index_0=peak_location[-1]+self.fit_interval_nm(peak_location[-1], displayed_plot, self.config['auto_right_baseline'],False)
-            self.basepoints.append(self._clickize(displayed_plot.vectors[1][0],displayed_plot.vectors[1][1],base_index_0))
-            base_index_1=self.basepoints[0].index+self.fit_interval_nm(self.basepoints[0].index, displayed_plot, self.config['auto_left_baseline'],False)
-            self.basepoints.append(self._clickize(displayed_plot.vectors[1][0],displayed_plot.vectors[1][1],base_index_1))
-        elif clicks>0:
-            print 'Select baseline'
-            if clicks==1:
-                self.basepoints=self._measure_N_points(N=1, whatset=1)
-                base_index_1=self.basepoints[0].index+self.fit_interval_nm(self.basepoints[0].index, displayed_plot, self.config['auto_left_baseline'], False)
-                self.basepoints.append(self._clickize(displayed_plot.vectors[1][0],displayed_plot.vectors[1][1],base_index_1))
-            else:
-                self.basepoints=self._measure_N_points(N=2, whatset=1)
-            
-        self.basecurrent=self.current.path
-        return self.basepoints