test_spectral_factorization_ZPK

wield.control.SISO.test.test_spectral_factorization_ZPK

This is a pytest module needing documentation

pytest-html report

Functions

FBNSsimpSS([gain])

This is a pytest needing documentation

FBNSsimpSSfull([gain])

This is a pytest needing documentation

test_ZPK_spectral_factorize()

test_ZPK_spectral_factorize2()

Details

FBNSsimpSS(gain=1)[source][github]

This is a pytest needing documentation

code
 1def FBNSsimpSS(gain=1):
 2    F_Fq_lo = 30 * 2 * np.pi
 3    F_Fq_hi = 300 * 2 * np.pi
 4    hp_order = 4 #lo_ord
 5    lp_order = 2
 6    F_p = []
 7    F_z = []
 8    for ord in range(1, hp_order + 1):
 9        F_p.append(-F_Fq_lo + 1j*F_Fq_lo)
10        F_p.append(-F_Fq_lo - 1j*F_Fq_lo)
11        F_z.append(0)
12        F_z.append(0)
13    for ord in range(1, lp_order + 1):
14        F_p.append(-F_Fq_hi)
15    F_k = 1
16
17    filt = SISO.zpk((F_z, F_p, F_k), fiducial_f=[], fiducial_rtol=1, angular=False)
18    filt = filt.normalize(f=200)
19    return filt * gain
pytest information

This code is wrapped in a pytest function using conventions detailed in Pytest Conventions. The full name of this test, as known by the documentation, is:

wield.control.SISO.test.test_spectral_factorization_ZPK.FBNSsimpSS

The full name is useful when building documentation, to link a reference to this page using :func:`name`, or directly include it with an autofunction directive. The collapse nodes below show every instance of the test run. There may only be one, but if the test was run multiple times through pytest parametrizations, the list can be longer.

FBNSsimpSSfull(gain=1)[source][github]

This is a pytest needing documentation

code
 1def FBNSsimpSSfull(gain=1):
 2    F_Fq_lo = 40 * 2 * np.pi
 3    F_Fq_hi = 300 * 2 * np.pi
 4    hp_order = 1 #lo_ord
 5    lp_order = 2
 6    F_p = []
 7    F_z = []
 8    for ord in range(hp_order):
 9        F_p.append(-F_Fq_lo + 0*1j*F_Fq_lo)
10        F_p.append(-F_Fq_lo - 0*1j*F_Fq_lo)
11        F_z.append(0)
12        F_z.append(0)
13    for ord in range(lp_order):
14        F_p.append(-F_Fq_hi)
15    F_k = 1
16    c_zpk = cheby2(8, 160, 4*2*np.pi, btype='high', analog=True, output='zpk')
17    F_z.extend(c_zpk[0])
18    F_p.extend(c_zpk[1])
19    F_k *= c_zpk[2]
20
21    filt = SISO.zpk((F_z, F_p, F_k), fiducial_f=[], fiducial_rtol=1, angular=False)
22    filt = filt.normalize(f=200)
23    return filt * gain
pytest information

This code is wrapped in a pytest function using conventions detailed in Pytest Conventions. The full name of this test, as known by the documentation, is:

wield.control.SISO.test.test_spectral_factorization_ZPK.FBNSsimpSSfull

The full name is useful when building documentation, to link a reference to this page using :func:`name`, or directly include it with an autofunction directive. The collapse nodes below show every instance of the test run. There may only be one, but if the test was run multiple times through pytest parametrizations, the list can be longer.

test_ZPK_spectral_factorize()[source][github]
code
docstring
"""
"""
 1def test_ZPK_spectral_factorize():
 2
 3    axB = mplfigB(Nrows=1)
 4    fs = 2048
 5    F_Hz = logspaced(1, 1000, 1000)
 6
 7    ss_flat = SISO.zpk((), (), 1, fiducial_f=[]).asSS
 8
 9    # test dynamic range with higher gain
