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_kwargs])

Plot the transfer functions

plot_spectrogram([abscissa, axis, ...])

Plots a spectrogram

Attributes

function_type

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

TimeHistoryArray

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

SpectrumArray or TimeHistoryArray

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={})[source]

Plot the transfer functions

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 {}.

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