Skip to content

Commit

Permalink
Localize touchstone & add test. (#169)
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterKraus authored Jun 22, 2024
1 parent df0fccc commit 9049783
Show file tree
Hide file tree
Showing 4 changed files with 10,025 additions and 15 deletions.
8 changes: 6 additions & 2 deletions src/yadg/extractors/touchstone/snp.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
import logging
from datatree import DataTree
from xarray import Dataset, DataArray
from uncertainties.core import str_to_number_with_uncert as tuple_fromstr
from babel.numbers import parse_decimal

from yadg import dgutils

Expand Down Expand Up @@ -188,6 +188,7 @@ def extract(
fn: str,
encoding: str,
timezone: str,
locale: str,
**kwargs: dict,
) -> DataTree:
with open(fn, encoding=encoding) as inf:
Expand Down Expand Up @@ -232,7 +233,10 @@ def extract(

# For .s3p and above, we'd have to append multiple lines together here
for k, v in zip(cols, parts):
val, dev = tuple_fromstr(v)
dec = parse_decimal(v, locale=locale)
exp = dec.as_tuple().exponent
val = float(dec)
dev = 10**exp
if k == "frequency":
data[k].append(val)
data[f"{k}_std_err"].append(dev)
Expand Down
27 changes: 14 additions & 13 deletions tests/test_x_touchstone_snp.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,24 @@


@pytest.mark.parametrize(
"infile",
"infile, locale",
[
"picovna.s1p",
"Device_r_40um.s1p",
"Device_r_60um.s1p",
"Fig8_0.6cm.s1p",
"Fig8_5.6cm.s1p",
"SCENARIO1_pulserside_30k_3G.s1p",
"SCENARIO4_pulserside_30k_3G.s1p",
"CABLE_3_5MM_1N_TYPE_CONNECTORS.S2P",
"VNA_radial_middle.s1p",
"VNA_radial_middle.s2p",
("picovna.s1p", "en_GB"),
("Device_r_40um.s1p", "en_GB"),
("Device_r_60um.s1p", "en_GB"),
("Fig8_0.6cm.s1p", "en_GB"),
("Fig8_5.6cm.s1p", "en_GB"),
("SCENARIO1_pulserside_30k_3G.s1p", "en_GB"),
("SCENARIO4_pulserside_30k_3G.s1p", "en_GB"),
("CABLE_3_5MM_1N_TYPE_CONNECTORS.S2P", "en_GB"),
("VNA_radial_middle.s1p", "en_GB"),
("VNA_radial_middle.s2p", "en_GB"),
("2024-06-20-01-empty.s1p", "de_DE"),
],
)
def test_touchstone_snp(infile, datadir):
def test_touchstone_snp(infile, locale, datadir):
os.chdir(datadir)
ret = extract(fn=infile, encoding="utf-8", timezone="Europe/Berlin")
ret = extract(fn=infile, encoding="utf-8", timezone="Europe/Berlin", locale=locale)
outfile = f"{infile}.pkl"
with open(outfile, "rb") as inp:
ref = pickle.load(inp)
Expand Down
Loading

0 comments on commit 9049783

Please sign in to comment.