:mod:`hooke.curve` classes.
"""
+import copy
+
import numpy
from ..command import Command, Argument, Failure
Data block to differentiate. For an approach/retract force curve, `0`
selects the approaching curve and `1` selects the retracting curve.
""".strip()),
- Argument(name='x column', type='int', default=0,
+ Argument(name='x column', type='string',
help="""
Column of data block to differentiate with respect to.
""".strip()),
- Argument(name='f column', type='int', default=1,
+ Argument(name='f column', type='string',
help="""
Column of data block to differentiate.
""".strip()),
help="""
Weighting scheme dictionary for finite differencing. Defaults to
central differencing.
+""".strip()),
+ Argument(name='output column name', type='string',
+ help="""
+Name of the new column for storing the derivative (without units, defaults to `derivative of <f column name> with respect to <x column name>`).
""".strip()),
],
help=self.__doc__, plugin=plugin)
def _run(self, hooke, inqueue, outqueue, params):
data = params['curve'].data[params['block']]
- outqueue.put(derivative(
- block, x_col=params['x column'], f_col=params['f column'],
- weights=params['weights']))
+ # HACK? rely on params['curve'] being bound to the local hooke
+ # playlist (i.e. not a copy, as you would get by passing a
+ # curve through the queue). Ugh. Stupid queues. As an
+ # alternative, we could pass lookup information through the
+ # queue...
+ new = Data((data.shape[0], data.shape[1]+1), dtype=data.dtype)
+ new.info = copy.deepcopy(data.info)
+ new[:,:-1] = data
+
+ x_col = data.info['columns'].index(params['x column'])
+ f_col = data.info['columns'].index(params['f column'])
+ d = derivative(
+ block, x_col=x_col, f_col=f_col, weights=params['weights'])
+
+ x_name,x_units = split_data_label(params['x column'])
+ f_name,f_units = split_data_label(params['f column'])
+ if params['output column name'] == None:
+ params['output column name'] = (
+ 'derivative of %s with respect to %s' % (
+ params['f column'], params['x column']))
+
+ new.info['columns'].append(
+ join_data_label(params['output distance column'],
+ '%s/%s' % (f_units/x_units)))
+ new[:,-1] = d[:,1]
+ params['curve'].data[params['block']] = new
+
class PowerSpectrumCommand (Command):
"""Calculate the power spectrum of a data block.
Otherwise, the chunks are end-to-end, and not overlapping.
""".strip()),
Argument(name='output block name', type='string',
- default='power spectrum',
help="""
-Name of the new data block (without `of <source block name> <source column name>`) for storing the power spectrum.
+Name of the new data block (defaults to `power spectrum of <source block name> <source column name>`) for storing the power spectrum.
""".strip()),
],
help=self.__doc__, plugin=plugin)
d, freq=params['freq'],
chunk_size=params['chunk size'],
overlap=params['overlap'])
+
name,data_units = split_data_label(params['column'])
b = Data((len(freq_axis),2), dtype=data.dtype)
- b.info['name'] = '%s of %s %s' % (
- params['output block name'], data.info['name'], params['column'])
+ if params['output block name'] == None:
+ params['output block name'] = 'power spectrum of %s %s' % (
+ params['output block name'], data.info['name'], params['column'])
+ b.info['name'] = params['output block name']
b.info['columns'] = [
join_data_label('frequency axis', params['freq units']),
join_data_label('power density',