Merged hooke.plugin.plotmanip into hooke.plugin.curve.
[hooke.git] / hooke / plugin / plotmanip.py
1
2 class Plotmanip (object):
3 #-----PLOT MANIPULATORS
4     def plotmanip_median(self, plot, current, customvalue=None):
5         '''
6         does the median of the y values of a plot
7         '''
8         if customvalue:
9             median_filter=customvalue
10         else:
11             median_filter=self.config['medfilt']
12
13         if median_filter==0:
14             return plot
15
16         if float(median_filter)/2 == int(median_filter)/2:
17             median_filter+=1
18
19         nplots=len(plot.vectors)
20         c=0
21         while c<nplots:
22             plot.vectors[c][1]=scipy.signal.medfilt(plot.vectors[c][1],median_filter)
23             c+=1
24
25         return plot
26
27
28     def plotmanip_correct(self, plot, current, customvalue=None):
29         '''
30         does the correction for the deflection for a force spectroscopy curve.
31         Assumes that:
32         - the current plot has a deflection() method that returns a vector of values
33         - the deflection() vector is as long as the X of extension + the X of retraction
34         - plot.vectors[0][0] is the X of extension curve
35         - plot.vectors[1][0] is the X of retraction curve
36
37         FIXME: both this method and the picoforce driver have to be updated, deflection() must return
38         a more senseful data structure!
39         '''
40         #use only for force spectroscopy experiments!
41         if current.curve.experiment != 'smfs':
42             return plot
43
44         if customvalue != None:
45             execute_me=customvalue
46         else:
47             execute_me=self.config['correct']
48         if not execute_me:
49             return plot
50
51         defl_ext,defl_ret=current.curve.deflection()
52         #halflen=len(deflall)/2
53
54         plot.vectors[0][0]=[(zpoint-deflpoint) for zpoint,deflpoint in zip(plot.vectors[0][0],defl_ext)]
55         plot.vectors[1][0]=[(zpoint-deflpoint) for zpoint,deflpoint in zip(plot.vectors[1][0],defl_ret)]
56
57         return plot
58
59
60     def plotmanip_centerzero(self, plot, current, customvalue=None):
61         '''
62         Centers the force curve so the median (the free level) corresponds to 0 N
63         Assumes that:
64         - plot.vectors[0][1] is the Y of extension curve
65         - plot.vectors[1][1] is the Y of retraction curve
66         
67        
68         '''
69         #use only for force spectroscopy experiments!
70         if current.curve.experiment != 'smfs':
71             return plot
72     
73         if customvalue != None:
74             execute_me=customvalue
75         else:
76             execute_me=self.config['centerzero']
77         if not execute_me:
78             return plot
79      
80         
81         
82         #levelapp=float(np.median(plot.vectors[0][1]))
83         levelret=float(np.median(plot.vectors[1][1][-300:-1]))
84
85         level=levelret  
86
87         approach=[i-level for i in plot.vectors[0][1]]
88         retract=[i-level for i in plot.vectors[1][1]]
89         
90         plot.vectors[0][1]=approach     
91         plot.vectors[1][1]=retract      
92         return plot