test_oplev

wield.control.fitting.SISO.test.v2.test_oplev

This is a pytest module needing documentation

pytest-html report

Functions

test_oplev_iy()

This is a pytest needing documentation

Details

test_oplev_iy()[source][github]

This is a pytest needing documentation

code
 1@pytest.mark.xfail(True, reason="Triggering some overflow to look into")
 2@skipdeco
 3def test_oplev_iy():
 4    from wield.utilities.file_io import load_any
 5
 6    fname = matlab_test_data.matfiles["OplevPlant.mat"]
 7    fdict = load_any(fname=fname, ftype="mat")
 8
 9    out = v2.data2filter(
10        F_Hz=fdict["ap"]["iy"]["ff"],
11        data=fdict["ap"]["iy"]["plant"],
12        F_nyquist_Hz=None,
13        delay_s=0,
14        hints=[sign_validate_and_plot_hint(tjoin('error'))],
15    )
16    with plot_on_assert(tjoin('output'), out.fitter, plot_anyway=True):
17        pass
18    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.fitting.SISO.test.v2.test_oplev.test_oplev_iy

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_oplev_iy
output
{'F_Hz': array([0.0000000e+00, 7.8125000e-03, 1.5625000e-02, ..., 4.9984375e+01,
       4.9992188e+01, 5.0000000e+01]), 'data': array([-4.8860516e-03+0.0000000e+00j, -4.5855157e-03+8.9761830e-05j,
       -4.3419674e-03+2.4111182e-04j, ...,  1.5403209e-09+2.9354810e-08j,
        1.2409613e-08+4.0623608e-08j,  2.2163795e-09+3.6025902e-08j]), 'F_nyquist_Hz': None, 'delay_s': 0, 'hints': [{'fitter_update_validate': <function sign_validate_and_plot_hint.<locals>.sign_validate_plot at 0x7f49febce020>, 'fitter_check_validate': <function sign_validate_and_plot_hint.<locals>.sign_validate_plot at 0x7f49febce020>, 'rational_fitter_validate': <function rational_fitter_validate at 0x7f49ff937380>}]}
TEE_LOGFILE None
A []
B []
------------:SNR Fix Test:
------------:rational fitting:
4P   0.02    chebychev rational fit
RELDEG:  0 0 0
3P   0.33    Initial Order: (Z=20, P=20, Z-P=0)
3P   0.39    Fastdrop Order: (Z=16, P=16, Z-P=0)
4P   0.41    mag fitting and phase patching
--------------:rational fitting:sample variance (from magnitude):
3A   1.03      Weight Scaling determined:  28.727737811076437
3A   1.03      Weight Scaling Used  5.359826285531691
--------------:rational fitting:Phase patching:
------------:Q-ranked order reduction:
4P  24.24    order reduced annealing
5P  59.70  zero flipping, maxzp 27, residuals=5.29e+01, 5.29e+01, reldeg=-9
5P  96.94  zero flipped, maxzp 27, residuals=5.12e+01, reldeg=-9
5P 159.73  zero flipped, maxzp 27, residuals=4.97e+01, reldeg=-9
5P 207.35  zero flipped, maxzp 27, residuals=4.73e+01, reldeg=-9
5P 249.26  zero flipped, maxzp 27, residuals=4.72e+01, reldeg=-9
5P 294.48  zero flipped, maxzp 27, residuals=4.56e+01, reldeg=-9
<wield.control.fitting.SISO.fitters_ZPK.MRF.MultiReprFilterS object at 0x7f49f49076e0>
None
rB(-80.16738089288114, -79.88051482031545, -2.3743776420202884, -0.008390248896272275, 0.3445053197470788±0.10916184388653634j, 0.6334971855642022±4.0714123810219975j, 81.17427052834026±45.60794196443892j, -79.9228464310736±46.62591954008791j, -86.90969757132956±51.37351811766385j, 91.49593794826549±56.45600619571937j, 108.72073928686964±73.17543680576108j)
rB()
<wield.control.fitting.SISO.representations.zpk_with_data.ZPKwData object at 0x7f49f49079b0>
Captured stderr call
3W   0.00  Estimating SNR from sample variance with nearby points (SNR_est_width=10 > 0).
           This technique works semi-OK, but could probably be much better..
           use the resulting fit to estimate the sample variance and generate
           improved SNR estimates, iterate.
3W   0.00  6015 SNR<1 element(s) dropped (of 6401).
           Too many low SNR elements confuses the rational nonparametric fitter.
3W   0.01    The number of effective data points N=(ΣW^2)^2/(ΣW^4)=3.79e-01*len(W)
             [where W=SNR] is below the configured 'SNR_regularize_scale'=10,
             given the maximum SNR=49.74241939769682. Now Finding an SNR ceiling that balances
             the ratio with max SNR.
3W   0.01    Using SNR<20.64128132953338 ceiling.
3W   0.38    Fitter_checkpoint improvement succeed, None
1W   1.10      Phase patching did not remove all unstable roots in
               a single pass. It is not programmed to accommodate this
               failure mode. Unstable zeros (or poles) may be wrong.
1W   1.15      Phase patching did not remove all unstable roots in
               a single pass. It is not programmed to accommodate this
               failure mode. Unstable zeros (or poles) may be wrong.
1W   1.25      Phase patching did not remove all unstable roots in
               a single pass. It is not programmed to accommodate this
               failure mode. Unstable zeros (or poles) may be wrong.
