kopia lustrzana https://github.com/NanoVNA-Saver/nanovna-saver
- Further logging
- Preparing for Magnitude-Angle Touchstone files - Minimum width for frequency input fieldspull/17/head
rodzic
7f48d7642e
commit
23fe8024f7
|
@ -159,6 +159,7 @@ class NanoVNASaver(QtWidgets.QWidget):
|
|||
sweep_control_layout.addRow(sweep_input_layout)
|
||||
|
||||
self.sweepStartInput = QtWidgets.QLineEdit("")
|
||||
self.sweepStartInput.setMinimumWidth(60)
|
||||
self.sweepStartInput.setAlignment(QtCore.Qt.AlignRight)
|
||||
self.sweepStartInput.textEdited.connect(self.updateCenterSpan)
|
||||
|
||||
|
@ -171,6 +172,7 @@ class NanoVNASaver(QtWidgets.QWidget):
|
|||
sweep_input_left_layout.addRow(QtWidgets.QLabel("Stop"), self.sweepEndInput)
|
||||
|
||||
self.sweepCenterInput = QtWidgets.QLineEdit("")
|
||||
self.sweepCenterInput.setMinimumWidth(60)
|
||||
self.sweepCenterInput.setAlignment(QtCore.Qt.AlignRight)
|
||||
self.sweepCenterInput.textEdited.connect(self.updateStartEnd)
|
||||
|
||||
|
|
|
@ -14,10 +14,13 @@
|
|||
# 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 collections
|
||||
import logging
|
||||
from typing import List
|
||||
|
||||
Datapoint = collections.namedtuple('Datapoint', 'freq re im')
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Touchstone:
|
||||
s11data: List[Datapoint] = []
|
||||
|
@ -31,43 +34,53 @@ class Touchstone:
|
|||
def load(self):
|
||||
self.s11data = []
|
||||
self.s21data = []
|
||||
|
||||
realimaginary = False
|
||||
magnitudeangle = False
|
||||
|
||||
factor = 1
|
||||
try:
|
||||
logger.info("Attempting to open file %s", self.filename)
|
||||
file = open(self.filename, "r")
|
||||
|
||||
lines = file.readlines()
|
||||
parsed_header = False
|
||||
for l in lines:
|
||||
l = l.strip()
|
||||
if l.startswith("!"):
|
||||
for line in lines:
|
||||
line = line.strip()
|
||||
if line.startswith("!"):
|
||||
continue
|
||||
if l.startswith("#") and not parsed_header:
|
||||
if line.startswith("#") and not parsed_header:
|
||||
# Check that this is a valid header
|
||||
if l == "# Hz S RI R 50":
|
||||
if line == "# Hz S RI R 50":
|
||||
parsed_header = True
|
||||
realimaginary = True
|
||||
factor = 1
|
||||
continue
|
||||
elif l == "# kHz S RI R 50":
|
||||
elif line == "# kHz S RI R 50":
|
||||
parsed_header = True
|
||||
realimaginary = True
|
||||
factor = 10**3
|
||||
continue
|
||||
elif l == "# MHz S RI R 50":
|
||||
elif line == "# MHz S RI R 50":
|
||||
parsed_header = True
|
||||
realimaginary = True
|
||||
factor = 10**6
|
||||
continue
|
||||
elif l == "# GHz S RI R 50":
|
||||
elif line == "# GHz S RI R 50":
|
||||
parsed_header = True
|
||||
realimaginary = True
|
||||
factor = 10**9
|
||||
continue
|
||||
else:
|
||||
# This is some other comment line
|
||||
continue
|
||||
if not parsed_header:
|
||||
print("Warning: Read line without having read header: " + l)
|
||||
logger.warning("Read line without having read header: %s", line)
|
||||
continue
|
||||
|
||||
try:
|
||||
values = l.split(maxsplit=5)
|
||||
if realimaginary:
|
||||
values = line.split(maxsplit=5)
|
||||
freq = values[0]
|
||||
re11 = values[1]
|
||||
im11 = values[2]
|
||||
|
@ -81,12 +94,15 @@ class Touchstone:
|
|||
re21 = float(re21)
|
||||
im21 = float(im21)
|
||||
self.s21data.append(Datapoint(freq, re21, im21))
|
||||
elif magnitudeangle:
|
||||
# TODO: Implement parsing code for Magnitude-Angle
|
||||
continue
|
||||
except ValueError as e:
|
||||
print("Error parsing line " + l + " : " + str(e))
|
||||
logger.exception("Failed to parse line: %s (%s)", line, e)
|
||||
|
||||
file.close()
|
||||
except IOError as e:
|
||||
print("Failed to open " + self.filename)
|
||||
logger.exception("Failed to open %s: %s", self.filename, e)
|
||||
return
|
||||
|
||||
def setFilename(self, filename):
|
||||
|
|
Ładowanie…
Reference in New Issue