def test_apply_av_invalid(): ts = [3., 3., 3., 3., 3., 3., 3., 3.] w = 4 with pytest.raises(ValueError) as excinfo: transform.apply_av("profile", "default") assert 'apply_av expects profile as an MP data structure' \ in str(excinfo.value) profile = compute(ts, windows=w) with pytest.raises(ValueError) as excinfo: transform.apply_av(profile, "custom", "av") assert 'apply_av expects custom_av to be array-like' \ in str(excinfo.value) with pytest.raises(ValueError) as excinfo: transform.apply_av(profile, "not a parameter") assert 'av parameter is invalid' \ in str(excinfo.value) with pytest.raises(ValueError) as excinfo: transform.apply_av(profile, "custom", [0.9, 0.9, 0.9]) assert 'Lengths of annotation vector and mp are different' \ in str(excinfo.value) with pytest.raises(ValueError) as excinfo: transform.apply_av(profile, "custom", [0.5, 0.5, 0.6, 1.2, -0.4]) assert 'Annotation vector values must be between 0 and 1' \ in str(excinfo.value)
def test_av_io_MPF(): ts = np.random.uniform(size=1024) w = 32 profile = compute(ts, w) profile = transform.apply_av(profile, "default") out = os.path.join(tempfile.gettempdir(), 'mp.mpf') io.to_disk(profile, out, format='mpf') dprofile = io.from_disk(out) keys = set(profile.keys()) keysb = set(dprofile.keys()) assert (keys == keysb) # check values same for k, v in profile.items(): if isinstance(v, np.ndarray): np.testing.assert_equal(v, dprofile[k]) elif k == 'data': pass else: assert (v == dprofile[k]) np.testing.assert_equal(profile['data']['ts'], dprofile['data']['ts']) np.testing.assert_equal(profile['data']['query'], dprofile['data']['query'])
def test_apply_clipping_av_valid(): ts = [3., 3., 3., 3., 3., 3., 3., 3.] w = 4 profile = compute(ts, windows=w) expect = profile['mp'] * 2 profile = transform.apply_av(profile, "clipping") np.testing.assert_almost_equal(profile['cmp'], expect)
def test_apply_default_av_valid(): ts = [3., 3., 3., 3., 3., 3.] w = 3 profile = compute(ts, windows=w) expect = profile['mp'] profile = transform.apply_av(profile, "default") np.testing.assert_almost_equal(profile['cmp'], expect)
def test_apply_custom_av_valid(): ts = [3., 3., 3., 3., 3., 3., 3., 3.] w = 4 profile = compute(ts, windows=w) expect = profile['mp'] * 2 av = [0., 0., 0., 0., 0.] profile = transform.apply_av(profile, "custom", av) np.testing.assert_almost_equal(profile['cmp'], expect)