Skip to content

Commit

Permalink
Merge pull request scikit-rf#1092 from ericwrice/touchstone
Browse files Browse the repository at this point in the history
  • Loading branch information
jhillairet authored Jun 14, 2024
2 parents 8c5729d + 1241a63 commit 81de284
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
Binary file added skrf/io/tests/ntwk_zip.zip
Binary file not shown.
18 changes: 17 additions & 1 deletion skrf/io/tests/test_touchstone.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import os
import unittest
from pathlib import Path
from zipfile import ZipFile

import numpy as np
import pytest

from skrf.io.touchstone import Touchstone
from skrf import Network
from skrf.io.touchstone import Touchstone, read_zipped_touchstones


class TouchstoneTestCase(unittest.TestCase):
Expand Down Expand Up @@ -221,6 +223,20 @@ def test_ansys_terminal_data(self):
])
assert np.allclose(net.z0, z0)

def test_read_zipped_touchstones(self):
file = ZipFile(os.path.join(self.test_dir, "ntwk_zip.zip"))
ntwk1 = Network(os.path.join(self.test_dir, "ntwk1.s2p"))
ntwk2 = Network(os.path.join(self.test_dir, "ntwk2.s2p"))
ntwk3 = Network(os.path.join(self.test_dir, "ntwk3.s2p"))

read1 = read_zipped_touchstones(file, "Folder1")
read2 = read_zipped_touchstones(file, "Folder2")
read3 = read_zipped_touchstones(file)

assert read1 == {"ntwk1": ntwk1}
assert read2 == {"ntwk1": ntwk1, "ntwk2": ntwk2}
assert read3 == {"ntwk3": ntwk3}


suite = unittest.TestLoader().loadTestsFromTestCase(TouchstoneTestCase)
unittest.TextTestRunner(verbosity=2).run(suite)
2 changes: 1 addition & 1 deletion skrf/io/touchstone.py
Original file line number Diff line number Diff line change
Expand Up @@ -871,7 +871,7 @@ def read_zipped_touchstones(ziparchive: zipfile.ZipFile, dir: str = "") -> dict[
networks = dict()
for fname in ziparchive.namelist(): # type: str
directory = os.path.split(fname)[0]
if dir == directory and re.match(r"s\d+p", fname.lower()):
if dir == directory and re.search(r"s\d+p$", fname.lower()):
network = Network.zipped_touchstone(fname, ziparchive)
networks[network.name] = network
return networks

0 comments on commit 81de284

Please sign in to comment.