Reads Touchstone files into AxisArrays. Supports Sonnet parameter sweeps.
The gory details:
To load a Touchstone file with extension .s1p
, .s2p
, .s3p
, etc. into an
AxisArray, it could not be
any easier:
julia> using Touchstone, FileIO, AxisArrays
julia> A = load(joinpath(Pkg.dir("Touchstone"), "test", "paramsweep", "BusResonator_17_param01.s2p"))
6-dimensional AxisArray{Float64,6,...} with axes:
:format, Symbol[:mag, :angle]
:parameter, Symbol[:S]
:to, Base.OneTo(2)
:from, Base.OneTo(2)
:f, [6.0, 6.05, 6.1, 6.15, 6.2, 6.25, 6.3, 6.35, 6.4, 6.45 β¦ 15.55, 15.6, 15.65, 15.7, 15.75, 15.8, 15.85, 15.9, 15.95, 16.0]
:BusLengthControl, [100.0]
And data, a 2Γ1Γ2Γ2Γ798Γ1 Array{Float64,6}:
[:, :, 1, 1, 1, 1] =
1.0
-3.613
[:, :, 2, 1, 1, 1] =
2.039e-5
75.309
...
Notice how some parameter appeared as a fourth dimension? That parameter was
included as a comment by Sonnet when the .s2p file was exported. Here's the
fun part. If you have a parameter sweep or even a multi-parameter sweep saved
as a collection of .s2p files in a folder, for example as exported by Sonnet,
you can use loadset
to import everything into one AxisArray:
julia> loadset(joinpath(Pkg.dir("Touchstone"), "test", "paramsweep"))
6-dimensional AxisArray{Float64,6,...} with axes:
:format, Symbol[:mag, :angle]
:parameter, Symbol[:S]
:to, [1, 2]
:from, [1, 2]
:f, [6.0, 6.05, 6.1, 6.15, 6.2, 6.25, 6.26015, 6.27006, 6.27975, 6.28922 β¦ 15.5886, 15.6, 15.65, 15.7, 15.75, 15.8, 15.85, 15.9, 15.95, 16.0]
:BusLengthControl, [100.0, 600.0, 1100.0, 1600.0, 2100.0, 2600.0, 3100.0, 3600.0, 4100.0, 4600.0, 5100.0]
And data, a 2Γ1Γ2Γ2Γ8561Γ11 Array{Float64,6}:
[:, :, 1, 1, 1, 1] =
1.0
-3.613
[:, :, 2, 1, 1, 1] =
2.039e-5
75.309
...
Note that sometimes Sonnet will save files with different frequency axes in one parameter
sweep depending on what adaptive band synthesis chose to do. If this happens, all of the
frequency axes are merged, and missing values are interpolated. Linear()
or Constant()
(nearest-neighbor) interpolation may be chosen using the interp
keyword argument in
loadset
.
The parameter is kept as a separate axis so that you can load S-parameters,
Y-parameters, Z-parameters and the like into one AxisArray
.
You can convert between the various formats (RealImag
, dBAngle
, MagAngle
):
julia> reformat(RealImag, A)
6-dimensional AxisArray{Float64,6,...} with axes:
:parameter, Symbol[:S]
:to, Base.OneTo(2)
:from, Base.OneTo(2)
:f, [6.0, 6.05, 6.1, 6.15, 6.2, 6.25, 6.3, 6.35, 6.4, 6.45 β¦ 15.55, 15.6, 15.65, 15.7, 15.75, 15.8, 15.85, 15.9, 15.95, 16.0]
:BusLengthControl, [100.0]
:format, Symbol[:real, :imag]
And data, a 1Γ2Γ2Γ798Γ1Γ2 Array{Float64,6}:
[:, :, 1, 1, 1, 1] =
0.998012 5.17103e-6
[:, :, 2, 1, 1, 1] =
5.17103e-6 0.900621
...
Take care as the axes are reordered, so it is better to use the special Axis-based indexing
(e.g. A[Axis{:format}(:mag), ...]
).
Once you have imported the data and formatted it to your liking then you can:
- Plot heatmaps with, for example, one axis as frequency and one axis as a swept parameter, etc.
- Do peak-finding as a function of a swept parameter
- Do other fun things
Touchstone v2 is not yet supported.