Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change calculation of admittance value and unit in marker plotting code #446

Merged
merged 1 commit into from
Jan 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions NanoVNASaver/Formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,18 @@ def format_phase(val: float) -> str:
return f"{math.degrees(val):.2f}""\N{DEGREE SIGN}"


def format_complex_adm(z: complex, allow_negative: bool = False) -> str:
if z == 0:
return "- S"
adm = 1/z

fmt_re = FMT_COMPLEX
if allow_negative:
fmt_re = FMT_COMPLEX_NEG
re = SITools.Value(adm.real, fmt=fmt_re)
im = SITools.Value(abs(adm.imag), fmt=FMT_COMPLEX)
return f"{re}{'-' if adm.imag < 0 else '+'}j{im} S"

def format_complex_imp(z: complex, allow_negative: bool = False) -> str:
fmt_re = FMT_COMPLEX
if allow_negative:
Expand Down
3 changes: 2 additions & 1 deletion NanoVNASaver/Marker/Delta.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from NanoVNASaver import RFTools
from NanoVNASaver.Formatting import (
format_capacitance,
format_complex_adm,
format_complex_imp,
format_frequency_space,
format_gain,
Expand Down Expand Up @@ -90,7 +91,7 @@ def updateLabels(self): # pylint: disable=arguments-differ
format_frequency_space(s11_b.freq - s11_a.freq))
self.label['lambda'].setText(
format_wavelength(s11_b.wavelength - s11_a.wavelength))
self.label['admittance'].setText(format_complex_imp(imp_p, True))
self.label['admittance'].setText(format_complex_adm(imp_p, True))
self.label['impedance'].setText(format_complex_imp(imp, True))

self.label['parc'].setText(cap_p_str)
Expand Down
3 changes: 2 additions & 1 deletion NanoVNASaver/Marker/Widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from NanoVNASaver import RFTools
from NanoVNASaver.Formatting import (
format_capacitance,
format_complex_adm,
format_complex_imp,
format_frequency_space,
format_gain,
Expand Down Expand Up @@ -328,7 +329,7 @@ def updateLabels(self,

self.label['actualfreq'].setText(format_frequency_space(_s11.freq))
self.label['lambda'].setText(format_wavelength(_s11.wavelength))
self.label['admittance'].setText(format_complex_imp(imp_p))
self.label['admittance'].setText(format_complex_adm(imp))
self.label['impedance'].setText(format_complex_imp(imp))
self.label['parc'].setText(cap_p_str)
self.label['parl'].setText(ind_p_str)
Expand Down