TouchstoneParser
It implements the specification (versions 1.0, 1.1, 2.0 and 2.1) and provides a simple API to access data and metadata.
Notes
While the core functionality has been tested using examples from the official Touchstone specification, it has not been extensively validated against a wide variety of real-world files. Contributions or bug reports are welcome.
Features
- [x] Parse Touchstone files in v1.0, v1.1, v2.0, v2.1 (
read_touchstone). - [x] Automatically detect format even if the filename does not contain the
.sNpextension - [x] Write Touchstone files in the desired format (
write_touchstone) - [x] Handle non-standard versions of the format (e.g., files generated by HFSS. Used skrf as reference because I didn't found other resources.)
- [x] Support for comments.
- [x] Convenient access to data via
ts.data,ts.frequency,ts.noise_data,ts.noise_frequency.
Roadmap
- [ ] Better validation to ensure Touchstone files strictly comply with the official specification.
- [ ] Enhanced customization options for writing files, including units, formatting, and ordering.
- [ ] Batch reading/writing for entire directories of Touchstone files.
Installation
] add https://github.com/uvegege/TouchstoneParser.jlUsage
It's easy to write and read Touchstone files:
using TouchstoneParser
# Example 18
f = [2.0, 22.0]
S = [
[[0.95 * cis(deg2rad(-26)), 3.57 * cis(deg2rad(157))];;
[0.04 * cis(deg2rad(76 )), 0.66 *cis(deg2rad(-14))]],
[[0.60 * cis(deg2rad(-144 )), 1.30 * cis(deg2rad(40))];;
[0.14 * cis(deg2rad(40)), 0.56 * cis(deg2rad(-85))]]
]
z0 = [50, 25.0]
noise_f = [4.0, 18.0]
noise_data = [NoiseData(0.7, 0.64 * cis(deg2rad(69)), 19), NoiseData(0.7, 0.46 * cis(deg2rad(-33)), 20)]
TouchstoneParser.write_touchstone("Example.s2p", f, S, z0;
version = "1.0", noise_data = noise_data, noise_f = noise_f, twoportorder = "21_12")
TouchstoneParser.write_touchstone("Example.ts", f, S, z0;
version = "2.1", noise_data = noise_data, noise_f = noise_f, twoportorder = "21_12")
ex_10 = read_touchstone("Example.s2p")
ex_21 = read_touchstone("Example.ts")
You can access the data like this:
ex_21.frequency # Vector of frequencies [ts.units]
ex_21.data # {ts.type} - parameters (Array{ComplexF64,3})
ex_21.noise_frequency # Noise frequency points (if present)
ex_21.noise_data # Noise data (if present)
ex_10.data == stack(S)
ex_21.data == stack(S)
ex_10.noise_data == noise_data
ex_21.noise_data == noise_dataMetadata
It is possible to inspect the metadata of the read file with some key fields of the TSParser struct.
For example, the comments field stores tuples containing the line where it was read and a string with the comment. This allows, for example, to extract the variables written in the touchstone by programs such as HFSS or CST using the simvariables(ts) function.