Load SParamData from CPython

304 views
Skip to first unread message

Michael Wollensack METAS

unread,
Sep 20, 2021, 2:48:48 AM9/20/21
to VNA Tools
Hi,

I would like to load SParamData (*.sdatb) files from Python (CPython) and not from IronPython.

Regards
Michael

Michael Wollensack METAS

unread,
Sep 20, 2021, 2:55:55 AM9/20/21
to VNA Tools

Hi,

 

you would need the following python packages:

 

https://pypi.org/project/pythonnet/

 

https://pypi.org/project/metas-unclib/

 

and the VNA Tools and the METAS UncLib versions should be the same. I'f not you've to modify the metas_unclib.py file that it loads the METAS UncLib from the VNA Tools installation path.

 

The following script is an example which loads an SParamData file:

 

Load SParamData using METAS UncLib and VNA Tools

Michael Wollensack METAS - 28.06.2019

In [1]:

vnatools_path = r'C:\Program Files (x86)\METAS\Metas.Vna.Tools'

In [2]:

data_path = r'C:\Users\Public\Documents\Metas.Vna.Tools\Matlab\Example_01.sdatb'

In [3]:

import os as _os

import clr as _clr

In [4]:

_clr.AddReference(_os.path.join(vnatools_path, "Metas.Vna.Data"))

Out[4]:

<System.Reflection.RuntimeAssembly at 0x22fbab7d128>

In [5]:

from metas_unclib import *

In [6]:

from Metas.UncLib.LinProp import UncNumber as _UncNumber

from Metas.Vna.Data.FileIO import Generic as _Generic

In [7]:

sdata = _Generic.LoadSParamData[_UncNumber](data_path)

In [8]:

print(sdata.NFreq)

3

In [9]:

print(sdata.NPorts)

2

In [10]:

frequency = np.asarray([float(fi) for fi in sdata.Frequency])

 

print(frequency)

[1.e+09 2.e+09 3.e+09]

In [11]:

ports = [str(pi) for pi in sdata.Ports]

 

print(ports)

['1', '2']

In [12]:

portzr = np.asarray([ucomplex(pi) for pi in sdata.PortZr])

 

print(portzr)

[(50+0j) ± 0j (50+0j) ± 0j]

In [13]:

_d = sdata.GetNArrayData()

_d2 = np.asarray([ucomplex(di) for di in _d.data])

_s = [si for si in _d.size]

data = _d2.reshape(_s, order='F')

 

print(data)

[[[(-0.00372+0.00539j) ± (0.0002828427124746192+0.0002803569007957765j)

   (0.235-0.214j) ± (0.00021213203435596438+0.00022360679774997925j)]

  [(0.235-0.213j) ± (0.00021166010488516752+0.00022315907859602344j)

   (-0.0039+0.00639j) ± (0.0002908607914449798+0.000292403830344269j)]]

 

[[(-0.000499+0.00912j) ± (0.00028530682766003245+0.00028231188426986186j)

   (0.0305-0.315j) ± (0.00025961509971494354+0.0001466287829861519j)]

  [(0.0305-0.315j) ± (0.00025865034312755125+0.0001456021977856104j)

   (0.00182+0.0088j) ± (0.00028390139133156755+0.00028722813232690144j)]]

 

[[(0.00381+0.0116j) ± (0.00038209923832536+0.00038078835761351054j)

   (-0.189-0.254j) ± (0.00021725560982400444+0.00018947295321496425j)]

  [(-0.189-0.254j) ± (0.00021725560982400425+0.0001894729532149644j)

   (0.00737+0.00774j) ± (0.0003885869230130046+0.00038858711885494306j)]]]

 

 

Regards

Michael

Reply all
Reply to author
Forward
0 new messages