Defined as:
sdynpy.core.sdynpy_data.SpectrumArrayModule:
sdynpy.core.sdynpy_dataSource: GitHub
Parent:
sdynpy.NDDataArrayParent:
sdynpy.SdynpyArrayParent:
numpy.ndarray
Signature¶
class sdynpy.SpectrumArray(shape, nelements, buffer=None, offset=0, strides=None, order=None)Data array used to store linear spectra (for example scaled FFT results)
Attributes¶
| Name | Summary |
|---|---|
function_type | Returns the function type of the data array |
function_type¶
Returns the function type of the data array
Methods¶
| Name | Summary |
|---|---|
apply_transformation | Applies response transformations spectra. |
ifft | Computes a time signal from the frequency spectrum |
interpolate_by_zero_pad | Interpolates a spectrum by zero padding or truncating its time response |
plot | Plot the spectra |
plot_spectrogram | Plots a spectrogram |
apply_transformation¶
Source: GitHub
def sdynpy.SpectrumArray.apply_transformation(self, transformation, invert_transformation=False)Applies response transformations spectra.
Parameters¶
transformation : Matrix The transformation to apply to the spectra. It should be a SDynPy matrix object with the “transformed” coordinates on the rows and the “physical” coordinates on the columns. The matrix can be either 2D or 3D (for a frequency dependent transform).
invert_reference_transformation : bool, optional Whether or not to invert the transformation when applying it to the spectra. The default is False, which is standard practice. The row/column ordering in the transformation should be flipped if this is set to true.
Returns¶
transformed_spectra : SpectrumArray The spectra with the transformation applied.
Raises¶
ValueError
If the physical degrees of freedom in the transformation does not
match the spectra.
ifft¶
Source: GitHub
def sdynpy.SpectrumArray.ifft(self, norm='backward', rtol=1, atol=1e-08, odd_num_samples=False, **scipy_irfft_kwargs)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.
odd_num_samples : bool, optional If True, then it is assumed that the output signal has an odd number of samples, meaning the signal will have a length of 2*(m-1)+1 where m is the number of frequency lines. Otherwise, the default value of 2*(m-1) is used, assuming an even signal. This is ignored if num_samples is specified.
scipy_irfft_kwargs Additional keywords that will be passed to SciPy’s irfft function.
Returns¶
TimeHistoryArray
The time history of the SpectrumArray.
Raises¶
ValueError
Raised if the spectra passed to this function do not have
equally spaced abscissa.
NotImplementedError
Raised if the user specifies scaling.
Notes¶
Note that the ifft uses the rfft function from scipy to compute the inverse fast fourier transform. This function is not round-trip equivalent for odd functions, because by default it assumes an even signal length. For an odd signal length, the user must either specify odd_num_samples = True or set num_samples to the correct number of samples.
interpolate_by_zero_pad¶
Source: GitHub
def sdynpy.SpectrumArray.interpolate_by_zero_pad(self, time_response_padded_length, return_time_response=False, odd_num_samples=False)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.
odd_num_samples : bool, optional If True, then it is assumed that the spectrum has been constructed from a signal with an odd number of samples. Note that this function uses the rfft function from scipy to compute the inverse fast fourier transform. The irfft function is not round-trip equivalent for odd functions, because by default it assumes an even signal length. For an odd signal length, the user must either specify odd_num_samples = True to make it round-trip equivalent.
Returns¶
SpectrumArray or TimeHistoryArray Spectrum array with appropriately spaced abscissa
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¶
Source: GitHub
def sdynpy.SpectrumArray.plot(self, one_axis=True, subplots_kwargs={}, plot_kwargs={}, abscissa_markers=None, abscissa_marker_labels=None, abscissa_marker_type='vline', abscissa_marker_plot_kwargs={})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 : matplotlib axis or array of axes On which the data were plotted
plot_spectrogram¶
Source: GitHub
def sdynpy.SpectrumArray.plot_spectrogram(self, abscissa=None, axis=None, subplots_kwargs={}, pcolormesh_kwargs={'shading': 'auto'}, log_scale=True)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
axisis 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 : matplotlib.axis The axis on which the spectrogram was plotted