Close parenthesis on column append in DifferenceCommand
[hooke.git] / hooke / plugin / procplots.py
1 #!/usr/bin/env python
2
3 '''
4 procplots.py
5
6 Process plots plugin for force curves.
7
8 Copyright ???? by ?
9 with modifications by Dr. Rolf Schmidt (Concordia University, Canada)
10
11 This program is released under the GNU General Public License version 2.
12 '''
13
14 import lib.libhooke as lh
15 import wxversion
16 wxversion.select(lh.WX_GOOD)
17
18 import copy
19 from numpy import arange, diff, fft, median
20 from scipy.signal import medfilt
21
22 from lib.peakspot import conv_dx
23 import lib.prettyformat
24
25 class procplotsCommands:
26
27 #-----PLOT MANIPULATORS
28     def plotmanip_median(self, plot, current, customvalue=False):
29         '''
30         does the median of the y values of a plot
31         '''
32         median_filter = self.GetIntFromConfig('procplots', 'median')
33         if median_filter == 0:
34             return plot
35
36         if float(median_filter) / 2 == int(median_filter) / 2:
37             median_filter += 1
38
39         for curve in plot.curves:
40             curve.y = medfilt(curve.y, median_filter).tolist()
41
42         return plot
43
44     def plotmanip_correct(self, plot, current, customvalue=False):
45         '''
46         does the correction for the deflection for a force spectroscopy curve.
47         Assumes that:
48         - the current plot has a deflection() method that returns a vector of values
49         - the deflection() vector is as long as the X of extension + the X of retraction
50         - plot.vectors[0][0] is the X of extension curve
51         - plot.vectors[1][0] is the X of retraction curve
52
53         FIXME: both this method and the picoforce driver have to be updated, deflection() must return
54         a more sensible data structure!
55         '''
56         #use only for force spectroscopy experiments!
57         if current.driver.experiment != 'smfs':
58             return plot
59
60         if not customvalue:
61             customvalue = self.GetBoolFromConfig('procplots', 'correct')
62         if not customvalue:
63             return plot
64
65         defl_ext, defl_ret = current.driver.deflection()
66
67         plot.curves[lh.EXTENSION].x = [(zpoint - deflpoint) for zpoint,deflpoint in zip(plot.curves[lh.EXTENSION].x, defl_ext)]
68         plot.curves[lh.RETRACTION].x = [(zpoint - deflpoint) for zpoint,deflpoint in zip(plot.curves[lh.RETRACTION].x, defl_ret)]
69
70         return plot