From 08355dc091135282e5a7151b2685cfbbe1298858 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Sat, 8 May 2010 06:39:24 -0400 Subject: [PATCH] Converted hooke.plugin.cut to new Plugin architecture. --- hooke/plugin/cut.py | 94 +++++++++++++++++++++++---------------------- 1 file changed, 49 insertions(+), 45 deletions(-) diff --git a/hooke/plugin/cut.py b/hooke/plugin/cut.py index f2e71cb..ec72efd 100644 --- a/hooke/plugin/cut.py +++ b/hooke/plugin/cut.py @@ -1,49 +1,53 @@ """Defines :class:`CutPlugin` and :class:`CutCommand`. """ -class cutCommands(object): - - def _plug_init(self): - self.cut_basecurrent=None - self.cut_basepoints=None - - - - - def do_cut(self,args): - ''' -CUT - (cut.py) - Cut the selected signal between two points. - With the first 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" - ''' - if len(args)==0: - print "This command need the number of the graph that you want save and a name for the output file." - return - - a=args.split() - - - whatset=int(a[0]) - outfile=a[1] - plot=self._get_displayed_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]] - - f=open(outfile,'w+') - for i in range(len(yarr)): - f.write(str(xarr[i])+";"+str(yarr[i])+"\n") +from . import Plugin, Command, Argument + + +class CutPlugin (Plugin): + def __init__(self): + super(CutPlugin, self).__init__(name='cut') + + def commands(self): + return [CutCommand()] + +class CutCommand (Command): + def __init__(self): + super(CutCommand, self).__init__( + name='cut', + arguments=[ + Argument(name='curve', type='curve', optional=False, help=""" +:class:``hooke.Curve`` to cut from. +""".strip()), + Argument(name='block', aliases=['set'], type='int', default=0, + help=""" +Data block to save. For an approach/retract force curve, `0` selects +the approacing curve and `1` selects the retracting curve. +""".strip()), + Argument(name='bounds', type='point', optional=False, count=2, + help=""" +Indicies of points bounding the selected data. +""".strip()), + Argument(name='output', type='file', default='cut.dat', + help=""" +File name for the output data. +""".strip()), + ], + help=""" +Cut the selected signal between two points and write it to a file. + +The data is saved in TAB-delimited ASCII text, where the first column +is "x" and the second is "y". There is no header row. +""".strip()) + + def _run(inqueue, outqueue, params): + i_min = min([p.index for p in params['points']]) + i_max = max([p.index for p in params['points']]) + + data = params['curve'][params['bound']] + cut_data = data[i_min:i_max+1,:] # slice rows from row-major data + # +1 to include data[i_max] row + + f = open(params['output'], 'w') + cut_data.tofile(f, sep='\t') f.close() -- 2.26.2