mpylab.tools.vna_data module¶
Read VNA traces and serialize phase-preserving, power-scaled DAT data.
- class mpylab.tools.vna_data.Trace(frequency: object, db: object, phase: object, parameter: str, reference: tuple = ())
Bases:
objectOne VNA trace, with frequencies in Hz, magnitude in dB and phase in degrees.
- Parameters:
frequency (array-like) – Strictly increasing, finite, nonnegative frequencies.
db (array-like) – Finite magnitude and phase arrays of the same length.
phase (array-like) – Finite magnitude and phase arrays of the same length.
parameter (str) – Trace name or S-parameter identifier.
reference (tuple of float, optional) – Touchstone reference resistances in ohms, one per port.
- db: object
- frequency: object
- parameter: str
- phase: object
- reference: tuple = ()
- mpylab.tools.vna_data.detect_sweep(frequencies, *, rtol=1e-05)
Classify frequency spacing without resampling.
- Parameters:
frequencies (array-like) – Strictly increasing, finite, nonnegative frequencies in Hz.
rtol (float, optional) – Relative spacing tolerance, default 1e-5.
- Returns:
linear,log,irregularorambiguous.- Return type:
str
- Raises:
ValueError – If the frequencies or tolerance are invalid.
- mpylab.tools.vna_data.read_csv(path, *, parameter=None, delimiter=None, columns=None, frequency_unit=None, skip_rows=0)
Read a VNA CSV with named dB/angle columns or explicit column indices.
- Parameters:
path (path-like) – UTF-8 CSV file (an optional BOM is accepted).
parameter (str, optional) – S-parameter to select, or
all. Ambiguous traces require selection.delimiter (str, optional) – Single-character CSV separator; by default detect comma, semicolon or tab.
columns (tuple of int, optional) – Zero-based frequency, dB and phase column indices. Bypasses header discovery.
frequency_unit (str, optional) – Hz, kHz, MHz or GHz. Required with explicit columns.
skip_rows (int, optional) – Number of initial physical lines to skip.
- Returns:
Selected traces in file order.
- Return type:
list of Trace
- Raises:
ValueError – If headers, numeric records or the frequency axis are invalid.
OSError – If the source cannot be read.
- mpylab.tools.vna_data.read_touchstone(path, *, parameter=None)
Read one- or two-port single-ended Touchstone S data.
- Parameters:
path (path-like) – .s1p, .s2p or Touchstone 2.0 .ts source.
parameter (str, optional) – Sij to extract, or
all. Two-port files require explicit selection.
- Returns:
Traces with unchanged reference resistances. No renormalization occurs.
- Return type:
list of Trace
- Raises:
ValueError – If malformed or unsupported, including noise data, mixed mode, zero magnitude, non-full matrices, or port counts other than one and two.
OSError – If the source cannot be read.
Notes
The supported 2.0 subset requires Version, Number of Ports, Number of Frequencies, Network Data and End; two-port data also needs Two-Port Data Order. Unknown keywords are rejected, not silently ignored.
- mpylab.tools.vna_data.render_dat(trace, *, source='', magnitude_error_db=0.2, phase_error_deg=1.0, sweep_rtol=1e-05)
Render validated polar dB DAT text, preserving the input frequency grid.
- Parameters:
trace (Trace) – VNA values to serialize.
source (str, optional) – Source label recorded in a comment.
magnitude_error_db (float, optional) – Symmetric dB half-span, default 0.2.
phase_error_deg (float, optional) – Phase standard uncertainty, default 1 degree, strictly below 180.
sweep_rtol (float, optional) – Relative tolerance used for the sweep classification comment.
- Returns:
DAT text with explicit lower, nominal and upper polar values.
- Return type:
str
- Raises:
ValueError – If errors or values cannot be represented by the DAT uncertainty model.
Notes
The reader uses half the linearized magnitude span as its standard uncertainty. Magnitude and phase uncertainties are independent; no frequency-to-frequency correlations are inferred.