Debian Codegraph @

skrf/tests/test_plotting.py

raw symbols SCIP
1 import sys
2
3 try:
4 import matplotlib as mpl
5 except ImportError:
6 pass
7
8 import numpy as np
9 import pytest
10
11 import skrf as rf
12
13 if "matplotlib" not in sys.modules:
14 pytest.skip(allow_module_level=True)
15
16
17 @pytest.fixture(params=rf.Network.PRIMARY_PROPERTIES)
18 def primary_properties(request):
19 return request.param
20
21 @pytest.fixture(params=["polar", "complex"])
22 def primary_methods(request):
23 return request.param
24
25 @pytest.fixture(params=rf.Network._generated_functions().keys())
26 def generated_functions(request):
27 return request.param
28
29 def test_primary_plotting(ntwk1_dc: rf.Network, primary_properties: str, primary_methods: str):
30 method = f"plot_{primary_properties}_{primary_methods}"
31 fig = getattr(ntwk1_dc, method)()
32
33 def test_generated_function_plots(ntwk1_dc: rf.Network, generated_functions: str):
34 method = f"plot_{generated_functions}"
35 fig = getattr(ntwk1_dc, method)()
36
37 def test_plot_passivity(ntwk1_dc: rf.Network):
38 ntwk1_dc.plot_passivity()
39
40 def test_plot_reciprocity(ntwk1_dc: rf.Network, ):
41 ntwk1_dc.plot_reciprocity()
42
43 def test_plot_reciprocity2(ntwk1_dc: rf.Network, ):
44 ntwk1_dc.plot_reciprocity2()
45
46 def test_plot_s_db_time(ntwk1_dc: rf.Network, ):
47 ntwk1_dc.plot_s_db_time()
48 ntwk1_dc.plot_s_db_time(m=0, n=0)
49
50 def test_plot_s_smith(ntwk1_dc: rf.Network, ):
51 ntwk1_dc.plot_s_smith()
52
53 def test_z_time_impulse_step_z0(ntwk1_dc: rf.Network, ):
54 se_diff = rf.concat_ports([ntwk1_dc, ntwk1_dc], port_order = 'second')
55 mm_diff = se_diff.copy()
56 mm_diff.se2gmm(p = 2)
57 fig, ax = mpl.pyplot.subplots(1, 1)
58 mm_diff.plot_z_time_step(0, 0, ax = ax)
59 mm_diff.plot_z_time_impulse(0, 1, ax = ax)
60 mm_diff.plot_z_time_step(2, 2, ax = ax)
61 mm_diff.plot_z_time_impulse(2, 3, ax = ax)
62 # test that start impedance is almost port z0 to 0.1%
63 z0_start = [
64 ax.lines[0].get_ydata()[0],
65 ax.lines[1].get_ydata()[0],
66 ax.lines[2].get_ydata()[0],
67 ax.lines[3].get_ydata()[0]]
68 np.testing.assert_allclose(z0_start, mm_diff.z0[0],
69 rtol = 1e-3,
70 err_msg = "plot_z_time_xxx start impedance does not match port impedance")
71
72 def test_x_y_labels(ntwk1_dc: rf.Network):
73 fig, ax = mpl.pyplot.subplots(1, 1)
74 ntwk1_dc.plot_s_db(ax = ax)
75 # check that there are 4 traces
76 np.testing.assert_equal(len(ax.lines), ntwk1_dc.nports**2,
77 err_msg = "missing trace")
78 # check x label
79 np.testing.assert_string_equal(ax.get_xlabel(), f"Frequency ({ntwk1_dc.frequency.unit})")
80 # check y label
81 np.testing.assert_string_equal(ax.get_ylabel(), rf.Network.Y_LABEL_DICT['db'])
82
83
84
85 @pytest.mark.parametrize("usetex", [True, False])
86 def test_plot_it_all(ntwk1_dc: rf.Network, usetex):
87 with mpl.rc_context({'text.usetex': usetex}):
88 ntwk1_dc.plot_it_all()
89
90 @pytest.mark.parametrize("usetex", [True, False])
91 def test_plot_polar(ntwk1_dc: rf.Network, usetex):
92 with mpl.rc_context({'text.usetex': usetex}):
93 ntwk1_dc.plot_s_polar()
94
95 def test_plot_uncertainty_bounds_s(ntwk_set_zip: rf.NetworkSet):
96 ntwk_set_zip.plot_uncertainty_bounds_s()
97
98 def test_plot_uncertainty_bounds_s_db(ntwk_set_zip: rf.NetworkSet):
99 ntwk_set_zip.plot_uncertainty_bounds_s_db()
100
101 def test_plot_uncertainty_bounds_s_time_db(ntwk_set_zip: rf.NetworkSet):
102 ntwk_set_zip.plot_uncertainty_bounds_s_time_db()
103
104 def test_plot_uncertainty_decomposition(ntwk_set_zip: rf.NetworkSet):
105 ntwk_set_zip.plot_uncertainty_decomposition()
106
107 def test_plot_minmax_bounds_s_db(ntwk_set_zip: rf.NetworkSet):
108 ntwk_set_zip.plot_minmax_bounds_s_db()
109
110 def test_plot_minmax_bounds_s_db10(ntwk_set_zip: rf.NetworkSet):
111 ntwk_set_zip.plot_minmax_bounds_s_db10()
112
113 def test_plot_minmax_bounds_s_time_db(ntwk_set_zip: rf.NetworkSet):
114 ntwk_set_zip.plot_minmax_bounds_s_time_db()
115
116 def test_plot_signature(ntwk_set_zip: rf.NetworkSet):
117 ntwk_set_zip.signature()
118
119 def test_generated_violin_plots(ntwk_set_zip: rf.NetworkSet, generated_functions: str):
120 if "time" not in generated_functions:
121 fig = ntwk_set_zip.plot_violin(generated_functions)
122 else:
123 with pytest.raises(NotImplementedError):
124 fig = ntwk_set_zip.plot_violin(generated_functions)