1 # Copyright (C) 2008-2012 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 modify it under the
7 # terms of the GNU Lesser General Public License as published by the Free
8 # Software Foundation, either version 3 of the License, or (at your option) any
11 # Hooke is distributed in the hope that it will be useful, but WITHOUT ANY
12 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
13 # A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
16 # You should have received a copy of the GNU Lesser General Public License
17 # along with Hooke. If not, see <http://www.gnu.org/licenses/>.
19 from ..libhooke import WX_GOOD
21 wxversion.select(WX_GOOD)
22 from wx import PostEvent
23 from numpy import arange, mean
25 from .. import curve as lhc
27 class superimposeCommands(object):
32 def do_selimpose(self,args):
34 SELIMPOSE (superimpose.py plugin)
35 Hand-selects the curve portion to superimpose
37 #fixme: set to superimpose should be in args
45 points=self._measure_two_points()
46 boundaries=[points[0].index, points[1].index]
50 #append the selected section
51 self.imposed.append([])
52 self.imposed[-1].append(theplot.vectors[1][0][boundaries[0]:boundaries[1]]) #x
53 self.imposed[-1].append(theplot.vectors[1][1][boundaries[0]:boundaries[1]]) #y
56 self.imposed[-1][0] = [item-self.imposed[-1][0][0] for item in self.imposed[-1][0]]
58 self.imposed[-1][1] = [item-self.imposed[-1][1][0] for item in self.imposed[-1][1]]
60 def do_plotimpose(self,args):
62 PLOTIMPOSE (sumperimpose.py plugin)
63 plots superimposed curves
65 imposed_object=lhc.PlotObject()
66 imposed_object.vectors=self.imposed
67 print 'Plotting',len(imposed_object.vectors),'imposed curves'
69 imposed_object.normalize_vectors()
71 imposed_object.units=self.plots[0].units
72 imposed_object.title='Imposed curves'
73 imposed_object.destination=1
75 plot_graph=self.list_of_events['plot_graph']
76 PostEvent(self.frame,plot_graph(plots=[imposed_object]))
78 def do_plotavgimpose(self,args):
80 PLOTAVGIMPOSE (superimpose.py plugin)
81 Plots the average of superimposed curves using a running window
84 #find extension of each superimposed curve
86 for curve in self.imposed:
87 min_x.append(min(curve[0]))
89 #find minimum extension
90 min_ext_limit=max(min_x)
92 x_avg=arange(step,min_ext_limit,step)
96 for curve in self.imposed:
97 for xvalue, yvalue in zip(curve[0],curve[1]):
98 if xvalue >= (value+step) and xvalue <= (value-step):
100 y_avg.append(mean(to_avg))
103 print len(x_avg), len(y_avg)
106 avg_object=lhc.PlotObject()
107 avg_object.vectors=[[x_avg, y_avg]]
108 avg_object.normalize_vectors()
109 avg_object.units=self.plots[0].units
110 avg_object.title="Average curve"
111 avg_object.destination=1
113 plot_graph=self.list_of_events['plot_graph']
114 PostEvent(self.frame,plot_graph(plots=[avg_object]))