waveform_base

class wavgen.waveform_base.Waveform(sample_length, amp=1.0)[source]

Bases: object

Basic Waveform object.

Attention

All other defined waveform objects (below) extend this class; therefore, they all share these attributes, at the least.

cls.OpenTemps

Tracks the number of Waveforms not explicitly saved to file. (temporarily saved) Necessary because, even if not explicitly asked to save to file, the system employs temporary files which make handling any sized waveform simple.

Type

int, Class Object

SampleLength

How long the waveform is in 16-bit samples.

Type

int

Amplitude

Fraction of the maximum card output voltage, to which the waveform is normalized to. (AKA relative amplitude between other Waveform objects)

Type

float

PlotObjects

List of matplotlib objects, so that they aren’t garbage collected.

Type

list

Latest

Indicates if the data reflects the most recent waveform definition.

Type

bool

FilePath

The name of the file where the waveform is saved.

Type

str

DataPath

The HDF5 pathway to where this waveform’s root exists. Used in the case where a single HDF5 file contains a database of several waveforms (Very efficient space wise).

Type

str

__init__(sample_length, amp=1.0)[source]
Parameters
  • sample_length (int) – Sets the SampleLength.

  • amp (float, optional) – Amplitude of waveform relative to maximum output voltage.

compute(p, q)[source]

Calculates the pth portion of the entire waveform.

Note

This is the function dispatched to parallel processes. The p argument indicates the interval of the whole waveform to calculate.

Parameters
  • p (int) – Index, starting from 0, indicating which interval of the whole waveform should be calculated. Intervals are size DATA_MAX in samples.

  • q (multiprocessing.Queue) – A Queue object shared by multiple processes. Each process places there results here once done, to be collected by the parent process.

compute_waveform(filepath=False, datapath=False, cpus=None)[source]

Computes the waveform to disk. If no filepath is given, then waveform data will be destroyed upon object cleanup.

Parameters
  • filepath (str, optional) – Searches for an HDF5 database file with the given name. If none exists, then one is created. If not provided, saves the waveform to a temporary file.

  • datapath (str, optional) – Describes a path to a group in the HDF5 database for saving this particular waveform dataset.

  • cpus (int, optional) – Sets the desired number of CPUs to utilized for the calculation. Will round down if too large a number given.

Note

The filepath parameter does not need to include a file-extension; only a name.

load(buffer, offset, size)[source]

Loads a portion of the waveform.

Parameters
  • buffer (numpy or h5py array) – Location to load data into.

  • offset (int) – Offset from the waveforms beginning in samples.

  • size (int) – How much waveform to load in samples.

plot()[source]

Convenient alias for plot_waveform()

rms2()[source]

Calculates the Mean Squared value of the Waveform.

Returns

Mean Squared sample value, normalized to be within [0, 1].

Return type

float

_valid_savepath(filepath, datapath)[source]

Checks specified location for pre-existing waveform.

If the desired data-path is discovered to be already occupied, the options are offered to Overwrite, Abort, or try a new location.

Parameters
  • filepath (str) – Potential name for HDF5 file to write to.

  • datapath (str) – Potential path in HDF5 file hierarchy to write to.

Returns

Returns a tuple of strings indicating the path-to-file & path-to-hdf5 group.

Return type

(str, str)