Пример #1
0
    def test_plot_result1(self):
        # Quick run `design` with all verb/plot on, just to check that no
        # errors occur. Actually plots are checked in test below and the other
        # tests.
        dat2 = DATA['case2'][()]
        fdesign.design(fI=fdesign.j0_1(5), verb=2, plot=2, **dat2[0])

        # plot_result for min amplitude
        dat1 = DATA['case1'][()]
        fdesign.plot_result(dat1[1], dat1[2], prntres=True)
        return plt.gcf()
Пример #2
0
 def test_design(self, capsys):
     # Check it doesn't fail, message is correct, and input doesn't matter
     # Same test as first in test_design
     fI = (fdesign.j0_1(5), fdesign.j1_1(5))
     dat1 = DATA['case1'][()]
     _, _ = fdesign.design(fI=fI, verb=1, plot=2, **dat1[0])
     out, _ = capsys.readouterr()
     assert "* WARNING :: `matplotlib` is not installed, no " in out
Пример #3
0
def test_design():
    # 1. General case with various spacing and shifts
    fI = (fdesign.j0_1(5), fdesign.j1_1(5))
    dat1 = DATA['case1'][()]
    _, out1 = fdesign.design(fI=fI, verb=0, plot=0, **dat1[0])

    # First value is always the same.
    # Second value jumps btw -2.722222 and -0.777778, so we don't check it.
    assert_allclose(out1[0][0], dat1[2][0][0])

    assert_allclose(out1[1], dat1[2][1], rtol=1e-3)
    assert_allclose(out1[2], dat1[2][2])

    # np.linalg(.qr) can have roundoff errors which are not deterministic,
    # which can yield different results for badly conditioned matrices. This
    # only affects the edge-cases, not the best result we are looking for.
    # However, we have to limit the following comparison; we check that at
    # least 50% are within a relative error of 0.1%.
    rate = np.sum(np.abs((out1[3] - dat1[2][3]) / dat1[2][3]) < 1e-3)
    assert rate > out1[3].size / 2

    # 2. Specific model with only one spacing/shift
    dat2 = DATA['case2'][()]
    _, out2 = fdesign.design(fI=fI, verb=0, plot=0, **dat2[0])
    assert_allclose(out2[0], dat2[2][0])
    assert_allclose(out2[1], dat2[2][1], rtol=1e-3)
    assert_allclose(out2[2], dat2[2][2])
    assert_allclose(out2[3], dat2[2][3], rtol=1e-3)

    # 3. Same, with only one transform
    dat2b = DATA['case3'][()]
    _, out2b = fdesign.design(fI=fI[0], verb=0, plot=0, **dat2b[0])
    assert_allclose(out2b[0], dat2b[2][0])
    assert_allclose(out2b[1], dat2b[2][1], rtol=1e-3)
    assert_allclose(out2b[2], dat2b[2][2])
    assert_allclose(out2b[3], dat2b[2][3], rtol=1e-3)

    # 4.a Maximize r
    dat4 = DATA['case4'][()]
    dat4[0]['save'] = True
    dat4[0]['name'] = 'tmpfilter'
    _, out4 = fdesign.design(fI=fI, verb=0, plot=0, **dat4[0])
    assert_allclose(out4[0], dat4[2][0])
    assert_allclose(out4[1], dat4[2][1], rtol=1e-3)
    assert_allclose(out4[2], dat4[2][2])
    assert_allclose(out4[3], dat4[2][3], rtol=1e-3)
    # Clean-up  # Should be replaced eventually by tmpdir
    os.remove('./filters/tmpfilter_base.txt')
    os.remove('./filters/tmpfilter_j0.txt')
    os.remove('./filters/tmpfilter_j1.txt')
    os.remove('./filters/tmpfilter_full.txt')

    # 4.b Without full output and all the other default inputs
    dat4[0]['full_output'] = False
    del dat4[0]['name']
    dat4[0]['finish'] = 'Wrong input'
    del dat4[0]['r']
    dat4[0]['reim'] = np.imag  # Set once to imag
    fdesign.design(fI=fI, verb=2, plot=0, **dat4[0])
    # Clean-up  # Should be replaced eventually by tmpdir
    os.remove('./filters/dlf_201_base.txt')
    os.remove('./filters/dlf_201_j0.txt')
    os.remove('./filters/dlf_201_j1.txt')

    # 5. j2 for fI
    with pytest.raises(ValueError, match="is only implemented for fC"):
        fI2 = fdesign.empy_hankel('j2', 0, 50, 100, 1)
        fdesign.design(fI=fI2, verb=0, plot=0, **dat4[0])
Пример #4
0
# Define main model
inp1 = {'spacing': (0.04, 0.1, 10),
        'shift': (-3, -0.5, 10),
        'n': 201,
        'cvar': 'amp',
        'save': False,
        'full_output': True,
        'r': np.logspace(0, 3, 10),
        'r_def': (1, 1, 2),
        'name': 'test',
        'finish': None,
        }

# 1. General case with various spacing and shifts
filt1, out1 = fdesign.design(verb=0, plot=0, fI=fI, **inp1)
case1 = (inp1, filt1, out1)

# 2. Specific model with only one spacing/shift
inp2 = dc(inp1)
inp2['spacing'] = 0.0641
inp2['shift'] = -1.2847
filt2, out2 = fdesign.design(verb=0, plot=0, fI=fI, **inp2)
case2 = (inp2, filt2, out2)

# 3 Same, with only one transform
filt3, out3 = fdesign.design(verb=0, plot=0, fI=fI[0], **inp2)
case3 = (inp2, filt3, out3)

# 4. Maximize r
inp4 = dc(inp2)