diff --git a/charon_vna/gui.py b/charon_vna/gui.py index 7e53652..e293037 100644 --- a/charon_vna/gui.py +++ b/charon_vna/gui.py @@ -23,6 +23,7 @@ from PySide6.QtWidgets import ( QWidget, ) from skrf import plotting as rf_plt +from util import db20, s2vswr from vna import Charon DEFAULT_CONFIG = dict( @@ -76,7 +77,7 @@ class PlotWidget(QWidget): self.ax.set_ylabel("Amplitude [dB]") def update_logmag(self, data: xr.DataArray) -> None: - self.update_rect(data, lambda s: 20 * np.log10(np.abs(s))) + self.update_rect(data, db20) def setup_phase(self) -> None: self.setup_rect() @@ -93,7 +94,7 @@ class PlotWidget(QWidget): self.ax.set_ylabel("VSWR") def update_vswr(self, data: xr.DataArray) -> None: - self.update_rect(data, lambda s: (1 + np.abs(s)) / (1 - np.abs(s))) + self.update_rect(data, s2vswr) def setup_smith(self) -> None: self.ax.grid(False) diff --git a/charon_vna/util.py b/charon_vna/util.py index e510d71..dff9dcd 100644 --- a/charon_vna/util.py +++ b/charon_vna/util.py @@ -1,6 +1,7 @@ import numpy as np import skrf as rf import xarray as xr +from numpy import typing as npt HAM_BANDS = [ [135.7e3, 137.8e3], @@ -37,12 +38,16 @@ HAM_BANDS = [ ] -def db10(p): +def db10(p: npt.ArrayLike[np.complex128]) -> npt.ArrayLike[float]: return 10 * np.log10(np.abs(p)) -def db20(p): - return 20 * np.log10(np.abs(p)) +def db20(v: npt.ArrayLike[np.complex128]) -> npt.ArrayLike[float]: + return 20 * np.log10(np.abs(v)) + + +def s2vswr(s: npt.ArrayLike[np.complex128]) -> npt.ArrayLike[float]: + return (1 + np.abs(s)) / (1 - np.abs(s)) def minmax(x):