Additional Modules
Spectral tools, Arias intensity, response spectra and small utilities used by
the core pydysp.channel.Channel and pydysp.test.Test classes.
Spectral Tools
- class pydysp.spectra.FourierSpectrum(f, s)[source]
Bases:
objectSingle-sided Fourier amplitude spectrum.
This dataclass stores the frequency axis and corresponding single-sided amplitude spectrum (magnitude of the FFT) for a real-valued time series.
- Parameters:
f (np.ndarray) – One-dimensional array of frequencies in Hz.
s (np.ndarray) – One-dimensional array of amplitude values corresponding to
f.
- f: ndarray
- s: ndarray
- peak()[source]
Return the frequency and amplitude at the maximum spectral peak.
- Returns:
f_peak (float) – Frequency at which the amplitude spectrum is maximum.
s_peak (float) – Maximum amplitude value.
- Raises:
ValueError – If the spectrum array
sis empty.- Return type:
tuple[float, float]
- plot(ax=None, fmax=50.0, **plot_kwargs)[source]
Plot the Fourier amplitude spectrum.
- Parameters:
ax (matplotlib.axes.Axes, optional) – Axes to plot on. If
None, a new figure and axes are created.fmax (float or None, optional) – Upper x-limit for the frequency axis in Hz. If
None, the full frequency range is shown. Default is50.0.**plot_kwargs – Additional keyword arguments forwarded to
matplotlib.axes.Axes.plot()(for examplecolor,linewidth).
- Returns:
Axes instance with the plotted spectrum.
- Return type:
matplotlib.axes.Axes
- class pydysp.spectra.WelchSpectrum(f, p)[source]
Bases:
objectPower spectral density (PSD) result from Welch’s method.
This dataclass stores the frequency axis and corresponding power spectral density values obtained using Welch’s method.
- Parameters:
f (np.ndarray) – One-dimensional array of frequencies in Hz.
p (np.ndarray) – One-dimensional array of PSD values corresponding to
f.
- f: ndarray
- p: ndarray
- peak()[source]
Return the frequency and PSD value at the maximum spectral peak.
- Returns:
f_peak (float) – Frequency at which the PSD is maximum.
p_peak (float) – Maximum PSD value.
- Raises:
ValueError – If the PSD array
pis empty.- Return type:
tuple[float, float]
- plot(ax=None, fmax=50.0, **plot_kwargs)[source]
Plot the Welch power spectral density.
- Parameters:
ax (matplotlib.axes.Axes, optional) – Axes to plot on. If
None, a new figure and axes are created.fmax (float or None, optional) – Upper x-limit for the frequency axis in Hz. If
None, the full frequency range is shown. Default is50.0.**plot_kwargs – Additional keyword arguments forwarded to
matplotlib.axes.Axes.plot().
- Returns:
Axes instance with the plotted PSD.
- Return type:
matplotlib.axes.Axes
Arias Intensity
- class pydysp.arias.AriasResult(t, Ia, t_start, t_end)[source]
Bases:
objectContainer for Arias intensity time history and significant-duration window.
This dataclass stores the Husid-style cumulative Arias intensity and the corresponding significant-duration window, typically defined between two Arias intensity percentiles (e.g. 5–95%).
- Parameters:
t (np.ndarray) – One-dimensional array of time values (in seconds) corresponding to the input acceleration record.
Ia (np.ndarray) – One-dimensional array of cumulative Arias intensity values evaluated at times
t.t_start (float) – Start time of the significant-duration window (e.g. the time at which a given lower percentile of Arias intensity is reached).
t_end (float) – End time of the significant-duration window (e.g. the time at which a given upper percentile of Arias intensity is reached).
Notes
The
AriasResultclass is typically created by higher-level routines that compute Arias intensity from acceleration time series. It is mainly used to: * Visualise the cumulative Arias intensity (Husid plot). * Provide a convenient representation of the significant-duration windowfor trimming and further analysis.
- t: ndarray
- Ia: ndarray
- t_start: float
- t_end: float
- plot(ax=None, show_window=True, **plot_kwargs)[source]
Plot the Arias intensity time history.
- Parameters:
ax (matplotlib.axes.Axes, optional) – Axes object to plot on. If
None, a new figure and axes are created withplt.subplots().show_window (bool, optional) – If
True, vertical dashed lines are drawn att_startandt_endto indicate the significant-duration window. The default isTrue.**plot_kwargs – Additional keyword arguments passed directly to
ax.plot(for examplecolor,linewidth, etc.).
- Returns:
The axes instance containing the Arias intensity plot.
- Return type:
matplotlib.axes.Axes
Notes
The x-axis is labelled as time in seconds, and the y-axis as Arias intensity in consistent units with the underlying acceleration record. A grid is enabled by default to facilitate reading the Husid plot.
Response Spectra
- class pydysp.response.ResponseSpectrum(T, Sd, Sv, Sa, ksi)[source]
Bases:
objectElastic response spectrum for a family of SDOF oscillators.
This dataclass stores spectral displacement, velocity and acceleration for a set of single-degree-of-freedom (SDOF) oscillators with the same damping ratio, evaluated over a grid of natural periods.
- Parameters:
T (np.ndarray) – One-dimensional array of natural periods in seconds.
Sd (np.ndarray) – Spectral displacement values in metres (same shape as
T).Sv (np.ndarray) – Spectral velocity values in metres per second (same shape as
T).Sa (np.ndarray) – Spectral pseudo-acceleration values in g (same shape as
T).ksi (float) – Damping ratio used to compute the spectrum (e.g. 0.05 for 5%).
- T: ndarray
- Sd: ndarray
- Sv: ndarray
- Sa: ndarray
- ksi: float
- peak()[source]
Return the dominant period and peak spectral acceleration.
- Returns:
T_peak (float) – Period at which
Saattains its maximum value.Sa_peak (float) – Maximum spectral acceleration value in g.
- Raises:
ValueError – If the spectral acceleration array
Sais empty.- Return type:
tuple[float, float]
- plot(ax=None, y='Sa', logx=False, logy=False, **plot_kwargs)[source]
Plot one of the response spectra (Sa, Sv or Sd).
- Parameters:
ax (matplotlib.axes.Axes, optional) – Axes to plot on. If
None, a new figure and axes are created.y ({"Sa", "Sv", "Sd"}, optional) – Which spectrum to plot: spectral acceleration
"Sa"(default), velocity"Sv", or displacement"Sd".logx (bool, optional) – If
True, use a logarithmic scale on the x-axis. Default isFalse.logy (bool, optional) – If
True, use a logarithmic scale on the y-axis. Default isFalse.**plot_kwargs – Additional keyword arguments forwarded to
matplotlib.axes.Axes.plot()(for examplecolor,linewidth, etc.).
- Returns:
Axes instance containing the plotted spectrum.
- Return type:
matplotlib.axes.Axes
- Raises:
ValueError – If
yis not one of"Sa","Sv", or"Sd".
- pydysp.response.sdof_newmark_response(acc, dt, omega, ksi)[source]
Newmark-beta (average-acceleration) SDOF response to base acceleration.
This function integrates the response of a linear single-degree-of-freedom (SDOF) oscillator subjected to ground acceleration using the Newmark-beta average-acceleration scheme, and returns peak relative displacement, relative velocity and absolute acceleration.
- Parameters:
acc (np.ndarray) – Ground acceleration time history \(a_g(t)\) in m/s².
dt (float) – Time step in seconds.
omega (float) – Circular frequency of the oscillator in rad/s.
ksi (float) – Damping ratio (e.g. 0.05 for 5% damping).
- Returns:
Sd (float) – Peak relative displacement in metres (maximum absolute value of relative displacement time history).
Sv (float) – Peak relative velocity in metres per second.
Sa (float) – Peak absolute acceleration in m/s² (sum of relative and ground acceleration).
- Return type:
tuple[float, float, float]
Notes
A unit mass \(m = 1\) is assumed, with stiffness
k = m * omega**2and viscous dampingc = 2 * ksi * omega * m.If the input acceleration array is empty, all returned values are 0.0.
Utilities
- pydysp.downsample.downsample(file_in, file_out, factor=20)[source]
Downsample array-like variables in a MATLAB
.matfile.This function loads a
.matfile, downsamples any array-like variables (NumPy arrays, MATLAB arrays, or objects exposing ashapeattribute withndim >= 1), and writes the result to a new.matfile. Non-array containers such as Pythonlistortupleare left unchanged.- Parameters:
file_in (str) – Path to the input MATLAB
.matfile.file_out (str) – Path to the output MATLAB
.matfile where the downsampled variables will be saved.factor (int, optional) – Downsampling factor applied along the first dimension. Must be a positive integer. Default is
20.
- Raises:
FileNotFoundError – If the input file cannot be found or opened.
ValueError – If
factoris not a positive integer.
- Return type:
None
Notes
Only objects exposing
shapeand having at least one dimension are downsampled. The operation is performed using slicingval[::factor].Keys such as
__header__,__version__and__globals__are preserved and written unchanged.SciPy warnings related to MATLAB struct fields beginning with an underscore are suppressed during saving.