nitypes.waveform.Spectrum

class nitypes.waveform.Spectrum(sample_count: SupportsIndex | None = ..., dtype: None = ..., *, data: None = ..., start_index: SupportsIndex | None = ..., capacity: SupportsIndex | None = ..., start_frequency: SupportsFloat | None = ..., frequency_increment: SupportsFloat | None = ..., extended_properties: collections.abc.Mapping[str, nitypes.waveform.typing.ExtendedPropertyValue] | None = ..., copy_extended_properties: bool = ...)
class Spectrum(sample_count: SupportsIndex | None = ..., dtype: type[_TOtherData] | numpy.dtype[_TOtherData] = ..., *, data: None = ..., start_index: SupportsIndex | None = ..., capacity: SupportsIndex | None = ..., start_frequency: SupportsFloat | None = ..., frequency_increment: SupportsFloat | None = ..., extended_properties: collections.abc.Mapping[str, nitypes.waveform.typing.ExtendedPropertyValue] | None = ..., copy_extended_properties: bool = ...)
class Spectrum(sample_count: SupportsIndex | None = ..., dtype: None = ..., *, data: numpy.typing.NDArray[_TOtherData] = ..., start_index: SupportsIndex | None = ..., capacity: SupportsIndex | None = ..., start_frequency: SupportsFloat | None = ..., frequency_increment: SupportsFloat | None = ..., extended_properties: collections.abc.Mapping[str, nitypes.waveform.typing.ExtendedPropertyValue] | None = ..., copy_extended_properties: bool = ...)
class Spectrum(sample_count: SupportsIndex | None = ..., dtype: numpy.typing.DTypeLike = ..., *, data: numpy.typing.NDArray[Any] | None = ..., start_index: SupportsIndex | None = ..., capacity: SupportsIndex | None = ..., start_frequency: SupportsFloat | None = ..., frequency_increment: SupportsFloat | None = ..., extended_properties: collections.abc.Mapping[str, nitypes.waveform.typing.ExtendedPropertyValue] | None = ..., copy_extended_properties: bool = ...)

Bases: Generic[_TData]

A frequency spectrum, which encapsulates analog data and frequency information.

Constructing

To construct a frequency spectrum, use the Spectrum class:

>>> Spectrum()
nitypes.waveform.Spectrum(0)
>>> Spectrum(5)
nitypes.waveform.Spectrum(5, data=array([0., 0., 0., 0., 0.]))

To construct a frequency spectrum from a NumPy array, use the Spectrum.from_array_1d method.

>>> import numpy as np
>>> Spectrum.from_array_1d(np.array([1.0, 2.0, 3.0]))
nitypes.waveform.Spectrum(3, data=array([1., 2., 3.]))

You can also use Spectrum.from_array_1d to construct a frequency spectrum from a sequence, such as a list. In this case, you must specify the NumPy data type.

>>> Spectrum.from_array_1d([1.0, 2.0, 3.0], np.float64)
nitypes.waveform.Spectrum(3, data=array([1., 2., 3.]))

The 2D version, Spectrum.from_array_2d, returns multiple waveforms, one for each row of data in the array or nested sequence.

>>> nested_list = [[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]]
>>> Spectrum.from_array_2d(nested_list, np.float64)
[nitypes.waveform.Spectrum(3, data=array([1., 2., 3.])),
nitypes.waveform.Spectrum(3, data=array([4., 5., 6.]))]

Class members

classmethod from_array_1d(array: numpy.typing.NDArray[_TOtherData], dtype: None = ..., *, copy: bool = ..., start_index: SupportsIndex | None = ..., sample_count: SupportsIndex | None = ..., start_frequency: SupportsFloat | None = ..., frequency_increment: SupportsFloat | None = ..., extended_properties: collections.abc.Mapping[str, nitypes.waveform.typing.ExtendedPropertyValue] | None = ...) Spectrum[_TOtherData]
classmethod from_array_1d(array: numpy.typing.NDArray[Any] | collections.abc.Sequence[Any], dtype: type[_TOtherData] | numpy.dtype[_TOtherData], *, copy: bool = ..., start_index: SupportsIndex | None = ..., sample_count: SupportsIndex | None = ..., start_frequency: SupportsFloat | None = ..., frequency_increment: SupportsFloat | None = ..., extended_properties: collections.abc.Mapping[str, nitypes.waveform.typing.ExtendedPropertyValue] | None = ...) Spectrum[_TOtherData]
classmethod from_array_1d(array: numpy.typing.NDArray[Any] | collections.abc.Sequence[Any], dtype: numpy.typing.DTypeLike = ..., *, copy: bool = ..., start_index: SupportsIndex | None = ..., sample_count: SupportsIndex | None = ..., start_frequency: SupportsFloat | None = ..., frequency_increment: SupportsFloat | None = ..., extended_properties: collections.abc.Mapping[str, nitypes.waveform.typing.ExtendedPropertyValue] | None = ...) Spectrum[Any]

Construct a spectrum from a one-dimensional array or sequence.