10    ss_bns = FBNSsimpSS(gain=100000).asSS
11
12    ss_sq = ss_bns.conjugate() * ss_bns + ss_flat.conjugate() * ss_flat
13
14    abssq = ss_flat.fresponse(f=F_Hz).mag**2 + ss_bns.fresponse(f=F_Hz).mag**2
15    axB.ax0.loglog(F_Hz, abssq**0.5)
16
17    fr = ss_sq.fresponse(f=F_Hz)
18    axB.ax0.loglog(F_Hz, fr.mag**0.5)
19    #axB.ax1.semilogx(*fr.fplot_deg225)
20
21    # print(scipy.linalg.eigvals(ss_sq.A))
22
23    ss_sqZPK = ss_sq.asZPK
24    fr = ss_sqZPK.fresponse(f=F_Hz)
25    axB.ax0.loglog(F_Hz, fr.mag**0.5)
26
27    # from wield.control.algorithms.zpk import srootset, zrootset
28    # classifier = srootset.default_root_classifier.classify_function(
29    #     tRootSet=srootset.SDomainRootSet,
30    #     hermitian=True,
31    #     time_symm=True,
32    #     return_unmatched=True
33    # )
34
35    def stable_root_extract(roots):
36        """
37        Return a square root filter
38
39        TODO, make this numerically better behaved and t
40        """
41        roots = np.asarray(roots)
42        lhp = roots[roots.real < 0]
43        eq0 = roots[roots.real == 0]
44        rhp = roots[roots.real > 0]
45        assert(len(lhp) == len(rhp))
46        assert(len(eq0) % 2 == 0)
47        eq0 = sorted(eq0, key=lambda r: abs(r.imag))
48
49        # skip every other real one
50        return list(lhp) + list(eq0[::4]) + list(eq0[1::4])
51    p = stable_root_extract(ss_sqZPK.p)
52    z = stable_root_extract(ss_sqZPK.z)
53    k = ss_sqZPK.k**0.5
54
55    ss_rt = SISO.zpk(
56        z,
57        p,
58        k,
59        fiducial_f=[]
60    )
61
62    fr = ss_rt.fresponse(f=F_Hz)
63    axB.ax0.loglog(*fr.fplot_mag)
64
65    ss_rt2 = SISO.design.root_factored_quadrature_sum(ss_bns, ss_flat)
66    fr = ss_rt.fresponse(f=F_Hz)
67    axB.ax0.loglog(*fr.fplot_mag)
68
69    #axB.ax1.semilogx(*fr.fplot_deg225)
70    axB.save(tjoin("Mag_show"))
71    return 
pytest information

This code is wrapped in a pytest function using conventions detailed in Pytest Conventions. The full name of this test, as known by the documentation, is:

wield.control.SISO.test.test_spectral_factorization_ZPK.test_ZPK_spectral_factorize

The full name is useful when building documentation, to link a reference to this page using :func:`name`, or directly include it with an autofunction directive. The collapse nodes below show every instance of the test run. There may only be one, but if the test was run multiple times through pytest parametrizations, the list can be longer.

test_ZPK_spectral_factorize
output
status: passed
duration: 2.017s
test_ZPK_spectral_factorize2()[source][github]
code
docstring
"""
"""
 1def test_ZPK_spectral_factorize2():
 2
 3    axB = mplfigB(Nrows=1)
 4    fs = 2048
 5    F_Hz = logspaced(1, 1000, 1000)
 6
 7    ss_flat = SISO.zpk((), (), .001, fiducial_f=[]).asSS
 8
 9    # test dynamic range with higher gain
10    ss_bns = FBNSsimpSSfull(gain=100000).asSS
11
12    ss_sq = ss_bns.conjugate() * ss_bns + ss_flat.conjugate() * ss_flat
13
14    abssq = ss_flat.fresponse(f=F_Hz).mag**2 + ss_bns.fresponse(f=F_Hz).mag**2
15    axB.ax0.loglog(F_Hz, abssq**0.5)
16
17    fr = ss_sq.fresponse(f=F_Hz)
18    axB.ax0.loglog(F_Hz, fr.mag**0.5, ls = "--")
19    #axB.ax1.semilogx(*fr.fplot_deg225)
20
21    # print(scipy.linalg.eigvals(ss_sq.A))
22
23    ss_sqZPK = ss_sq.asZPK
24    fr = ss_sqZPK.fresponse(f=F_Hz)
25    axB.ax0.loglog(F_Hz, fr.mag**0.5, lw = 3, alpha = 0.5, ls=':')
26
27    # from wield.control.algorithms.zpk import srootset, zrootset
28    # classifier = srootset.default_root_classifier.classify_function(
29    #     tRootSet=srootset.SDomainRootSet,
30    #     hermitian=True,
31    #     time_symm=True,
32    #     return_unmatched=True
33    # )
34
35    def stable_root_extract(roots):
36        """
37        Return a square root filter
38
39        TODO, make this numerically better behaved and t
40        """
41        roots = np.asarray(roots)
42        lhp = roots[roots.real < 0]
43        eq0 = roots[roots.real == 0]
44        rhp = roots[roots.real > 0]
45        assert(len(lhp) == len(rhp))
46        assert(len(eq0) % 2 == 0)
47        eq0 = sorted(eq0, key=lambda r: abs(r.imag))
48
49        # skip every other real one
50        return list(lhp) + list(eq0[::4]) + list(eq0[1::4])
51    p = stable_root_extract(ss_sqZPK.p)
52    z = stable_root_extract(ss_sqZPK.z)
53    k = ss_sqZPK.k**0.5
54
55    ss_rt = SISO.zpk(
56        z,
57        p,
58        k,
59        fiducial_f=[]
60    )
61
62    fr = ss_rt.fresponse(f=F_Hz)
63    axB.ax0.loglog(*fr.fplot_mag, ls = ':')
64
65    ss_rt2 = SISO.design.root_factored_quadrature_sum(ss_bns, ss_flat)
66    fr = ss_rt.fresponse(f=F_Hz)
67    axB.ax0.loglog(*fr.fplot_mag, ls = '--')
68
69    #axB.ax1.semilogx(*fr.fplot_deg225)
70    axB.save(tjoin("Mag_show"))
71    return 
pytest information

