1 # Copyright (C) 2008-2010 Massimo Sandal <devicerandom@gmail.com>
2 # W. Trevor King <wking@drexel.edu>
4 # This file is part of Hooke.
6 # Hooke is free software: you can redistribute it and/or
7 # modify it under the terms of the GNU Lesser General Public
8 # License as published by the Free Software Foundation, either
9 # version 3 of the License, or (at your option) any later version.
11 # Hooke is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU Lesser General Public License for more details.
16 # You should have received a copy of the GNU Lesser General Public
17 # License along with Hooke. If not, see
18 # <http://www.gnu.org/licenses/>.
20 from ..libhooke import WX_GOOD
22 wxversion.select(WX_GOOD)
23 from wx import PostEvent
24 from numpy import arange, mean
26 from .. import curve as lhc
28 class superimposeCommands(object):
33 def do_selimpose(self,args):
35 SELIMPOSE (superimpose.py plugin)
36 Hand-selects the curve portion to superimpose
38 #fixme: set to superimpose should be in args
46 points=self._measure_two_points()
47 boundaries=[points[0].index, points[1].index]
51 #append the selected section
52 self.imposed.append([])
53 self.imposed[-1].append(theplot.vectors[1][0][boundaries[0]:boundaries[1]]) #x
54 self.imposed[-1].append(theplot.vectors[1][1][boundaries[0]:boundaries[1]]) #y
57 self.imposed[-1][0] = [item-self.imposed[-1][0][0] for item in self.imposed[-1][0]]
59 self.imposed[-1][1] = [item-self.imposed[-1][1][0] for item in self.imposed[-1][1]]
61 def do_plotimpose(self,args):
63 PLOTIMPOSE (sumperimpose.py plugin)
64 plots superimposed curves
66 imposed_object=lhc.PlotObject()
67 imposed_object.vectors=self.imposed
68 print 'Plotting',len(imposed_object.vectors),'imposed curves'
70 imposed_object.normalize_vectors()
72 imposed_object.units=self.plots[0].units
73 imposed_object.title='Imposed curves'
74 imposed_object.destination=1
76 plot_graph=self.list_of_events['plot_graph']
77 PostEvent(self.frame,plot_graph(plots=[imposed_object]))
79 def do_plotavgimpose(self,args):
81 PLOTAVGIMPOSE (superimpose.py plugin)
82 Plots the average of superimposed curves using a running window
85 #find extension of each superimposed curve
87 for curve in self.imposed:
88 min_x.append(min(curve[0]))
90 #find minimum extension
91 min_ext_limit=max(min_x)
93 x_avg=arange(step,min_ext_limit,step)
97 for curve in self.imposed:
98 for xvalue, yvalue in zip(curve[0],curve[1]):
99 if xvalue >= (value+step) and xvalue <= (value-step):
100 to_avg.append(yvalue)
101 y_avg.append(mean(to_avg))
104 print len(x_avg), len(y_avg)
107 avg_object=lhc.PlotObject()
108 avg_object.vectors=[[x_avg, y_avg]]
109 avg_object.normalize_vectors()
110 avg_object.units=self.plots[0].units
111 avg_object.title="Average curve"
112 avg_object.destination=1
114 plot_graph=self.list_of_events['plot_graph']
115 PostEvent(self.frame,plot_graph(plots=[avg_object]))