WLC and FJC output are now with 2 decimal precision. Added a comment on autopeak...
[hooke.git] / curvetools.py
1 # -*- coding: utf-8 -*-
2 from libhooke import WX_GOOD, ClickedPoint
3 import wxversion
4 wxversion.select(WX_GOOD)
5 from wx import PostEvent
6 import numpy as np
7 import scipy as sp
8 import copy
9 import os.path
10 import time
11
12
13 class curvetoolsCommands:
14
15       def print_prec(self, arr, prec):
16          try:
17            nparr=np.array(arr)
18            np.set_printoptions(precision=prec)
19            #we remove the parentesis if the array is longer that 1
20            if len(nparr)>1:
21              strvals=str(nparr)[1:-1]
22            return strvals
23          except:
24            return "Error in the array."
25
26       def fit_interval_nm(self,start_index,plot,nm,backwards):
27           '''
28           Calculates the number of points to fit, given a fit interval in nm
29           start_index: index of point
30           plot: plot to use
31           backwards: if true, finds a point backwards.
32           '''
33           whatset=1 #FIXME: should be decidable
34           x_vect=plot.vectors[1][0]
35           
36           c=0
37           i=start_index
38           start=x_vect[start_index]
39           maxlen=len(x_vect)
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!
42                   return c
43               
44               if backwards:
45                   i-=1
46               else:
47                   i+=1
48               c+=1
49           return c
50
51
52
53       def find_current_peaks(self,noflatten, a=True, maxpeak=True):
54             #Find peaks.
55             if a==True:
56                   a=self.convfilt_config['mindeviation']
57             try:
58                   abs_devs=float(a)
59             except:
60                   print "Bad input, using default."
61                   abs_devs=self.convfilt_config['mindeviation']
62
63             defplot=self.current.curve.default_plots()[0]
64             if not noflatten:
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
69
70
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
79
80
81
82       def baseline_points(self,peak_location, displayed_plot):
83             clicks=self.config['baseline_clicks']
84             if clicks==0:
85                 self.basepoints=[]
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))
90             elif clicks>0:
91                 print 'Select baseline'
92                 if clicks==1:
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))
96                 else:
97                     self.basepoints=self._measure_N_points(N=2, whatset=1)
98             
99             self.basecurrent=self.current.path
100             return self.basepoints
101
102
103