diff --git a/docs/source/version.6_1.rst b/docs/source/version.6_1.rst index 5ba8c190..ea50a673 100644 --- a/docs/source/version.6_1.rst +++ b/docs/source/version.6_1.rst @@ -23,3 +23,4 @@ Breaking changes in ``yadg-6.1`` are: Bug fixes in ``yadg-6.1`` include: - Fixed metadata extraction and added support for another version of the CVA technique in :mod:`yadg.extractors.eclab.mpr`. Thanks to `@acavell `_ for providing test files. + - Fixed timestamp parsing for D/M/Y formats of PicoVNA files in :mod:`yadg.extractors.touchstone.snp`. diff --git a/src/yadg/extractors/ezchrom/asc.py b/src/yadg/extractors/ezchrom/asc.py index 534cf16f..5f24d017 100644 --- a/src/yadg/extractors/ezchrom/asc.py +++ b/src/yadg/extractors/ezchrom/asc.py @@ -83,15 +83,15 @@ def extract( timezone=timezone, ) if line.startswith("Sampling Rate:"): - assert ( - "Hz" in line - ), f"datasc: Incorrect units for rate in file {fn}: {line}" + assert "Hz" in line, ( + f"datasc: Incorrect units for rate in file {fn}: {line}" + ) parts = line.split("\t") samplerates = [float(each.strip()) for each in parts[1:-1]] if line.startswith("Total Data Points:"): - assert ( - "Pts." in line - ), f"datasc: Incorrect units for number of points in file {fn}: {line}" + assert "Pts." in line, ( + f"datasc: Incorrect units for number of points in file {fn}: {line}" + ) parts = line.split("\t") npoints = [int(each.strip()) for each in parts[1:-1]] if line.startswith("X Axis Title:"): @@ -127,9 +127,9 @@ def extract( data = {} units = {} for ti, npts in enumerate(npoints): - assert ( - xunits[ti] == "Minutes" - ), f"datasc: X units label of trace {ti} in {fn} was not understood." + assert xunits[ti] == "Minutes", ( + f"datasc: X units label of trace {ti} in {fn} was not understood." + ) dt = 60 xmul = xmuls[ti] * dt / samplerates[ti] ymul = ymuls[ti] diff --git a/src/yadg/extractors/fhimcpt/vna.py b/src/yadg/extractors/fhimcpt/vna.py index 04f0d940..8dfb2dff 100644 --- a/src/yadg/extractors/fhimcpt/vna.py +++ b/src/yadg/extractors/fhimcpt/vna.py @@ -51,9 +51,9 @@ def extract( ) -> DataTree: with open(fn, "r", encoding=encoding) as infile: lines = infile.readlines() - assert ( - len(lines) > 2 - ), f"qftrace: Only {len(lines)-1} points supplied in {fn}; fitting impossible." + assert len(lines) > 2, ( + f"qftrace: Only {len(lines) - 1} points supplied in {fn}; fitting impossible." + ) # process header bw = [10000.0, 1.0] diff --git a/src/yadg/extractors/phi/spe.py b/src/yadg/extractors/phi/spe.py index 878f03f0..8637fb89 100644 --- a/src/yadg/extractors/phi/spe.py +++ b/src/yadg/extractors/phi/spe.py @@ -305,7 +305,7 @@ def _process_traces(spe: list[bytes], trace_defs: list[dict]) -> dict: retstep=True, ) # Construct data from trace_header - data_dtype = np.dtype(f'{trace_header["data_dtype"].decode()}') + data_dtype = np.dtype(f"{trace_header['data_dtype'].decode()}") data_offset = trace_header["end_of_data"] - trace_header["num_data_bytes"] datapoints = np.frombuffer( data, diff --git a/src/yadg/extractors/touchstone/snp.py b/src/yadg/extractors/touchstone/snp.py index 9c4e29f9..9f6f7c6a 100644 --- a/src/yadg/extractors/touchstone/snp.py +++ b/src/yadg/extractors/touchstone/snp.py @@ -124,10 +124,12 @@ def process_comments(lines: list[str], tz: str) -> dict: pass # PicoVNA 108 files elif "Ref Plane:" in comstr and len(lines) == 3: - fmt = "%m/%d/%Y %I:%M:%S %p" - uts = dgutils.str_to_uts( - timestamp=lines[0], timezone=tz, format=fmt, strict=False - ) + for fmt in ["%m/%d/%Y %I:%M:%S %p", "%d/%m/%Y %H:%M:%S"]: + uts = dgutils.str_to_uts( + timestamp=lines[0], timezone=tz, format=fmt, strict=False + ) + if uts is not None: + break attrs["Ref Plane"] = lines[1].split(":")[1].strip() attrs["Model"] = "PicoVNA 108" # Agilent N523* and E50* export diff --git a/src/yadg/main.py b/src/yadg/main.py index a478dadd..28635e5a 100644 --- a/src/yadg/main.py +++ b/src/yadg/main.py @@ -31,7 +31,7 @@ def run_with_arguments(): parser.add_argument( "--version", action="version", - version=f'%(prog)s version {metadata.version("yadg")}', + version=f"%(prog)s version {metadata.version('yadg')}", ) verbose = argparse.ArgumentParser(add_help=False) diff --git a/src/yadg/subcommands.py b/src/yadg/subcommands.py index f6cad5f5..8a8a6e8c 100644 --- a/src/yadg/subcommands.py +++ b/src/yadg/subcommands.py @@ -151,7 +151,7 @@ def preset( """ assert os.path.exists(folder) and os.path.isdir(folder), ( - f"Supplied folder path '{folder}' does not exist " "or is not a valid folder." + f"Supplied folder path '{folder}' does not exist or is not a valid folder." ) if not os.path.isabs(folder) and not process: @@ -161,7 +161,7 @@ def preset( ) assert os.path.exists(preset) and os.path.isfile(preset), ( - f"Supplied preset path '{preset}' does not exist " "or is not a valid file." + f"Supplied preset path '{preset}' does not exist or is not a valid file." ) logger.info("Reading input file from '%s'.", preset) @@ -223,7 +223,7 @@ def extract( path = Path(infile) assert path.is_file(), ( - f"Supplied object filename '{infile}' does not exist " "or is not a valid file." + f"Supplied object filename '{infile}' does not exist or is not a valid file." ) if outfile is None: diff --git a/tests/test_schema.py b/tests/test_schema.py index d6108d39..9fd85241 100644 --- a/tests/test_schema.py +++ b/tests/test_schema.py @@ -182,7 +182,7 @@ def test_datagram_from_schema_file(inp_fn, ts, datadir): os.chdir(datadir) ret = datagram_from_file(inp_fn) assert len(ret.children) == ts["nsteps"], ( - "wrong number of steps: " f"got: {len(ret.children)}, expected: {ts['nsteps']}" + f"wrong number of steps: got: {len(ret.children)}, expected: {ts['nsteps']}" ) for k, v in ts["kwargs"].items(): assert ret[ts["step"]][k][ts["item"]] == v, "kwargs not passed correctly" diff --git a/tests/test_timezones.py b/tests/test_timezones.py index 194dd555..b9e7b7dd 100644 --- a/tests/test_timezones.py +++ b/tests/test_timezones.py @@ -33,21 +33,21 @@ def test_isotimestamp_parsing_utc(datadir): dg = datagram_from_file("iso_utc.json") assert dg["0"].uts[0] == 1622557825.0, "Z-suffix parsed to 'uts' correctly" - assert ( - dg["0"].uts[1] == 1622557825.0 + 7200 + 1 - ), "±HH:MM-suffix parsed to 'uts' correctly" - assert ( - dg["0"].uts[2] == 1622557825.0 + 2 - ), "no suffix with timezone = UTC parsed to 'uts' correctly" + assert dg["0"].uts[1] == 1622557825.0 + 7200 + 1, ( + "±HH:MM-suffix parsed to 'uts' correctly" + ) + assert dg["0"].uts[2] == 1622557825.0 + 2, ( + "no suffix with timezone = UTC parsed to 'uts' correctly" + ) def test_isotimestamp_parsing_cet(datadir): os.chdir(datadir) dg = datagram_from_file("iso_cet.json") assert dg["0"].uts[0] == 1622557825.0, "Z-suffix parsed to 'uts' correctly" - assert ( - dg["0"].uts[1] == 1622557825.0 + 7200 + 1 - ), "±HH:MM-suffix parsed to 'uts' correctly" - assert ( - dg["0"].uts[2] == 1622557825.0 - 7200 + 2 - ), "no suffix with timezone = CEST parsed to 'uts' correctly" + assert dg["0"].uts[1] == 1622557825.0 + 7200 + 1, ( + "±HH:MM-suffix parsed to 'uts' correctly" + ) + assert dg["0"].uts[2] == 1622557825.0 - 7200 + 2, ( + "no suffix with timezone = CEST parsed to 'uts' correctly" + ) diff --git a/tests/test_x_touchstone_snp.py b/tests/test_x_touchstone_snp.py index 9583749b..6828520f 100644 --- a/tests/test_x_touchstone_snp.py +++ b/tests/test_x_touchstone_snp.py @@ -9,6 +9,7 @@ "infile, locale", [ ("picovna.s1p", "en_GB"), + ("picovna_DMY.s1p", "en_GB"), ("Device_r_40um.s1p", "en_GB"), ("Device_r_60um.s1p", "en_GB"), ("Fig8_0.6cm.s1p", "en_GB"), diff --git a/tests/test_x_touchstone_snp/picovna_DMY.s1p b/tests/test_x_touchstone_snp/picovna_DMY.s1p new file mode 100644 index 00000000..462ff186 --- /dev/null +++ b/tests/test_x_touchstone_snp/picovna_DMY.s1p @@ -0,0 +1,106 @@ +! 27/01/2025 08:23:54 +! Ref Plane: 0.000 mm +# MHZ S MA R 50 +! +2500.0000 1.00344 158.31 +2500.5000 1.00299 158.26 +2501.0000 1.00322 158.18 +2501.5000 1.00326 158.08 +2502.0000 1.0034 158.03 +2502.5000 1.0029 157.96 +2503.0000 1.00322 157.87 +2503.5000 1.00324 157.81 +2504.0000 1.00345 157.73 +2504.5000 1.00334 157.65 +2505.0000 1.00342 157.58 +2505.5000 1.00338 157.50 +2506.0000 1.00333 157.43 +2506.5000 1.00318 157.36 +2507.0000 1.00314 157.29 +2507.5000 1.00352 157.21 +2508.0000 1.00324 157.15 +2508.5000 1.00335 157.07 +2509.0000 1.00319 157.01 +2509.5000 1.00321 156.93 +2510.0000 1.00319 156.86 +2510.5000 1.00291 156.79 +2511.0000 1.00321 156.72 +2511.5000 1.00331 156.66 +2512.0000 1.00326 156.58 +2512.5000 1.00339 156.51 +2513.0000 1.00317 156.44 +2513.5000 1.00335 156.37 +2514.0000 1.0029 156.30 +2514.5000 1.00328 156.23 +2515.0000 1.00352 156.15 +2515.5000 1.00295 156.10 +2516.0000 1.00325 156.04 +2516.5000 1.00296 155.96 +2517.0000 1.00327 155.89 +2517.5000 1.00305 155.82 +2518.0000 1.00298 155.76 +2518.5000 1.00301 155.68 +2519.0000 1.00297 155.61 +2519.5000 1.00322 155.55 +2520.0000 1.00292 155.47 +2520.5000 1.00288 155.40 +2521.0000 1.00309 155.33 +2521.5000 1.00287 155.27 +2522.0000 1.00297 155.20 +2522.5000 1.00312 155.12 +2523.0000 1.00316 155.06 +2523.5000 1.00274 154.99 +2524.0000 1.00302 154.92 +2524.5000 1.00322 154.84 +2525.0000 1.003 154.79 +2525.5000 1.00294 154.71 +2526.0000 1.00308 154.64 +2526.5000 1.00282 154.57 +2527.0000 1.00295 154.51 +2527.5000 1.003 154.42 +2528.0000 1.00297 154.36 +2528.5000 1.00306 154.27 +2529.0000 1.00313 154.20 +2529.5000 1.00288 154.13 +2530.0000 1.00292 154.06 +2530.5000 1.0029 153.99 +2531.0000 1.003 153.92 +2531.5000 1.00291 153.84 +2532.0000 1.00307 153.77 +2532.5000 1.00273 153.69 +2533.0000 1.00271 153.63 +2533.5000 1.00299 153.55 +2534.0000 1.00284 153.46 +2534.5000 1.00294 153.41 +2535.0000 1.00269 153.32 +2535.5000 1.00256 153.25 +2536.0000 1.00266 153.19 +2536.5000 1.00242 153.10 +2537.0000 1.0025 153.04 +2537.5000 1.00285 152.97 +2538.0000 1.00257 152.89 +2538.5000 1.0026 152.83 +2539.0000 1.0027 152.75 +2539.5000 1.00265 152.68 +2540.0000 1.00238 152.60 +2540.5000 1.00252 152.53 +2541.0000 1.00253 152.45 +2541.5000 1.00254 152.37 +2542.0000 1.00222 152.32 +2542.5000 1.00235 152.24 +2543.0000 1.00233 152.17 +2543.5000 1.00205 152.10 +2544.0000 1.00224 152.02 +2544.5000 1.00222 151.95 +2545.0000 1.00228 151.88 +2545.5000 1.00193 151.80 +2546.0000 1.00217 151.74 +2546.5000 1.00201 151.67 +2547.0000 1.00186 151.57 +2547.5000 1.00173 151.52 +2548.0000 1.00194 151.43 +2548.5000 1.0017 151.38 +2549.0000 1.00184 151.31 +2549.5000 1.00188 151.23 +2550.0000 1.00178 151.16 +2550.5000 1.00166 151.08 diff --git a/tests/test_x_touchstone_snp/picovna_DMY.s1p.pkl b/tests/test_x_touchstone_snp/picovna_DMY.s1p.pkl new file mode 100644 index 00000000..e4fb6a09 Binary files /dev/null and b/tests/test_x_touchstone_snp/picovna_DMY.s1p.pkl differ