Skip to content

Commit 3127be4

Browse files
committed
touchstone.snp: Fix picovna timestamp parsing. (#204)
* Fix timestamp parsing for touchstone. * tests * docs * ruff changes.
1 parent 262569a commit 3127be4

File tree

12 files changed

+144
-34
lines changed

12 files changed

+144
-34
lines changed

docs/source/version.6_1.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ Breaking changes in ``yadg-6.1`` are:
2323
Bug fixes in ``yadg-6.1`` include:
2424

2525
- Fixed metadata extraction and added support for another version of the CVA technique in :mod:`yadg.extractors.eclab.mpr`. Thanks to `@acavell <https://github.com/acavell>`_ for providing test files.
26+
- Fixed timestamp parsing for D/M/Y formats of PicoVNA files in :mod:`yadg.extractors.touchstone.snp`.

src/yadg/extractors/ezchrom/asc.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,15 @@ def extract(
8383
timezone=timezone,
8484
)
8585
if line.startswith("Sampling Rate:"):
86-
assert (
87-
"Hz" in line
88-
), f"datasc: Incorrect units for rate in file {fn}: {line}"
86+
assert "Hz" in line, (
87+
f"datasc: Incorrect units for rate in file {fn}: {line}"
88+
)
8989
parts = line.split("\t")
9090
samplerates = [float(each.strip()) for each in parts[1:-1]]
9191
if line.startswith("Total Data Points:"):
92-
assert (
93-
"Pts." in line
94-
), f"datasc: Incorrect units for number of points in file {fn}: {line}"
92+
assert "Pts." in line, (
93+
f"datasc: Incorrect units for number of points in file {fn}: {line}"
94+
)
9595
parts = line.split("\t")
9696
npoints = [int(each.strip()) for each in parts[1:-1]]
9797
if line.startswith("X Axis Title:"):
@@ -127,9 +127,9 @@ def extract(
127127
data = {}
128128
units = {}
129129
for ti, npts in enumerate(npoints):
130-
assert (
131-
xunits[ti] == "Minutes"
132-
), f"datasc: X units label of trace {ti} in {fn} was not understood."
130+
assert xunits[ti] == "Minutes", (
131+
f"datasc: X units label of trace {ti} in {fn} was not understood."
132+
)
133133
dt = 60
134134
xmul = xmuls[ti] * dt / samplerates[ti]
135135
ymul = ymuls[ti]

src/yadg/extractors/fhimcpt/vna.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ def extract(
5151
) -> DataTree:
5252
with open(fn, "r", encoding=encoding) as infile:
5353
lines = infile.readlines()
54-
assert (
55-
len(lines) > 2
56-
), f"qftrace: Only {len(lines)-1} points supplied in {fn}; fitting impossible."
54+
assert len(lines) > 2, (
55+
f"qftrace: Only {len(lines) - 1} points supplied in {fn}; fitting impossible."
56+
)
5757

5858
# process header
5959
bw = [10000.0, 1.0]

src/yadg/extractors/phi/spe.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ def _process_traces(spe: list[bytes], trace_defs: list[dict]) -> dict:
305305
retstep=True,
306306
)
307307
# Construct data from trace_header
308-
data_dtype = np.dtype(f'{trace_header["data_dtype"].decode()}')
308+
data_dtype = np.dtype(f"{trace_header['data_dtype'].decode()}")
309309
data_offset = trace_header["end_of_data"] - trace_header["num_data_bytes"]
310310
datapoints = np.frombuffer(
311311
data,

src/yadg/extractors/touchstone/snp.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,12 @@ def process_comments(lines: list[str], tz: str) -> dict:
124124
pass
125125
# PicoVNA 108 files
126126
elif "Ref Plane:" in comstr and len(lines) == 3:
127-
fmt = "%m/%d/%Y %I:%M:%S %p"
128-
uts = dgutils.str_to_uts(
129-
timestamp=lines[0], timezone=tz, format=fmt, strict=False
130-
)
127+
for fmt in ["%m/%d/%Y %I:%M:%S %p", "%d/%m/%Y %H:%M:%S"]:
128+
uts = dgutils.str_to_uts(
129+
timestamp=lines[0], timezone=tz, format=fmt, strict=False
130+
)
131+
if uts is not None:
132+
break
131133
attrs["Ref Plane"] = lines[1].split(":")[1].strip()
132134
attrs["Model"] = "PicoVNA 108"
133135
# Agilent N523* and E50* export

src/yadg/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def run_with_arguments():
3131
parser.add_argument(
3232
"--version",
3333
action="version",
34-
version=f'%(prog)s version {metadata.version("yadg")}',
34+
version=f"%(prog)s version {metadata.version('yadg')}",
3535
)
3636

3737
verbose = argparse.ArgumentParser(add_help=False)

src/yadg/subcommands.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def preset(
151151
152152
"""
153153
assert os.path.exists(folder) and os.path.isdir(folder), (
154-
f"Supplied folder path '{folder}' does not exist " "or is not a valid folder."
154+
f"Supplied folder path '{folder}' does not exist or is not a valid folder."
155155
)
156156

157157
if not os.path.isabs(folder) and not process:
@@ -161,7 +161,7 @@ def preset(
161161
)
162162

163163
assert os.path.exists(preset) and os.path.isfile(preset), (
164-
f"Supplied preset path '{preset}' does not exist " "or is not a valid file."
164+
f"Supplied preset path '{preset}' does not exist or is not a valid file."
165165
)
166166

167167
logger.info("Reading input file from '%s'.", preset)
@@ -223,7 +223,7 @@ def extract(
223223
path = Path(infile)
224224

225225
assert path.is_file(), (
226-
f"Supplied object filename '{infile}' does not exist " "or is not a valid file."
226+
f"Supplied object filename '{infile}' does not exist or is not a valid file."
227227
)
228228

229229
if outfile is None:

tests/test_schema.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ def test_datagram_from_schema_file(inp_fn, ts, datadir):
182182
os.chdir(datadir)
183183
ret = datagram_from_file(inp_fn)
184184
assert len(ret.children) == ts["nsteps"], (
185-
"wrong number of steps: " f"got: {len(ret.children)}, expected: {ts['nsteps']}"
185+
f"wrong number of steps: got: {len(ret.children)}, expected: {ts['nsteps']}"
186186
)
187187
for k, v in ts["kwargs"].items():
188188
assert ret[ts["step"]][k][ts["item"]] == v, "kwargs not passed correctly"

tests/test_timezones.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,21 @@ def test_isotimestamp_parsing_utc(datadir):
3333
dg = datagram_from_file("iso_utc.json")
3434

3535
assert dg["0"].uts[0] == 1622557825.0, "Z-suffix parsed to 'uts' correctly"
36-
assert (
37-
dg["0"].uts[1] == 1622557825.0 + 7200 + 1
38-
), "±HH:MM-suffix parsed to 'uts' correctly"
39-
assert (
40-
dg["0"].uts[2] == 1622557825.0 + 2
41-
), "no suffix with timezone = UTC parsed to 'uts' correctly"
36+
assert dg["0"].uts[1] == 1622557825.0 + 7200 + 1, (
37+
"±HH:MM-suffix parsed to 'uts' correctly"
38+
)
39+
assert dg["0"].uts[2] == 1622557825.0 + 2, (
40+
"no suffix with timezone = UTC parsed to 'uts' correctly"
41+
)
4242

4343

4444
def test_isotimestamp_parsing_cet(datadir):
4545
os.chdir(datadir)
4646
dg = datagram_from_file("iso_cet.json")
4747
assert dg["0"].uts[0] == 1622557825.0, "Z-suffix parsed to 'uts' correctly"
48-
assert (
49-
dg["0"].uts[1] == 1622557825.0 + 7200 + 1
50-
), "±HH:MM-suffix parsed to 'uts' correctly"
51-
assert (
52-
dg["0"].uts[2] == 1622557825.0 - 7200 + 2
53-
), "no suffix with timezone = CEST parsed to 'uts' correctly"
48+
assert dg["0"].uts[1] == 1622557825.0 + 7200 + 1, (
49+
"±HH:MM-suffix parsed to 'uts' correctly"
50+
)
51+
assert dg["0"].uts[2] == 1622557825.0 - 7200 + 2, (
52+
"no suffix with timezone = CEST parsed to 'uts' correctly"
53+
)

tests/test_x_touchstone_snp.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"infile, locale",
1010
[
1111
("picovna.s1p", "en_GB"),
12+
("picovna_DMY.s1p", "en_GB"),
1213
("Device_r_40um.s1p", "en_GB"),
1314
("Device_r_60um.s1p", "en_GB"),
1415
("Fig8_0.6cm.s1p", "en_GB"),

0 commit comments

Comments
 (0)