Merged hooke.plugin.plotmanip into hooke.plugin.curve.
[hooke.git] / hooke / plugin / generalvclamp.py
index 9c0593e925940f8f845c59ba17c9db0a30f64005..d15260822d3c4b96e8506df104717199fc31430b 100644 (file)
@@ -39,6 +39,25 @@ warnings.simplefilter('ignore',np.RankWarning)
 
 class generalvclampCommands(object):
 
+    def do_subtplot(self, args):
+        '''
+        SUBTPLOT
+        (procplots.py plugin)
+        Plots the difference between ret and ext current curve
+        -------
+        Syntax: subtplot
+        '''
+        #FIXME: sub_filter and sub_order must be args
+
+        if len(self.plots[0].vectors) != 2:
+            print 'This command only works on a curve with two different plots.'
+            pass
+
+        outplot=self.subtract_curves(sub_order=1)
+
+        plot_graph=self.list_of_events['plot_graph']
+        wx.PostEvent(self.frame,plot_graph(plots=[outplot]))
+
     def _plug_init(self):
         self.basecurrent=None
         self.basepoints=None
@@ -356,3 +375,80 @@ class generalvclampCommands(object):
         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