The frequencysignal module#
Handle frequency-domain stress signals for pyLife workflows.
Provide helpers for smoothing frequency-indexed power spectral densities before spectral comparison or frequency-domain fatigue assessment.
Warning
This module is not considered finalized even though it is part of
pylife-2.0. Breaking changes might occur in upcoming minor releases.
- class pylife.stress.frequencysignal.psdSignal(df)[source]#
Handle routines for frequency-indexed PSD signals.
The class stores a pandas data frame schema where the index is a frequency index in Hz and each column contains one power spectral density, e.g. in MPa²/Hz for a stress signal. The current methods are also used as legacy unbound helpers with a
pandas.DataFrameasself.- Parameters:
df (pandas.DataFrame) – Frequency-domain signal with frequency index in Hz and PSD columns.
Notes
The RMS value follows the one-sided PSD convention
\[x_\mathrm{rms} = \sqrt{\int_0^\infty S_{xx}(f)\,df}.\]Examples
>>> from pylife.stress.frequencysignal import psdSignal >>> psd = pd.DataFrame({"stress": [1.0, 1.0]}, index=[1.0, 2.0]) >>> round(float(psdSignal.rms_psd(psd).iloc[0]), 6) 1.0
- psd_smoother(fsel, factor_rms_nodes=0.5)[source]#
Smooth a PSD by optimizing values at selected frequency nodes.
Replace a dense frequency-indexed PSD by a compact node-based representation. The optimization balances preservation of the RMS value against preservation of the PSD values at the selected nodes.
- Parameters:
fsel (array_like) – Frequency nodes in Hz used for the smoothed PSD.
factor_rms_nodes (float, optional) – Weighting factor between node-value error and RMS error.
0considers only the error of node PSD values, while1considers only the RMS error. Default is0.5.
- Returns:
Smoothed PSD with frequency index in Hz. The index contains the original minimum frequency, unique selected nodes, and the original maximum frequency.
- Return type:
Notes
For every input column, the optimized node PSD values minimize
\[\alpha \frac{(r_\mathrm{in} - r_\mathrm{smooth})^2} {r_\mathrm{in}^2} + (1 - \alpha) \frac{\lVert \log_{10}(S_\mathrm{node}/H) \rVert^2} {\lVert \log_{10}(S_\mathrm{node}) \rVert^2},\]where \(\alpha\) is
factor_rms_nodesand \(H\) are the optimized node values.
- rms_psd()[source]#
Compute the RMS value of every PSD column.
- Returns:
Root mean square value of each column, in the unit of the square root of the PSD unit times Hz, e.g. MPa for a stress PSD given in MPa²/Hz. The index holds the original column names.
- Return type:
Notes
The PSD is first resampled onto 2048 logarithmically spaced frequency points between the smallest and the largest frequency of the index and then integrated with the trapezoidal rule,
\[x_\mathrm{rms} = \sqrt{\int_{f_\mathrm{min}}^{f_\mathrm{max}} S_{xx}(f)\,df}.\]Examples
>>> from pylife.stress.frequencysignal import psdSignal >>> psd = pd.DataFrame({"stress": [1.0, 1.0]}, index=[1.0, 2.0]) >>> round(float(psdSignal.rms_psd(psd).iloc[0]), 6) 1.0