def test_sample_rate(): ali = alignment.Alignment( np.asarray([[0, 1], [1, 2]]), np.asarray(['a', 'b'])) with pytest.raises(ValueError) as err: onehot.FramedOneHotProcessor(sample_rate=2).process(ali) assert 'sample rate too low' in str(err.value) feats = onehot.FramedOneHotProcessor(sample_rate=1000).process(ali) assert feats.nframes == frames.Frames(sample_rate=1000).nframes(2000) assert feats.dtype == bool
def test_framed(alignments): ali = alignments['S01F1522_0010'] assert ali.duration() == pytest.approx(0.7) feat = onehot.FramedOneHotProcessor().process(ali) assert all(feat.data.sum(axis=1) != 0) assert feat.shape[1] == len(ali.get_tokens_inventory()) length = onehot.FramedOneHotProcessor().frame.frame_length assert ali.duration() - length <= feat.times[-1, -1] assert feat.times[-1, -1] <= ali.duration() + length
def test_params_framed(): params = { 'tokens': ['a', 'b', 'c'], 'sample_rate': 2, 'frame_shift': 10, 'frame_length': 25, 'window_type': 'blackman', 'blackman_coeff': 0.5} proc = onehot.FramedOneHotProcessor(**params) assert params == proc.get_params() proc = onehot.FramedOneHotProcessor() proc.set_params(**params) assert params == proc.get_params()
def test_window(alignments, window): ali = alignments['S01F1522_0010'] ntokens = len(ali.get_tokens_inventory()) feat = onehot.FramedOneHotProcessor(window_type=window).process(ali) assert all(feat.data.sum(axis=1) != 0) assert feat.shape == (68, ntokens)