ppcpy.retrievals.ramanhelpers#

Functions

moving_linfit_varied_win

moving_smooth_varied_win

movingslope

MOVINGSLOPE estimates the local slope of a sequence of points using a sliding window.

movingslope_variedWin

MOVINGSLOPE_VARIEDWIN calculates the slope of the signal with a moving slope.

savgol_filter

Savitzky-Golay filter

sigGenWithNoise

SIGGENWITHNOISE generate noise-containing signal with a certain noise-adding algorithm.

ppcpy.retrievals.ramanhelpers.movingslope_variedWin(signal: ndarray, winWidth: int | ndarray) ndarray[source]#

MOVINGSLOPE_VARIEDWIN calculates the slope of the signal with a moving slope. This is a wrapper for the movingslope function to make it compatible with height-independent smoothing windows.

Parameters:
  • signal (array_like) – Signal for each bin.

  • winWidth (int or ndarray) – If winWidth is an integer, the width of the window will be fixed. If winWidth is a k x 3 matrix, the width of the window will vary with height, like [[1, 20, 3], [18, 30, 5], [25, 40, 7]], which means: - The width will be 3 between indices 1 and 20, - 5 between indices 18 and 30, - and 7 between indices 25 and 40.

Returns:

  • slope (ndarray) – Slope at each bin.

  • History

  • ——-

  • - 2018-08-03 (First edition by Zhenping.)

ppcpy.retrievals.ramanhelpers.moving_smooth_varied_win(signal, winWidth)[source]#
ppcpy.retrievals.ramanhelpers.moving_linfit_varied_win(height, signal, winWidth)[source]#
ppcpy.retrievals.ramanhelpers.movingslope(vec: ndarray, supportlength: int = 3, modelorder: int = 1, dt: float = 1) ndarray[source]#

MOVINGSLOPE estimates the local slope of a sequence of points using a sliding window.

Parameters:
  • vec (array_like) – Row or column vector to be differentiated. Must have at least 2 elements.

  • supportlength (int, optional) – Number of points used for the moving window. Default is 3.

  • modelorder (int, optional) – Defines the order of the windowed model used to estimate the slope. Default is 1 (linear model).

  • dt (float, optional) – Spacing for sequences that do not have unit spacing. Default is 1.

Returns:

  • Dvec (ndarray) – Derivative estimates, same size and shape as vec.

  • History

  • ——-

  • - Original MATLAB implementation by John D’Errico.

  • Authors

  • ——-

  • - woodchips@rochester.rr.com

ppcpy.retrievals.ramanhelpers.sigGenWithNoise(signal: ndarray, noise: ndarray = None, nProfile: int = 1, method: str = 'norm') ndarray[source]#

SIGGENWITHNOISE generate noise-containing signal with a certain noise-adding algorithm.

Parameters:
  • signal (array) – Signal strength.

  • noise (array, optional) – Noise. Unit should be the same as signal. Default is sqrt(signal).

  • nProfile (int, optional) – Number of signal profiles to generate. Default is 1.

  • method (str, optional) – ‘norm’: Normally distributed noise -> signalGen = signal + norm * noise. ‘poisson’: Poisson distributed noise -> signalGen = poisson(signal, nProfile). Default is ‘norm’.

Returns:

  • signalGen (array) – Noise-containing signal. Shape is (len(signal), nProfile).

  • History

  • ——-

  • - 2021-06-13 (First edition by Zhenping.)

  • - 2026-02-04 (Modifications to reduce computational time, Buholdt)

ppcpy.retrievals.ramanhelpers.savgol_filter(x: ndarray, window_length: int, polyorder: int = 2, deriv: int = 0, delta: float = 1.0, fill_val: float = nan) ndarray[source]#

Savitzky-Golay filter

A Savitzky-Golay filter that works with NaN values.

Parameters:
  • x (ndarray) – Signal to be smoothed

  • window_length (int) – Width of savgol filter

  • polyorder (int, optional) – The order of the polynomial used to make the filter. must be less than ‘window_length’. Default is 2.

  • deriv (int, optional) – The order of the derivative to compute for the filter. Default is 0.

  • delta (float, optional) – The spacing of which the filter will be applied. This is only used if ‘deriv’ > 0. Defualt is 1.0.

  • fill_val (float, optional) – Value to be used for filling edges in order to recreate the input dimension. Default is np.nan.

Returns:

out – Smoothed signal

Return type:

ndarray

Notes

This function is inspiered by scipy.signal’s Savitzky-Golay filter [1].

References

[1] Virtanen, et al., Scipy 1.0: Fundamental Algorithms for Scientific Computing in Python, Nature Methods, 2020, 17, 261-272, https://rdcu.be/b08Wh, 10.1038/s41592-019-0686-2 [2] A. Savitzky, M. J. E. Golay, Smoothing and Differentiation of Data by Simplified Least Squares Procedures. Analytical Chemistry, 1964, 36 (8), pp 1627-1639. [3] Jianwen Luo, Kui Ying, and Jing Bai. 2005. Savitzky-Golay smoothing and differentiation filter for even number data. Signal Process. 85, 7 (July 2005), 1429-1434.