Channel API
- class pydysp.channel.Channel(data, dt=None, t0=0.0, time=None, name_input=None, name_user=None, label_axis=None, label_legend=None, description_long=None, quantity=None, units=None, raw_units=None, calibration_factor=1.0, drift_params=<factory>, filter_params=<factory>, baseline_params=<factory>, trim_params=<factory>, processing_notes=<factory>, tags=<factory>, meta=<factory>)[source]
Bases:
objectSingle time-history channel with metadata and processing parameters.
This class represents a single 1D time-history signal together with timing information, physical metadata (quantity, units), and a set of processing parameters (drift, filter, baseline, trim). Processing is non-destructive: methods update parameters and return new
Channelinstances, while the raw data remain unchanged.- Parameters:
data (np.ndarray) – One-dimensional array of raw signal values.
dt (float, optional) – Sampling interval in seconds. If not provided, an explicit
timearray must be supplied.t0 (float, optional) – Start time in seconds. Used to build the time vector when
dtis provided buttimeis not. Default is0.0.time (np.ndarray, optional) – Explicit time array matching
datain shape. If provided, it is used to inferdtandt0if they are not set.name_input (str, optional) – Original name as found in the input file or data source.
name_user (str, optional) – User-defined short name (for example
"Acc1").label_axis (str, optional) – Axis label for plotting, typically including units (for example
"Acc1 [g]").label_legend (str, optional) – Legend label for plotting (for example
"Acc1: Footing").description_long (str, optional) – Long human-readable description of the channel.
quantity (str, optional) – Physical quantity type (for example
"displacement","force","acceleration").units (str, optional) – Engineering units for the physical quantity (for example
"m","kN","g").raw_units (str, optional) – Raw data acquisition units (for example
"V").calibration_factor (float, optional) – Multiplicative factor used to convert raw data to physical units. Default is
1.0(no scaling).drift_params (dict, optional) – Parameters controlling drift correction. By default an empty dict; when set, merged with
DRIFT_DEFAULTS.filter_params (dict, optional) – Parameters controlling Butterworth filtering. By default an empty dict; when set, merged with
FILTER_DEFAULTS.baseline_params (dict, optional) – Parameters controlling baseline correction via
scipy.signal.detrend.trim_params (dict, optional) – Parameters defining a time window for trimming (typically containing
"t_start"and"t_end"in seconds).processing_notes (list of str, optional) – Free-form notes describing processing steps applied to the channel.
tags (set of str, optional) – Tags used for grouping, such as
{"q:acceleration"}.meta (dict, optional) – Free-form metadata dictionary (for example sensor type, location).
Notes
Processed data are obtained through
processed()orxy(), which apply drift correction, filtering, baseline correction, trimming, and calibration in a fixed order. Results can be cached for efficiency.- DRIFT_DEFAULTS = {'points': 50}
- FILTER_DEFAULTS = {'btype': 'lowpass', 'fc': 50.0, 'order': 2}
- BASELINE_DEFAULTS = {'type': 'linear'}
- data: ndarray
- dt: float | None = None
- t0: float = 0.0
- time: ndarray | None = None
- name_input: str | None = None
- name_user: str | None = None
- label_axis: str | None = None
- label_legend: str | None = None
- description_long: str | None = None
- quantity: str | None = None
- units: str | None = None
- raw_units: str | None = None
- calibration_factor: float = 1.0
- drift_params: Dict[str, Any]
- filter_params: Dict[str, Any]
- baseline_params: Dict[str, Any]
- trim_params: Dict[str, Any]
- processing_notes: list[str]
- tags: set[str]
- meta: Dict[str, Any]
- property duration: float
Total duration of the channel in seconds.
- Returns:
Duration computed from the first and last entries of the time vector. Returns
0.0for an empty channel.- Return type:
float
- info()[source]
Return a human-readable summary of channel metadata and processing.
The summary includes basic signal characteristics, timing, physical meaning and calibration, naming and labels, tags, processing parameters and notes, and any additional metadata.
- Returns:
Multi-line summary string suitable for printing.
- Return type:
str
- drift_corrected(**override)[source]
Return a new channel with updated drift correction parameters.
Drift correction is applied lazily in
processed(). This method only updates the stored parameters, clears the processing cache and appends a processing note.- Parameters:
**override (Any) – Keyword arguments that override or extend the current drift parameters. Merged with
DRIFT_DEFAULTSanddrift_params.- Returns:
New channel instance with updated drift parameters and tags.
- Return type:
- filtered(**override)[source]
Return a new channel with updated Butterworth filter parameters.
Filtering is applied lazily in
processed(). This method records the requested filter specification, clears the processing cache and appends a processing note.- Parameters:
**override (Any) – Keyword arguments that override or extend the current filter parameters. Merged with
FILTER_DEFAULTSandfilter_params.- Returns:
New channel instance with updated filter parameters and tags.
- Return type:
- baseline_corrected(**override)[source]
Return a new channel with updated baseline correction parameters.
Baseline correction is applied lazily in
processed()usingscipy.signal.detrend(). This method records the detrend parameters, clears the processing cache and appends a processing note.- Parameters:
**override (Any) – Keyword arguments forwarded to
scipy.signal.detrend()when baseline correction is applied.- Returns:
New channel instance with updated baseline parameters and tags.
- Return type:
- trimmed(**override)[source]
Return a new channel with updated trimming window parameters.
Trimming is applied in
processed()by restricting the time and data arrays to a specified interval.- Parameters:
**override (Any) – Keyword arguments that override or extend the current trimming parameters. Typical keys are
"t_start"and"t_end"in seconds.- Returns:
New channel instance with updated trimming parameters and tags.
- Return type:
- trim_by_threshold(threshold=0.01, use_abs=True, buffer_before=0.0, buffer_after=0.0, processed=True, use_cache=True)[source]
Trim the channel to where the signal exceeds a given threshold.
The trimming window is defined from the first to the last sample where the signal magnitude exceeds
threshold, optionally in absolute value, with configurable buffers before and after this window.- Parameters:
threshold (float, optional) – Amplitude threshold used to detect the start and end of the significant portion of the record. Default is
0.01.use_abs (bool, optional) – If
True(default), the threshold is applied to the absolute value of the signal. IfFalse, it is applied to the raw signal.buffer_before (float, optional) – Time (seconds) to extend the trimming window before the first threshold-crossing sample. Default is
0.0.buffer_after (float, optional) – Time (seconds) to extend the trimming window after the last threshold-crossing sample. Default is
0.0.processed (bool, optional) – If
True(default), trimming is based on the processed signal returned byxy(). IfFalse, the raw data are used.use_cache (bool, optional) – If
True(default), use the processing cache when obtaining the signal.
- Returns:
New channel instance with updated trimming parameters.
- Return type:
- Raises:
ValueError – If the channel is empty, no samples exceed the threshold, or the resulting window is empty after buffering.
- trim_by_fraction_of_peak(fraction=0.05, *, use_abs=True, buffer_before=0.0, buffer_after=0.0, processed=True, use_cache=True)[source]
Trim the channel to where the signal exceeds a fraction of its peak.
The trimming window is defined using a threshold equal to
fractiontimes the signal peak amplitude, optionally in absolute value, with configurable buffers before and after.- Parameters:
fraction (float, optional) – Fraction of the peak amplitude used to define the threshold. Must be in the range
(0, 1]. Default is0.05(5% of peak).use_abs (bool, optional) – If
True(default), the peak and threshold are computed using the absolute value of the signal. IfFalse, they are computed from the raw signal.buffer_before (float, optional) – Time (seconds) to extend the trimming window before the first threshold-crossing sample. Default is
0.0.buffer_after (float, optional) – Time (seconds) to extend the trimming window after the last threshold-crossing sample. Default is
0.0.processed (bool, optional) – If
True(default), use the processed signal; otherwise use the raw data.use_cache (bool, optional) – If
True(default), use the processing cache when obtaining the signal.
- Returns:
New channel instance with updated trimming parameters.
- Return type:
- Raises:
ValueError – If
fractionis out of range, the channel is empty, the peak amplitude is non-positive, or the resulting window is empty.
- trim_by_arias(lower=0.05, upper=0.95, g=9.81, buffer_before=0.0, buffer_after=0.0, processed=True, use_cache=True)[source]
Trim the channel using an Arias-intensity-based significant duration.
The trimming window is defined between the times when the cumulative Arias intensity reaches fractions
lowerandupperof its final value, optionally extended with time buffers.- Parameters:
lower (float, optional) – Lower fraction of final Arias intensity (for example
0.05for 5%). Must satisfy0 <= lower < upper <= 1. Default is0.05.upper (float, optional) – Upper fraction of final Arias intensity (for example
0.95for 95%). Default is0.95.g (float, optional) – Gravity acceleration used to convert acceleration in g to m/s². Default is
9.81.buffer_before (float, optional) – Time (seconds) to extend the trimming window before the lower Arias intensity crossing. Default is
0.0.buffer_after (float, optional) – Time (seconds) to extend the trimming window after the upper Arias intensity crossing. Default is
0.0.processed (bool, optional) – If
True(default), use the processed acceleration signal when computing Arias intensity.use_cache (bool, optional) – If
True(default), use the processing cache when obtaining the signal.
- Returns:
New channel instance with updated trimming parameters.
- Return type:
- Raises:
ValueError – If the channel is empty, the final Arias intensity is non-positive, the
lower/uppervalues are invalid, or the resulting window is empty after buffering.
Notes
The channel data are assumed to represent acceleration in units of g.
- processed(use_cache=True)[source]
Return time and data after applying all processing steps.
The following operations are applied in a fixed order:
Drift correction (if
drift_paramsare set).Butterworth filtering (if
filter_paramsare set).Baseline detrend (if
baseline_paramsare set).Trimming by time window (if
trim_paramsare set).Calibration-factor scaling.
- Parameters:
use_cache (bool, optional) – If
True(default), cached processed results are returned when available and the processing signature has not changed.- Returns:
t (np.ndarray) – Time array after trimming (if applied).
y (np.ndarray) – Processed data array after all enabled steps.
- Raises:
ValueError – If processing parameters are inconsistent (for example invalid filter cutoff, trimming window outside the time range, or missing
dtfor filtering or response-related calculations).- Return type:
tuple[ndarray, ndarray]
- xy(processed=True, use_cache=True)[source]
Return coordinate arrays for plotting.
- Parameters:
processed (bool, optional) – If
True(default), return the processed time and data arrays fromprocessed(). IfFalse, return the rawtimeanddataattributes.use_cache (bool, optional) – If
True(default) andprocessedisTrue, use the processing cache when computing processed data.
- Returns:
x (np.ndarray) – Time array.
y (np.ndarray) – Data array (raw or processed depending on
processed).
- Return type:
tuple[ndarray, ndarray]
- max_abs(processed=True, use_cache=True)[source]
Return the time and value of the maximum absolute amplitude.
- Parameters:
processed (bool, optional) – If
True(default), use the processed data; otherwise use the raw data.use_cache (bool, optional) – If
True(default) andprocessedisTrue, use the processing cache.
- Returns:
t_peak (float) – Time at which the maximum absolute amplitude occurs.
y_peak (float) – Data value at the maximum absolute amplitude.
- Raises:
ValueError – If the channel is empty.
- Return type:
tuple[float, float]
- max_value(processed=True, use_cache=True)[source]
Return the time and value of the maximum (positive) data value.
- Parameters:
processed (bool, optional) – If
True(default), use the processed data; otherwise use the raw data.use_cache (bool, optional) – If
True(default) andprocessedisTrue, use the processing cache.
- Returns:
t_peak (float) – Time at which the maximum value occurs.
y_peak (float) – Maximum data value.
- Raises:
ValueError – If the channel is empty.
- Return type:
tuple[float, float]
- min_value(processed=True, use_cache=True)[source]
Return the time and value of the minimum (negative) data value.
- Parameters:
processed (bool, optional) – If
True(default), use the processed data; otherwise use the raw data.use_cache (bool, optional) – If
True(default) andprocessedisTrue, use the processing cache.
- Returns:
t_peak (float) – Time at which the minimum value occurs.
y_peak (float) – Minimum data value.
- Raises:
ValueError – If the channel is empty.
- Return type:
tuple[float, float]
- rms(processed=True, use_cache=True)[source]
Compute the root-mean-square (RMS) value of the channel.
- Parameters:
processed (bool, optional) – If
True(default), compute RMS of the processed data; otherwise use the raw data.use_cache (bool, optional) – If
True(default) andprocessedisTrue, use the processing cache.
- Returns:
RMS value of the signal.
- Return type:
float
- Raises:
ValueError – If the channel is empty.
- fourier(processed=True, use_cache=True)[source]
Compute the (single-sided) Fourier amplitude spectrum of the channel.
The spectrum is computed via zero-padded FFT to the next power-of-two length, and the single-sided amplitude spectrum is returned.
- Parameters:
processed (bool, optional) – If
True(default), use the processed data; otherwise use the raw data.use_cache (bool, optional) – If
True(default) andprocessedisTrue, use the processing cache.
- Returns:
Object containing frequency array and amplitude spectrum.
- Return type:
- Raises:
ValueError – If the channel is empty or
dtis missing/invalid.
- fourier_peak(processed=True, use_cache=True)[source]
Return the dominant frequency and amplitude from the Fourier spectrum.
- Parameters:
processed (bool, optional) – If
True(default), use the processed data; otherwise use the raw data.use_cache (bool, optional) – If
True(default) andprocessedisTrue, use the processing cache.
- Returns:
f_peak (float) – Frequency at which the spectrum amplitude is maximum.
s_peak (float) – Maximum amplitude of the Fourier spectrum.
- Return type:
tuple[float, float]
- welch_psd(processed=True, use_cache=True, **kwargs)[source]
Compute the power spectral density (PSD) using Welch’s method.
- Parameters:
processed (bool, optional) – If
True(default), use the processed data; otherwise use the raw data.use_cache (bool, optional) – If
True(default) andprocessedisTrue, use the processing cache.**kwargs – Additional keyword arguments forwarded to
scipy.signal.welch(). Ifnpersegis not provided, a default ofmin(256, n)is used.
- Returns:
Object containing frequency array and PSD values.
- Return type:
- Raises:
ValueError – If the channel is empty or
dtis missing/invalid.
- welch_peak(processed=True, use_cache=True, **kwargs)[source]
Return the dominant frequency and PSD amplitude from the Welch spectrum.
- Parameters:
processed (bool, optional) – If
True(default), use the processed data; otherwise use the raw data.use_cache (bool, optional) – If
True(default) andprocessedisTrue, use the processing cache.**kwargs – Additional keyword arguments forwarded to
welch_psd()and then toscipy.signal.welch().
- Returns:
f_peak (float) – Frequency at which the PSD is maximum.
p_peak (float) – Maximum PSD value.
- Return type:
tuple[float, float]
- arias_intensity(g=9.81, processed=True, use_cache=True)[source]
Compute cumulative Arias intensity and significant-duration window.
The channel is assumed to contain acceleration in units of g. The resulting Arias intensity is computed via numerical integration of squared acceleration, and the 5–95% significant-duration window is identified.
- Parameters:
g (float, optional) – Gravity acceleration used to convert from g to m/s². Default is
9.81.processed (bool, optional) – If
True(default), use the processed acceleration signal; otherwise use the raw data.use_cache (bool, optional) – If
True(default) andprocessedisTrue, use the processing cache.
- Returns:
Object containing time array, cumulative Arias intensity, and start/end times of the 5–95% significant-duration window.
- Return type:
- Raises:
ValueError – If the channel is empty or the final Arias intensity is non-positive.
- response_spectrum(periods=array([0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4, 0.45, 0.5, 0.55, 0.6, 0.65, 0.7, 0.75, 0.8, 0.85, 0.9, 0.95, 1., 1.05, 1.1, 1.15, 1.2, 1.25, 1.3, 1.35, 1.4, 1.45, 1.5, 1.55, 1.6, 1.65, 1.7, 1.75, 1.8, 1.85, 1.9, 1.95, 2., 2.05, 2.1, 2.15, 2.2, 2.25, 2.3, 2.35, 2.4, 2.45, 2.5, 2.55, 2.6, 2.65, 2.7, 2.75, 2.8, 2.85, 2.9, 2.95, 3., 3.05, 3.1, 3.15, 3.2, 3.25, 3.3, 3.35, 3.4, 3.45, 3.5, 3.55, 3.6, 3.65, 3.7, 3.75, 3.8, 3.85, 3.9, 3.95, 4., 4.05, 4.1, 4.15, 4.2, 4.25, 4.3, 4.35, 4.4, 4.45, 4.5, 4.55, 4.6, 4.65, 4.7, 4.75, 4.8, 4.85, 4.9, 4.95, 5.]), g=9.81, ksi=0.05, processed=True, use_cache=True)[source]
Compute an elastic response spectrum for a grid of periods.
The response spectrum is computed by subjecting a set of linear single-degree-of-freedom (SDOF) oscillators, with specified damping ratio, to the acceleration record using the Newmark-beta average acceleration method.
- Parameters:
periods (np.ndarray, optional) – One-dimensional array of natural periods (in seconds) at which the spectrum is evaluated. Default is
np.linspace(0.05, 5.0, 100).g (float, optional) – Gravity acceleration used to convert from g to m/s². Default is
9.81.ksi (float, optional) – Damping ratio of the SDOF systems (for example
0.05for 5% damping). Default is0.05.processed (bool, optional) – If
True(default), use the processed acceleration signal; otherwise use the raw data.use_cache (bool, optional) – If
True(default) andprocessedisTrue, use the processing cache.
- Returns:
Object containing periods, spectral displacement (
Sd), velocity (Sv) and acceleration (Sain units of g), and the damping ratio.- Return type:
- Raises:
ValueError – If the channel is empty,
dtis missing/invalid,periodsis not 1D, or contains non-positive values.
- plot(ax=None, processed=True, use_cache=True, include_label=True, include_kind=False, include_legend=False, plot_type='timehistory', **plot_kwargs)[source]
Plot the channel in one of several supported representations.
The default behaviour (
plot_type='timehistory') is to plot the time history. Other values ofplot_typedelegate to helper methods to plot Fourier spectrum, power spectral density, Arias intensity or response spectrum.Supported
plot_typevalues"timehistory","time","time_history""fourier","fft""psd","welch","power""arias","husid""response","response_spectrum","rs"
- param ax:
Axes to plot on. If
None, a new figure and axes are created withmatplotlib.pyplot.subplots().- type ax:
matplotlib.axes.Axes, optional
- param processed:
If
True(default), use processed data for time-domain plotting and for spectral quantities. IfFalse, use raw data.- type processed:
bool, optional
- param use_cache:
If
True(default) andprocessedisTrue, use the processing cache.- type use_cache:
bool, optional
- param include_label:
For time-history plots, if
True(default) uselabel_axisas the y-axis label when available.- type include_label:
bool, optional
- param include_kind:
For time-history plots, if
True, build a generic y-label fromquantityandunits(e.g."Acceleration [g]"). This overrides any existing y-label if set.- type include_kind:
bool, optional
- param include_legend:
For time-history plots, if
True, add a legend usinglabel_legendorname_user.- type include_legend:
bool, optional
- param plot_type:
Representation to plot. See list above. Default is
"timehistory".- type plot_type:
str, optional
- param **plot_kwargs:
Additional keyword arguments forwarded to the underlying plotting method (for example line style, color,
fmax,periods).- returns:
Axes instance containing the requested plot.
- rtype:
matplotlib.axes.Axes
- raises ValueError:
If an unknown
plot_typeis given.
- Parameters:
ax (Axes | None)
processed (bool)
use_cache (bool)
include_label (bool)
include_kind (bool)
include_legend (bool)
plot_type (str)
plot_kwargs (Any)
- Return type:
Axes
- plot_fourier(ax=None, processed=True, use_cache=True, fmax=50.0, **plot_kwargs)[source]
Plot the Fourier amplitude spectrum of the channel.
- Parameters:
ax (matplotlib.axes.Axes, optional) – Axes to plot on. If
None, a new figure and axes are created.processed (bool, optional) – If
True(default), compute the spectrum from processed data; otherwise use raw data.use_cache (bool, optional) – If
True(default) andprocessedisTrue, use the processing cache.fmax (float or None, optional) – Maximum frequency shown on the plot (in Hz). If
None, the full frequency range is used. Default is50.0.**plot_kwargs – Additional keyword arguments forwarded to
FourierSpectrum.plot().
- Returns:
Axes instance containing the Fourier spectrum plot.
- Return type:
matplotlib.axes.Axes
- plot_psd(ax=None, processed=True, use_cache=True, fmax=50.0, **welch_kwargs)[source]
Plot the power spectral density (PSD) using Welch’s method.
- Parameters:
ax (matplotlib.axes.Axes, optional) – Axes to plot on. If
None, a new figure and axes are created.processed (bool, optional) – If
True(default), compute the PSD from processed data; otherwise use raw data.use_cache (bool, optional) – If
True(default) andprocessedisTrue, use the processing cache.fmax (float or None, optional) – Maximum frequency shown on the plot (in Hz). If
None, the full frequency range is used. Default is50.0.**welch_kwargs – Additional keyword arguments forwarded to
welch_psd()and then toscipy.signal.welch().
- Returns:
Axes instance containing the PSD plot.
- Return type:
matplotlib.axes.Axes
- plot_arias(ax=None, g=9.81, processed=True, use_cache=True, show_window=True, **plot_kwargs)[source]
Plot the Arias intensity time history (Husid plot) for this channel.
- Parameters:
ax (matplotlib.axes.Axes, optional) – Axes to plot on. If
None, a new figure and axes are created.g (float, optional) – Gravity acceleration used to convert acceleration from g to m/s². Default is
9.81.processed (bool, optional) – If
True(default), compute Arias intensity from processed acceleration; otherwise use raw data.use_cache (bool, optional) – If
True(default) andprocessedisTrue, use the processing cache.show_window (bool, optional) – If
True(default), plot vertical lines marking the 5–95% significant-duration window.**plot_kwargs – Additional keyword arguments forwarded to
AriasResult.plot().
- Returns:
Axes instance containing the Arias intensity plot.
- Return type:
matplotlib.axes.Axes
Notes
The channel data are assumed to represent acceleration in units of g.
- plot_response_spectrum(ax=None, periods=array([0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4, 0.45, 0.5, 0.55, 0.6, 0.65, 0.7, 0.75, 0.8, 0.85, 0.9, 0.95, 1., 1.05, 1.1, 1.15, 1.2, 1.25, 1.3, 1.35, 1.4, 1.45, 1.5, 1.55, 1.6, 1.65, 1.7, 1.75, 1.8, 1.85, 1.9, 1.95, 2., 2.05, 2.1, 2.15, 2.2, 2.25, 2.3, 2.35, 2.4, 2.45, 2.5, 2.55, 2.6, 2.65, 2.7, 2.75, 2.8, 2.85, 2.9, 2.95, 3., 3.05, 3.1, 3.15, 3.2, 3.25, 3.3, 3.35, 3.4, 3.45, 3.5, 3.55, 3.6, 3.65, 3.7, 3.75, 3.8, 3.85, 3.9, 3.95, 4., 4.05, 4.1, 4.15, 4.2, 4.25, 4.3, 4.35, 4.4, 4.45, 4.5, 4.55, 4.6, 4.65, 4.7, 4.75, 4.8, 4.85, 4.9, 4.95, 5.]), ksi=0.05, processed=True, use_cache=True, y='Sa', logx=False, logy=False, **plot_kwargs)[source]
Plot the elastic response spectrum for this channel.
- Parameters:
ax (matplotlib.axes.Axes, optional) – Axes to plot on. If
None, a new figure and axes are created.periods (np.ndarray, optional) – One-dimensional array of natural periods (in seconds) at which the spectrum is evaluated. Default is
np.linspace(0.05, 5.0, 100).ksi (float, optional) – Damping ratio of the SDOF systems (for example
0.05for 5% damping). Default is0.05.processed (bool, optional) – If
True(default), compute the spectrum from processed data; otherwise use raw data.use_cache (bool, optional) – If
True(default) andprocessedisTrue, use the processing cache.y ({"Sa", "Sv", "Sd"}, optional) – Response quantity to plot: spectral acceleration
"Sa", velocity"Sv"or displacement"Sd". Default is"Sa".logx (bool, optional) – If
True, use a logarithmic scale on the x-axis (period). Default isFalse.logy (bool, optional) – If
True, use a logarithmic scale on the y-axis (response). Default isFalse.**plot_kwargs – Additional keyword arguments forwarded to
ResponseSpectrum.plot().
- Returns:
Axes instance containing the response spectrum plot.
- Return type:
matplotlib.axes.Axes