class ExportCommand (Command):
"""Export a :class:`hooke.curve.Curve` data block as TAB-delimeted
ASCII text.
+
+ A "#" prefixed header will optionally appear at the beginning of
+ the file naming the columns.
"""
def __init__(self, plugin):
super(ExportCommand, self).__init__(
Argument(name='output', type='file', default='curve.dat',
help="""
File name for the output data. Defaults to 'curve.dat'
+""".strip()),
+ Argument(name='header', type='bool', default=True,
+ help="""
+True if you want the column-naming header line.
""".strip()),
],
help=self.__doc__, plugin=plugin)
def _run(self, hooke, inqueue, outqueue, params):
data = params['curve'].data[int(params['block'])] # HACK, int() should be handled by ui
- numpy.savetxt(params['output'], data, delimiter='\t')
+
+ f = open(params['output'], 'w')
+ if params['header'] == True:
+ f.write('# %s \n' % ('\t'.join(data.info['columns'])))
+ numpy.savetxt(f, data, delimiter='\t')
+ f.close()
class DifferenceCommand (Command):
"""Calculate the derivative (actually, the discrete differentiation)
class CutCommand (Command):
"""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.
+ The data is saved in TAB-delimited ASCII text. A "#" prefixed
+ header will optionally appear at the beginning of the file naming
+ the columns.
"""
def __init__(self, plugin):
super(CutCommand, self).__init__(
Argument(name='output', type='file', default='cut.dat',
help="""
File name for the output data.
+""".strip()),
+ Argument(name='header', type='bool', default=True,
+ help="""
+True if you want the column-naming header line.
""".strip()),
],
help=self.__doc__, plugin=plugin)
cut_data = data[i_min:i_max+1,:] # slice rows from row-major data
# +1 to include data[i_max] row
- numpy.savetxt(params['output'], cut_data, delimiter='\t')
+ f = open(params['output'], 'w')
+ if params['header'] == True:
+ f.write('# %s \n' % ('\t'.join(cut_data.info['columns'])))
+ numpy.savetxt(f, cut_data, delimiter='\t')
+ f.close()