3 """The `cut` module provides :class:`CutPlugin` and
7 from ..command import Command, Argument, Failure
8 from ..plugin import Plugin
11 class CutPlugin (Plugin):
13 super(CutPlugin, self).__init__(name='cut')
19 # Define common or complicated arguments
21 def current_curve_callback(hooke, command, argument, value):
22 playlist = hooke.playlists.current()
24 raise Failure('No playlists loaded')
25 curve = playlist.current()
27 raise Failure('No curves in playlist %s' % playlist.name)
30 CurveArgument = Argument(
31 name='curve', type='curve', callback=current_curve_callback,
33 :class:`hooke.curve.Curve` to cut from. Defaults to the current curve.
39 class CutCommand (Command):
40 """Cut the selected signal between two points and write it to a file.
42 The data is saved in TAB-delimited ASCII text, where the first column
43 is "x" and the second is "y". There is no header row.
46 super(CutCommand, self).__init__(
50 Argument(name='block', aliases=['set'], type='int', default=0,
52 Data block to save. For an approach/retract force curve, `0` selects
53 the approacing curve and `1` selects the retracting curve.
55 Argument(name='bounds', type='point', optional=False, count=2,
57 Indicies of points bounding the selected data.
59 Argument(name='output', type='file', default='cut.dat',
61 File name for the output data.
66 def _run(self, hooke, inqueue, outqueue, params):
67 if params['curve'] == None:
68 params['curve'] = hooke.playlists.current().current()
70 i_min = min([p.index for p in params['points']])
71 i_max = max([p.index for p in params['points']])
73 data = params['curve'][params['bound']]
74 cut_data = data[i_min:i_max+1,:] # slice rows from row-major data
75 # +1 to include data[i_max] row
77 f = open(params['output'], 'w')
78 cut_data.tofile(f, sep='\t')