Example #1
0
def test_blockfile_bounds():
    """Test if BlockFile(-1, nblocks + 1) reproduces original file"""
    from electrolib.blocks.blockfile import BlockFile
    from electrolib.sources.sinfile import SinFile
    sfile = SinFile(secsblock=5, duration=60)
    bfile = BlockFile(sfile, -1, sfile.nblocks + 1)
    sblock = sfile.get_blocks(0, sfile.nblocks)
    bblock = bfile.get_blocks(0, bfile.nblocks)
    for name in sblock:
        assert numpy.allclose(sblock[name], bblock[name])
Example #2
0
def test_blockfile_matches_get_blocks():
    """Test if BlockFile(5, 10) is the same as blocks 5-10 from orig"""
    from electrolib.blocks.blockfile import BlockFile
    from electrolib.sources.sinfile import SinFile
    sfile = SinFile(secsblock=5, duration=60)
    bfile = BlockFile(sfile, 5, 10)
    sblock = sfile.get_blocks(5, 10)
    bblock = bfile.get_blocks(0, bfile.nblocks)
    for name in sblock:
        assert numpy.allclose(sblock[name], bblock[name])
Example #3
0
def test_DWTFile_1_threshold():
    """DWTFile inverts correctly"""
    from electrolib.filters.dwtfile import DWTFile
    from electrolib.sources.sinfile import SinFile
    sinfile = SinFile()
    nlevels = 3
    filtfile = DWTFile(sinfile, 'db2', nlevels, 'none', 1)
    nstep = 3 # Arbitrary
    for n in range(0, sinfile.nblocks, nstep):
        blocks1 = sinfile.get_blocks(n, n + nstep)
        blocks2 = filtfile.get_blocks(n, n + nstep)
        for name in blocks1:
            x1 = blocks1[name]
            x2 = blocks2[name]
            assert np.allclose(x1, x2)
Example #4
0
def test_sinusoidal():
    """Test SinFile produces sinusoidal output"""
    # Create SinFile
    from electrolib.sources.sinfile import SinFile
    import numpy
    amplitude = 100
    sf = SinFile(nchan=5, freq_range=(1, 5), amp=100)
    # Test output
    chan = sf.get_chan()
    n1, n2 = 0, 5
    blocks = sf.get_blocks(n1, n2)
    for cname, ch in zip(blocks, chan):
        t = sf.t(n1, n2, ch)
        omega = 2 * numpy.pi * ch.finfo['frequency']
        xp = amplitude * numpy.sin(omega * t)
        assert blocks[cname].any()
        assert numpy.allclose(xp.astype(int), blocks[cname])