Debian Codegraph @

skrf/vi/vna/hp/tests/test_8510c_sweep_plan.py

raw symbols SCIP
1 """
2 The user requests a big sweep with different spacings in different frequency
3 blocks, but the HP8510 instrument only supports smaller sweeps with fixed
4 spacing. What to do? Break up the big sweep, naturally.
5
6 SweepPlan.from_hz(array_of_hz)
7 ->
8 SweepPlan
9 SweepSection
10 SweepSection
11 SweepSection
12
13 Each SweepSection represents a sweep the instrument can actually perform.
14 Together, the SweepSections in a SweepPlan satisfy the user's request.
15
16 There is room for cleverness: conducting an 800 point sweep by running an
17 801 point sweep and discarding a point saved 20 minutes in a recent script.
18
19 Cleverness is only good if it works, and these tests make sure that
20 SweepPlan.from_hz returns a plan that hits exactly the frequencies it is
21 supposed to.
22 """
23
24 import sys
25
26 import numpy as np
27 import pytest
28
29 try:
30 from skrf.vi.vna.hp.hp8510c_sweep_plan import SweepPlan
31 except ImportError:
32 pass
33
34 if "matplotlib" not in sys.modules:
35 pytest.skip(allow_module_level=True)
36
37 def test_800pt_swp():
38 """ Test: magic size - 1
39 """
40 test_hz_0 = np.linspace(100,1000,800)
41 test_sp_0 = SweepPlan.from_hz(test_hz_0)
42 assert test_sp_0._matches_f_list(test_hz_0)
43
44 def test_801pt_swp():
45 """ Test: magic size
46 """
47 test_hz_0 = np.linspace(100,1000,801)
48 test_sp_0 = SweepPlan.from_hz(test_hz_0)
49 assert test_sp_0._matches_f_list(test_hz_0)
50
51 def test_802pt_swp():
52 """ Test: magic size + 1
53 """
54 test_hz_0 = np.linspace(100,1000,802)
55 test_sp_0 = SweepPlan.from_hz(test_hz_0)
56 assert test_sp_0._matches_f_list(test_hz_0)
57
58 def test_1001pt_swp():
59 """ Test: typical size
60 """
61 test_hz_1 = np.linspace(100,1000,1001)
62 test_sp_1 = SweepPlan.from_hz(test_hz_1)
63 assert test_sp_1._matches_f_list(test_hz_1)
64
65 def test_multi_swp():
66 """ Test: multiple frequency blocks in a single sweep
67 """
68 test_hz_2 = np.concatenate(([1,2,3], np.linspace(100,1000,1001)))
69 test_sp_2 = SweepPlan.from_hz(test_hz_2)
70 assert test_sp_2._matches_f_list(test_hz_2)
71
72 def test_multi_swp_with_single():
73 """ Test: multiple frequency blocks, one of them has size one
74 """
75 test_hz_3 = np.concatenate(([1,2,3], np.linspace(100,1000,1001), [9999]))
76 test_sp_3 = SweepPlan.from_hz(test_hz_3)
77 assert test_sp_3._matches_f_list(test_hz_3)