| 1 |
import os |
| 2 |
import unittest |
| 3 |
|
| 4 |
import numpy as np |
| 5 |
import pytest |
| 6 |
|
| 7 |
from skrf.media import DistributedCircuit |
| 8 |
from skrf.network import Frequency, Network |
| 9 |
|
| 10 |
|
| 11 |
class MediaTestCase(unittest.TestCase): |
| 12 |
""" |
| 13 |
|
| 14 |
""" |
| 15 |
def setUp(self): |
| 16 |
""" |
| 17 |
|
| 18 |
""" |
| 19 |
self.files_dir = os.path.join( |
| 20 |
os.path.dirname(os.path.abspath(__file__)), |
| 21 |
'qucs_prj' |
| 22 |
) |
| 23 |
fname = os.path.join(self.files_dir,\ |
| 24 |
'distributedCircuit,line1mm.s2p') |
| 25 |
qucs_ntwk = Network(fname) |
| 26 |
self.a_media = DistributedCircuit( |
| 27 |
frequency = qucs_ntwk.frequency, |
| 28 |
R=1e5, G=1, L=1e-6, C=8e-12 |
| 29 |
) |
| 30 |
|
| 31 |
def test_constructor(self): |
| 32 |
"Test various initializations" |
| 33 |
nb_f = 3 |
| 34 |
freq = Frequency(1, 10, npoints=nb_f, unit='MHz') |
| 35 |
|
| 36 |
media = DistributedCircuit(frequency=freq, C=100e-12, L=50e-9, R=1, G=0) |
| 37 |
print(media) |
| 38 |
|
| 39 |
media = DistributedCircuit(frequency=freq, C=[100e-12]*nb_f, L=[50e-9]*nb_f, R=[1]*nb_f, G=[0]*nb_f) |
| 40 |
print(media) |
| 41 |
media = DistributedCircuit(frequency=freq, C=100e-12, L=50e-9, R=np.linspace(1, 10, nb_f), G=0) |
| 42 |
print(media) |
| 43 |
with pytest.raises(ValueError): |
| 44 |
media = DistributedCircuit(frequency=freq, C=[100e-12] * 1, L=[50e-9] * 2, R=[1] * nb_f, G=0) |
| 45 |
|
| 46 |
def test_line(self): |
| 47 |
""" |
| 48 |
""" |
| 49 |
fname = os.path.join(self.files_dir,\ |
| 50 |
'distributedCircuit,line1mm.s2p') |
| 51 |
qucs_ntwk = Network(fname) |
| 52 |
|
| 53 |
a_media = DistributedCircuit( |
| 54 |
frequency = qucs_ntwk.frequency, |
| 55 |
R=1e5, G=1, L=1e-6, C=8e-12 |
| 56 |
) |
| 57 |
skrf_ntwk = a_media.thru(z0=50)**a_media.line(1e-3,'m')\ |
| 58 |
**a_media.thru(z0=50) |
| 59 |
self.assertEqual(qucs_ntwk, skrf_ntwk) |
| 60 |
|
| 61 |
|
| 62 |
def test_write_csv(self): |
| 63 |
fname = os.path.join(self.files_dir,\ |
| 64 |
'out.csv') |
| 65 |
self.a_media.write_csv(fname) |
| 66 |
os.remove(fname) |
| 67 |
|
| 68 |
|
| 69 |
def test_from_csv(self): |
| 70 |
fname = os.path.join(self.files_dir,\ |
| 71 |
'out.csv') |
| 72 |
self.a_media.write_csv(fname) |
| 73 |
a_media = DistributedCircuit.from_csv(fname) |
| 74 |
self.assertEqual(a_media,self.a_media) |
| 75 |
os.remove(fname) |