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', help="""
26 :class:`hooke.curve.Curve` to cut from. Defaults to the current curve.
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, hooke, inqueue, outqueue, params):
45 if params['curve'] == None:
46 params['curve'] = hooke.playlists.current().current()
48 i_min = min([p.index for p in params['points']])
49 i_max = max([p.index for p in params['points']])
51 data = params['curve'][params['bound']]
52 cut_data = data[i_min:i_max+1,:] # slice rows from row-major data
53 # +1 to include data[i_max] row
55 f = open(params['output'], 'w')
56 cut_data.tofile(f, sep='\t')