Wfm
- class RigolWFM.wfm.Wfm(file_name: str)[source]
Bases:
objectClass with parsed data from a waveform file.
Methods Summary
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, frame])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.
pwl()Return a piecewise linear (PWL) table for LTspice.
Return a string of comma separated values for sigrok.
trim(duration)Trim every trace to a window of duration around the displayed point.
wav(filename, *[, channel, scale])Save one or two channels as a signed 16-bit WAV file.
Methods Documentation
- classmethod from_file(file_name: str, model: str = 'auto', selected: str = '1234', frame: int = 0) 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’
frame – zero-based frame of a Tektronix FastFrame capture; other formats hold a single frame and accept only 0
- 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.
- pwl() str[source]
Return a piecewise linear (PWL) table for LTspice.
Unlike a WAV source, which LTspice interprets using a fixed -1 V to +1 V full-scale range, a PWL file contains explicit time/voltage pairs, preserving the waveform’s voltage scale and offset. It is a headerless, two-column plain-text file representing one waveform; this exporter uses tabs as separators.
Since a PWL source starts when the simulation does, times are shifted so that the first sample sits at t=0. Both columns carry seven significant digits, which keeps the file small while staying well inside the resolution of any scope this library reads.
- Returns:
The PWL table, or an empty string when no channel carries data.
- Raises:
ValueError – if more than one channel is enabled and selected, since one file describes one waveform.
- trim(duration: float) None[source]
Trim every trace to a window of duration around the displayed point.
One window is computed and applied to the analog channels and the logic traces alike, so a trimmed export stays aligned across all of them. The window is centered on the time offset the scope was displaying and slid back inside the record if it would overhang either end; a duration longer than the record keeps everything.
- Parameters:
duration – length of the window to keep, in seconds.
- 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=0and the second aschan=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, setVpeakon 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, setVpeak = 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.