1 # Copyright (C) 2009-2010 Fabrizio Benedetti
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
7 # under the terms of the GNU Lesser General Public License as
8 # published by the Free Software Foundation, either version 3 of the
9 # License, or (at your option) any later version.
11 # Hooke is distributed in the hope that it will be useful, but WITHOUT
12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
14 # 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 hooke.libhooke import WX_GOOD, ClickedPoint
23 wxversion.select(WX_GOOD)
24 from wx import PostEvent
32 warnings.simplefilter('ignore',np.RankWarning)
35 class multidistanceCommands(object):
37 def do_multidistance(self,args):
41 Based on the convolution recognition automatically give the distances between the peaks found.
42 The command allow also to remove the unwanted peaks that can be due to interference.
43 When you first issue the command, it will ask for the filename. If you are giving the filename
44 of an existing file, autopeak will resume it and append measurements to it. If you are giving
45 a new filename, it will create the file and append to it until you close Hooke.
46 You can also define a minimun deviation of the peaks.
49 multidistance [deviation]
50 deviation = number of times the convolution signal is above the noise absolute deviation.
55 peaks_location, peak_size=self.find_current_peaks(noflatten)
57 #if no peaks, we have nothing to plot. exit.
58 if len(peaks_location)==0:
61 #otherwise, we plot the peak locations.
62 xplotted_ret=self.plots[0].vectors[1][0]
63 yplotted_ret=self.plots[0].vectors[1][1]
64 xgood=[xplotted_ret[index] for index in peaks_location]
65 ygood=[yplotted_ret[index] for index in peaks_location]
67 recplot=self._get_displayed_plot()
68 recplot.vectors.append([xgood,ygood])
69 if recplot.styles==[]:
70 recplot.styles=[None,None,'scatter']
71 recplot.colors=[None,None,None]
73 recplot.styles+=['scatter']
74 recplot.colors+=[None]
76 self._send_plot([recplot])
78 print 'Peaks to ignore (0,1...n from contact point,return to take all)'
79 print 'N to discard measurement'
80 exclude_raw=raw_input('Input:')
85 if not exclude_raw=='':
86 exclude=exclude_raw.split(',')
87 #we convert in numbers the input
89 exclude=[int(item) for item in exclude]
91 print 'Bad input, taking nothing.'
94 # we remove the peaks that we don't want from the list, we need a counter beacause if we remove
95 # a peaks the other peaks in the list are shifted by one at each step
99 peaks_location=peaks_location[1:]
102 peaks_location= peaks_location[0:new_a]+peaks_location[new_a+1:]
103 peak_size= peak_size[0:new_a]+peak_size[new_a+1:]
106 #we calculate the distance vector
108 for i in range(len(peaks_location)-1):
109 dist.append(xplotted_ret[peaks_location[i]]-xplotted_ret[peaks_location[i+1]])
116 if self.autofile=='':
117 self.autofile=raw_input('Multidistance filename? (return to ignore) ')
118 if self.autofile=='':
122 if not os.path.exists(self.autofile):
123 f=open(self.autofile,'w+')
124 f.write('Analysis started '+time.asctime()+'\n')
125 f.write('----------------------------------------\n')
126 f.write('; Delta Distance length (m)\n')
127 f.write(self.current.path+'\n')
135 f=open(self.autofile,'a+')
137 f.write(self.current.path+'\n')