1W   1.36      Phase patching did not remove all unstable roots in
               a single pass. It is not programmed to accommodate this
               failure mode. Unstable zeros (or poles) may be wrong.
1W   2.10      Phase patching did not remove all unstable roots in
               a single pass. It is not programmed to accommodate this
               failure mode. Unstable zeros (or poles) may be wrong.
3W   2.10    High Confidence that an unstable pole exists at 2.6073791152266104+2.6754669663107586i Hz!
             Adding it to the filter. Prevent this with 'never_unstable_poles'
3W   2.10    High Confidence that an unstable pole exists at 0.7041661326225369+0.7565356015498867i Hz!
             Adding it to the filter. Prevent this with 'never_unstable_poles'
5W   2.10    High Confidence that an unstable zero exists at 6.060215386981508+7.539410694180567e+18i Hz
             Adding it to the filter. Prevent this with 'never_unstable_zeros'
5W   2.10    High Confidence that an unstable zero exists at 2.49289506692862+0.25338418881597985i Hz
             Adding it to the filter. Prevent this with 'never_unstable_zeros'
3W   2.10    High Confidence that an unstable pole exists at 0.0004425258451575154+1.062577937635966i Hz!
             Adding it to the filter. Prevent this with 'never_unstable_poles'
3W   2.10    High Confidence that an unstable pole exists at 2.5777117713492295e-06+0.1962881126089361i Hz!
             Adding it to the filter. Prevent this with 'never_unstable_poles'
5W   2.10    High Confidence that an unstable zero exists at 1.2443441055813007+0.07798366116554925i Hz
             Adding it to the filter. Prevent this with 'never_unstable_zeros'
3W  23.67  Fitter_checkpoint improvement succeed, None
3W  24.23    Fitter_checkpoint improvement succeed, None
3W  59.68  Fitter_checkpoint improvement succeed, None
captured errors:
@pytest.mark.xfail(True, reason="Triggering some overflow to look into")
    @skipdeco
    def test_oplev_iy():
        from wield.utilities.file_io import load_any

        fname = matlab_test_data.matfiles["OplevPlant.mat"]
        fdict = load_any(fname=fname, ftype="mat")

>       out = v2.data2filter(
            F_Hz=fdict["ap"]["iy"]["ff"],
            data=fdict["ap"]["iy"]["plant"],
            F_nyquist_Hz=None,
            delay_s=0,
            hints=[sign_validate_and_plot_hint(tjoin('error'))],
        )

../../src/wield/control/fitting/SISO/test/v2/test_oplev.py:38: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
../../src/wield/control/fitting/SISO/v2/data2filter.py:423: in data2filter
    baseline_order = fit_full(aid, emphasis)
../../src/wield/control/fitting/SISO/v2/data2filter.py:489: in fit_full
    return _reduce(aid)
../../src/wield/control/fitting/SISO/v2/data2filter.py:1135: in _reduce
    order_reduce_flip.order_reduce_flip(
../../src/wield/control/fitting/SISO/v2/algorithms/order_reduce_flip.py:136: in order_reduce_flip
    ret = ranking_delay_flip(
../../src/wield/control/fitting/SISO/v2/algorithms/order_reduce_flip.py:94: in ranking_delay_flip
    did_reduce = aid.fitter_check(
../../src/wield/control/fitting/SISO/v2/fit_aid.py:371: in fitter_check
    val_func(self, fitter_new)
../../src/wield/control/fitting/SISO/testing/utilities.py:219: in sign_validate_plot
    sign_validate(aid, fitter)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

aid = <wield.control.fitting.SISO.v2.fit_aid.FitAid object at 0x7f49ff9990a0>
fitter = <wield.control.fitting.SISO.fitters_ZPK.MRF.MultiReprFilterS object at 0x7f49f49076e0>

    def sign_validate(aid, fitter):
        """
        To be added as a hint to data2filter
        """
        rep = fitter.ZPKrep
        xfer = rep.xfer_fit
        data = rep.data
        rat = data / xfer
        rat_ang = np.exp(1j * np.angle(rat))
        ang_avg_rep = np.sum(rat_ang * rep.W ** 2) / np.sum(rep.W ** 2)

        xfer = fitter.xfer_fit
        data = fitter.data
        rat = data / xfer
        rat_ang = np.exp(1j * np.angle(rat))
        ang_avg_fit = np.sum(rat_ang * fitter.W ** 2) / np.sum(fitter.W ** 2)
        # print("SGN: ", ang_avg_rep, ang_avg_fit)
        # axB = plots.plots.plot_fit(
        #    fitter,
        #    fname = 'test1.png',
        # )
        # axB = plots.plots.plot_fitter_flag(
        #    fitter,
        #    fname = 'test3.png',
        # )
        # axB = plots.plots.plot_fit(
        #    fitter.ZPKrep,
        #    fname = 'test2.png',
        # )

        if isinstance(fitter, fitters_ZPK.MultiReprFilterBase):
            for coding in list(fitter.num_codings) + list(fitter.den_codings):
                rB = representations.RootBunch(
                    u=coding.roots(),
                    constraint=representations.root_constraints.no_constraint,
                )
                h1 = coding.transfer()
                h, lnG = rB.val_lnG(fitter.Xex_grid)
                h = h * np.exp(lnG)
                assert_almost_equal(h / h1, 1, 4)

>       assert ang_avg_fit.real > 0 and ang_avg_rep.real > 0
E       AssertionError

../../src/wield/control/fitting/SISO/testing/utilities.py:191: AssertionError