Skip to content

Commit

Permalink
just linting
Browse files Browse the repository at this point in the history
  • Loading branch information
zarath committed May 27, 2022
1 parent ee3048d commit 00d9884
Show file tree
Hide file tree
Showing 33 changed files with 146 additions and 146 deletions.
12 changes: 6 additions & 6 deletions NanoVNASaver/Analysis/Analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Analysis:

@classmethod
def find_crossing_zero(cls, data):
'''
"""
Find values crossing zero
return list of tuples (before, crossing, after)
Expand All @@ -44,7 +44,7 @@ def find_crossing_zero(cls, data):
:param cls:
:param data: list of values
'''
"""
my_data = np.array(data)
zeroes = np.where(my_data == 0)[0]

Expand All @@ -65,7 +65,7 @@ def find_crossing_zero(cls, data):

@classmethod
def find_minimums(cls, data, threshold):
'''
"""
Find values above threshold
return list of tuples (start, lowest, end)
Expand All @@ -75,7 +75,7 @@ def find_minimums(cls, data, threshold):
:param cls:
:param data: list of values
:param threshold:
'''
"""

minimums = []
min_start = -1
Expand All @@ -100,15 +100,15 @@ def find_minimums(cls, data, threshold):

@classmethod
def find_maximums(cls, data, threshold=None):
'''
"""
Find peacs
:param cls:
:param data: list of values
:param threshold:
'''
"""
peaks, _ = signal.find_peaks(
data, width=2, distance=3, prominence=1)

Expand Down
8 changes: 4 additions & 4 deletions NanoVNASaver/Analysis/AntennaAnalysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@


class MagLoopAnalysis(VSWRAnalysis):
'''
"""
Find min vswr and change sweep to zoom.
Useful for tuning magloop.
'''
"""
max_dips_shown = 1

vswr_bandwith_value = 2.56 # -3 dB ?!?
Expand Down Expand Up @@ -115,10 +115,10 @@ def runAnalysis(self):
QTimer.singleShot(2000, self._safe_sweep)

def _safe_sweep(self):
'''
"""
sweep only if button enabled
to prevent multiple/concurrent sweep
'''
"""

if self.app.sweep_control.btn_start.isEnabled():
self.app.sweep_start()
Expand Down
20 changes: 9 additions & 11 deletions NanoVNASaver/Analysis/VSWRAnalysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,10 @@ def runAnalysis(self):
for _ in range(results_header, self.layout.rowCount()):
self.layout.removeRow(self.layout.rowCount() - 1)

# if len(crossing) > max_dips_shown:
# self.layout.addRow(QtWidgets.QLabel("<b>More than " + str(max_dips_shown) +
# " dips found. Lowest shown.</b>"))
# self.crossing = crossing[:max_dips_shown]
# if len(crossing) > max_dips_shown:
# self.layout.addRow(QtWidgets.QLabel("<b>More than " + str(max_dips_shown) +
# " dips found. Lowest shown.</b>"))
# self.crossing = crossing[:max_dips_shown]
if len(crossing) > 0:
extended_data = []
for m in crossing:
Expand Down Expand Up @@ -262,9 +262,9 @@ def runAnalysis(self):


class EFHWAnalysis(ResonanceAnalysis):
'''
"""
find only resonance when HI impedance
'''
"""
old_data = []

def reset(self):
Expand Down Expand Up @@ -296,7 +296,7 @@ def runAnalysis(self):

extended_data = OrderedDict()

#both = np.intersect1d([i[1] for i in crossing], maximums)
# both = np.intersect1d([i[1] for i in crossing], maximums)
both = []

tolerance = 2
Expand All @@ -320,7 +320,6 @@ def runAnalysis(self):
else:
extended_data[m] = my_data
for i in range(min(len(both), len(self.app.markers))):

# self.app.markers[i].label = {}
# for l in TYPES:
# self.app.markers[i][l.label_id] = MarkerLabel(l.name)
Expand Down Expand Up @@ -366,7 +365,6 @@ def runAnalysis(self):
self.old_data.append(extended_data)

for i, index in enumerate(sorted(extended_data.keys())):

