-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsuperimpose.py
98 lines (78 loc) · 3.14 KB
/
superimpose.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/env python
from libhooke import WX_GOOD
import wxversion
wxversion.select(WX_GOOD)
from wx import PostEvent
import libhookecurve as lhc
from numpy import arange, mean
class superimposeCommands:
def _plug_init(self):
self.imposed=[]
def do_selimpose(self,args):
'''
SELIMPOSE (superimpose.py plugin)
Hand-selects the curve portion to superimpose
'''
#fixme: set to superimpose should be in args
if args=='clear':
self.imposed=[]
return
current_set=1
points=self._measure_two_points()
boundaries=[points[0].index, points[1].index]
boundaries.sort()
theplot=self.plots[0]
#append the selected section
self.imposed.append([])
self.imposed[-1].append(theplot.vectors[1][0][boundaries[0]:boundaries[1]]) #x
self.imposed[-1].append(theplot.vectors[1][1][boundaries[0]:boundaries[1]]) #y
#align X first point
self.imposed[-1][0] = [item-self.imposed[-1][0][0] for item in self.imposed[-1][0]]
#align Y first point
self.imposed[-1][1] = [item-self.imposed[-1][1][0] for item in self.imposed[-1][1]]
def do_plotimpose(self,args):
'''
PLOTIMPOSE (sumperimpose.py plugin)
plots superimposed curves
'''
imposed_object=lhc.PlotObject()
imposed_object.vectors=self.imposed
print 'Plotting',len(imposed_object.vectors),'imposed curves'
imposed_object.normalize_vectors()
imposed_object.units=self.plots[0].units
imposed_object.title='Imposed curves'
imposed_object.destination=1
plot_graph=self.list_of_events['plot_graph']
PostEvent(self.frame,plot_graph(plots=[imposed_object]))
def do_plotavgimpose(self,args):
'''
PLOTAVGIMPOSE (superimpose.py plugin)
Plots the average of superimposed curves using a running window
'''
step=(-5*(10**-10))
#find extension of each superimposed curve
min_x=[]
for curve in self.imposed:
min_x.append(min(curve[0]))
#find minimum extension
min_ext_limit=max(min_x)
x_avg=arange(step,min_ext_limit,step)
y_avg=[]
for value in x_avg:
to_avg=[]
for curve in self.imposed:
for xvalue, yvalue in zip(curve[0],curve[1]):
if xvalue >= (value+step) and xvalue <= (value-step):
to_avg.append(yvalue)
y_avg.append(mean(to_avg))
print 'len x len y'
print len(x_avg), len(y_avg)
print y_avg
avg_object=lhc.PlotObject()
avg_object.vectors=[[x_avg, y_avg]]
avg_object.normalize_vectors()
avg_object.units=self.plots[0].units
avg_object.title="Average curve"
avg_object.destination=1
plot_graph=self.list_of_events['plot_graph']
PostEvent(self.frame,plot_graph(plots=[avg_object]))