Added multidistance plugin.
authorfabrizio.benedetti.82 <devnull@localhost>
Tue, 3 Nov 2009 15:44:12 +0000 (15:44 +0000)
committerfabrizio.benedetti.82 <devnull@localhost>
Tue, 3 Nov 2009 15:44:12 +0000 (15:44 +0000)
hooke.conf
multidistance.py [new file with mode: 0644]

index 68e1920199a202bf0c752e90cf96a96d3f578c56..75a31f96a0116909bf8e37e004bb7e34d8574a62 100755 (executable)
@@ -36,6 +36,7 @@ This section defines which plugins have to be loaded by Hooke.
     <autopeak/>\r
     <pcluster/>\r
     <generaltccd/>\r
+    <multidistance/>\r
 </plugins>\r
 \r
 <!--\r
diff --git a/multidistance.py b/multidistance.py
new file mode 100644 (file)
index 0000000..c93900f
--- /dev/null
@@ -0,0 +1,141 @@
+# -*- coding: utf-8 -*-
+from libhooke import WX_GOOD, ClickedPoint
+import wxversion
+wxversion.select(WX_GOOD)
+from wx import PostEvent
+import numpy as np
+import scipy as sp
+import copy
+import os.path
+import time
+
+import warnings
+warnings.simplefilter('ignore',np.RankWarning)
+
+
+class multidistanceCommands:
+    
+    def do_multidistance(self,args):
+     '''
+     MULTIDISTANCE
+     multidistance.py
+     Based on the convolution recognition automatically give the distances between the peaks found.
+     The command allow also to remove the unwanted peaks that can be due to interference.
+     When you first issue the command, it will ask for the filename. If you are giving the filename
+     of an existing file, autopeak will resume it and append measurements to it. If you are giving
+     a new filename, it will create the file and append to it until you close Hooke.
+     You can also define a minimun deviation of the peaks.
+     
+     Syntax:
+     multidistance [deviation]
+     deviation = number of times the convolution signal is above the noise absolute deviation.
+     '''
+
+     def find_current_peaks(noflatten, a):
+            #Find peaks.
+           if len(a)==0:
+                 a=self.convfilt_config['mindeviation']
+            try:
+                 abs_devs=float(a)
+            except:
+                print "Bad input, using default."
+                 abs_devs=self.convfilt_config['mindeviation']
+
+            defplot=self.current.curve.default_plots()[0]
+            if not noflatten:
+                flatten=self._find_plotmanip('flatten') #Extract flatten plotmanip
+                defplot=flatten(defplot, self.current, customvalue=1) #Flatten curve before feeding it to has_peaks
+            pk_loc,peak_size=self.has_peaks(defplot, abs_devs)
+            return pk_loc, peak_size
+
+      
+     noflatten=False
+     peaks_location, peak_size=find_current_peaks(noflatten, args)
+     
+     #if no peaks, we have nothing to plot. exit.
+     if len(peaks_location)==0:
+            return
+        
+     #otherwise, we plot the peak locations.
+     xplotted_ret=self.plots[0].vectors[1][0]
+     yplotted_ret=self.plots[0].vectors[1][1]
+     xgood=[xplotted_ret[index] for index in peaks_location]
+     ygood=[yplotted_ret[index] for index in peaks_location]
+        
+     recplot=self._get_displayed_plot()
+     recplot.vectors.append([xgood,ygood])
+     if recplot.styles==[]:
+         recplot.styles=[None,None,'scatter']
+         recplot.colors=[None,None,None]
+     else:
+         recplot.styles+=['scatter']
+         recplot.colors+=[None]
+
+     self._send_plot([recplot])
+
+     print 'Peaks to ignore (0,1...n from contact point,return to take all)'
+     print 'N to discard measurement'
+     exclude_raw=raw_input('Input:')
+     if exclude_raw=='N':
+        print 'Discarded.'
+        return
+     
+     if not exclude_raw=='':
+        exclude=exclude_raw.split(',')
+       #we convert in numbers the input
+        try:
+            exclude=[int(item) for item in exclude]
+        except:
+            print 'Bad input, taking nothing.'
+           return
+
+#    we remove the peaks that we don't want from the list, we need a counter beacause if we remove
+#    a peaks the other peaks in the list are shifted by one at each step
+        count=0
+        for a in exclude:
+          if (a==0):
+             peaks_location=peaks_location[1:]
+          else:
+             new_a=a-count
+             peaks_location=  peaks_location[0:new_a]+peaks_location[new_a+1:]
+             peak_size=            peak_size[0:new_a]+peak_size[new_a+1:]
+          count+=1
+     
+     #we calculate the distance vector
+     dist=[]
+     for i in range(len(peaks_location)-1):
+         dist.append(xplotted_ret[peaks_location[i]]-xplotted_ret[peaks_location[i+1]])
+     
+     
+
+
+
+        #Save file info
+     if self.autofile=='':
+            self.autofile=raw_input('Multidistance filename? (return to ignore) ')
+            if self.autofile=='':
+                print 'Not saved.'
+                return
+        
+     if not os.path.exists(self.autofile):
+            f=open(self.autofile,'w+')
+            f.write('Analysis started '+time.asctime()+'\n')
+            f.write('----------------------------------------\n')
+            f.write('; Delta Distance length (m)\n')
+           f.write(self.current.path+'\n')
+           for o in dist:
+              f.write(";")
+              f.write(str(o))
+            f.write("\n")
+            f.close()
+            
+     print 'Saving...'
+     f=open(self.autofile,'a+')
+        
+     f.write(self.current.path+'\n')
+     for i in dist:
+          f.write(";")
+          f.write(str(i))
+
+     f.write("\n")            
+     f.close()