self.layout.addRow(
f"{format_frequency_short(self.app.data.s11[index].freq)}",
QtWidgets.QLabel(f" ({diff[i]['freq']})"
Expand All @@ -389,15 +387,15 @@ def runAnalysis(self):
writer.writerow(row)

def compare(self, old, new, fields=None):
'''
"""
Compare data to help changes
NB
must be same sweep
( same index must be same frequence )
:param old:
:param new:
'''
"""
fields = fields or [("freq", str), ]

def no_compare():
Expand Down
34 changes: 17 additions & 17 deletions NanoVNASaver/Calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,14 +198,14 @@ def _calc_port_1(self, freq: int, cal: CalData):
g2 * g3 * gm2 - g2 * g3 * gm3 -
(g2 * gm2 - g3 * gm3) * g1)
cal["e00"] = - ((g2 * gm3 - g3 * gm3) * g1 * gm2 -
(g2 * g3 * gm2 - g2 * g3 * gm3 -
(g3 * gm2 - g2 * gm3) * g1) * gm1
) / denominator
(g2 * g3 * gm2 - g2 * g3 * gm3 -
(g3 * gm2 - g2 * gm3) * g1) * gm1
) / denominator
cal["e11"] = ((g2 - g3) * gm1 - g1 * (gm2 - gm3) +
g3 * gm2 - g2 * gm3) / denominator
g3 * gm2 - g2 * gm3) / denominator
cal["delta_e"] = - ((g1 * (gm2 - gm3) - g2 * gm2 + g3 *
gm3) * gm1 + (g2 * gm3 - g3 * gm3) *
gm2) / denominator
gm3) * gm1 + (g2 * gm3 - g3 * gm3) *
gm2) / denominator

def _calc_port_2(self, freq: int, cal: CalData):
gt = self.gamma_through(freq)
Expand All @@ -218,9 +218,9 @@ def _calc_port_2(self, freq: int, cal: CalData):
cal["e30"] = cal["isolation"].z
cal["e10e01"] = cal["e00"] * cal["e11"] - cal["delta_e"]
cal["e22"] = gm7 / (
gm7 * cal["e11"] * gt**2 + cal["e10e01"] * gt**2)
gm7 * cal["e11"] * gt ** 2 + cal["e10e01"] * gt ** 2)
cal["e10e32"] = (gm4 - gm6) * (
1 - cal["e11"] * cal["e22"] *gt**2) / gt
1 - cal["e11"] * cal["e22"] * gt ** 2) / gt

def calc_corrections(self):
if not self.isValid1Port():
Expand Down Expand Up @@ -254,8 +254,8 @@ def gamma_short(self, freq: int) -> complex:
if not self.useIdealShort:
logger.debug("Using short calibration set values.")
Zsp = complex(0, 2 * math.pi * freq * (
self.shortL0 + self.shortL1 * freq +
self.shortL2 * freq**2 + self.shortL3 * freq**3))
self.shortL0 + self.shortL1 * freq +
self.shortL2 * freq ** 2 + self.shortL3 * freq ** 3))
# Referencing https://arxiv.org/pdf/1606.02446.pdf (18) - (21)
g = (Zsp / 50 - 1) / (Zsp / 50 + 1) * cmath.exp(
complex(0, 2 * math.pi * 2 * freq * self.shortLength * -1))
Expand All @@ -266,8 +266,8 @@ def gamma_open(self, freq: int) -> complex:
if not self.useIdealOpen:
logger.debug("Using open calibration set values.")
Zop = complex(0, 2 * math.pi * freq * (
self.openC0 + self.openC1 * freq +
self.openC2 * freq**2 + self.openC3 * freq**3))
self.openC0 + self.openC1 * freq +
self.openC2 * freq ** 2 + self.openC3 * freq ** 3))
g = ((1 - 50 * Zop) / (1 + 50 * Zop)) * cmath.exp(
complex(0, 2 * math.pi * 2 * freq * self.openLength * -1))
return g
Expand Down Expand Up @@ -324,8 +324,8 @@ def gen_interpolation(self):
kind="slinear", bounds_error=False,
fill_value=(delta_e[0], delta_e[-1])),
"e10e01": interp1d(freq, e10e01,
kind="slinear", bounds_error=False,
fill_value=(e10e01[0], e10e01[-1])),
kind="slinear", bounds_error=False,
fill_value=(e10e01[0], e10e01[-1])),
"e30": interp1d(freq, e30,
kind="slinear", bounds_error=False,
fill_value=(e30[0], e30[-1])),
Expand All @@ -340,13 +340,13 @@ def gen_interpolation(self):
def correct11(self, dp: Datapoint):
i = self.interp
s11 = (dp.z - i["e00"](dp.freq)) / (
(dp.z * i["e11"](dp.freq)) - i["delta_e"](dp.freq))
(dp.z * i["e11"](dp.freq)) - i["delta_e"](dp.freq))
return Datapoint(dp.freq, s11.real, s11.imag)

def correct21(self, dp: Datapoint, dp11: Datapoint):
i = self.interp
s21 = (dp.z - i["e30"](dp.freq)) / i["e10e32"](dp.freq)
s21 = s21 * (i["e10e01"](dp.freq)/(i["e11"](dp.freq)*dp11.z-i["delta_e"](dp.freq)))
s21 = s21 * (i["e10e01"](dp.freq) / (i["e11"](dp.freq) * dp11.z - i["delta_e"](dp.freq)))
return Datapoint(dp.freq, s21.real, s21.imag)

# TODO: implement tests
Expand Down Expand Up @@ -381,7 +381,7 @@ def load(self, filename):
continue
if line.startswith("#"):
if not parsed_header and line == (
"# Hz ShortR ShortI OpenR OpenI LoadR LoadI"
"# Hz ShortR ShortI OpenR OpenI LoadR LoadI"
" ThroughR ThroughI ThrureflR ThrureflI IsolationR IsolationI"):
parsed_header = True
continue
Expand Down
1 change: 1 addition & 0 deletions NanoVNASaver/Controls/Control.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

logger = logging.getLogger(__name__)


class Control(QtWidgets.QGroupBox):
updated = QtCore.pyqtSignal(object)

Expand Down
4 changes: 2 additions & 2 deletions NanoVNASaver/Controls/MarkerControl.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,11 @@
from NanoVNASaver.Marker import Marker
from NanoVNASaver.Controls.Control import Control


logger = logging.getLogger(__name__)


class ShowButton(QtWidgets.QPushButton):
def setText(self, text: str=''):
def setText(self, text: str = ''):
if not text:
text = ("Show data"
if Defaults.cfg.gui.markers_hidden else "Hide data")
Expand Down Expand Up @@ -87,6 +86,7 @@ def settings(hidden: bool):
Defaults.cfg.gui.markers_hidden)
self.showMarkerButton.setText()
self.showMarkerButton.repaint()

settings(self.app.marker_frame.isHidden())

def toggle_delta(self):
Expand Down
1 change: 1 addition & 0 deletions NanoVNASaver/Controls/SerialControl.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

logger = logging.getLogger(__name__)


class SerialControl(Control):

def __init__(self, app: QtWidgets.QWidget):
Expand Down
8 changes: 5 additions & 3 deletions NanoVNASaver/Formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.
import math
from numbers import Number
from typing import Union

from NanoVNASaver import SITools

Expand All @@ -42,13 +43,14 @@
parse_clamp_min=0)
FMT_PARSE_VALUE = SITools.Format(
parse_sloppy_unit=True, parse_sloppy_kilo=True)
FMT_VSWR = SITools.Format(max_nr_digits=3)


def format_frequency(freq: Number) -> str:
return str(SITools.Value(freq, "Hz", FMT_FREQ))


def format_frequency_inputs(freq: float) -> str:
def format_frequency_inputs(freq: Union[Number, str]) -> str:
return str(SITools.Value(freq, "Hz", FMT_FREQ_INPUTS))


Expand Down Expand Up @@ -140,7 +142,7 @@ def format_wavelength(length: Number) -> str:
return str(SITools.Value(length, "m", FMT_WAVELENGTH))


def format_y_axis(val: float, unit: str="") -> str:
def format_y_axis(val: float, unit: str = "") -> str:
return str(SITools.Value(val, unit, FMT_SHORT))


Expand All @@ -152,7 +154,7 @@ def parse_frequency(freq: str) -> int:


def parse_value(val: str, unit: str = "",
fmt: SITools.Format = FMT_PARSE_VALUE) -> int:
fmt: SITools.Format = FMT_PARSE_VALUE) -> float:
try:
val.replace(',', '.')
return float(SITools.Value(val, unit, fmt))
Expand Down
Loading

0 comments on commit 00d9884

Please sign in to comment.