review.py plugin allows to review curves in groups of ten (à la Igor Pro), select...
authoralbertogomcas <devnull@localhost>
Fri, 5 Feb 2010 05:56:15 +0000 (05:56 +0000)
committeralbertogomcas <devnull@localhost>
Fri, 5 Feb 2010 05:56:15 +0000 (05:56 +0000)
hooke.conf
review.py [new file with mode: 0644]

index 73e47bc2c191142ae0f609a6d601ce3762f2f984..a86ca200b3ea8c943ea07930014689cdafe19bbb 100755 (executable)
@@ -38,15 +38,16 @@ This section defines which plugins have to be loaded by Hooke.
     <pcluster/>\r
     <generaltccd/>\r
     <multidistance/>\r
-    <jumpstat/>\r
+    <jumpstat/>
+    <review/>  \r
 </plugins>\r
 \r
 <!--\r
 This section defines which drivers have to be loaded by Hooke.\r
     -->\r
 <drivers>\r
-    <picoforce/>\r
-    <!-- picoforcealt/ -->\r
+    <!--picoforce/-->\r
+    <picoforcealt/>\r
     <hemingclamp/>\r
     <csvdriver/>\r
     <!-- tutorialdriver/ -->\r
diff --git a/review.py b/review.py
new file mode 100644 (file)
index 0000000..e27767e
--- /dev/null
+++ b/review.py
@@ -0,0 +1,151 @@
+#!/usr/bin/env python
+
+'''review.py
+Alberto Gomez-Casado (c) 2010 University of Twente
+'''
+
+from libhooke import WX_GOOD
+import wxversion
+wxversion.select(WX_GOOD)
+from wx import PostEvent
+import numpy as np
+import shutil
+import libinput as linp
+import copy
+import os.path
+
+import warnings
+warnings.simplefilter('ignore',np.RankWarning)
+
+
+class reviewCommands:
+
+    def do_review(self,args):
+        '''
+        REVIEW
+        (review.py)
+        Presents curves (in current playlist) in groups of ten. User can indicate which curves will be selected to be saved in a separate directory for further analysis.
+       By default curves are presented separated -30 nm in x and -100 pN in y. 
+       Curve number one of each set is the one showing the approach.
+        ------------
+        Syntax:
+        review [x spacing (nm)] [y spacing (pN]
+
+        '''
+
+       args=args.split()
+
+       if len(args)==2:
+               try:
+                       xgap=int(args[0])*1e-9 #scale to SI units 
+                       ygap=int(args[1])*1e-12
+               except:
+                       print 'Spacings must be numeric! Using defaults'
+                       xgap=-30*1e-9
+                       ygap=-100*1e-12 
+       else:
+               xgap=-30*1e-9
+               ygap=-100*1e-12 
+                 
+        print 'Processing playlist...'
+        print '(Please wait)'
+        keep_list=[]
+        
+       c=0
+       print 'You can stop the review at any moment by entering \'q\' you can go back ten curves entering \'b\''
+       print 'What curve no. you would like to start? (Enter for starting from the first)'
+       skip=raw_input()
+       
+       if skip.isdigit()==False:
+           skip=0
+       else:
+           skip=int(skip)
+           print 'Skipping '+str(skip)+ ' curves'
+           c=skip      
+
+        while c < len(self.current_list):
+               
+       
+           #take a group of ten curves and plot them with some spacing
+                               
+           curveset=self.current_list[c:c+10]
+       
+           base=self.current_list[c]   
+           self.do_plot(0)     
+           multiplot=copy.deepcopy(self._get_displayed_plot(0))
+
+           for i in range(1,10):
+               if i >= len(curveset):
+                       print 'End of the list'
+                       print 'WARNING: maybe you want to finish!'
+                       break
+               nextitem=curveset[i]
+               nextitem.identify(self.drivers)
+               nextplot=self.plotmanip_correct(nextitem.curve.default_plots()[0],nextitem)
+               nextvect=nextplot.vectors
+               nextitem.curve.close_all()
+
+               nextx=nextvect[0][0]
+               nexty=nextvect[0][1]
+               #center y around 0      
+               ymedian=np.median(nexty)
+               pos=0           
+               for j in range(0,len(nextx)):
+                       nextx[j]=nextx[j]+i*xgap
+                       nexty[j]=nexty[j]+i*ygap-ymedian
+               multiplot.add_set(nextx,nexty) 
+               multiplot.styles.append('lines')
+               multiplot.colors.append(None)
+               
+           self._send_plot([multiplot])                
+                               
+           
+           print 'Which ones you want to keep?'        
+           keep=raw_input()
+           if keep.isalpha():
+               if keep=='b':
+                       print 'Going back ten curves'
+                       c-=10
+                       if c<0:
+                               print 'We are already at the start'
+                               c=0
+                       continue
+               if keep=='q':
+                       break
+           else:
+               for i in keep.split():
+                       if i.isdigit() and int(i)>0 and int(i)<11: #if it is not digit the int() call is never made, so no exception should be happening
+                               keep_item=curveset[int(i)-1].path
+                               if keep_item in keep_list:
+                                       print 'This curve ('+keep_item+') was already selected, skipping'
+                               else:
+                                       keep_list.append(keep_item)
+                       else:
+                               print 'You entered an invalid value: '+i
+                                       
+           c+=10
+
+       print 'Kept '+str(len(keep_list))+' curves from '+str(min(c+i+1,len(self.current_list)))
+
+       allok=0  #flag to keep from losing all the work in a slight mistake
+       while allok==0:
+               save=linp.safeinput('Do you want to save the selected curves?',['y','n'])
+               if save=='y':
+                       savedir=linp.safeinput('Destination directory?')
+                       savedir=os.path.abspath(savedir)
+                       if not os.path.isdir(savedir):
+                               print 'Destination is not a directory. Try again'
+                               continue
+               if save=='n':
+                       break
+               
+               for item in keep_list:
+                       try:
+                               shutil.copy(item, savedir)
+                               allok=1
+                       except (OSError, IOError):
+                               print 'Cannot copy file. '+item+' Perhaps you gave me a wrong directory?'
+                               allok=0
+                               break
+
+       return True