sdynpy.core.sdynpy_data.SpectrumArray
- class SpectrumArray(shape, nelements, buffer=None, offset=0, strides=None, order=None)[source]
Bases:
NDDataArray
Data array used to store linear spectra (for example scaled FFT results)
- __init__()
Methods
ifft
([norm, rtol, atol])Computes a time signal from the frequency spectrum
interpolate_by_zero_pad
(...[, ...])Interpolates a spectrum by zero padding or truncating its time response
plot
([one_axis, subplots_kwargs, ...])Plot the spectra
plot_spectrogram
([abscissa, axis, ...])Plots a spectrogram
Attributes
Returns the function type of the data array
- property function_type
Returns the function type of the data array
- ifft(norm='backward', rtol=1, atol=1e-08, **scipy_irfft_kwargs)[source]
Computes a time signal from the frequency spectrum
- Parameters
norm (str, optional) – The type of normalization applied to the fft computation. The default is “backward”.
rtol (float, optional) – Relative tolerance used in the abcsissa spacing check. The default is 1e-5.
atol (float, optional) – Relative tolerance used in the abscissa spacing check. The default is 1e-8.
scipy_irfft_kwargs – Additional keywords that will be passed to SciPy’s irfft function.
- Raises
ValueError – Raised if the spectra passed to this function do not have equally spaced abscissa.
NotImplementedError – Raised if the user specifies scaling.
- Returns
The time history of the SpectrumArray.
- Return type
- interpolate_by_zero_pad(time_response_padded_length, return_time_response=False)[source]
Interpolates a spectrum by zero padding or truncating its time response
- Parameters
time_response_padded_length (int) – Length of the final zero-padded time response
return_time_response (bool, optional) – If True, the zero-padded impulse response function will be returned. If False, it will be transformed back to a transfer function prior to being returned.
- Returns
Spectrum array with appropriately spaced abscissa
- Return type
Notes
This function will automatically set the last frequency line of the SpectrumArray to zero because it won’t be accurate anyway. If time_response_padded_length is less than the current function’s num_elements, then it will be truncated instead of zero-padded.
- plot(one_axis=True, subplots_kwargs={}, plot_kwargs={}, abscissa_markers=None, abscissa_marker_labels=None, abscissa_marker_type='vline', abscissa_marker_plot_kwargs={})[source]
Plot the spectra
- Parameters
one_axis (bool, optional) – Set to True to plot all data on one axis. Set to False to plot data on multiple subplots. one_axis can also be set to a matplotlib axis to plot data on an existing axis. The default is True.
subplots_kwargs (dict, optional) – Keywords passed to the matplotlib subplots function to create the figure and axes. The default is {}.
plot_kwargs (dict, optional) – Keywords passed to the matplotlib plot function. The default is {}.
abscissa_markers (ndarray, optional) – Array containing abscissa values to mark on the plot to denote significant events.
abscissa_marker_labels (str or ndarray) – Array of strings to label the abscissa_markers with, or alternatively a format string that accepts index and abscissa inputs (e.g. ‘{index:}: {abscissa:0.2f}’). By default no label will be applied.
abscissa_marker_type (str) – The type of marker to use. This can either be the string ‘vline’ or a valid matplotlib symbol specifier (e.g. ‘o’, ‘x’, ‘.’).
abscissa_marker_plot_kwargs (dict) – Additional keyword arguments used when plotting the abscissa label markers.
- Returns
axis – On which the data were plotted
- Return type
matplotlib axis or array of axes
- plot_spectrogram(abscissa=None, axis=None, subplots_kwargs={}, pcolormesh_kwargs={'shading': 'auto'}, log_scale=True)[source]
Plots a spectrogram
- Parameters
abscissa (np.ndarray) – Optional argument to specify as the abscissa values. If not specified, this will be the index of the flattened SpectrumArray.
axis (matplotlib.axis, optional) – An optional argument that specifies the axis to plot the spectrogram on
subplots_kwargs (dict, optional) – Optional keywords to specify to the subplots function that creates a new figure if axis is not specified.
pcolormesh_kwargs (dict, optional) – Optional arguments to pass to the pcolormesh function
log_scale (bool) – If True, the colormap will be applied logarithmically
- Returns
ax – The axis on which the spectrogram was plotted
- Return type
matplotlib.axis