1 # -*- coding: utf-8 -*-
2 from libhooke import WX_GOOD, ClickedPoint
4 wxversion.select(WX_GOOD)
5 from wx import PostEvent
13 class curvetoolsCommands:
15 def print_prec(self, arr, prec):
18 np.set_printoptions(precision=prec)
19 #we remove the parentesis if the array is longer that 1
21 strvals=str(nparr)[1:-1]
24 return "Error in the array."
26 def fit_interval_nm(self,start_index,plot,nm,backwards):
28 Calculates the number of points to fit, given a fit interval in nm
29 start_index: index of point
31 backwards: if true, finds a point backwards.
33 whatset=1 #FIXME: should be decidable
34 x_vect=plot.vectors[1][0]
38 start=x_vect[start_index]
40 while abs(x_vect[i]-x_vect[start_index])*(10**9) < nm:
41 if i==0 or i==maxlen-1: #we reached boundaries of vector!
53 def find_current_peaks(self,noflatten, a=True, maxpeak=True):
56 a=self.convfilt_config['mindeviation']
60 print "Bad input, using default."
61 abs_devs=self.convfilt_config['mindeviation']
63 defplot=self.current.curve.default_plots()[0]
65 flatten=self._find_plotmanip('flatten') #Extract flatten plotmanip
66 defplot=flatten(defplot, self.current, customvalue=1) #Flatten curve before feeding it to has_peaks
67 pk_location,peak_size=self.has_peaks(defplot, abs_devs, maxpeak)
68 return pk_location, peak_size
71 def pickup_contact_point(self,N=1,whatset=1):
72 '''macro to pick up the contact point by clicking'''
73 contact_point=self._measure_N_points(N=1, whatset=1)[0]
74 contact_point_index=contact_point.index
75 self.wlccontact_point=contact_point
76 self.wlccontact_index=contact_point.index
77 self.wlccurrent=self.current.path
78 return contact_point, contact_point_index
82 def baseline_points(self,peak_location, displayed_plot):
83 clicks=self.config['baseline_clicks']
86 base_index_0=peak_location[-1]+self.fit_interval_nm(peak_location[-1], displayed_plot, self.config['auto_right_baseline'],False)
87 self.basepoints.append(self._clickize(displayed_plot.vectors[1][0],displayed_plot.vectors[1][1],base_index_0))
88 base_index_1=self.basepoints[0].index+self.fit_interval_nm(self.basepoints[0].index, displayed_plot, self.config['auto_left_baseline'],False)
89 self.basepoints.append(self._clickize(displayed_plot.vectors[1][0],displayed_plot.vectors[1][1],base_index_1))
91 print 'Select baseline'
93 self.basepoints=self._measure_N_points(N=1, whatset=1)
94 base_index_1=self.basepoints[0].index+self.fit_interval_nm(self.basepoints[0].index, displayed_plot, self.config['auto_left_baseline'], False)
95 self.basepoints.append(self._clickize(displayed_plot.vectors[1][0],displayed_plot.vectors[1][1],base_index_1))
97 self.basepoints=self._measure_N_points(N=2, whatset=1)
99 self.basecurrent=self.current.path
100 return self.basepoints