Wfm

class RigolWFM.Wfm(file_name: str)[source]

Bases: object

Class with parsed data from a waveform file.

Methods Summary

best_scaling()

Return appropriate scaling for plot.

csv()

Return a string of comma separated values.

describe()

Return a string describing the contents of the waveform file.

from_file(file_name[, model, selected])

Create Wfm object from a file.

from_url(url[, model, selected])

Return a waveform object given a URL.

mat(filename)

Save waveform arrays as a MATLAB v5 .mat file.

npz(filename)

Save waveform arrays as a NumPy .npz archive.

plot()

Plot the data in oscilloscope style and return the Figure.

sigrokcsv()

Return a string of comma separated values for sigrok.

wav(filename, *[, channel, scale])

Save one or two channels as a signed 16-bit WAV file.

Methods Documentation

best_scaling() tuple[float, str, float, str][source]

Return appropriate scaling for plot.

csv() str[source]

Return a string of comma separated values.

describe() str[source]

Return a string describing the contents of the waveform file.

classmethod from_file(file_name: str, model: str = 'auto', selected: str = '1234') Wfm[source]

Create Wfm object from a file.

Parameters:
  • file_name – name of file

  • model – oscilloscope family, e.g. ‘E’, ‘Z’, ‘LeCroy’, ‘Tek’; defaults to auto-detect

  • selected – string of channels to process e.g., ‘12’

Returns:

a Wfm object for the file

classmethod from_url(url: str, model: str = 'auto', selected: str = '1234') Wfm[source]

Return a waveform object given a URL.

This is a bit complicated because the parser must have a local file to work with. The process is to download the file to a temporary location and then process that file. There is a lot that can go wrong - bad url, bad download, or an error parsing the file.

Parameters:
  • url – location of the file

  • model – oscilloscope family, e.g. ‘E’ or ‘Z’; defaults to auto-detect

  • selected – string of channels to process e.g., ‘12’

Returns:

a Wfm object for the file

mat(filename: str | PathLike[str] | IO[bytes]) None[source]

Save waveform arrays as a MATLAB v5 .mat file.

npz(filename: str | PathLike[str] | IO[bytes]) None[source]

Save waveform arrays as a NumPy .npz archive.

plot() Figure[source]

Plot the data in oscilloscope style and return the Figure.

sigrokcsv() str[source]

Return a string of comma separated values for sigrok.

wav(filename: str | PathLike[str] | IO[bytes], *, channel: int | list[int] = 1, scale: Literal['auto', 'scope'] = 'auto') None[source]

Save one or two channels as a signed 16-bit WAV file.

Parameters:
  • filename – Destination path (str or PathLike) or a writable binary file-like object.

  • channel – Channel number(s) to export. Pass a single int for mono output, or a list of two ints for stereo output. Each channel must be enabled and selected. In LTspice, the first channel is addressed as chan=0 and the second as chan=1.

  • scale – How to map voltages to the ±32767 integer range. "auto" maps each channel’s own min/max volts to ±32767. This preserves waveform shape, but absolute voltage information is lost. In LTspice, set Vpeak on the WAV source to half the signal’s peak-to-peak voltage.

    "scope" maps each channel’s ±(4 × V/div) full-scale range to ±32767 while keeping zero volts at zero. In LTspice, set Vpeak = 4 × V/div.

Raises:

ValueError – If more than two channels are requested, or if any requested channel is not found, not enabled, or not selected.