Parameters:
  • array – The spectrum data as a one-dimensional array or a sequence.

  • dtype – The NumPy data type for the spectrum data. This argument is required when array is a sequence.

  • copy – Specifies whether to copy the array or save a reference to it.

  • start_index – The sample index at which the spectrum data begins.

  • sample_count – The number of samples in the spectrum.

  • start_frequency – The start frequency of the spectrum.

  • frequency_increment – The frequency increment of the spectrum.

  • extended_properties – The extended properties of the spectrum.

Returns:

A spectrum containing the specified data.

classmethod from_array_2d(array: numpy.typing.NDArray[_TOtherData], dtype: None = ..., *, copy: bool = ..., start_index: SupportsIndex | None = ..., sample_count: SupportsIndex | None = ..., start_frequency: SupportsFloat | None = ..., frequency_increment: SupportsFloat | None = ..., extended_properties: collections.abc.Mapping[str, nitypes.waveform.typing.ExtendedPropertyValue] | None = ...) collections.abc.Sequence[Spectrum[_TOtherData]]
classmethod from_array_2d(array: numpy.typing.NDArray[Any] | collections.abc.Sequence[collections.abc.Sequence[Any]], dtype: type[_TOtherData] | numpy.dtype[_TOtherData], *, copy: bool = ..., start_index: SupportsIndex | None = ..., sample_count: SupportsIndex | None = ..., start_frequency: SupportsFloat | None = ..., frequency_increment: SupportsFloat | None = ..., extended_properties: collections.abc.Mapping[str, nitypes.waveform.typing.ExtendedPropertyValue] | None = ...) collections.abc.Sequence[Spectrum[_TOtherData]]
classmethod from_array_2d(array: numpy.typing.NDArray[Any] | collections.abc.Sequence[collections.abc.Sequence[Any]], dtype: numpy.typing.DTypeLike = ..., *, copy: bool = ..., start_index: SupportsIndex | None = ..., sample_count: SupportsIndex | None = ..., start_frequency: SupportsFloat | None = ..., frequency_increment: SupportsFloat | None = ..., extended_properties: collections.abc.Mapping[str, nitypes.waveform.typing.ExtendedPropertyValue] | None = ...) collections.abc.Sequence[Spectrum[Any]]

Construct a list of spectrums from a two-dimensional array or nested sequence.

Parameters:
  • array – The spectrum data as a two-dimensional array or a nested sequence.

  • dtype – The NumPy data type for the spectrum data. This argument is required when array is a sequence.

  • copy – Specifies whether to copy the array or save a reference to it.

  • start_index – The sample index at which the spectrum data begins.

  • sample_count – The number of samples in the spectrum.

  • start_frequency – The start frequency of the spectrum.

  • frequency_increment – The frequency increment of the spectrum.

  • extended_properties – The extended properties of the spectrum.

Returns:

A list containing a spectrum for each row of the specified data.

When constructing multiple spectrums, the same extended properties, timing information, and scale mode are applied to all spectrums. Consider assigning these properties after construction.

__slots__ = ['_data', '_start_index', '_sample_count', '_start_frequency', '_frequency_increment',...
property data: numpy.typing.NDArray[_TData]

The spectrum data.

get_data(start_index: SupportsIndex | None = 0, sample_count: SupportsIndex | None = None) numpy.typing.NDArray[_TData]

Get a subset of the spectrum data.

Parameters:
  • start_index – The sample index at which the data begins.

  • sample_count – The number of samples to return.

Returns:

A subset of the spectrum data.

property sample_count: int

The number of samples in the spectrum.

property start_index: int

The sample index of the underlying array at which the spectrum data begins.

property capacity: int

The total capacity available for spectrum data.

Setting the capacity resizes the underlying NumPy array in-place.

  • Other Python objects with references to the array will see the array size change.

  • If the array has a reference to an external buffer (such as an array.array), attempting to resize it raises ValueError.

property dtype: numpy.dtype[_TData]

The NumPy dtype for the spectrum data.

property start_frequency: float

The start frequency of the spectrum.

property frequency_increment: float

The frequency increment of the spectrum.

property extended_properties: nitypes.waveform.ExtendedPropertyDictionary

The extended properties for the spectrum.

property channel_name: str

The name of the device channel from which the spectrum was acquired.

property units: str

The unit of measurement, such as volts, of the spectrum.

append(other: numpy.typing.NDArray[_TData] | Spectrum[_TData] | collections.abc.Sequence[Spectrum[_TData]], /) None

Append data to the spectrum.

Parameters:

other – The array or spectrum(s) to append.

Raises:
  • ValueError – The other array has the wrong number of dimensions.

  • TypeError – The data types of the current spectrum and other array or spectrum(s) do not match, or an argument has the wrong data type.

When appending spectrums:

  • Extended properties of the other spectrum(s) are merged into the current spectrum if they are not already set in the current spectrum.

load_data(array: numpy.typing.NDArray[_TData], *, copy: bool = True, start_index: SupportsIndex | None = 0, sample_count: SupportsIndex | None = None) None

Load new data into an existing spectrum.

Parameters:
  • array – A NumPy array containing the data to load.

  • copy – Specifies whether to copy the array or save a reference to it.

  • start_index – The sample index at which the spectrum data begins.

  • sample_count – The number of samples in the spectrum.

__eq__(value: object, /) bool

Return self==value.

__reduce__() tuple[Any, Ellipsis]

Return object state for pickling.

__repr__() str

Return repr(self).