kopia lustrzana https://github.com/NanoVNA-Saver/nanovna-saver
Pylint ...
rodzic
38a54e801c
commit
cb1c1a99f5
|
@ -19,7 +19,7 @@ import math
|
|||
|
||||
from PyQt5 import QtWidgets
|
||||
|
||||
from NanoVNASaver.RFTools import RFTools
|
||||
from NanoVNASaver.Formatting import format_frequency
|
||||
|
||||
from NanoVNASaver.Analysis import Analysis
|
||||
|
||||
|
@ -178,8 +178,9 @@ class BandPassAnalysis(Analysis):
|
|||
lower_cutoff_gain)
|
||||
logger.debug("Found true lower cutoff frequency at %d", lower_cutoff_frequency)
|
||||
|
||||
self.lower_cutoff_label.setText(RFTools.formatFrequency(lower_cutoff_frequency) +
|
||||
" (" + str(round(lower_cutoff_gain, 1)) + " dB)")
|
||||
self.lower_cutoff_label.setText(
|
||||
f"{format_frequency(lower_cutoff_frequency)}"
|
||||
f" ({round(lower_cutoff_gain, 1)} dB)")
|
||||
|
||||
self.app.markers[1].setFrequency(str(lower_cutoff_frequency))
|
||||
self.app.markers[1].frequencyInput.setText(str(lower_cutoff_frequency))
|
||||
|
@ -202,17 +203,19 @@ class BandPassAnalysis(Analysis):
|
|||
logger.debug("Found true upper cutoff frequency at %d", upper_cutoff_frequency)
|
||||
|
||||
self.upper_cutoff_label.setText(
|
||||
RFTools.formatFrequency(upper_cutoff_frequency) +
|
||||
f"{format_frequency(upper_cutoff_frequency)}"
|
||||
f" ({round(upper_cutoff_gain, 1)} dB)")
|
||||
self.app.markers[2].setFrequency(str(upper_cutoff_frequency))
|
||||
self.app.markers[2].frequencyInput.setText(str(upper_cutoff_frequency))
|
||||
|
||||
span = upper_cutoff_frequency - lower_cutoff_frequency
|
||||
center_frequency = math.sqrt(lower_cutoff_frequency * upper_cutoff_frequency)
|
||||
center_frequency = math.sqrt(
|
||||
lower_cutoff_frequency * upper_cutoff_frequency)
|
||||
q = center_frequency / span
|
||||
|
||||
self.span_label.setText(RFTools.formatFrequency(span))
|
||||
self.center_frequency_label.setText(RFTools.formatFrequency(center_frequency))
|
||||
self.span_label.setText(format_frequency(span))
|
||||
self.center_frequency_label.setText(
|
||||
format_frequency(center_frequency))
|
||||
self.quality_label.setText(str(round(q, 2)))
|
||||
|
||||
self.app.markers[0].setFrequency(str(round(center_frequency)))
|
||||
|
@ -231,7 +234,8 @@ class BandPassAnalysis(Analysis):
|
|||
self.result_label.setText("Lower 6 dB location not found.")
|
||||
return
|
||||
lower_six_db_cutoff_frequency = self.app.data21[lower_six_db_location].freq
|
||||
self.lower_six_db_label.setText(RFTools.formatFrequency(lower_six_db_cutoff_frequency))
|
||||
self.lower_six_db_label.setText(
|
||||
format_frequency(lower_six_db_cutoff_frequency))
|
||||
|
||||
ten_db_location = -1
|
||||
for i in range(lower_cutoff_location, -1, -1):
|
||||
|
@ -258,14 +262,14 @@ class BandPassAnalysis(Analysis):
|
|||
if sixty_db_location > 0:
|
||||
sixty_db_cutoff_frequency = self.app.data21[sixty_db_location].freq
|
||||
self.lower_sixty_db_label.setText(
|
||||
RFTools.formatFrequency(sixty_db_cutoff_frequency))
|
||||
format_frequency(sixty_db_cutoff_frequency))
|
||||
elif ten_db_location != -1 and twenty_db_location != -1:
|
||||
ten = self.app.data21[ten_db_location].freq
|
||||
twenty = self.app.data21[twenty_db_location].freq
|
||||
sixty_db_frequency = ten * \
|
||||
10 ** (5 * (math.log10(twenty) - math.log10(ten)))
|
||||
self.lower_sixty_db_label.setText(
|
||||
RFTools.formatFrequency(sixty_db_frequency) + " (derived)")
|
||||
f"{format_frequency(sixty_db_frequency)} (derived)")
|
||||
else:
|
||||
self.lower_sixty_db_label.setText("Not calculated")
|
||||
|
||||
|
@ -293,11 +297,13 @@ class BandPassAnalysis(Analysis):
|
|||
self.result_label.setText("Upper 6 dB location not found.")
|
||||
return
|
||||
upper_six_db_cutoff_frequency = self.app.data21[upper_six_db_location].freq
|
||||
self.upper_six_db_label.setText(RFTools.formatFrequency(upper_six_db_cutoff_frequency))
|
||||
self.upper_six_db_label.setText(
|
||||
format_frequency(upper_six_db_cutoff_frequency))
|
||||
|
||||
six_db_span = upper_six_db_cutoff_frequency - lower_six_db_cutoff_frequency
|
||||
|
||||
self.six_db_span_label.setText(RFTools.formatFrequency(six_db_span))
|
||||
self.six_db_span_label.setText(
|
||||
format_frequency(six_db_span))
|
||||
|
||||
ten_db_location = -1
|
||||
for i in range(upper_cutoff_location, len(self.app.data21), 1):
|
||||
|
@ -323,14 +329,14 @@ class BandPassAnalysis(Analysis):
|
|||
if sixty_db_location > 0:
|
||||
sixty_db_cutoff_frequency = self.app.data21[sixty_db_location].freq
|
||||
self.upper_sixty_db_label.setText(
|
||||
RFTools.formatFrequency(sixty_db_cutoff_frequency))
|
||||
format_frequency(sixty_db_cutoff_frequency))
|
||||
elif ten_db_location != -1 and twenty_db_location != -1:
|
||||
ten = self.app.data21[ten_db_location].freq
|
||||
twenty = self.app.data21[twenty_db_location].freq
|
||||
sixty_db_frequency = ten * \
|
||||
10 ** (5 * (math.log10(twenty) - math.log10(ten)))
|
||||
self.upper_sixty_db_label.setText(
|
||||
RFTools.formatFrequency(sixty_db_frequency) + " (derived)")
|
||||
f"{format_frequency(sixty_db_frequency)} (derived)")
|
||||
else:
|
||||
self.upper_sixty_db_label.setText("Not calculated")
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ import math
|
|||
from PyQt5 import QtWidgets
|
||||
|
||||
from NanoVNASaver.Analysis import Analysis
|
||||
from NanoVNASaver.RFTools import RFTools
|
||||
from NanoVNASaver.Formatting import format_frequency
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
@ -132,8 +132,9 @@ class BandStopAnalysis(Analysis):
|
|||
|
||||
logger.debug("Found true lower cutoff frequency at %d", lower_cutoff_frequency)
|
||||
|
||||
self.lower_cutoff_label.setText(RFTools.formatFrequency(lower_cutoff_frequency) +
|
||||
" (" + str(round(lower_cutoff_gain, 1)) + " dB)")
|
||||
self.lower_cutoff_label.setText(
|
||||
f"{format_frequency(lower_cutoff_frequency)}"
|
||||
f" ({round(lower_cutoff_gain, 1)} dB)")
|
||||
|
||||
self.app.markers[1].setFrequency(str(lower_cutoff_frequency))
|
||||
self.app.markers[1].frequencyInput.setText(str(lower_cutoff_frequency))
|
||||
|
@ -154,8 +155,9 @@ class BandStopAnalysis(Analysis):
|
|||
|
||||
logger.debug("Found true upper cutoff frequency at %d", upper_cutoff_frequency)
|
||||
|
||||
self.upper_cutoff_label.setText(RFTools.formatFrequency(upper_cutoff_frequency) +
|
||||
" (" + str(round(upper_cutoff_gain, 1)) + " dB)")
|
||||
self.upper_cutoff_label.setText(
|
||||
f"{format_frequency(upper_cutoff_frequency)}"
|
||||
f" ({round(upper_cutoff_gain, 1)} dB)")
|
||||
self.app.markers[2].setFrequency(str(upper_cutoff_frequency))
|
||||
self.app.markers[2].frequencyInput.setText(str(upper_cutoff_frequency))
|
||||
|
||||
|
@ -163,8 +165,9 @@ class BandStopAnalysis(Analysis):
|
|||
center_frequency = math.sqrt(lower_cutoff_frequency * upper_cutoff_frequency)
|
||||
q = center_frequency / span
|
||||
|
||||
self.span_label.setText(RFTools.formatFrequency(span))
|
||||
self.center_frequency_label.setText(RFTools.formatFrequency(center_frequency))
|
||||
self.span_label.setText(format_frequency(span))
|
||||
self.center_frequency_label.setText(
|
||||
format_frequency(center_frequency))
|
||||
self.quality_label.setText(str(round(q, 2)))
|
||||
|
||||
self.app.markers[0].setFrequency(str(round(center_frequency)))
|
||||
|
@ -183,7 +186,8 @@ class BandStopAnalysis(Analysis):
|
|||
self.result_label.setText("Lower 6 dB location not found.")
|
||||
return
|
||||
lower_six_db_cutoff_frequency = self.app.data21[lower_six_db_location].freq
|
||||
self.lower_six_db_label.setText(RFTools.formatFrequency(lower_six_db_cutoff_frequency))
|
||||
self.lower_six_db_label.setText(
|
||||
format_frequency(lower_six_db_cutoff_frequency))
|
||||
|
||||
ten_db_location = -1
|
||||
for i in range(lower_cutoff_location, len(self.app.data21)):
|
||||
|
@ -209,14 +213,13 @@ class BandStopAnalysis(Analysis):
|
|||
if sixty_db_location > 0:
|
||||
sixty_db_cutoff_frequency = self.app.data21[sixty_db_location].freq
|
||||
self.lower_sixty_db_label.setText(
|
||||
RFTools.formatFrequency(sixty_db_cutoff_frequency))
|
||||
format_frequency(sixty_db_cutoff_frequency))
|
||||
elif ten_db_location != -1 and twenty_db_location != -1:
|
||||
ten = self.app.data21[ten_db_location].freq
|
||||
twenty = self.app.data21[twenty_db_location].freq
|
||||
sixty_db_frequency = ten * 10 ** (5 * (math.log10(twenty) - math.log10(ten)))
|
||||
self.lower_sixty_db_label.setText(
|
||||
RFTools.formatFrequency(sixty_db_frequency) +
|
||||
" (derived)")
|
||||
f"{format_frequency(sixty_db_frequency)} (derived)")
|
||||
else:
|
||||
self.lower_sixty_db_label.setText("Not calculated")
|
||||
|
||||
|
@ -246,11 +249,13 @@ class BandStopAnalysis(Analysis):
|
|||
self.result_label.setText("Upper 6 dB location not found.")
|
||||
return
|
||||
upper_six_db_cutoff_frequency = self.app.data21[upper_six_db_location].freq
|
||||
self.upper_six_db_label.setText(RFTools.formatFrequency(upper_six_db_cutoff_frequency))
|
||||
self.upper_six_db_label.setText(
|
||||
format_frequency(upper_six_db_cutoff_frequency))
|
||||
|
||||
six_db_span = upper_six_db_cutoff_frequency - lower_six_db_cutoff_frequency
|
||||
|
||||
self.six_db_span_label.setText(RFTools.formatFrequency(six_db_span))
|
||||
self.six_db_span_label.setText(
|
||||
format_frequency(six_db_span))
|
||||
|
||||
ten_db_location = -1
|
||||
for i in range(upper_cutoff_location, -1, -1):
|
||||
|
@ -276,15 +281,14 @@ class BandStopAnalysis(Analysis):
|
|||
if sixty_db_location > 0:
|
||||
sixty_db_cutoff_frequency = self.app.data21[sixty_db_location].freq
|
||||
self.upper_sixty_db_label.setText(
|
||||
RFTools.formatFrequency(sixty_db_cutoff_frequency))
|
||||
format_frequency(sixty_db_cutoff_frequency))
|
||||
elif ten_db_location != -1 and twenty_db_location != -1:
|
||||
ten = self.app.data21[ten_db_location].freq
|
||||
twenty = self.app.data21[twenty_db_location].freq
|
||||
sixty_db_frequency = ten * 10 ** (
|
||||
5 * (math.log10(twenty) - math.log10(ten)))
|
||||
self.upper_sixty_db_label.setText(
|
||||
RFTools.formatFrequency(sixty_db_frequency) +
|
||||
" (derived)")
|
||||
f"{format_frequency(sixty_db_frequency)} (derived)")
|
||||
else:
|
||||
self.upper_sixty_db_label.setText("Not calculated")
|
||||
|
||||
|
|
|
@ -19,10 +19,8 @@ import math
|
|||
|
||||
from PyQt5 import QtWidgets
|
||||
|
||||
from NanoVNASaver.RFTools import RFTools
|
||||
|
||||
from NanoVNASaver.Analysis import Analysis
|
||||
|
||||
from NanoVNASaver.Formatting import format_frequency
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
@ -123,8 +121,9 @@ class HighPassAnalysis(Analysis):
|
|||
cutoff_gain)
|
||||
logger.debug("Found true cutoff frequency at %d", cutoff_frequency)
|
||||
|
||||
self.cutoff_label.setText(RFTools.formatFrequency(cutoff_frequency) +
|
||||
" (" + str(round(cutoff_gain, 1)) + " dB)")
|
||||
self.cutoff_label.setText(
|
||||
f"{format_frequency(cutoff_frequency)}"
|
||||
f" {round(cutoff_gain, 1)} dB)")
|
||||
self.app.markers[1].setFrequency(str(cutoff_frequency))
|
||||
self.app.markers[1].frequencyInput.setText(str(cutoff_frequency))
|
||||
|
||||
|
@ -139,7 +138,8 @@ class HighPassAnalysis(Analysis):
|
|||
self.result_label.setText("6 dB location not found.")
|
||||
return
|
||||
six_db_cutoff_frequency = self.app.data21[six_db_location].freq
|
||||
self.six_db_label.setText(RFTools.formatFrequency(six_db_cutoff_frequency))
|
||||
self.six_db_label.setText(
|
||||
format_frequency(six_db_cutoff_frequency))
|
||||
|
||||
ten_db_location = -1
|
||||
for i in range(cutoff_location, -1, -1):
|
||||
|
@ -165,13 +165,14 @@ class HighPassAnalysis(Analysis):
|
|||
if sixty_db_location > 0:
|
||||
if sixty_db_location > 0:
|
||||
sixty_db_cutoff_frequency = self.app.data21[sixty_db_location].freq
|
||||
self.sixty_db_label.setText(RFTools.formatFrequency(sixty_db_cutoff_frequency))
|
||||
self.sixty_db_label.setText(
|
||||
format_frequency(sixty_db_cutoff_frequency))
|
||||
elif ten_db_location != -1 and twenty_db_location != -1:
|
||||
ten = self.app.data21[ten_db_location].freq
|
||||
twenty = self.app.data21[twenty_db_location].freq
|
||||
sixty_db_frequency = ten * 10 ** (5 * (math.log10(twenty) - math.log10(ten)))
|
||||
self.sixty_db_label.setText(RFTools.formatFrequency(sixty_db_frequency) +
|
||||
" (derived)")
|
||||
self.sixty_db_label.setText(
|
||||
f"{format_frequency(sixty_db_frequency)} (derived)")
|
||||
else:
|
||||
self.sixty_db_label.setText("Not calculated")
|
||||
|
||||
|
|
|
@ -20,12 +20,11 @@ import math
|
|||
from PyQt5 import QtWidgets
|
||||
|
||||
from NanoVNASaver.Analysis import Analysis
|
||||
from NanoVNASaver.RFTools import RFTools
|
||||
from NanoVNASaver.Formatting import format_frequency
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
|
||||
class LowPassAnalysis(Analysis):
|
||||
def __init__(self, app):
|
||||
super().__init__(app)
|
||||
|
@ -128,8 +127,9 @@ class LowPassAnalysis(Analysis):
|
|||
cutoff_gain)
|
||||
logger.debug("Found true cutoff frequency at %d", cutoff_frequency)
|
||||
|
||||
self.cutoff_label.setText(RFTools.formatFrequency(cutoff_frequency) +
|
||||
" (" + str(round(cutoff_gain, 1)) + " dB)")
|
||||
self.cutoff_label.setText(
|
||||
f"{format_frequency(cutoff_frequency)}"
|
||||
f" ({round(cutoff_gain, 1)} dB)")
|
||||
self.app.markers[1].setFrequency(str(cutoff_frequency))
|
||||
self.app.markers[1].frequencyInput.setText(str(cutoff_frequency))
|
||||
|
||||
|
@ -145,7 +145,8 @@ class LowPassAnalysis(Analysis):
|
|||
self.result_label.setText("6 dB location not found.")
|
||||
return
|
||||
six_db_cutoff_frequency = self.app.data21[six_db_location].freq
|
||||
self.six_db_label.setText(RFTools.formatFrequency(six_db_cutoff_frequency))
|
||||
self.six_db_label.setText(
|
||||
format_frequency(six_db_cutoff_frequency))
|
||||
|
||||
ten_db_location = -1
|
||||
for i in range(cutoff_location, len(self.app.data21)):
|
||||
|
@ -174,14 +175,14 @@ class LowPassAnalysis(Analysis):
|
|||
if sixty_db_location > 0:
|
||||
sixty_db_cutoff_frequency = self.app.data21[sixty_db_location].freq
|
||||
self.sixty_db_label.setText(
|
||||
RFTools.formatFrequency(sixty_db_cutoff_frequency))
|
||||
format_frequency(sixty_db_cutoff_frequency))
|
||||
elif ten_db_location != -1 and twenty_db_location != -1:
|
||||
ten = self.app.data21[ten_db_location].freq
|
||||
twenty = self.app.data21[twenty_db_location].freq
|
||||
sixty_db_frequency = ten * \
|
||||
10 ** (5 * (math.log10(twenty) - math.log10(ten)))
|
||||
self.sixty_db_label.setText(RFTools.formatFrequency(
|
||||
sixty_db_frequency) + " (derived)")
|
||||
self.sixty_db_label.setText(
|
||||
f"{format_frequency(sixty_db_frequency)} (derived)")
|
||||
else:
|
||||
self.sixty_db_label.setText("Not calculated")
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ from PyQt5 import QtWidgets
|
|||
import numpy as np
|
||||
|
||||
from NanoVNASaver.Analysis import Analysis, PeakSearchAnalysis
|
||||
from NanoVNASaver.RFTools import RFTools
|
||||
from NanoVNASaver.Formatting import format_frequency
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
@ -115,10 +115,10 @@ class SimplePeakSearchAnalysis(Analysis):
|
|||
return
|
||||
|
||||
self.peak_frequency.setText(
|
||||
RFTools.formatFrequency(self.app.data[idx_peak].freq))
|
||||
format_frequency(self.app.data[idx_peak].freq))
|
||||
self.peak_value.setText(str(round(data[idx_peak], 3)) + suffix)
|
||||
|
||||
if self.checkbox_move_marker.isChecked() and len(self.app.markers) >= 1:
|
||||
self.app.markers[0].setFrequency(str(self.app.data[idx_peak].freq))
|
||||
self.app.markers[0].frequencyInput.setText(
|
||||
RFTools.formatFrequency(self.app.data[idx_peak].freq))
|
||||
format_frequency(self.app.data[idx_peak].freq))
|
||||
|
|
|
@ -20,7 +20,7 @@ from PyQt5 import QtWidgets
|
|||
import numpy as np
|
||||
|
||||
from NanoVNASaver.Analysis import Analysis, PeakSearchAnalysis
|
||||
from NanoVNASaver.RFTools import RFTools
|
||||
from NanoVNASaver.Formatting import format_frequency
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
@ -117,23 +117,23 @@ class VSWRAnalysis(Analysis):
|
|||
logger.debug(
|
||||
"Section from %d to %d, lowest at %d", start, end, lowest)
|
||||
self.layout.addRow("Start", QtWidgets.QLabel(
|
||||
RFTools.formatFrequency(self.app.data[start].freq)))
|
||||
format_frequency(self.app.data[start].freq)))
|
||||
self.layout.addRow(
|
||||
"Minimum",
|
||||
QtWidgets.QLabel(
|
||||
RFTools.formatFrequency(self.app.data[lowest].freq) +
|
||||
" (" + str(round(data[lowest], 2)) + ")"))
|
||||
f"{format_frequency(self.app.data[lowest].freq)}"
|
||||
f" ({round(data[lowest], 2)})"))
|
||||
self.layout.addRow("End", QtWidgets.QLabel(
|
||||
RFTools.formatFrequency(self.app.data[end].freq)))
|
||||
format_frequency(self.app.data[end].freq)))
|
||||
self.layout.addRow(
|
||||
"Span",
|
||||
QtWidgets.QLabel(
|
||||
RFTools.formatFrequency(self.app.data[end].freq -
|
||||
self.app.data[start].freq)))
|
||||
format_frequency(self.app.data[end].freq -
|
||||
self.app.data[start].freq)))
|
||||
self.layout.addWidget(PeakSearchAnalysis.QHLine())
|
||||
else:
|
||||
self.layout.addRow("Low spot", QtWidgets.QLabel(
|
||||
RFTools.formatFrequency(self.app.data[lowest].freq)))
|
||||
format_frequency(self.app.data[lowest].freq)))
|
||||
self.layout.addWidget(PeakSearchAnalysis.QHLine())
|
||||
# Remove the final separator line
|
||||
self.layout.removeRow(self.layout.rowCount()-1)
|
||||
|
|
|
@ -22,7 +22,7 @@ import numpy as np
|
|||
from PyQt5 import QtWidgets, QtGui, QtCore
|
||||
|
||||
from NanoVNASaver.Formatting import parse_frequency
|
||||
from NanoVNASaver.RFTools import Datapoint, RFTools
|
||||
from NanoVNASaver.RFTools import Datapoint
|
||||
from .Chart import Chart
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
@ -244,9 +244,11 @@ class FrequencyChart(Chart):
|
|||
if span > 0:
|
||||
if self.logarithmicX:
|
||||
span = math.log(self.fstop) - math.log(self.fstart)
|
||||
return self.leftMargin +\
|
||||
round(self.chartWidth * (math.log(d.freq) - math.log(self.fstart)) / span)
|
||||
return self.leftMargin + round(self.chartWidth * (d.freq - self.fstart) / span)
|
||||
return self.leftMargin + round(
|
||||
self.chartWidth * (math.log(d.freq) -
|
||||
math.log(self.fstart)) / span)
|
||||
return self.leftMargin + round(
|
||||
self.chartWidth * (d.freq - self.fstart) / span)
|
||||
return math.floor(self.width()/2)
|
||||
|
||||
def frequencyAtPosition(self, x, limit=True) -> int:
|
||||
|
|
|
@ -26,6 +26,7 @@ from .Frequency import FrequencyChart
|
|||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class InductanceChart(FrequencyChart):
|
||||
def __init__(self, name=""):
|
||||
super().__init__(name)
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
import math
|
||||
import logging
|
||||
from typing import List, Set
|
||||
from typing import List
|
||||
|
||||
from PyQt5 import QtWidgets, QtGui
|
||||
|
||||
|
@ -162,8 +162,6 @@ class MagnitudeChart(FrequencyChart):
|
|||
return math.sqrt(p.re**2 + p.im**2)
|
||||
|
||||
def copy(self):
|
||||
new_chart: LogMagChart = super().copy()
|
||||
new_chart = super().copy()
|
||||
new_chart.span = self.span
|
||||
return new_chart
|
||||
|
||||
|
||||
|
|
|
@ -93,7 +93,7 @@ class PolarChart(SquareChart):
|
|||
qp.setPen(pen)
|
||||
if len(self.data) > 0:
|
||||
fstart = self.data[0].freq
|
||||
fstop = self.data[len(self.data) -1].freq
|
||||
fstop = self.data[len(self.data) - 1].freq
|
||||
else:
|
||||
fstart = self.reference[0].freq
|
||||
fstop = self.reference[len(self.reference) - 1].freq
|
||||
|
|
|
@ -39,7 +39,7 @@ class SmithChart(SquareChart):
|
|||
|
||||
def paintEvent(self, a0: QtGui.QPaintEvent) -> None:
|
||||
qp = QtGui.QPainter(self)
|
||||
#qp.begin(self) # Apparently not needed?
|
||||
# qp.begin(self) # Apparently not needed?
|
||||
self.drawSmithChart(qp)
|
||||
self.drawValues(qp)
|
||||
qp.end()
|
||||
|
|
|
@ -22,6 +22,7 @@ from NanoVNASaver.Charts.Chart import Chart
|
|||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class SquareChart(Chart):
|
||||
def __init__(self, name):
|
||||
super().__init__(name)
|
||||
|
|
|
@ -15,14 +15,20 @@
|
|||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
import math
|
||||
from numbers import Number
|
||||
|
||||
from NanoVNASaver import SITools
|
||||
|
||||
FMT_FREQ = SITools.Format(space_str=" ")
|
||||
FMT_FREQ = SITools.Format()
|
||||
FMT_FREQ_SHORT = SITools.Format(max_nr_digits=4)
|
||||
FMT_FREQ_SPACE = SITools.Format(space_str=" ")
|
||||
FMT_FREQ_SWEEP = SITools.Format(max_nr_digits=9, allow_strip=True)
|
||||
FMT_FREQ_INPUTS = SITools.Format(
|
||||
max_nr_digits=10, allow_strip=True, printable_min=0, unprintable_under="- ")
|
||||
max_nr_digits=10, allow_strip=True,
|
||||
printable_min=0, unprintable_under="- ")
|
||||
FMT_Q_FACTOR = SITools.Format(
|
||||
max_nr_digits=4, assume_infinity=False, min_offset=0, max_offset=0, allow_strip=True)
|
||||
max_nr_digits=4, assume_infinity=False,
|
||||
min_offset=0, max_offset=0, allow_strip=True)
|
||||
FMT_GROUP_DELAY = SITools.Format(max_nr_digits=5, space_str=" ")
|
||||
FMT_REACT = SITools.Format(max_nr_digits=5, space_str=" ", allow_strip=True)
|
||||
FMT_COMPLEX = SITools.Format(max_nr_digits=3, allow_strip=True,
|
||||
|
@ -31,14 +37,26 @@ FMT_PARSE = SITools.Format(parse_sloppy_unit=True, parse_sloppy_kilo=True,
|
|||
parse_clamp_min=0)
|
||||
|
||||
|
||||
def format_frequency(freq: float, fmt=FMT_FREQ) -> str:
|
||||
return str(SITools.Value(freq, "Hz", fmt))
|
||||
def format_frequency(freq: Number) -> str:
|
||||
return str(SITools.Value(freq, "Hz", FMT_FREQ))
|
||||
|
||||
|
||||
def format_frequency_inputs(freq: float) -> str:
|
||||
return str(SITools.Value(freq, "Hz", FMT_FREQ_INPUTS))
|
||||
|
||||
|
||||
def format_frequency_short(freq: Number) -> str:
|
||||
return str(SITools.Value(freq, "Hz", FMT_FREQ_SHORT))
|
||||
|
||||
|
||||
def format_frequency_space(freq: float, fmt=FMT_FREQ_SPACE) -> str:
|
||||
return str(SITools.Value(freq, "Hz", fmt))
|
||||
|
||||
|
||||
def format_frequency_sweep(freq: Number) -> str:
|
||||
return str(SITools.Value(freq, "Hz", FMT_FREQ_SWEEP))
|
||||
|
||||
|
||||
def format_gain(val: float, invert: bool = False) -> str:
|
||||
if invert:
|
||||
val = -val
|
||||
|
@ -54,9 +72,11 @@ def format_q_factor(val: float) -> str:
|
|||
def format_vswr(val: float) -> str:
|
||||
return f"{val:.3f}"
|
||||
|
||||
|
||||
def format_magnitude(val: float) -> str:
|
||||
return f"{val:.3f}"
|
||||
|
||||
|
||||
def format_resistance(val: float) -> str:
|
||||
if val < 0:
|
||||
return "- \N{OHM SIGN}"
|
||||
|
@ -88,6 +108,7 @@ def format_complex_imp(z: complex) -> str:
|
|||
im = SITools.Value(abs(z.imag), fmt=FMT_COMPLEX)
|
||||
return f"{re}{'-' if z.imag < 0 else '+'}j{im} \N{OHM SIGN}"
|
||||
|
||||
|
||||
def parse_frequency(freq: str) -> int:
|
||||
try:
|
||||
return int(SITools.Value(freq, "Hz", FMT_PARSE))
|
||||
|
|
|
@ -24,6 +24,7 @@ from NanoVNASaver.Hardware.VNA import VNA, Version
|
|||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class AVNA(VNA):
|
||||
name = "AVNA"
|
||||
|
||||
|
|
|
@ -64,6 +64,7 @@ def get_interfaces() -> List[Tuple[str, str]]:
|
|||
return_ports.append((port, f"{port}({t.name})"))
|
||||
return return_ports
|
||||
|
||||
|
||||
def get_VNA(app, serial_port: serial.Serial) -> 'VNA':
|
||||
logger.info("Finding correct VNA type...")
|
||||
|
||||
|
|
|
@ -82,7 +82,7 @@ class NanoVNA_F(NanoVNA):
|
|||
|
||||
image = QtGui.QImage(
|
||||
unwrapped_array,
|
||||
self.screenwidth, self.screenheight,
|
||||
self.screenwidth, self.screenheight,
|
||||
QtGui.QImage.Format_ARGB32)
|
||||
logger.debug("Captured screenshot")
|
||||
return QtGui.QPixmap(image)
|
||||
|
|
|
@ -109,7 +109,6 @@ class NanoVNAV2(VNA):
|
|||
return None
|
||||
return Version(f"{resp[0]}.{resp[1]}.0")
|
||||
|
||||
|
||||
def readFrequencies(self) -> List[str]:
|
||||
self.checkValid()
|
||||
return [
|
||||
|
@ -187,7 +186,6 @@ class NanoVNAV2(VNA):
|
|||
return None
|
||||
return Version(f"{resp[0]}.0.{resp[1]}")
|
||||
|
||||
|
||||
def setSweep(self, start, stop):
|
||||
step = (stop - start) / (self.datapoints - 1)
|
||||
if start == self.sweepStartHz and step == self.sweepStepHz:
|
||||
|
|
|
@ -178,9 +178,12 @@ class VNA:
|
|||
|
||||
# TODO: should be dropped and the serial part should be a connection class which handles
|
||||
# unconnected devices
|
||||
|
||||
|
||||
class InvalidVNA(VNA):
|
||||
name = "Invalid"
|
||||
_datapoints = (0, )
|
||||
|
||||
def __init__(self, app: QtWidgets.QWidget, serial_port: serial.Serial):
|
||||
super().__init__(app, serial_port)
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ from NanoVNASaver import RFTools
|
|||
from NanoVNASaver.Formatting import (
|
||||
format_capacitance,
|
||||
format_complex_imp,
|
||||
format_frequency,
|
||||
format_frequency_space,
|
||||
format_gain,
|
||||
format_group_delay,
|
||||
format_inductance,
|
||||
|
@ -306,7 +306,7 @@ class Marker(QtCore.QObject, Value):
|
|||
else:
|
||||
x_p_str = ind_p_str
|
||||
|
||||
self.label['actualfreq'].setText(format_frequency(s11.freq))
|
||||
self.label['actualfreq'].setText(format_frequency_space(s11.freq))
|
||||
self.label['admittance'].setText(format_complex_imp(imp_p))
|
||||
self.label['impedance'].setText(format_complex_imp(imp))
|
||||
self.label['parc'].setText(cap_p_str)
|
||||
|
|
|
@ -24,20 +24,27 @@ from typing import List
|
|||
import serial
|
||||
from PyQt5 import QtWidgets, QtCore, QtGui
|
||||
|
||||
from .Windows import AboutWindow, AnalysisWindow, CalibrationWindow, \
|
||||
DeviceSettingsWindow, DisplaySettingsWindow, SweepSettingsWindow, \
|
||||
from .Windows import (
|
||||
AboutWindow, AnalysisWindow, CalibrationWindow,
|
||||
DeviceSettingsWindow, DisplaySettingsWindow, SweepSettingsWindow,
|
||||
TDRWindow
|
||||
from .Formatting import parse_frequency
|
||||
)
|
||||
from .Formatting import (
|
||||
format_frequency, format_frequency_short, format_frequency_sweep,
|
||||
parse_frequency,
|
||||
)
|
||||
from .Hardware import get_interfaces, get_VNA, InvalidVNA
|
||||
from .RFTools import RFTools, Datapoint
|
||||
from .RFTools import Datapoint
|
||||
from .Charts.Chart import Chart
|
||||
from .Charts import CapacitanceChart, \
|
||||
CombinedLogMagChart, GroupDelayChart, InductanceChart, \
|
||||
LogMagChart, PhaseChart, \
|
||||
MagnitudeChart, MagnitudeZChart, \
|
||||
QualityFactorChart, VSWRChart, PermeabilityChart, PolarChart, \
|
||||
RealImaginaryChart, \
|
||||
SmithChart, SParameterChart, TDRChart
|
||||
from .Charts import (
|
||||
CapacitanceChart,
|
||||
CombinedLogMagChart, GroupDelayChart, InductanceChart,
|
||||
LogMagChart, PhaseChart,
|
||||
MagnitudeChart, MagnitudeZChart,
|
||||
QualityFactorChart, VSWRChart, PermeabilityChart, PolarChart,
|
||||
RealImaginaryChart,
|
||||
SmithChart, SParameterChart, TDRChart,
|
||||
)
|
||||
from .Calibration import Calibration
|
||||
from .Inputs import FrequencyInputWidget
|
||||
from .Marker import Marker
|
||||
|
@ -621,15 +628,15 @@ class NanoVNASaver(QtWidgets.QWidget):
|
|||
self.sweepStartInput.text() == "" or
|
||||
self.sweepEndInput.text() == ""):
|
||||
self.sweepStartInput.setText(
|
||||
RFTools.formatSweepFrequency(int(frequencies[0])))
|
||||
format_frequency_sweep(int(frequencies[0])))
|
||||
self.sweepEndInput.setText(
|
||||
RFTools.formatSweepFrequency(int(frequencies[100]) + 100000))
|
||||
format_frequency_sweep(int(frequencies[100]) + 100000))
|
||||
elif (self.sweepStartInput.text() == "" or
|
||||
self.sweepEndInput.text() == ""):
|
||||
self.sweepStartInput.setText(
|
||||
RFTools.formatSweepFrequency(int(frequencies[0])))
|
||||
format_frequency_sweep(int(frequencies[0])))
|
||||
self.sweepEndInput.setText(
|
||||
RFTools.formatSweepFrequency(int(frequencies[100])))
|
||||
format_frequency_sweep(int(frequencies[100])))
|
||||
self.sweepStartInput.textEdited.emit(
|
||||
self.sweepStartInput.text())
|
||||
self.sweepStartInput.textChanged.emit(
|
||||
|
@ -737,7 +744,7 @@ class NanoVNASaver(QtWidgets.QWidget):
|
|||
|
||||
if min_vswr_freq > -1:
|
||||
self.s11_min_swr_label.setText(
|
||||
f"{round(min_vswr, 3)} @ {RFTools.formatFrequency(min_vswr_freq)}")
|
||||
f"{round(min_vswr, 3)} @ {format_frequency(min_vswr_freq)}")
|
||||
if min_vswr > 1:
|
||||
self.s11_min_rl_label.setText(
|
||||
f"{round(20*math.log10((min_vswr-1)/(min_vswr+1)), 3)} dB")
|
||||
|
@ -762,9 +769,9 @@ class NanoVNASaver(QtWidgets.QWidget):
|
|||
|
||||
if max_gain_freq > -1:
|
||||
self.s21_min_gain_label.setText(
|
||||
f"{round(min_gain, 3)} dB @ {RFTools.formatFrequency(min_gain_freq)}")
|
||||
f"{round(min_gain, 3)} dB @ {format_frequency(min_gain_freq)}")
|
||||
self.s21_max_gain_label.setText(
|
||||
f"{round(max_gain, 3)} dB @ {RFTools.formatFrequency(max_gain_freq)}")
|
||||
f"{round(max_gain, 3)} dB @ {format_frequency(max_gain_freq)}")
|
||||
else:
|
||||
self.s21_min_gain_label.setText("")
|
||||
self.s21_max_gain_label.setText("")
|
||||
|
@ -788,8 +795,8 @@ class NanoVNASaver(QtWidgets.QWidget):
|
|||
fcenter = int(round((fstart+fstop)/2))
|
||||
if fspan < 0 or fstart < 0 or fstop < 0:
|
||||
return
|
||||
self.sweepSpanInput.setText(RFTools.formatSweepFrequency(fspan))
|
||||
self.sweepCenterInput.setText(RFTools.formatSweepFrequency(fcenter))
|
||||
self.sweepSpanInput.setText(format_frequency_sweep(fspan))
|
||||
self.sweepCenterInput.setText(format_frequency_sweep(fcenter))
|
||||
|
||||
def updateStartEnd(self):
|
||||
fcenter = parse_frequency(self.sweepCenterInput.text())
|
||||
|
@ -800,8 +807,8 @@ class NanoVNASaver(QtWidgets.QWidget):
|
|||
fstop = int(round(fcenter + fspan/2))
|
||||
if fstart < 0 or fstop < 0:
|
||||
return
|
||||
self.sweepStartInput.setText(RFTools.formatSweepFrequency(fstart))
|
||||
self.sweepEndInput.setText(RFTools.formatSweepFrequency(fstop))
|
||||
self.sweepStartInput.setText(format_frequency_sweep(fstart))
|
||||
self.sweepEndInput.setText(format_frequency_sweep(fstop))
|
||||
|
||||
def updateStepSize(self):
|
||||
fspan = parse_frequency(self.sweepSpanInput.text())
|
||||
|
@ -812,7 +819,7 @@ class NanoVNASaver(QtWidgets.QWidget):
|
|||
if segments > 0:
|
||||
fstep = fspan / (segments * self.vna.datapoints - 1)
|
||||
self.sweepStepLabel.setText(
|
||||
f"{RFTools.formatShortFrequency(fstep)}/step")
|
||||
f"{format_frequency_short(fstep)}/step")
|
||||
|
||||
def setReference(self, s11data=None, s21data=None, source=None):
|
||||
if not s11data:
|
||||
|
|
|
@ -16,9 +16,8 @@
|
|||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
import math
|
||||
import cmath
|
||||
from numbers import Number
|
||||
from typing import List, NamedTuple
|
||||
from NanoVNASaver.SITools import Value, Format, clamp_value
|
||||
from NanoVNASaver.SITools import Format, clamp_value
|
||||
|
||||
FMT_FREQ = Format()
|
||||
FMT_SHORT = Format(max_nr_digits=4)
|
||||
|
@ -145,18 +144,3 @@ def groupDelay(data: List[Datapoint], index: int) -> float:
|
|||
delta_angle = -1 * (delta_angle % math.tau)
|
||||
val = -delta_angle / math.tau / delta_freq
|
||||
return val
|
||||
|
||||
|
||||
class RFTools:
|
||||
# TODO: Remove this class when unused
|
||||
@staticmethod
|
||||
def formatFrequency(freq: Number) -> str:
|
||||
return str(Value(freq, "Hz", FMT_FREQ))
|
||||
|
||||
@staticmethod
|
||||
def formatShortFrequency(freq: Number) -> str:
|
||||
return str(Value(freq, "Hz", FMT_SHORT))
|
||||
|
||||
@staticmethod
|
||||
def formatSweepFrequency(freq: Number) -> str:
|
||||
return str(Value(freq, "Hz", FMT_SWEEP))
|
||||
|
|
|
@ -25,6 +25,7 @@ from NanoVNASaver.Hardware import Version
|
|||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class AboutWindow(QtWidgets.QWidget):
|
||||
def __init__(self, app: QtWidgets.QWidget):
|
||||
super().__init__()
|
||||
|
|
|
@ -22,6 +22,7 @@ from NanoVNASaver.Windows.Screenshot import ScreenshotWindow
|
|||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class DeviceSettingsWindow(QtWidgets.QWidget):
|
||||
def __init__(self, app: QtWidgets.QWidget):
|
||||
super().__init__()
|
||||
|
@ -103,7 +104,7 @@ class DeviceSettingsWindow(QtWidgets.QWidget):
|
|||
for item in features:
|
||||
self.featureList.addItem(item)
|
||||
|
||||
self.btnCaptureScreenshot.setDisabled(not "Screenshots" in features)
|
||||
self.btnCaptureScreenshot.setDisabled("Screenshots" not in features)
|
||||
if "Customizable data points" in features:
|
||||
self.datapoints.clear()
|
||||
cur_dps = self.app.vna.datapoints
|
||||
|
|
|
@ -23,6 +23,7 @@ from NanoVNASaver.Windows.MarkerSettings import MarkerSettingsWindow
|
|||
from NanoVNASaver.Marker import Marker
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class DisplaySettingsWindow(QtWidgets.QWidget):
|
||||
def __init__(self, app: QtWidgets.QWidget):
|
||||
super().__init__()
|
||||
|
|
|
@ -18,7 +18,9 @@ import logging
|
|||
|
||||
from PyQt5 import QtWidgets, QtCore
|
||||
|
||||
from NanoVNASaver.RFTools import RFTools
|
||||
from NanoVNASaver.Formatting import (
|
||||
format_frequency_short, format_frequency_sweep,
|
||||
)
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
@ -142,8 +144,8 @@ class SweepSettingsWindow(QtWidgets.QWidget):
|
|||
stop += round(span * padding / 100)
|
||||
|
||||
self.band_limit_label.setText(
|
||||
f"Sweep span: {RFTools.formatShortFrequency(start)}"
|
||||
f" to {RFTools.formatShortFrequency(stop)}")
|
||||
f"Sweep span: {format_frequency_short(start)}"
|
||||
f" to {format_frequency_short(stop)}")
|
||||
|
||||
def setBandSweep(self):
|
||||
index_start = self.band_list.model().index(self.band_list.currentIndex(), 1)
|
||||
|
@ -166,8 +168,8 @@ class SweepSettingsWindow(QtWidgets.QWidget):
|
|||
start = max(1, start)
|
||||
stop += round(span * padding / 100)
|
||||
|
||||
self.app.sweepStartInput.setText(RFTools.formatSweepFrequency(start))
|
||||
self.app.sweepEndInput.setText(RFTools.formatSweepFrequency(stop))
|
||||
self.app.sweepStartInput.setText(format_frequency_sweep(start))
|
||||
self.app.sweepEndInput.setText(format_frequency_sweep(stop))
|
||||
self.app.sweepEndInput.textEdited.emit(self.app.sweepEndInput.text())
|
||||
|
||||
def updateAveraging(self):
|
||||
|
|
|
@ -15,5 +15,5 @@
|
|||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
version = '0.2.3-dg5gbh'
|
||||
#debug = False
|
||||
# debug = False
|
||||
debug = True
|
||||
|
|
|
@ -19,8 +19,7 @@ import sys
|
|||
import unittest
|
||||
|
||||
# Import targets to be tested
|
||||
from NanoVNASaver import RFTools
|
||||
rft = RFTools.RFTools()
|
||||
from NanoVNASaver.Formatting import format_frequency_sweep
|
||||
|
||||
class TestCases(unittest.TestCase):
|
||||
|
||||
|
@ -28,15 +27,15 @@ class TestCases(unittest.TestCase):
|
|||
# simple well-formed integers with no trailing zeros. Most importantly
|
||||
# there is no loss of accuracy in the result. Returned values are not
|
||||
# truncated if result would lose meaningful data.
|
||||
self.assertEqual(rft.formatSweepFrequency(1), '1Hz')
|
||||
self.assertEqual(rft.formatSweepFrequency(12), '12Hz')
|
||||
self.assertEqual(rft.formatSweepFrequency(123), '123Hz')
|
||||
self.assertEqual(rft.formatSweepFrequency(1234), '1.234kHz')
|
||||
self.assertEqual(rft.formatSweepFrequency(12345), '12.345kHz')
|
||||
self.assertEqual(rft.formatSweepFrequency(123456), '123.456kHz')
|
||||
self.assertEqual(rft.formatSweepFrequency(1234567), '1.234567MHz')
|
||||
self.assertEqual(rft.formatSweepFrequency(12345678), '12.345678MHz')
|
||||
self.assertEqual(rft.formatSweepFrequency(123456789), '123.456789MHz')
|
||||
self.assertEqual(format_frequency_sweep(1), '1Hz')
|
||||
self.assertEqual(format_frequency_sweep(12), '12Hz')
|
||||
self.assertEqual(format_frequency_sweep(1234), '1.234kHz')
|
||||
self.assertEqual(format_frequency_sweep(12345), '12.345kHz')
|
||||
self.assertEqual(format_frequency_sweep(123456), '123.456kHz')
|
||||
self.assertEqual(format_frequency_sweep(123), '123Hz')
|
||||
self.assertEqual(format_frequency_sweep(1234567), '1.234567MHz')
|
||||
self.assertEqual(format_frequency_sweep(12345678), '12.345678MHz')
|
||||
self.assertEqual(format_frequency_sweep(123456789), '123.456789MHz')
|
||||
|
||||
# def test_defaultMinDigits(self):
|
||||
# # simple integers with trailing zeros.
|
||||
|
|
|
@ -23,14 +23,14 @@ from NanoVNASaver import Formatting as fmt
|
|||
class TestCases(unittest.TestCase):
|
||||
|
||||
def test_format_frequency(self):
|
||||
self.assertEqual(fmt.format_frequency(1), '1.00000 Hz')
|
||||
self.assertEqual(fmt.format_frequency(12), '12.0000 Hz')
|
||||
self.assertEqual(fmt.format_frequency(123), '123.000 Hz')
|
||||
self.assertEqual(fmt.format_frequency(1234), '1.23400 kHz')
|
||||
self.assertEqual(fmt.format_frequency(1234567), '1.23457 MHz')
|
||||
self.assertEqual(fmt.format_frequency(1234567890), '1.23457 GHz')
|
||||
self.assertEqual(fmt.format_frequency(0), '0.00000 Hz')
|
||||
self.assertEqual(fmt.format_frequency(-1), '-1.00000 Hz')
|
||||
self.assertEqual(fmt.format_frequency_space(1), '1.00000 Hz')
|
||||
self.assertEqual(fmt.format_frequency_space(12), '12.0000 Hz')
|
||||
self.assertEqual(fmt.format_frequency_space(123), '123.000 Hz')
|
||||
self.assertEqual(fmt.format_frequency_space(1234), '1.23400 kHz')
|
||||
self.assertEqual(fmt.format_frequency_space(1234567), '1.23457 MHz')
|
||||
self.assertEqual(fmt.format_frequency_space(1234567890), '1.23457 GHz')
|
||||
self.assertEqual(fmt.format_frequency_space(0), '0.00000 Hz')
|
||||
self.assertEqual(fmt.format_frequency_space(-1), '-1.00000 Hz')
|
||||
|
||||
def test_format_frequency_inputs(self):
|
||||
self.assertEqual(fmt.format_frequency_inputs(1), '1Hz')
|
||||
|
|
Ładowanie…
Reference in New Issue