This code is wrapped in a pytest function using conventions detailed in Pytest Conventions. The full name of this test, as known by the documentation, is:

wield.control.SISO.test.test_spectral_factorization_ZPK.test_ZPK_spectral_factorize2

The full name is useful when building documentation, to link a reference to this page using :func:`name`, or directly include it with an autofunction directive. The collapse nodes below show every instance of the test run. There may only be one, but if the test was run multiple times through pytest parametrizations, the list can be longer.

test_ZPK_spectral_factorize2
output
status: failed
duration: 0.086s
captured errors:
def test_ZPK_spectral_factorize2():
        """
        """
        axB = mplfigB(Nrows=1)
        fs = 2048
        F_Hz = logspaced(1, 1000, 1000)

        ss_flat = SISO.zpk((), (), .001, fiducial_f=[]).asSS

        # test dynamic range with higher gain
        ss_bns = FBNSsimpSSfull(gain=100000).asSS

        ss_sq = ss_bns.conjugate() * ss_bns + ss_flat.conjugate() * ss_flat

        abssq = ss_flat.fresponse(f=F_Hz).mag**2 + ss_bns.fresponse(f=F_Hz).mag**2
        axB.ax0.loglog(F_Hz, abssq**0.5)

        fr = ss_sq.fresponse(f=F_Hz)
        axB.ax0.loglog(F_Hz, fr.mag**0.5, ls = "--")
        #axB.ax1.semilogx(*fr.fplot_deg225)

        # print(scipy.linalg.eigvals(ss_sq.A))

        ss_sqZPK = ss_sq.asZPK
        fr = ss_sqZPK.fresponse(f=F_Hz)
        axB.ax0.loglog(F_Hz, fr.mag**0.5, lw = 3, alpha = 0.5, ls=':')

        # from wield.control.algorithms.zpk import srootset, zrootset
        # classifier = srootset.default_root_classifier.classify_function(
        #     tRootSet=srootset.SDomainRootSet,
        #     hermitian=True,
        #     time_symm=True,
        #     return_unmatched=True
        # )

        def stable_root_extract(roots):
            """
            Return a square root filter

            TODO, make this numerically better behaved and t
            """
            roots = np.asarray(roots)
            lhp = roots[roots.real < 0]
            eq0 = roots[roots.real == 0]
            rhp = roots[roots.real > 0]
            assert(len(lhp) == len(rhp))
            assert(len(eq0) % 2 == 0)
            eq0 = sorted(eq0, key=lambda r: abs(r.imag))

            # skip every other real one
            return list(lhp) + list(eq0[::4]) + list(eq0[1::4])
        p = stable_root_extract(ss_sqZPK.p)
>       z = stable_root_extract(ss_sqZPK.z)

../../src/wield/control/SISO/test/test_spectral_factorization_ZPK.py:209: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

roots = array([ 7.83794746e+01+0.00000000e+00j, -1.62621035e-13+0.00000000e+00j,
       -1.35333992e+08+1.35333993e+08j, -1.35...290008e+01j,  5.63691163e+01-9.46290008e+01j,
        7.22109829e+01+4.80860718e+01j,  7.22109829e+01-4.80860718e+01j])

    def stable_root_extract(roots):
        """
        Return a square root filter

        TODO, make this numerically better behaved and t
        """
        roots = np.asarray(roots)
        lhp = roots[roots.real < 0]
        eq0 = roots[roots.real == 0]
        rhp = roots[roots.real > 0]
>       assert(len(lhp) == len(rhp))
E       assert 13 == 11
E        +  where 13 = len(array([-1.62621035e-13+0.00000000e+00j, -1.35333992e+08+1.35333993e+08j,\n       -1.35333992e+08-1.35333993e+08j, -6.60...+02j,\n       -2.51535709e+01-1.51793732e+02j, -4.64553611e+01+1.18432920e+02j,\n       -4.64553611e+01-1.18432920e+02j]))
E        +  and   11 = len(array([7.83794746e+01+0.00000000e+00j, 1.35333994e+08+1.35333993e+08j,\n       1.35333994e+08-1.35333993e+08j, 1.605027...08e+01j,\n       5.63691163e+01-9.46290008e+01j, 7.22109829e+01+4.80860718e+01j,\n       7.22109829e+01-4.80860718e+01j]))

../../src/wield/control/SISO/test/test_spectral_factorization_ZPK.py:202: AssertionError