from ..plugin import Builtin
from ..plugin.playlist import current_playlist_callback
from ..util.calculus import derivative
+from ..util.fft import unitary_avg_power_spectrum
class CurvePlugin (Builtin):
super(CurvePlugin, self).__init__(name='curve')
def commands(self):
- return [InfoCommand(), ExportCommand()]
+ return [InfoCommand(), ExportCommand(),
+ DifferenceCommand(), DerivativeCommand(),
+ PowerSpectrumCommand()]
# Define common or complicated arguments
help="""
Column of data block to differentiate with respect to.
""".strip()),
- Argument(name='y column', type='int', default=1,
+ Argument(name='f column', type='int', default=1,
help="""
Column of data block to differentiate.
""".strip()),
assert a[:,params['x column']] == b[:,params['x column']]:
out = Data((a.shape[0],2), dtype=a.dtype)
out[:,0] = a[:,params['x column']]
- out[:,1] = a[:,params['y column']] - b[:,params['y column']]:
+ out[:,1] = a[:,params['f column']] - b[:,params['f column']]
outqueue.put(out)
class DerivativeCommand (Command):
help="""
Column of data block to differentiate with respect to.
""".strip()),
- Argument(name='y column', type='int', default=1,
+ Argument(name='f column', type='int', default=1,
help="""
Column of data block to differentiate.
""".strip()),
def _run(self, hooke, inqueue, outqueue, params):
data = params['curve'].data[params['block']]
outqueue.put(derivative(
- block, x_col=params['x column'], y_col=params['y column'],
+ block, x_col=params['x column'], f_col=params['f column'],
weights=params['weights']))
+
+class PowerSpectrumCommand (Command):
+ """Calculate the power spectrum of a data block.
+ """
+ def __init__(self):
+ super(PowerSpectrumCommand, self).__init__(
+ name='block power spectrum',
+ arguments=[
+ CurveArgument,
+ Argument(name='block', aliases=['set'], type='int', default=0,
+ help="""
+Data block to act on. For an approach/retract force curve, `0`
+selects the approacing curve and `1` selects the retracting curve.
+""".strip()),
+ Argument(name='f column', type='int', default=1,
+ help="""
+Column of data block to differentiate with respect to.
+""".strip()),
+ Argument(name='freq', type='float', default=1.0,
+ help="""
+Sampling frequency.
+""".strip()),
+ Argument(name='chunk size', type='int', 2048,
+ help="""
+Number of samples per chunk. Use a power of two.
+""".strip()),
+ Argument(name='overlap', type='bool', default=False,
+ help="""
+If `True`, each chunk overlaps the previous chunk by half its length.
+Otherwise, the chunks are end-to-end, and not overlapping.
+""".strip()),
+ ],
+ help=self.__doc__)
+
+ def _run(self, hooke, inqueue, outqueue, params):
+ data = params['curve'].data[params['block']]
+ outqueue.put(unitary_avg_power_spectrum(
+ data[:,params['f column']], freq=params['freq'],
+ chunk_size=params['chunk size'],
+ overlap=params['overlap']))