File input/output
Touchstone import
Imports an S matrix frequency sweep from a touchstone file. |
Example
import ipkiss3.all as i3
from ipkiss3.io.touchstone import import_touchstone_smatrix
import numpy as np
touchstone_4port = """! 4-port S-parameter data, taken at three frequency points
# GHZ S MA R 50
5.00000 0.60 161.24 0.40 -42.20 0.42 -66.58 0.53 -79.34 !row 1
0.40 -42.20 0.60 161.20 0.53 -79.34 0.42 -66.58 !row 2
0.42 -66.58 0.53 -79.34 0.60 161.24 0.40 -42.20 !row 3
0.53 -79.34 0.42 -66.58 0.40 -42.20 0.60 161.24 !row 4
6.00000 0.57 150.37 0.40 -44.34 0.41 -81.24 0.57 -95.77 !row 1
0.40 -44.34 0.57 150.37 0.57 -95.77 0.41 -81.24 !row 2
0.41 -81.24 0.57 -95.77 0.57 150.37 0.40 -44.34 !row 3
0.57 -95.77 0.41 -81.24 0.40 -44.34 0.57 150.37 !row 4
7.00000 0.50 136.69 0.45 -46.41 0.37 -99.09 0.62 -114.19 !row 1
0.45 -46.41 0.50 136.69 0.62 -114.19 0.37 -99.09 !row 2
0.37 -99.09 0.62 -114.19 0.50 136.69 0.45 -46.41 !row 3
0.62 -114.19 0.37 -99.09 0.45 -46.41 0.50 136.69 !row 4
"""
fn = "touchstone_4port_example.s4p"
with open(fn, 'w') as f:
f.write(touchstone_4port)
term_mode_map = {("opt1", 0): 0,
("opt2", 0): 1,
("opt3", 0): 2,
("opt4", 0): 3
}
S = import_touchstone_smatrix(fn, term_mode_map=term_mode_map)
S.visualize(
term_pairs=[("opt1", "opt2"),("opt1", "opt3"),("opt1", "opt4")],
title="S-parameters",
xlabel="frequency [GHz]",
ylabel="magnitude",
)
The imported data can be interpolated automatically with BSplineSModel
and used as a compact model.
See Circuit simulation with scatter matrix files for a tutorial.
Touchstone export
Exports an S matrix frequency / wavelength sweep to a touchstone file. |
Example
from ipkiss3.io.touchstone import import_touchstone_smatrix, export_touchstone_smatrix
term_mode_map = {
("opt1", 0): 0,
("opt2", 0): 1,
("opt3", 0): 2,
("opt4", 0): 3
}
S = import_touchstone_smatrix(filename="touchstone_4port_example.s4p", term_mode_map=term_mode_map)
# change the format to real / imaginary instead of magnitude / angle
export_touchstone_smatrix(smatrix1dsweep=S, filename="touchstone_4port_example_export", param_format='RI')
""" The resulting output should be the following
! Touchstone file export by IPKISS
! Luceda port opt4: mode 0:3
! Luceda port opt2: mode 0:1
! Luceda port opt3: mode 0:2
! Luceda port opt1: mode 0:0
# GHz S RI R 50.0
5.0 -0.56812440798159958 0.19296283853518795 0.29632183851470006 -0.26868823572919609 ...
0.29632183851470006 -0.26868823572919609 -0.5679895560694177 0.19335941713830671 ...
0.16693665375723588 -0.38539869438327984 0.09803970583787712 -0.52085335371793717 ...
0.09803970583787712 -0.52085335371793717 0.16693665375723588 -0.38539869438327984 ...
6.0 -0.49546462429403598 0.28180632724119187 0.28608198939291601 -0.27956590519051411 ...
0.28608198939291601 -0.27956590519051411 -0.49546462429403598 0.28180632724119187 ...
0.062441313054034865 -0.40521732739862937 -0.057305158068901609 -0.56711208668013613 ...
0.057305158068901609 -0.56711208668013613 0.062441313054034865 -0.40521732739862937 ...
7.0 -0.3638265243449566 0.3429726813946975 0.31027191362976669 -0.32593149527549903 ...
0.31027191362976669 -0.32593149527549903 -0.3638265243449566 0.3429726813946975 ...
0.058454719591767589 -0.36535331633563672 -0.25405357621626995 -0.56555882135435209 ...
-0.25405357621626995 -0.56555882135435209 -0.058454719591767589 -0.36535331633563672 ...
"""