Skip to content

Commit

Permalink
Merge pull request scikit-rf#1117 from Asachoo/TouchStoneFormat
Browse files Browse the repository at this point in the history
Adding S-parameter definition in Touchstone V1 comment
  • Loading branch information
mhuser authored Jul 13, 2024
2 parents 5d0c939 + df717fa commit b67a5c2
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
6 changes: 5 additions & 1 deletion skrf/io/touchstone.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

import numpy as np

from ..constants import FREQ_UNITS, S_DEF_HFSS_DEFAULT
from ..constants import FREQ_UNITS, S_DEF_HFSS_DEFAULT, S_DEFINITIONS
from ..media import DefinedGammaZ0
from ..network import Network
from ..util import get_fid
Expand Down Expand Up @@ -498,6 +498,10 @@ def load_file(self, fid: typing.TextIO):

self.s_def = S_DEF_HFSS_DEFAULT
self.has_hfss_port_impedances = True
# Load the reference impedance convention from the comments
for s_def in S_DEFINITIONS:
if f'S-parameter uses the {s_def} definition' in self.comments:
self.s_def = s_def
elif self.reference is None:
self.z0 = np.broadcast_to(self.resistance, (len(state.f), state.rank)).copy()
else:
Expand Down
3 changes: 2 additions & 1 deletion skrf/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -2409,7 +2409,8 @@ def get_buffer() -> io.StringIO:
# exactly this format, to work
# [HZ/KHZ/MHZ/GHZ] [S/Y/Z/G/H] [MA/DB/RI] [R n]
if write_z0:
output.write('!Data is not renormalized\n')
output.write('! Data is not renormalized\n')
output.write(f'! S-parameter uses the {self.s_def} definition\n')
output.write(f'# {ntwk.frequency.unit} S {form} R\n')
else:
# Write "r_ref.real" instead of "r_ref", so we get a real number "a" instead
Expand Down
2 changes: 2 additions & 0 deletions skrf/tests/test_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -1074,6 +1074,8 @@ def test_sparam_from_hfss_with_power_wave(self):
ntwk_orig.write_touchstone(os.path.join(self.test_dir, pwfile_skrf), write_z0=True, form='RI')
ntwk_skrf = rf.Network(os.path.join(self.test_dir, pwfile_skrf))

# check if the s_def could be correctly recovered from scikit-rf's Touchstone file
self.assertTrue(ntwk_orig.s_def == ntwk_skrf.s_def)
self.assertTrue(ntwk_orig == ntwk_skrf)

def test_network_from_z_or_y(self):
Expand Down
5 changes: 3 additions & 2 deletions skrf/tests/tmp_skrf_oneport_powerwave.s1p
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
! YY = 1
!Data is not renormalized
!
!Created with skrf (http://scikit-rf.org).
!Data is not renormalized
! Created with skrf (http://scikit-rf.org).
! Data is not renormalized
! S-parameter uses the power definition
# GHz S RI R
! Port[1] = 1
!freq ReS11 ImS11
Expand Down

0 comments on commit b67a5c2

Please sign in to comment.