swgo.psa package#
Submodules#
- swgo.psa.utils.wrap_1d_nn(func)#
Decorator to wrap func - which acts on 1-d arrays and two scalar arguments - such that it works for 2-d arrays and either scalar or 1-d arguments.
Module contents#
Pulse-shape analysis for SWGO.
- swgo.psa.adaptive_centroid(waveforms: _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes], peak_indices: int | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes], rel_descend_limits: float | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes]) ndarray #
For each waveform, calculates the centroid for all samples around peak_index down to rel_descend_limit * waveform[peak_index].
- Parameters:
waveforms (ArrayLike of shape (n_channels, n_samples)) – Waveforms stored in a 2-dimensional array-like.
peak_indices (ArrayLike of ints or scalar int) – Peak index for each channel. If a scalar is given, the same peak index is used for all channels.
rel_descend_limits (ArrayLike of floats or scalar float) – Fraction of the peak value down to which samples are accumulated in the centroid calculation for each channel. If a scalar is given, the same limit is used for all channels.
- Returns:
centroids – Peak centroids in units “samples”; peak_index if centroid calculation failed.
- Return type:
1-dimensional np.ndarray of floats or (0-dimensional array of) float
- swgo.psa.adaptive_sum(waveforms: _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes], peak_indices: int | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes], descend_limits: float | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes]) ndarray #
For each waveform, calculates the sum of all samples around peak_index down to descend_limit.
- Parameters:
waveforms (ArrayLike of shape (n_channels, n_samples)) – Waveforms stored in a 2-dimensional array-like.
peak_index (ArrayLike of ints or scalar int) – Peak index for each channel. If a scalar is given, the same peak index is used for all channels.
descend_limit (ArrayLike of floats or scalar float) – Absolute value down to which samples are accumulated for each channel. If a scalar is given, the same limit is used for all channels.
- Returns:
sample_sum – Sum of samples; 0 if waveform[peak_index] <= descend_limit or len(waveform) == 0.
- Return type:
1-dimensional np.ndarray of floats or (0-dimensional array of) float
- swgo.psa.deconvolve_pole_zero(waveforms: _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes], baselines: _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes], pole_zero: float, upsampling: int = 1) ndarray #
Applies pole-zero deconvolution and optional upsampling with a double moving average filter (using upsample()).
- Parameters:
waveforms (ArrayLike of shape (n_channels, n_samples)) – Waveforms stored in a numpy array.
baselines (ArrayLike of shape (n_channels, ) or scalar float) – Baseline estimates for each channel that are subtracted from the waveforms before deconvolution.
pole_zero (float) – Deconvolution parameter.
upsampling (int (default: 1)) – Upsampling factor to use (>= 1); if > 1, the input waveforms are resampled at upsampling times their original sampling rate.
- Returns:
deconvolved_waveforms – Deconvolved and upsampled waveforms stored in a numpy array. Shape: (n_channels, upsampling * n_samples)
- Return type:
ndarray
- swgo.psa.differentiate(waveforms: _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes], upsampling: int = 1) ndarray #
Applies simple differentiation and optional upsampling with a double moving average filter (using upsample()).
- Parameters:
waveforms (ArrayLike of shape (n_channels, n_samples)) – Waveforms stored in a numpy array.
upsampling (int (default: 1)) – Upsampling factor to use (>= 1); if > 1, the input waveforms are resampled at upsampling times their original sampling rate.
- Returns:
differentiated_waveforms – Differentiated waveforms stored in a numpy array. Shape: (n_channels, upsampling * n_samples)
- Return type:
ndarray
- swgo.psa.upsample(waveforms: _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes], upsampling: int) ndarray #
Applies simple upsampling by interpolating with a double moving average filter.
- Parameters:
waveforms (ArrayLike of shape (n_channels, n_samples)) – Waveforms stored in a numpy array.
upsampling (int) – Upsampling factor to use (>= 1); if > 1, the input waveforms are resampled at upsampling times their original sampling rate.
- Returns:
upsampled_waveforms – Upsampled waveforms stored in a numpy array. Shape: (n_channels, upsampling * n_samples)
- Return type:
ndarray
Notes
See scipy.signal.resample and scipy.signal.resample_poly for more sophisticated algorithms.