kopia lustrzana https://github.com/NanoVNA-Saver/nanovna-saver
Use with for locking / linting
rodzic
6fa8929f94
commit
675e7adc2c
|
@ -40,6 +40,7 @@ RXP_CAL_LINE = re.compile(r"""^\s*
|
|||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def correct_delay(d: Datapoint, delay: float, reflect: bool = False):
|
||||
mult = 2 if reflect else 1
|
||||
corr_data = d.z * cmath.exp(
|
||||
|
@ -78,12 +79,13 @@ class CalData(UserDict):
|
|||
f' {d["isolation"].re} {d["isolation"].im}')
|
||||
return s
|
||||
|
||||
|
||||
class CalDataSet:
|
||||
def __init__(self):
|
||||
self.data = defaultdict(CalData)
|
||||
|
||||
def insert(self, name: str, dp: Datapoint):
|
||||
if not name in self.data[dp.freq]:
|
||||
if name not in self.data[dp.freq]:
|
||||
raise KeyError(name)
|
||||
self.data[dp.freq]["freq"] = dp.freq
|
||||
self.data[dp.freq][name] = dp
|
||||
|
|
|
@ -601,7 +601,6 @@ class NanoVNASaver(QtWidgets.QWidget):
|
|||
self.connect_device()
|
||||
else:
|
||||
self.disconnect_device()
|
||||
return
|
||||
|
||||
def connect_device(self):
|
||||
if not self.interface:
|
||||
|
@ -692,15 +691,11 @@ class NanoVNASaver(QtWidgets.QWidget):
|
|||
self.worker.stopped = True
|
||||
|
||||
def saveData(self, data, data21, source=None):
|
||||
if self.dataLock.acquire(blocking=True):
|
||||
with self.dataLock:
|
||||
self.data = data
|
||||
self.data21 = data21
|
||||
if self.s21att > 0:
|
||||
self.data21 = corr_att_data(data21, self.s21att)
|
||||
else:
|
||||
self.data21 = data21
|
||||
else:
|
||||
logger.error("Failed acquiring data lock while saving.")
|
||||
self.dataLock.release()
|
||||
self.data21 = corr_att_data(self.data21, self.s21att)
|
||||
if source is not None:
|
||||
self.sweepSource = source
|
||||
else:
|
||||
|
@ -710,7 +705,7 @@ class NanoVNASaver(QtWidgets.QWidget):
|
|||
).lstrip()
|
||||
|
||||
def markerUpdated(self, marker: Marker):
|
||||
if self.dataLock.acquire(blocking=True):
|
||||
with self.dataLock:
|
||||
marker.findLocation(self.data)
|
||||
for m in self.markers:
|
||||
m.resetLabels()
|
||||
|
@ -718,10 +713,9 @@ class NanoVNASaver(QtWidgets.QWidget):
|
|||
|
||||
for c in self.subscribing_charts:
|
||||
c.update()
|
||||
self.dataLock.release()
|
||||
|
||||
def dataUpdated(self):
|
||||
if self.dataLock.acquire(blocking=True):
|
||||
with self.dataLock:
|
||||
for m in self.markers:
|
||||
m.resetLabels()
|
||||
m.updateLabels(self.data, self.data21)
|
||||
|
@ -781,10 +775,7 @@ class NanoVNASaver(QtWidgets.QWidget):
|
|||
self.s21_min_gain_label.setText("")
|
||||
self.s21_max_gain_label.setText("")
|
||||
|
||||
else:
|
||||
logger.error("Failed acquiring data lock while updating.")
|
||||
self.updateTitle()
|
||||
self.dataLock.release()
|
||||
self.dataAvailable.emit()
|
||||
|
||||
def sweepFinished(self):
|
||||
|
|
|
@ -149,7 +149,7 @@ def serial_to_parallel(z: complex) -> complex:
|
|||
return complex(z_sq_sum / z.real, z_sq_sum / z.imag)
|
||||
|
||||
|
||||
def corr_att_data(data: List[Datapoint], att: float):
|
||||
def corr_att_data(data: List[Datapoint], att: float) -> List[Datapoint]:
|
||||
"""Correct the ratio for a given attenuation on s21 input"""
|
||||
if att <= 0:
|
||||
return data
|
||||
|
@ -157,8 +157,6 @@ def corr_att_data(data: List[Datapoint], att: float):
|
|||
att = 10**(att/20)
|
||||
ndata = []
|
||||
for dp in data:
|
||||
freq, re, im = dp
|
||||
orig = complex(re, im)
|
||||
corrected = orig * att
|
||||
ndata.append(Datapoint(freq, corrected.real, corrected.imag))
|
||||
corrected = dp.z * att
|
||||
ndata.append(Datapoint(dp.freq, corrected.real, corrected.imag))
|
||||
return ndata
|
||||
|
|
Ładowanie…
Reference in New Issue