From: fabrizio.benedetti.82 Date: Fri, 7 May 2010 09:07:54 +0000 (+0000) Subject: Correct number of digits of many output, improvement in the utility 'cut' and 'txt'. X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=14afae225bbe4117d5871a39fbaf2c3f6d45aec2;p=hooke.git Correct number of digits of many output, improvement in the utility 'cut' and 'txt'. --- diff --git a/autopeak.py b/autopeak.py index ed4cea8..4176698 100644 --- a/autopeak.py +++ b/autopeak.py @@ -256,12 +256,12 @@ class autopeakCommands: print 'Using fit function: ',self.config['fit_function'] print 'Measurements for all peaks detected:' - print 'contour (nm)', c_lengths - print 'sigma contour (nm)',sigma_c_lengths - print 'p (nm)',p_lengths - print 'sigma p (nm)',sigma_p_lengths - print 'forces (pN)',forces - print 'slopes (N/m)',slopes + print 'contour (nm)', self.print_prec(c_lengths,1) + print 'sigma contour (nm)',self.print_prec(sigma_c_lengths,2) + print 'p (nm)',self.print_prec(p_lengths,3) + print 'sigma p (nm)',self.print_prec(sigma_p_lengths,3) + print 'forces (pN)',self.print_prec(forces,1) + print 'slopes (N/m)',self.print_prec(slopes,3) controller=False while controller==False: @@ -300,12 +300,12 @@ class autopeakCommands: sigma_p_lengths=[item for item in sigma_p_lengths if item != None] print 'Measurements for chosen peaks:' - print 'contour (nm)',c_lengths - print 'sigma contour (nm)',sigma_c_lengths - print 'p (nm)',p_lengths - print 'sigma p (nm)',sigma_p_lengths - print 'forces (pN)',forces - print 'slopes (N/m)',slopes + print 'contour (nm)', self.print_prec(c_lengths,1) + print 'sigma contour (nm)',self.print_prec(sigma_c_lengths,2) + print 'p (nm)',self.print_prec(p_lengths,3) + print 'sigma p (nm)',self.print_prec(sigma_p_lengths,3) + print 'forces (pN)',self.print_prec(forces,1) + print 'slopes (N/m)',self.print_prec(slopes,3) #Save file info if self.autofile=='': diff --git a/curvetools.py b/curvetools.py index 51a8fd4..7c16be9 100755 --- a/curvetools.py +++ b/curvetools.py @@ -12,6 +12,17 @@ import time class curvetoolsCommands: + def print_prec(self, arr, prec): + try: + nparr=np.array(arr) + np.set_printoptions(precision=prec) + #we remove the parentesis if the array is longer that 1 + if len(nparr)>1: + strvals=str(nparr)[1:-1] + return strvals + except: + return "Error in the array." + def fit_interval_nm(self,start_index,plot,nm,backwards): ''' Calculates the number of points to fit, given a fit interval in nm diff --git a/cut.py b/cut.py index 975c2d3..03d1eb4 100644 --- a/cut.py +++ b/cut.py @@ -13,14 +13,15 @@ class cutCommands: CUT (cut.py) Cut the selected signal between two points. - With the first parameter you have to select the signal (for FS for example + The first parameters is useful to select the window, with a single window wichplot is "0" (zero). + With the second parameter you have to select the signal (for FS for example you can select with "0" the approacing curve and 1 for the retracting curve. This depend also on how many set of data you have on the graph). With the second parameter you select the output name file for the selection. The data is arranged in two simple column without a header, the first column is the "x" data and the second the "y". ----------------- - Syntax: distance "whatset" "namefile" + Syntax: cut "whichplot" "whatset" "namefile" ''' if len(args)==0: print "This command need the number of the graph that you want save and a name for the output file." @@ -28,23 +29,32 @@ CUT a=args.split() - - whatset=int(a[0]) - outfile=a[1] + whichplot=int(a[0]) + whatset=int(a[1]) + outfile=a[2] plot=self._get_displayed_plot() - + #print plot + print 'Select two points' points=self._measure_N_points(N=2, whatset=whatset) minbound=min(points[0].index, points[1].index) maxbound=max(points[0].index, points[1].index) - boundpoints=[minbound, maxbound] - yarr=plot.vectors[whatset][1][boundpoints[0]:boundpoints[1]] - xarr=plot.vectors[whatset][0][boundpoints[0]:boundpoints[1]] + + xarr=[] + yarr=[] + try: + dataset=self.plots[whichplot].vectors[whatset] + except: + print "Invalid whichplot." + return + + xarr=dataset[0][minbound:maxbound] + yarr=dataset[1][minbound:maxbound] + + f=open(outfile,'w+') for i in range(len(yarr)): f.write(str(xarr[i])+";"+str(yarr[i])+"\n") f.close() - - diff --git a/generalvclamp.py b/generalvclamp.py index 0795312..2c3f655 100644 --- a/generalvclamp.py +++ b/generalvclamp.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -# -*- coding: iso-8859-1 -*- +# -*- coding: utf-8 -*- ''' generalvclamp.py @@ -44,7 +44,7 @@ class generalvclampCommands: return else: dx,unitx,dy,unity=self._delta(set=1) - print str(dx*(10**9))+' nm' + print "%.1f nm" %(dx*(10**9)) to_dump='distance '+self.current.path+' '+str(dx*(10**9))+' nm' self.outlet.push(to_dump) @@ -61,7 +61,7 @@ class generalvclampCommands: print 'This command makes no sense for a force clamp experiment.' return dx,unitx,dy,unity=self._delta(set=1) - print str(dy*(10**12))+' pN' + print " %.1f pN"%(dy*(10**12)) to_dump='force '+self.current.path+' '+str(dy*(10**12))+' pN' self.outlet.push(to_dump) @@ -118,7 +118,7 @@ class generalvclampCommands: avg=np.mean(to_average) forcebase=abs(y-avg) - print str(forcebase*(10**12))+' pN' + print "%.1f pN"%(forcebase*(10**12)) to_dump='forcebase '+self.current.path+' '+str(forcebase*(10**12))+' pN' self.outlet.push(to_dump) diff --git a/hooke.conf b/hooke.conf index 3a49693..48d83da 100755 --- a/hooke.conf +++ b/hooke.conf @@ -38,8 +38,9 @@ This section defines which plugins have to be loaded by Hooke. - - + + + @@ -54,8 +55,8 @@ This section defines which drivers have to be loaded by Hooke. - - + + @@ -71,7 +72,7 @@ and -IMPORTANTLY- their order. - + diff --git a/hooke_cli.py b/hooke_cli.py index 00699be..4e430cd 100755 --- a/hooke_cli.py +++ b/hooke_cli.py @@ -658,7 +658,9 @@ Columns are, in order: X1 , Y1 , X2 , Y2 , X3 , Y3 ... ------------- -Syntax: txt [filename] {plot to export} +Syntax: txt [filename] {plot to export} or + txt [filename] all + all : To save all the curves in different windows in a single file. ''' def do_txt(self,args): @@ -678,33 +680,57 @@ Syntax: txt [filename] {plot to export} else: filename=linp.checkalphainput(args[0],self.current.path+'.txt',[]) try: - whichplot=int(args[1]) + if args[1]=="all": + whichplot="all" + else: + whichplot=int(args[1]) except: pass + + if whichplot!="all": + try: + outofplot=self.plots[whichplot].vectors + except: + print "Plot index out of range." + return 0 + columns=[] + for dataset in self.plots[whichplot].vectors: + for i in range(0,len(dataset)): + columns.append([]) + for value in dataset[i]: + #columns[-1].append(str(value*(10**9))) + columns[-1].append(str(value)) + rows=transposed2(columns, 'nan') + rows=[' , '.join(item) for item in rows] + text='\n'.join(rows) + + txtfile=open(filename,'w+') + #Save units of measure in header + txtfile.write('X:'+self.plots[whichplot].units[0]+'\n') + txtfile.write('Y:'+self.plots[whichplot].units[1]+'\n') + txtfile.write(text) + txtfile.close() - try: - outofplot=self.plots[whichplot].vectors - except: - print "Plot index out of range." - return 0 - - columns=[] - for dataset in self.plots[whichplot].vectors: - for i in range(0,len(dataset)): - columns.append([]) - for value in dataset[i]: - columns[-1].append(str(value)) - - rows=transposed2(columns, 'nan') - rows=[' , '.join(item) for item in rows] - text='\n'.join(rows) - - txtfile=open(filename,'w+') - #Save units of measure in header - txtfile.write('X:'+self.plots[whichplot].units[0]+'\n') - txtfile.write('Y:'+self.plots[whichplot].units[1]+'\n') - txtfile.write(text) - txtfile.close() + else: + columns=[] + for wp in range(len(self.plots)): + for dataset in self.plots[wp].vectors: + for i in range(0,len(dataset)): + columns.append([]) + for value in dataset[i]: + #columns[-1].append(str(value*(10**9))) + columns[-1].append(str(value)) + rows=transposed2(columns, 'nan') + rows=[' , '.join(item) for item in rows] + text='\n'.join(rows) + + txtfile=open(filename,'w+') + #Save units of measure in header + for i in range(len(self.plots)): + txtfile.write('X:'+self.plots[i].units[0]+'\n') + txtfile.write('Y:'+self.plots[i].units[1]+'\n') + txtfile.write(text) + txtfile.close() #LOGGING, REPORTING, NOTETAKING