1 """Defines :class:`CutPlugin` and :class:`CutCommand`.
4 from ..command import Command, Argument
5 from ..plugin import Plugin
8 class CutPlugin (Plugin):
10 super(CutPlugin, self).__init__(name='cut')
15 class CutCommand (Command):
16 """Cut the selected signal between two points and write it to a file.
18 The data is saved in TAB-delimited ASCII text, where the first column
19 is "x" and the second is "y". There is no header row.
22 super(CutCommand, self).__init__(
25 Argument(name='curve', type='curve', optional=False, help="""
26 :class:`hooke.curve.Curve` to cut from.
28 Argument(name='block', aliases=['set'], type='int', default=0,
30 Data block to save. For an approach/retract force curve, `0` selects
31 the approacing curve and `1` selects the retracting curve.
33 Argument(name='bounds', type='point', optional=False, count=2,
35 Indicies of points bounding the selected data.
37 Argument(name='output', type='file', default='cut.dat',
39 File name for the output data.
44 def _run(self, inqueue, outqueue, params):
45 i_min = min([p.index for p in params['points']])
46 i_max = max([p.index for p in params['points']])
48 data = params['curve'][params['bound']]
49 cut_data = data[i_min:i_max+1,:] # slice rows from row-major data
50 # +1 to include data[i_max] row
52 f = open(params['output'], 'w')
53 cut_data.tofile(f, sep='\t')