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)