# Loading touchstone (.snp) files

**URL:** https://discourse.julialang.org/t/loading-touchstone-snp-files/66012
**Category:** Signal and Image Processing
**Tags:** question
**Created:** [August 8, 2021, 10:52am UTC](https://discourse.julialang.org/t/loading-touchstone-snp-files/66012 "2021-08-08T10:52:35Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![Valery](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/valery/32/21803_2.png) [@Valery](https://discourse.julialang.org/u/Valery)
#### Post date: [August 8, 2021, 10:52am UTC](https://discourse.julialang.org/t/loading-touchstone-snp-files/66012/1 "2021-08-08T10:52:35Z")

</div>

At the moment, what is the most convenient way to load touchstone (`.snp`) files in Julia ?

I typically want to load scattering parameter of a multi-channel array extracted from software like Advanced Software Design (ADS).

---

<div class="post-metadata">

### Author: ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)
#### Post date: [August 8, 2021, 11:02am UTC](https://discourse.julialang.org/t/loading-touchstone-snp-files/66012/2 "2021-08-08T11:02:52Z")

</div>

A google search finds a (deleted) project (EDAData.jl) by @MA_Laforge  
Let’s see if s/he is still around.

---

<div class="post-metadata">

### Author: ![PeterSimon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petersimon/32/25193_2.png) [@PeterSimon](https://discourse.julialang.org/u/PeterSimon)
#### Post date: [August 9, 2021, 12:53am UTC](https://discourse.julialang.org/t/loading-touchstone-snp-files/66012/3 "2021-08-09T00:53:17Z")

</div>

There is also [Touchstone.jl](https://github.com/PainterQubits/Touchstone.jl). Also the archived package [Marconi](https://github.com/kiranshila/Marconi.jl) provides functions to read and write Touchstone files.

---

<div class="post-metadata">

### Author: ![Valery](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/valery/32/21803_2.png) [@Valery](https://discourse.julialang.org/u/Valery)
#### Post date: [August 10, 2021, 6:21am UTC](https://discourse.julialang.org/t/loading-touchstone-snp-files/66012/4 "2021-08-10T06:21:56Z")

</div>

I saw this one, but I could not find documentation on how to use it.

---

<div class="post-metadata">

### Author: ![PeterSimon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petersimon/32/25193_2.png) [@PeterSimon](https://discourse.julialang.org/u/PeterSimon)
#### Post date: [August 10, 2021, 3:01pm UTC](https://discourse.julialang.org/t/loading-touchstone-snp-files/66012/5 "2021-08-10T15:01:03Z")

</div>

> [@Valery](#):
>
> I saw this one

Not sure which one you’re referring to, but Touchstone.jl provides what looks like a comprehensive Readme.md with a section on [Usage](https://github.com/PainterQubits/Touchstone.jl#usage). For Marconi, there is substantial documentation, in particular for [FileIO](https://kiranshila.github.io/Marconi.jl/latest/man/FileIO/).

---

<div class="post-metadata">

### Author: ![Valery](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/valery/32/21803_2.png) [@Valery](https://discourse.julialang.org/u/Valery)
#### Post date: [August 11, 2021, 8:02am UTC](https://discourse.julialang.org/t/loading-touchstone-snp-files/66012/6 "2021-08-11T08:02:34Z")

</div>

Sorry. I was actually referring to this one (for which I could not find any documentation): [https://github.com/mpichl87/Touchstone.jl](https://github.com/mpichl87/Touchstone.jl)

I will try the one from Marconi as soon as I have time.

---

<div class="post-metadata">

### Author: ![PeterSimon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petersimon/32/25193_2.png) [@PeterSimon](https://discourse.julialang.org/u/PeterSimon)
#### Post date: [August 11, 2021, 5:03pm UTC](https://discourse.julialang.org/t/loading-touchstone-snp-files/66012/7 "2021-08-11T17:03:43Z")

</div>

From your comments it appears that you’re not familiar with the “badges” that are displayed on many Github pages. On the [Touchstone.jl](https://github.com/mpichl87/Touchstone.jl) repo you referenced, there is a badge that looks like this:  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/d/a/da5fe76fab8bf5486df591e4faf0b89a4fb916f1.png)  
This badge is a link to the “stable” version of the documentation (i.e. the version associated with the latest tagged release of the package). In that link there is documentation for the “Public Interface” (i.e. the exported names from the package) which includes [parse\_touchstone\_file](https://mpichl87.github.io/Touchstone.jl/stable/public.html#Touchstone.parse_touchstone_file) which I think is what you want. An example of its use can be found in the unit tests starting [here](https://github.com/mpichl87/Touchstone.jl/blob/b31c8b1ea0df6b32f4d0f8da18a8ee2b226f562b/test/TestFilesTouchstone.jl#L42).

---

<div class="post-metadata">

### Author: ![MA\_Laforge](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ma_laforge/32/385_2.png) [@MA\_Laforge](https://discourse.julialang.org/u/MA_Laforge)
#### Post date: [August 13, 2021, 3:53am UTC](https://discourse.julialang.org/t/loading-touchstone-snp-files/66012/8 "2021-08-13T03:53:27Z")

</div>

> [@oheil](#):
>
> A google search finds a (deleted) project (EDAData.jl)

Oh, wow: I believe that package was deleted about a year ago.

In case you are still curious @Valery: the new home of my touchstone reader is now the `EDAData` module (namespace) of the `CMDimCircuits.jl` package:  
 → [CMDimCircuits.jl/doc/EDAData.md at master · ma-laforge/CMDimCircuits.jl · GitHub](https://github.com/ma-laforge/CMDimCircuits.jl/blob/master/doc/EDAData.md)

### Background on deprecating `EDAData.jl`

In the days of `EDAData.jl`, I had trouble maintaining/synchronizing my heavily fragmented solution of circuit-related packages. Since each package had to be in its own .git repository, I had to tag & release multiple julia packages simultaneously, and it was very labour intensive/error prone.

Although this one-to-one relationship is no longer strictly necessary, I haven’t personally figured out a good way to get things to work smoothly.

### An example of reading touchstone

```julia-auto
import CMDimCircuits
import CMDimCircuits.EDAData
using CMDimCircuits.NetwAnalysis #for mx2elem

#Read in S-parameter matrix:
S = EDAData.read_snp("lineS_5.0m.s2p", numports=2)

#Obtain data as DataF1 object (keeps frequency & SP data together for easier math)
s21 = S[2,1]

#Unpack all DataF1 objects simultaneously instead:
(s11, s12, s21, s22) = mx2elem(S)

#NOTE:
# DataF1 objects keep frequency & "y-values" together when applying math:
Δ = s11*s22 - s12*s21
K = ( 1 - abs(s11)^2 - abs(s22)^2 + abs(Δ)^2 ) / ( abs(s12)*abs(s21) )
#(Would also work with parametric sweeps of S-parameter data!)

#But you can also get (frequency/"y-value") data
#as simple vectors, if preferred:
f = S[2,1].x
s21 = S[2,1].y

```

---

<div class="post-metadata">

### Author: ![MA\_Laforge](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ma_laforge/32/385_2.png) [@MA\_Laforge](https://discourse.julialang.org/u/MA_Laforge)
#### Post date: [August 13, 2021, 4:03am UTC](https://discourse.julialang.org/t/loading-touchstone-snp-files/66012/9 "2021-08-13T04:03:08Z")

</div>

### A word of caution

Please note that my implementation is not super robust at the moment. It likely is not fully compliant with the standard.

### InspectDR

Since you are likely are in need of generating Smith plots, InspectDR can do that:  
 → [GitHub - ma-laforge/InspectDR.jl: Fast, interactive Julia/GTK+ plots (+Smith charts +Gtk widget +Cairo-only images)](https://github.com/ma-laforge/InspectDR.jl)

 ![image](https://global.discourse-cdn.com/julialang/original/3X/2/c/2c54ee936f68c15cc8133967fb8e3a5956e1f35f.png)

 ![image](https://global.discourse-cdn.com/julialang/original/3X/1/e/1e1bffcd6cdab6d8c43a50e41672ee5dbcbec87b.png)
