1 # -*- coding: utf-8 -*-
2 from hooke.libhooke import WX_GOOD, ClickedPoint
5 wxversion.select(WX_GOOD)
6 from wx import PostEvent
14 warnings.simplefilter('ignore',np.RankWarning)
17 class multidistanceCommands(object):
19 def do_multidistance(self,args):
23 Based on the convolution recognition automatically give the distances between the peaks found.
24 The command allow also to remove the unwanted peaks that can be due to interference.
25 When you first issue the command, it will ask for the filename. If you are giving the filename
26 of an existing file, autopeak will resume it and append measurements to it. If you are giving
27 a new filename, it will create the file and append to it until you close Hooke.
28 You can also define a minimun deviation of the peaks.
31 multidistance [deviation]
32 deviation = number of times the convolution signal is above the noise absolute deviation.
35 def find_current_peaks(noflatten, a):
38 a=self.convfilt_config['mindeviation']
42 print "Bad input, using default."
43 abs_devs=self.convfilt_config['mindeviation']
45 defplot=self.current.curve.default_plots()[0]
47 flatten=self._find_plotmanip('flatten') #Extract flatten plotmanip
48 defplot=flatten(defplot, self.current, customvalue=1) #Flatten curve before feeding it to has_peaks
49 pk_loc,peak_size=self.has_peaks(defplot, abs_devs)
50 return pk_loc, peak_size
54 peaks_location, peak_size=find_current_peaks(noflatten, args)
56 #if no peaks, we have nothing to plot. exit.
57 if len(peaks_location)==0:
60 #otherwise, we plot the peak locations.
61 xplotted_ret=self.plots[0].vectors[1][0]
62 yplotted_ret=self.plots[0].vectors[1][1]
63 xgood=[xplotted_ret[index] for index in peaks_location]
64 ygood=[yplotted_ret[index] for index in peaks_location]
66 recplot=self._get_displayed_plot()
67 recplot.vectors.append([xgood,ygood])
68 if recplot.styles==[]:
69 recplot.styles=[None,None,'scatter']
70 recplot.colors=[None,None,None]
72 recplot.styles+=['scatter']
73 recplot.colors+=[None]
75 self._send_plot([recplot])
77 print 'Peaks to ignore (0,1...n from contact point,return to take all)'
78 print 'N to discard measurement'
79 exclude_raw=raw_input('Input:')
84 if not exclude_raw=='':
85 exclude=exclude_raw.split(',')
86 #we convert in numbers the input
88 exclude=[int(item) for item in exclude]
90 print 'Bad input, taking nothing.'
93 # we remove the peaks that we don't want from the list, we need a counter beacause if we remove
94 # a peaks the other peaks in the list are shifted by one at each step
98 peaks_location=peaks_location[1:]
101 peaks_location= peaks_location[0:new_a]+peaks_location[new_a+1:]
102 peak_size= peak_size[0:new_a]+peak_size[new_a+1:]
105 #we calculate the distance vector
107 for i in range(len(peaks_location)-1):
108 dist.append(xplotted_ret[peaks_location[i]]-xplotted_ret[peaks_location[i+1]])
115 if self.autofile=='':
116 self.autofile=raw_input('Multidistance filename? (return to ignore) ')
117 if self.autofile=='':
121 if not os.path.exists(self.autofile):
122 f=open(self.autofile,'w+')
123 f.write('Analysis started '+time.asctime()+'\n')
124 f.write('----------------------------------------\n')
125 f.write('; Delta Distance length (m)\n')
126 f.write(self.current.path+'\n')
134 f=open(self.autofile,'a+')
136 f.write(self.current.path+'\n')