Esempio n. 1
0
def test_digitalfilter():                                   # 1.a DigitalFilter
    # Assure a DigitalFilter has attribute 'name'.
    out1 = filters.DigitalFilter('test')
    out2 = filters.DigitalFilter('test', 'savenametest')
    assert out1.name == 'test'
    assert out1.savename == out1.name
    assert out1.name == out2.name
    assert out2.savename == 'savenametest'
Esempio n. 2
0
def test_digitalfilter():  # 1.a DigitalFilter
    # Assure a DigitalFilter has attribute 'name'.
    out1 = filters.DigitalFilter('test')
    out2 = filters.DigitalFilter('test', 'savenametest')
    out3 = filters.DigitalFilter('test', filter_coeff=[
        'abc',
    ])
    assert out1.name == 'test'
    assert out1.savename == out1.name
    assert out1.name == out2.name
    assert out1.filter_coeff == ['j0', 'j1', 'sin', 'cos']
    assert out2.savename == 'savenametest'
    assert out3.filter_coeff == ['j0', 'j1', 'sin', 'cos', 'abc']
Esempio n. 3
0
def test_get_spline_values():                            # 9. get_spline_values
    # Check one example
    filt = filters.key_81_CosSin_2009()
    out, new_inp = transform.get_spline_values(filt, np.arange(1, 6), -1)
    # Expected values
    oout = np.array([[6.70925256e-05, 8.19469958e-05, 1.00090287e-04,
                      1.22250552e-04, 1.49317162e-04, 1.82376393e-04,
                      2.22755030e-04, 2.72073608e-04, 3.32311455e-04,
                      4.05886127e-04, 4.95750435e-04, 6.05510949e-04,
                      7.39572743e-04, 9.03316189e-04, 1.10331288e-03,
                      1.34758940e-03, 1.64594941e-03, 2.01036715e-03,
                      2.45546798e-03, 2.99911536e-03, 3.66312778e-03,
                      4.47415437e-03, 5.46474449e-03, 6.67465399e-03,
                      8.15244080e-03, 9.95741367e-03, 1.21620125e-02,
                      1.48547156e-02, 1.81435907e-02, 2.21606317e-02,
                      2.70670566e-02, 3.30597776e-02, 4.03793036e-02,
                      4.93193928e-02, 6.02388424e-02, 7.35758882e-02,
                      8.98657928e-02, 1.09762327e-01, 1.34064009e-01,
                      1.63746151e-01, 2.00000000e-01, 2.44280552e-01,
                      2.98364940e-01, 3.64423760e-01, 4.45108186e-01,
                      5.43656366e-01, 6.64023385e-01, 8.11039993e-01,
                      9.90606485e-01, 1.20992949e+00, 1.47781122e+00,
                      1.80500270e+00, 2.20463528e+00, 2.69274761e+00,
                      3.28892935e+00, 4.01710738e+00, 4.90650604e+00,
                      5.99282001e+00, 7.31964689e+00, 8.94023690e+00,
                      1.09196300e+01, 1.33372662e+01, 1.62901737e+01,
                      1.98968631e+01, 2.43020835e+01, 2.96826318e+01,
                      3.62544484e+01, 4.42812832e+01, 5.40852815e+01,
                      6.60599120e+01, 8.06857587e+01, 9.85498082e+01,
                      1.20369008e+02, 1.47019038e+02, 1.79569458e+02,
                      2.19326632e+02, 2.67886153e+02, 3.27196886e+02,
                      3.99639179e+02, 4.88120396e+02, 5.96191597e+02,
                      7.28190061e+02, 8.89413350e+02, 1.08633192e+03,
                      1.32684880e+03, 1.62061679e+03, 1.97942581e+03,
                      2.41767615e+03, 2.95295631e+03, 3.60674899e+03]])
    onew_inp = np.array([5., 4.09365377, 3.35160023, 2.74405818, 2.24664482,
                         1.83939721, 1.50597106, 1.23298482, 1.00948259,
                         0.82649444])
    # Comparison
    assert_allclose(out, oout)
    assert_allclose(new_inp, onew_inp)

    # Ensure output dimension
    hfilt = filters.anderson_801_1982()
    out, _ = transform.get_spline_values(hfilt, np.array([1, 1.1]), -1)
    assert_allclose(out.size, 804)

    # Check a hypothetical short filter, with small pts_per_dec, and ensure
    # at least four points are returned
    filt = filters.DigitalFilter('shortest')
    filt.base = np.array([1., 1.1])
    out, new_inp = transform.get_spline_values(filt, np.array([1.]), 1)
    assert_allclose(out.size, 4)

    # Check standard example
    ffilt = filters.key_81_CosSin_2009()
    inp = np.arange(1, 6)
    out, new_inp = transform.get_spline_values(ffilt, inp, 0)
    assert_allclose(inp, new_inp)
    assert_allclose(out, ffilt.base/inp[:, None])
Esempio n. 4
0
def test_storeandsave(tmpdir):  # 1.b Save/Load
    # Store a filter
    inpfilt = filters.wer_201_2018()
    inpfilt.savename = 'savetest'
    inpfilt.tofile(tmpdir)
    assert len(tmpdir.listdir()) == 3
    assert os.path.isfile(os.path.join(tmpdir, 'savetest_base.txt')) is True
    assert os.path.isfile(os.path.join(tmpdir, 'savetest_j0.txt')) is True
    assert os.path.isfile(os.path.join(tmpdir, 'savetest_j1.txt')) is True

    # Load a filter
    outfilt = filters.DigitalFilter('savetest')
    outfilt.fromfile(tmpdir)
    assert_allclose(outfilt.base, inpfilt.base)
    assert_allclose(outfilt.j0, inpfilt.j0)
    assert_allclose(outfilt.j1, inpfilt.j1)
    assert_allclose(outfilt.factor, inpfilt.factor)
Esempio n. 5
0
def test_digitalfilter():  # 1. DigitalFilter
    # Assure a DigitalFilter has attribute 'name'.
    out = filters.DigitalFilter('test')
    assert out.name == 'test'