From: fabrizio.benedetti.82 Date: Wed, 27 Jan 2010 08:02:51 +0000 (+0000) Subject: Added two plugin: jumpstat.py and multidistance.py. Change to the function has_peaks... X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=c48aef65ea19fd0fb8fb4afaa94f8a4e401c945c;p=hooke.git Added two plugin: jumpstat.py and multidistance.py. Change to the function has_peaks. Moved some basics routines in the new file curvetools.py. --- diff --git a/autopeak.py b/autopeak.py index 8a7baaf..49f2646 100644 --- a/autopeak.py +++ b/autopeak.py @@ -82,52 +82,7 @@ class autopeakCommands: auto_min_p ; auto_max_p = Minimum and maximum persistence length (if using WLC) or Kuhn length (if using FJC) outside of which the peak is automatically discarded (in nm) ''' - - #MACROS. - #FIXME: to move outside function - def fit_interval_nm(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 pickup_contact_point(): - '''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 find_current_peaks(noflatten): - #Find peaks. - 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 - peak_location,peak_size=self.has_peaks(defplot, self.convfilt_config['mindeviation']) - return peak_location, peak_size - #default fit etc. variables pl_value=None T=self.config['temperature'] @@ -191,7 +146,7 @@ class autopeakCommands: #--END COMMAND LINE PARSING-- - peak_location, peak_size = find_current_peaks(noflatten) + peak_location, peak_size = self.find_current_peaks(noflatten) if len(peak_location) == 0: print 'No peaks to fit.' @@ -201,23 +156,7 @@ class autopeakCommands: #Pick up force baseline if rebase: - clicks=self.config['baseline_clicks'] - if clicks==0: - self.basepoints=[] - base_index_0=peak_location[-1]+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+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=whatset) - base_index_1=self.basepoints[0].index+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=whatset) - - self.basecurrent=self.current.path + self.basepoints=self.baseline_points(peak_location, displayed_plot) boundaries=[self.basepoints[0].index, self.basepoints[1].index] boundaries.sort() @@ -235,7 +174,7 @@ class autopeakCommands: #WLC FITTING #define fit interval if not usepoints: - fit_points=fit_interval_nm(peak, displayed_plot, self.config['auto_fit_nm'], True) + fit_points=self.fit_interval_nm(peak, displayed_plot, self.config['auto_fit_nm'], True) peak_point=self._clickize(displayed_plot.vectors[1][0],displayed_plot.vectors[1][1],peak) other_fit_point=self._clickize(displayed_plot.vectors[1][0],displayed_plot.vectors[1][1],peak-fit_points) @@ -311,7 +250,6 @@ class autopeakCommands: #Show wlc fits and peak locations self._send_plot([fitplot]) - #self.do_peaks('') print 'Using fit function: ',self.config['fit_function'] print 'Measurements for all peaks detected:' diff --git a/curvetools.py b/curvetools.py new file mode 100755 index 0000000..51a8fd4 --- /dev/null +++ b/curvetools.py @@ -0,0 +1,92 @@ +# -*- coding: utf-8 -*- +from libhooke import WX_GOOD, ClickedPoint +import wxversion +wxversion.select(WX_GOOD) +from wx import PostEvent +import numpy as np +import scipy as sp +import copy +import os.path +import time + + +class curvetoolsCommands: + + 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 + + + diff --git a/flatfilts.py b/flatfilts.py index 3e9f9c8..0843481 100755 --- a/flatfilts.py +++ b/flatfilts.py @@ -1,4 +1,5 @@ #!/usr/bin/env python +# -*- coding: utf-8 -*- ''' FLATFILTS @@ -147,7 +148,7 @@ class flatfiltsCommands: #-----Convolution-based peak recognition and filtering. #Requires the libpeakspot.py library - def has_peaks(self, plot, abs_devs=None): + def has_peaks(self, plot, abs_devs=None, maxpeak=True, window=10): ''' Finds peak position in a force curve. FIXME: should be moved in libpeakspot.py @@ -176,12 +177,24 @@ class flatfiltsCommands: above=lps.abovenoise(convoluted,noise_level,cut_index,abs_devs) peak_location,peak_size=lps.find_peaks(above,seedouble=self.convfilt_config['seedouble']) - #take the maximum + #take the minimum or the maximum of a peak for i in range(len(peak_location)): peak=peak_location[i] - maxpk=min(yret[peak-10:peak+10]) - index_maxpk=yret[peak-10:peak+10].index(maxpk)+(peak-10) - peak_location[i]=index_maxpk + valpk=min(yret[peak-window:peak+window]) #maximum in force (near the unfolding point) + index_pk=yret[peak-window:peak+window].index(valpk)+(peak-window) + + if maxpeak==False: + valpk=max(yret[peak:peak+window]) #minimum in force, near the baseline + index_pk=yret[peak:peak+window].index(valpk)+(peak) + +# Let's explain that for the minimum. Immaging that we know that there is a peak at position/region 100 and you have found its y-value, +# Now you look in the array, from 100-10 to 100+10 (if the window is 10). +# This "100-10 to 100+10" is substancially a new array with its index. In this array you have 20 +# elements, so the index of your y-value will be 10. +# Now to find the index in the TOTAL array you have to add the "position" of the "region" (that in this case +# correspond to 100) and also substract the window size ---> (+100-10) + + peak_location[i]=index_pk return peak_location,peak_size @@ -319,7 +332,10 @@ class flatfiltsCommands: item.peak_size=peak_size item.curve=None #empty the item object, to further avoid memory leak notflat_list.append(item) - + + for i in range(1000): + k=0 + #Warn that no flattening had been done. if not ('flatten' in self.config['plotmanips']): print 'Flatten manipulator was not found. Processing was done without flattening.' diff --git a/hooke.conf b/hooke.conf index bda5613..73e47bc 100755 --- a/hooke.conf +++ b/hooke.conf @@ -23,6 +23,7 @@ This section defines which plugins have to be loaded by Hooke. --> + @@ -37,6 +38,7 @@ This section defines which plugins have to be loaded by Hooke. +