## Summary¶

Signal processing functions

Resampling & smoothing.

class WhittakerSmoother(signal, smoothness_param, deriv_order=1)[source]

Bases: `object`

References

smooth(w)[source]
als_baseline(intensities, asymmetry_param=0.05, smoothness_param=1000000.0, max_iters=10, conv_thresh=1e-05, verbose=False)[source]

Computes the asymmetric least squares baseline

Parameters
• intensities (array_like) – vector to smooth

• asymmetry_param (float) – value will shift the baseline fit below or above your average line. To cancel gaussian noise, you would want the value to be `0.5`. To remove a positive peak would want it to be close to `0`. To remove a negative peaks (from a transmittance signal for instance) you would want it to be close to `1`. Default `0.05`

• smoothness_param (float) – Relative importance of smoothness of the predicted response: the higher, the smoother the baseline. Suggested range: `1e2` to `1e8`. Default `1e6`

Other Parameters
• max_iters (int) – number of iterations

• conv_thresh (float) – convergence

• verbose (boolean)

Examples

```from neq.math.smooth import als_baseline
I = als_baseline(I, smoothness_param=1e5, aymmetry_param=0.1)
```

References

Notes

Implementation:

• uses `WhittakerSmoother()` internally

baseline(y, deg=None, max_it=None, tol=None)[source]

Computes the baseline of a given data.

Iteratively performs a polynomial fitting in the data to detect its baseline. At every iteration, the fitting weights on the regions with peaks are reduced to identify the baseline only.

Parameters
• y (ndarray) – Data to detect the baseline.

• deg (int (default: 3)) – Degree of the polynomial that will estimate the data baseline. A low degree may fail to detect all the baseline present, while a high degree may make the data too oscillatory, especially at the edges.

• max_it (int (default: 100)) – Maximum number of iterations to perform.

• tol (float (default: 1e-3)) – Tolerance to use when comparing the difference between the current fit coefficients and the ones from the last iteration. The iteration procedure will stop when the difference between them is lower than tol.

Returns

Array with the baseline amplitude for every original point in y

Return type

ndarray

References

This function has been taken from the PeakUtils package. Their source code can be found here: https://bitbucket.org/lucashnegri/peakutils More info: https://peakutils.readthedocs.io/en/latest/

resample(xspace, vector, xspace_new, k=1, ext='error', energy_threshold='default', print_conservation=True)[source]

Resample (xspace, vector) on a new space (xspace_new) of evenly distributed data and whose bounds are taken as the same as `xspace`.

Uses spline interpolation to create the intermediary points. Number of points is the same as the initial xspace, times a resolution factor. Verifies energy conservation on the intersecting range at the end.

Parameters
• xspace (array) – space on which vector was generated

• vector (array) – quantity to resample

• xspace_new (array) – space on which to resample

Other Parameters
• resfactor (array) – xspace vector to resample on

• k (int) – order of spline interpolation. 3: cubic, 1: linear. Default 1.

• ext (‘error’, ‘extrapolate’, 0, 1) – Controls the value returned for elements of xspace_new not in the interval defined by xspace. If ‘error’, raise a ValueError. If ‘extrapolate’, well, extrapolate. If ‘0’ or 0, then fill with 0. If 1, fills with 1. Default ‘error’.

• energy_threshold (float or `None` or ```'default') -- if energy conservation (integrals on the intersecting range) is above this threshold, raise an error. If ``None```, dont check for energy conservation. If `'default'`, look up the value in `radis.config` [“RESAMPLING_TOLERANCE_THRESHOLD”] Default `'default'`

• print_conservation (boolean) – if True, prints energy conservation

Returns

array

Return type

resampled vector on evenly spaced array. Number of element is conserved.

Notes

Note that depending upon the from_space > to_space operation, sorting may be reversed.

Examples

Resample a `Spectrum` radiance on an evenly spaced wavenumber space:

```w_nm, I_nm = s.get('radiance')
w_cm, I_cm = resample_even(nm2cm(w_nm), I_nm)
```
resample_even(xspace, vector, resfactor=2, k=1, ext='error', energy_threshold=0.001, print_conservation=True)[source]

Resample (xspace, vector) on a new space (xspace_new) of evenly distributed data and whose bounds are taken as the same as `xspace`.

Uses spline interpolation to create the intermediary points. Number of points is the same as the initial xspace, times a resolution factor. Verifies energy conservation at the end.

Parameters
• xspace (array) – space on which vector was generated

• vector (array) – quantity to resample

• resfactor (float) – increase of resolution. If 1, output vector has the same number of points as the input vector. Default 2.

• k (int) – order of spline interpolation. 3: cubic, 1: linear. Default 1.

• ext (‘error’, ‘extrapolate’, 0) – Controls the value returned for elements of xspace_new not in the interval defined by xspace. If ‘error’, raise a ValueError. If ‘extrapolate’, well, extrapolate. If ‘0’ or 0, then fill with 0. Default ‘error’.

• energy_threshold (float) – if energy conservation (integrals) is above this threshold, raise an error

• print_conservation (boolean) – if True, prints energy conservation

Returns

• xspace_new (array) – evenly spaced mapping of xspace (same min, same max)

• vector_new (array) – resampled vector on evenly spaced array. Number of element is conserved.

• Note that depending upon the from_space > to_space operation, sorting may

• be reversed.

Examples

Resample a `Spectrum` radiance on an evenly spaced wavenumber space:

```w_nm, I_nm = s.get('radiance')
w_cm, I_cm = resample_even(nm2cm(w_nm), I_nm)
```

You can also use `resample_even()` directly