diff --git a/src/dspeed/processing_chain.py b/src/dspeed/processing_chain.py index 72eab0f..49ac64e 100644 --- a/src/dspeed/processing_chain.py +++ b/src/dspeed/processing_chain.py @@ -2245,45 +2245,46 @@ def build_processing_chain( A dictionary or YAML/JSON filename containing the recipes for computing DSP parameter from raw parameters. The format is as follows: - .. code-block:: json - :force: - - { - "name1, name2" : { - "function" : "func1" - "module" : "mod1" - "args" : ["arg1", 3, "arg2"] - "kwargs" : {"key1": "val1"} - "init_args" : ["arg1", 3, "arg2"] - "unit" : ["u1", "u2"] - "defaults" : {"arg1": "defval1"} - }, - ... - } + .. code-block:: yaml + + outputs: [par1, par2] + processors: + "name1, name2": + function: func1 + module: mod1 + args: [arg1, 3, arg2] + kwargs: + key1: val1 + init_args: [arg1, 3, arg2] + unit: [u1 u2] + defaults: + arg1: defval1 - ``name1, name2`` -- dictionary. key contains comma-separated names of parameters computed - - ``function`` -- string, name of function to call. Function - should implement the :class:`numpy.gufunc` interface, a factory - function returning a ``gufunc``, or an arbitrary function that - can be mapped onto a ``gufunc`` - - ``module`` -- string, name of module containing function - - ``args``-- list of strings or numerical values. Contains - list of names of computed and input parameters or - constant values used as inputs to function. Note that - outputs should be fed by reference as args! Arguments read - from the database are prepended with ``db``. - - ``kwargs`` -- dictionary. Keyword arguments for - :meth:`ProcesssingChain.add_processor`. - - ``init_args`` -- list of strings or numerical values. List - of names of computed and input parameters or constant values - used to initialize a :class:`numpy.gufunc` via a factory - function - - ``unit`` -- list of strings. Units for parameters - - ``defaults`` -- dictionary. Default value to be used for - arguments read from the database - - The dictionary can also be nested in another, keyed as ``processors`` + - ``name1, name2`` -- dictionary. key contains comma-separated + names of parameters computed + + - ``function`` -- string, name of function to call. Function + should implement the :class:`numpy.gufunc` interface, a factory + function returning a ``gufunc``, or an arbitrary function that + can be mapped onto a ``gufunc`` + - ``module`` -- string, name of module containing function + - ``args``-- list of strings or numerical values. Contains + list of names of computed and input parameters or + constant values used as inputs to function. Note that + outputs should be fed by reference as args! Arguments read + from the database are prepended with ``db``. + - ``kwargs`` -- dictionary. Keyword arguments for + :meth:`ProcessingChain.add_processor`. + - ``init_args`` -- list of strings or numerical values. List + of names of computed and input parameters or constant values + used to initialize a :class:`numpy.gufunc` via a factory + function + - ``unit`` -- list of strings. Units for parameters + - ``defaults`` -- dictionary. Default value to be used for + arguments read from the database tb_in input table. This table will be linked to use as inputs when diff --git a/src/dspeed/processors/bl_subtract.py b/src/dspeed/processors/bl_subtract.py index 6ba4e04..7ee9327 100644 --- a/src/dspeed/processors/bl_subtract.py +++ b/src/dspeed/processors/bl_subtract.py @@ -1,3 +1,5 @@ +"""DSP processors for subtracting a constant baseline from waveforms.""" + from __future__ import annotations import numpy as np diff --git a/src/dspeed/processors/convolutions.py b/src/dspeed/processors/convolutions.py index 37b8497..157b0d3 100644 --- a/src/dspeed/processors/convolutions.py +++ b/src/dspeed/processors/convolutions.py @@ -1,3 +1,5 @@ +"""Convolution-based waveform filter processors.""" + from __future__ import annotations import numpy as np diff --git a/src/dspeed/processors/dwt.py b/src/dspeed/processors/dwt.py index f1d346b..5ad2820 100644 --- a/src/dspeed/processors/dwt.py +++ b/src/dspeed/processors/dwt.py @@ -1,3 +1,5 @@ +"""Discrete wavelet transform processors for waveform analysis.""" + from __future__ import annotations import numpy as np diff --git a/src/dspeed/processors/energy_kernels.py b/src/dspeed/processors/energy_kernels.py index 28138f5..7a05055 100644 --- a/src/dspeed/processors/energy_kernels.py +++ b/src/dspeed/processors/energy_kernels.py @@ -1,3 +1,5 @@ +"""Energy estimation kernels for DSP pipelines.""" + from __future__ import annotations import numpy as np diff --git a/src/dspeed/processors/fixed_time_pickoff.py b/src/dspeed/processors/fixed_time_pickoff.py index 38a7824..c5eb02b 100644 --- a/src/dspeed/processors/fixed_time_pickoff.py +++ b/src/dspeed/processors/fixed_time_pickoff.py @@ -1,3 +1,5 @@ +"""Processors computing fixed-time pick-off metrics.""" + from __future__ import annotations import numpy as np diff --git a/src/dspeed/processors/gaussian_filter1d.py b/src/dspeed/processors/gaussian_filter1d.py index 870363a..a3da71f 100644 --- a/src/dspeed/processors/gaussian_filter1d.py +++ b/src/dspeed/processors/gaussian_filter1d.py @@ -1,3 +1,5 @@ +"""Processors applying one-dimensional Gaussian smoothing filters.""" + # Copyright (C) 2003-2005 Peter J. Verveer # # Redistribution and use in source and binary forms, with or without diff --git a/src/dspeed/processors/get_multi_local_extrema.py b/src/dspeed/processors/get_multi_local_extrema.py index 9903578..fc57b13 100644 --- a/src/dspeed/processors/get_multi_local_extrema.py +++ b/src/dspeed/processors/get_multi_local_extrema.py @@ -1,3 +1,5 @@ +"""Processors finding multiple local extrema in waveforms.""" + from __future__ import annotations import numpy as np diff --git a/src/dspeed/processors/get_wf_centroid.py b/src/dspeed/processors/get_wf_centroid.py index 5e3a39d..765d969 100644 --- a/src/dspeed/processors/get_wf_centroid.py +++ b/src/dspeed/processors/get_wf_centroid.py @@ -1,3 +1,5 @@ +"""Processors estimating waveform centroids.""" + from __future__ import annotations import numpy as np diff --git a/src/dspeed/processors/histogram.py b/src/dspeed/processors/histogram.py index a88e9cb..edbdbb6 100644 --- a/src/dspeed/processors/histogram.py +++ b/src/dspeed/processors/histogram.py @@ -1,3 +1,5 @@ +"""Histogramming utilities for waveform-derived quantities.""" + from __future__ import annotations import numpy as np diff --git a/src/dspeed/processors/histogram_stats.py b/src/dspeed/processors/histogram_stats.py index 84ac1f4..a04e9e2 100644 --- a/src/dspeed/processors/histogram_stats.py +++ b/src/dspeed/processors/histogram_stats.py @@ -1,3 +1,5 @@ +"""Processors computing summary statistics from histograms.""" + from __future__ import annotations import numpy as np diff --git a/src/dspeed/processors/iir_filter.py b/src/dspeed/processors/iir_filter.py index 9879798..dcc3fae 100644 --- a/src/dspeed/processors/iir_filter.py +++ b/src/dspeed/processors/iir_filter.py @@ -1,3 +1,5 @@ +"""Helpers for constructing IIR filter processors.""" + from __future__ import annotations from collections.abc import Collection diff --git a/src/dspeed/processors/inject_ringing.py b/src/dspeed/processors/inject_ringing.py index a40ad52..dacf472 100644 --- a/src/dspeed/processors/inject_ringing.py +++ b/src/dspeed/processors/inject_ringing.py @@ -1,3 +1,5 @@ +"""Processors injecting damped oscillatory ringing into waveforms.""" + from __future__ import annotations import numpy as np diff --git a/src/dspeed/processors/inl_correction.py b/src/dspeed/processors/inl_correction.py index d62e233..a289679 100644 --- a/src/dspeed/processors/inl_correction.py +++ b/src/dspeed/processors/inl_correction.py @@ -1,3 +1,5 @@ +"""Integral non-linearity correction processors.""" + from __future__ import annotations import numpy as np diff --git a/src/dspeed/processors/kernels.py b/src/dspeed/processors/kernels.py index 7c1136a..ec4554b 100644 --- a/src/dspeed/processors/kernels.py +++ b/src/dspeed/processors/kernels.py @@ -1,3 +1,5 @@ +"""Kernel generator utilities for DSP filters.""" + from __future__ import annotations import numpy as np diff --git a/src/dspeed/processors/linear_slope_fit.py b/src/dspeed/processors/linear_slope_fit.py index 13fb254..eeb06b8 100644 --- a/src/dspeed/processors/linear_slope_fit.py +++ b/src/dspeed/processors/linear_slope_fit.py @@ -1,3 +1,5 @@ +"""Processors for fitting a linear slope to waveform segments.""" + from __future__ import annotations import numpy as np diff --git a/src/dspeed/processors/log_check.py b/src/dspeed/processors/log_check.py index c77262e..e7fb8f5 100644 --- a/src/dspeed/processors/log_check.py +++ b/src/dspeed/processors/log_check.py @@ -1,3 +1,5 @@ +"""Processors performing logarithmic consistency checks on waveforms.""" + from __future__ import annotations import numpy as np diff --git a/src/dspeed/processors/min_max.py b/src/dspeed/processors/min_max.py index 662c0ac..4eaa1ed 100644 --- a/src/dspeed/processors/min_max.py +++ b/src/dspeed/processors/min_max.py @@ -1,3 +1,5 @@ +"""Processors computing minimum and maximum waveform statistics.""" + from __future__ import annotations import numpy as np diff --git a/src/dspeed/processors/ml.py b/src/dspeed/processors/ml.py index 06a4dcc..0c24e18 100644 --- a/src/dspeed/processors/ml.py +++ b/src/dspeed/processors/ml.py @@ -46,9 +46,7 @@ **nb_kwargs, ) def relu(x_in: np.ndarray, x_out: np.ndarray) -> None: - """ - relu activation function 0 if x_in < 0 else x_in - """ + """Apply the rectified linear unit activation function.""" x_out[:] = x_in * (x_in > 0) @@ -58,9 +56,7 @@ def relu(x_in: np.ndarray, x_out: np.ndarray) -> None: **nb_kwargs, ) def leaky_relu(x_in: np.ndarray, x_out: np.ndarray) -> None: - """ - leaky relu activation function 0 if x_in < 0 else 0.01 x_in - """ + """Apply a leaky ReLU activation with a 0.01 negative slope.""" x_out[:] = x_in * (x_in > 0) + 0.01 * x_in * (x_in < 0) @@ -70,9 +66,7 @@ def leaky_relu(x_in: np.ndarray, x_out: np.ndarray) -> None: **nb_kwargs, ) def sigmoid(x_in: np.ndarray, x_out: np.ndarray) -> None: - """ - sigmoid activation function - """ + """Apply the logistic sigmoid activation function.""" x_out[:] = 1 / (1 + np.exp(-x_in)) @@ -82,9 +76,7 @@ def sigmoid(x_in: np.ndarray, x_out: np.ndarray) -> None: **nb_kwargs, ) def softmax(x_in: np.ndarray, x_out: np.ndarray) -> None: - """ - softmax activation function - """ + """Apply a numerically stable softplus-style activation.""" x_out[:] = np.log(1 + np.exp(x_in)) @@ -100,24 +92,20 @@ def softmax(x_in: np.ndarray, x_out: np.ndarray) -> None: def dense_layer_no_bias( x_in: np.ndarray, kernel: np.ndarray, activation_func: np.int8, x_out: np.ndarray ) -> None: - """ - Basic dense neural network layer with no bias, f(x.W) + """Dense neural network layer without a bias term. Parameters ---------- - w_in - the input waveform shape n. + x_in + Input vector with length ``n``. kernel - the matrix of weights shape (n x m). + Matrix of weights with shape ``(n, m)``. activation_func - the activation function to use specify with char: - s - sigmoid - r - relu - l - leaky relu - m - softmax - t - tanh + Character flag indicating which activation to apply. Supported values + are ``s`` (sigmoid), ``r`` (ReLU), ``l`` (leaky ReLU), ``m`` (softplus), + and ``t`` (hyperbolic tangent). x_out - the output vector shape m. + Output vector with length ``m``. YAML Configuration Example -------------------------- @@ -169,26 +157,22 @@ def dense_layer_with_bias( activation_func: np.int8, x_out: np.ndarray, ) -> None: - """ - Basic dense neural network layer with bias added f(x.W+b) + """Dense neural network layer with an additive bias term. Parameters ---------- - w_in - the input waveform shape n. + x_in + Input vector with length ``n``. kernel - the matrix of weights shape (n x m). + Matrix of weights with shape ``(n, m)``. bias - the bias with shape m. + Bias vector with length ``m``. activation_func - the activation function to use specify with char: - s - sigmoid - r - relu - l - leaky relu - m - softmax - t - tanh + Character flag indicating which activation to apply. Supported values + are ``s`` (sigmoid), ``r`` (ReLU), ``l`` (leaky ReLU), ``m`` (softplus), + and ``t`` (hyperbolic tangent). x_out - the output vector shape m. + Output vector with length ``m``. YAML Configuration Example -------------------------- diff --git a/src/dspeed/processors/moving_windows.py b/src/dspeed/processors/moving_windows.py index e314e17..c4a0679 100644 --- a/src/dspeed/processors/moving_windows.py +++ b/src/dspeed/processors/moving_windows.py @@ -1,3 +1,5 @@ +"""Processors for applying moving window average convolution to waveforms.""" + from __future__ import annotations import numpy as np diff --git a/src/dspeed/processors/multi_a_filter.py b/src/dspeed/processors/multi_a_filter.py index 9a134c8..d1582da 100644 --- a/src/dspeed/processors/multi_a_filter.py +++ b/src/dspeed/processors/multi_a_filter.py @@ -1,3 +1,5 @@ +"""Processors for identifying multiple maxima and their amplitudes in a waveform.""" + import numpy as np from numba import guvectorize diff --git a/src/dspeed/processors/multi_t_filter.py b/src/dspeed/processors/multi_t_filter.py index de40c25..7d88a56 100644 --- a/src/dspeed/processors/multi_t_filter.py +++ b/src/dspeed/processors/multi_t_filter.py @@ -1,3 +1,5 @@ +"""Processors for identifying multiple leading edges in waveforms.""" + from __future__ import annotations import numpy as np diff --git a/src/dspeed/processors/nnls.py b/src/dspeed/processors/nnls.py index 3a0c81f..546b803 100644 --- a/src/dspeed/processors/nnls.py +++ b/src/dspeed/processors/nnls.py @@ -1,3 +1,5 @@ +"""Helpers for running non-negative least-squares optimizations.""" + from __future__ import annotations import numpy as np diff --git a/src/dspeed/processors/optimize.py b/src/dspeed/processors/optimize.py index 587d2e9..5cd9db0 100644 --- a/src/dspeed/processors/optimize.py +++ b/src/dspeed/processors/optimize.py @@ -1,3 +1,5 @@ +"""Processors for identifying optimal pole-zero coefficients.""" + from __future__ import annotations from typing import Callable diff --git a/src/dspeed/processors/param_lookup.py b/src/dspeed/processors/param_lookup.py index b79f092..d308b66 100644 --- a/src/dspeed/processors/param_lookup.py +++ b/src/dspeed/processors/param_lookup.py @@ -1,3 +1,5 @@ +"""Processors for looking up parameters from calibration tables.""" + from __future__ import annotations import numpy as np diff --git a/src/dspeed/processors/peak_snr_threshold.py b/src/dspeed/processors/peak_snr_threshold.py index 5d52302..9758e95 100644 --- a/src/dspeed/processors/peak_snr_threshold.py +++ b/src/dspeed/processors/peak_snr_threshold.py @@ -1,3 +1,5 @@ +"""Processors for identifying significant local minima.""" + from __future__ import annotations import numpy as np diff --git a/src/dspeed/processors/pmt_pulse_injector.py b/src/dspeed/processors/pmt_pulse_injector.py index 7c875f6..37da7f3 100644 --- a/src/dspeed/processors/pmt_pulse_injector.py +++ b/src/dspeed/processors/pmt_pulse_injector.py @@ -1,3 +1,5 @@ +"""Processors that inject parameterized photomultiplier pulses into waveforms.""" + from __future__ import annotations import numpy as np diff --git a/src/dspeed/processors/pole_zero.py b/src/dspeed/processors/pole_zero.py index 41c8a7f..7e4078e 100644 --- a/src/dspeed/processors/pole_zero.py +++ b/src/dspeed/processors/pole_zero.py @@ -1,3 +1,5 @@ +"""Pole-zero cancellation processors for waveform shaping.""" + from __future__ import annotations import numpy as np diff --git a/src/dspeed/processors/poly_fit.py b/src/dspeed/processors/poly_fit.py index 90c1b96..44fd20f 100644 --- a/src/dspeed/processors/poly_fit.py +++ b/src/dspeed/processors/poly_fit.py @@ -1,3 +1,5 @@ +"""Polynomial fitting processors for waveforms.""" + from __future__ import annotations import numpy as np diff --git a/src/dspeed/processors/presum.py b/src/dspeed/processors/presum.py index 7a21790..2357191 100644 --- a/src/dspeed/processors/presum.py +++ b/src/dspeed/processors/presum.py @@ -1,3 +1,5 @@ +"""Processors for down-sampling waveform using pre-summing.""" + from __future__ import annotations import numpy as np diff --git a/src/dspeed/processors/pulse_injector.py b/src/dspeed/processors/pulse_injector.py index 7d857b3..06f26b0 100644 --- a/src/dspeed/processors/pulse_injector.py +++ b/src/dspeed/processors/pulse_injector.py @@ -1,3 +1,5 @@ +"""Processors that inject analytic pulses into waveforms.""" + from __future__ import annotations from math import exp, log diff --git a/src/dspeed/processors/rc_cr2.py b/src/dspeed/processors/rc_cr2.py index caf350c..b7bd82e 100644 --- a/src/dspeed/processors/rc_cr2.py +++ b/src/dspeed/processors/rc_cr2.py @@ -1,3 +1,5 @@ +"""Processors implementing RC-CR^2 shaping filters.""" + from __future__ import annotations import numpy as np diff --git a/src/dspeed/processors/recursive_filter.py b/src/dspeed/processors/recursive_filter.py index ba2fb20..0930e06 100644 --- a/src/dspeed/processors/recursive_filter.py +++ b/src/dspeed/processors/recursive_filter.py @@ -1,3 +1,5 @@ +"""Generic processors used to implement recursive digital filters from poles and zeros.""" + from __future__ import annotations import numpy as np diff --git a/src/dspeed/processors/round_to_nearest.py b/src/dspeed/processors/round_to_nearest.py index f2b09ce..767cefc 100644 --- a/src/dspeed/processors/round_to_nearest.py +++ b/src/dspeed/processors/round_to_nearest.py @@ -1,3 +1,5 @@ +"""Processors for rounding values to multiples of provided value.""" + from __future__ import annotations import numpy as np diff --git a/src/dspeed/processors/saturation.py b/src/dspeed/processors/saturation.py index 81dcc09..c00d87d 100644 --- a/src/dspeed/processors/saturation.py +++ b/src/dspeed/processors/saturation.py @@ -1,3 +1,5 @@ +"""Processors that check for samples at saturation limit.""" + from __future__ import annotations import numpy as np diff --git a/src/dspeed/processors/soft_pileup_corr.py b/src/dspeed/processors/soft_pileup_corr.py index e42bb07..591b0ab 100644 --- a/src/dspeed/processors/soft_pileup_corr.py +++ b/src/dspeed/processors/soft_pileup_corr.py @@ -1,3 +1,5 @@ +"""Processors implementing soft pile-up corrections.""" + from __future__ import annotations import numpy as np diff --git a/src/dspeed/processors/svm.py b/src/dspeed/processors/svm.py index 0474fcc..1bf084f 100644 --- a/src/dspeed/processors/svm.py +++ b/src/dspeed/processors/svm.py @@ -1,3 +1,5 @@ +"""Support vector machine inference processors.""" + from __future__ import annotations import pickle diff --git a/src/dspeed/processors/tf_model.py b/src/dspeed/processors/tf_model.py index aa8f6a9..0d3eb5b 100644 --- a/src/dspeed/processors/tf_model.py +++ b/src/dspeed/processors/tf_model.py @@ -1,3 +1,5 @@ +"""Generate a processor from a tensorflow model stored in a keras file.""" + from __future__ import annotations import numpy as np @@ -6,8 +8,7 @@ def tf_model(filepath: str) -> GUFuncWrapper: - """ - Initializer to load a tensorflow model to use in a ProcessingChain + """Initializer to load a TensorFlow model to use in a ProcessingChain. Parameters ---------- diff --git a/src/dspeed/processors/time_over_threshold.py b/src/dspeed/processors/time_over_threshold.py index 7f56745..e934f11 100644 --- a/src/dspeed/processors/time_over_threshold.py +++ b/src/dspeed/processors/time_over_threshold.py @@ -1,3 +1,5 @@ +"""Processors computing time-over-threshold metrics.""" + from __future__ import annotations import numpy as np diff --git a/src/dspeed/processors/time_point_thresh.py b/src/dspeed/processors/time_point_thresh.py index c6067a3..092b33d 100644 --- a/src/dspeed/processors/time_point_thresh.py +++ b/src/dspeed/processors/time_point_thresh.py @@ -1,3 +1,5 @@ +"""Processors locating waveform time points via thresholding.""" + from __future__ import annotations import numpy as np diff --git a/src/dspeed/processors/trap_filters.py b/src/dspeed/processors/trap_filters.py index 0e19822..a237497 100644 --- a/src/dspeed/processors/trap_filters.py +++ b/src/dspeed/processors/trap_filters.py @@ -1,3 +1,5 @@ +"""Trapezoidal filter utilities and processors.""" + from __future__ import annotations import numpy as np diff --git a/src/dspeed/processors/unit_conversion.py b/src/dspeed/processors/unit_conversion.py index 0ff6137..f7cde41 100644 --- a/src/dspeed/processors/unit_conversion.py +++ b/src/dspeed/processors/unit_conversion.py @@ -1,3 +1,5 @@ +"""Unit conversion helpers for processing chain coordinate systems.""" + from __future__ import annotations import numpy as np diff --git a/src/dspeed/processors/upsampler.py b/src/dspeed/processors/upsampler.py index 5f9ebb8..a42e945 100644 --- a/src/dspeed/processors/upsampler.py +++ b/src/dspeed/processors/upsampler.py @@ -1,3 +1,5 @@ +"""Processors for upsampling waveforms via interpolation.""" + from __future__ import annotations from math import ceil, floor diff --git a/src/dspeed/processors/wf_alignment.py b/src/dspeed/processors/wf_alignment.py index 011a515..c886882 100644 --- a/src/dspeed/processors/wf_alignment.py +++ b/src/dspeed/processors/wf_alignment.py @@ -1,3 +1,5 @@ +"""Processors for waveform alignment and interpolation.""" + from __future__ import annotations import numpy as np diff --git a/src/dspeed/processors/where.py b/src/dspeed/processors/where.py index 600bd21..750efa5 100644 --- a/src/dspeed/processors/where.py +++ b/src/dspeed/processors/where.py @@ -1,3 +1,5 @@ +"""Conditional selection processor that wraps :func:`numpy.where`.""" + from __future__ import annotations import numpy as np @@ -17,17 +19,18 @@ **nb_kwargs, ) def where(condition, a, b, out): - """Return elements chosen from x or y depending on condition. - - Parameters: - condition: - boolean array to select which input to use - a: - input to use if condition is ``True`` - b: - input to use if condition is ``False`` - output: - array containing output values + """Return elements chosen from ``a`` or ``b`` depending on ``condition``. + + Parameters + ---------- + condition + Boolean mask that selects which input to use. + a + Value to emit wherever ``condition`` is ``True``. + b + Value to emit wherever ``condition`` is ``False``. + out + Destination array that receives the selected values. YAML Configuration Example -------------------------- diff --git a/src/dspeed/processors/wiener_filter.py b/src/dspeed/processors/wiener_filter.py index 0df0fae..f65c00a 100644 --- a/src/dspeed/processors/wiener_filter.py +++ b/src/dspeed/processors/wiener_filter.py @@ -1,3 +1,5 @@ +"""Wiener filter processors for waveform denoising.""" + from __future__ import annotations import numpy as np diff --git a/src/dspeed/processors/windower.py b/src/dspeed/processors/windower.py index e4b274c..9c5572e 100644 --- a/src/dspeed/processors/windower.py +++ b/src/dspeed/processors/windower.py @@ -1,3 +1,5 @@ +"""Windowing utility processors for waveform preparation.""" + from __future__ import annotations import numpy as np