From d54936bcc10ac82c59a3c6e4b009c7dca898d623 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Mon, 17 May 2010 21:58:57 -0400 Subject: [PATCH] Finish translating the hooke.plugin.curve Commands from procplots. --- hooke/plugin/curve.py | 53 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 48 insertions(+), 5 deletions(-) diff --git a/hooke/plugin/curve.py b/hooke/plugin/curve.py index bf21918..594f158 100644 --- a/hooke/plugin/curve.py +++ b/hooke/plugin/curve.py @@ -29,6 +29,7 @@ from ..curve import Data 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): @@ -36,7 +37,9 @@ 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 @@ -170,7 +173,7 @@ approacing curve and `1` selects the retracting curve. 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()), @@ -183,7 +186,7 @@ Column of data block to differentiate. 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): @@ -203,7 +206,7 @@ selects the approacing curve and `1` selects the retracting curve. 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()), @@ -218,5 +221,45 @@ central differencing. 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'])) -- 2.26.2