X-Git-Url: http://git.tremily.us/?a=blobdiff_plain;f=hooke%2Fplugin%2Fmultidistance.py;h=7c8291ac4135680619a098ac28d779a77c4033bc;hb=9f844eb89787f4b089cff3c7101b3b0dc3091519;hp=c93900fb85675e17d5a07a663406442acbc8b790;hpb=5c9e831f851ddb1cb9d0b06ff18c9d63ddf02aea;p=hooke.git diff --git a/hooke/plugin/multidistance.py b/hooke/plugin/multidistance.py index c93900f..7c8291a 100644 --- a/hooke/plugin/multidistance.py +++ b/hooke/plugin/multidistance.py @@ -1,5 +1,24 @@ -# -*- coding: utf-8 -*- -from libhooke import WX_GOOD, ClickedPoint +# Copyright (C) 2009-2010 Fabrizio Benedetti +# W. Trevor King +# +# This file is part of Hooke. +# +# Hooke is free software: you can redistribute it and/or modify it +# under the terms of the GNU Lesser General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# Hooke is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General +# Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with Hooke. If not, see +# . + +from hooke.libhooke import WX_GOOD, ClickedPoint + import wxversion wxversion.select(WX_GOOD) from wx import PostEvent @@ -13,8 +32,8 @@ import warnings warnings.simplefilter('ignore',np.RankWarning) -class multidistanceCommands: - +class multidistanceCommands(object): + def do_multidistance(self,args): ''' MULTIDISTANCE @@ -25,43 +44,26 @@ class multidistanceCommands: 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) + peaks_location, peak_size=self.find_current_peaks(noflatten) #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==[]: @@ -79,7 +81,7 @@ class multidistanceCommands: if exclude_raw=='N': print 'Discarded.' return - + if not exclude_raw=='': exclude=exclude_raw.split(',') #we convert in numbers the input @@ -100,13 +102,13 @@ class multidistanceCommands: 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]]) - - + + @@ -116,7 +118,7 @@ class multidistanceCommands: 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') @@ -128,14 +130,14 @@ class multidistanceCommands: 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.write("\n") f.close()