Ejemplo n.º 1
0
def createtemparf(filename, datatype=0):
    root, ext = os.path.splitext(filename)
    arffile = arf.open_file(tempfile.mktemp())
    if ext == '.lbl':
        lbl_rec = lbl.read(filename)
        print(lbl_rec)
        dset = arf.create_dataset(arffile, os.path.split(filename)[-1],
                                  lbl_rec, units=['','s','s'], datatype=2002)
        dset.attrs['units'] = 's'
    elif ext == '.wav':
        wavfile = ewave.open(filename)        
        arf.create_dataset(arffile, os.path.split(filename)[-1], wavfile.read(),
                           sampling_rate=wavfile.sampling_rate, datatype=1)
    elif ext =='.pcm':
        from arfx import pcmio
        pcmfile = pcmio.open(filename)
        arf.create_dataset(arffile, os.path.split(filename)[-1], pcmfile.read(),
                           sampling_rate=pcmfile.sampling_rate, datatype=datatype)
    elif ext == '.pcm_seq2':
        from arfx import io
        pcmseqfile = io.open(filename)
        dataset_basename = os.path.split(filename)[-1]
        for i in xrange(pcmseqfile.nentries):
            dataset_name = '_'.join([dataset_basename, str(i)])
            arf.create_dataset(arffile, dataset_name, pcmseqfile.read(),
                               sampling_rate=pcmseqfile.sampling_rate, 
                               timestamp=pcmseqfile.timestamp, datatype=datatype)
            #try block added because pcmseqfile.nentries doesn't seem to always be accurate
            try:
                pcmseqfile.entry += 1
            except ValueError:
                continue

    return arffile['/']
Ejemplo n.º 2
0
def test_writeread(tmpdir):
    fname = os.path.join(tmpdir.dirname, 'temp.lbl')
    times = np.reshape(np.arange(0,20), (-1,2))
    labels = [chr(i) for i in np.arange(10) + 65]
    dtype = [('name', np.unicode_, max([len(x) for x in labels])),
             ('start', float), ('stop', float)]
    rec_array = np.array([(l, sta, sto) for l, (sta, sto) in zip(labels, times)],
                    dtype=dtype)
    lbl.write(fname, rec_array)
    rec_array2 = lbl.read(fname)
    assert ''.join(rec_array['name']) == ''.join(rec_array2['name']), 'label names do not match'
    assert np.all(np.isclose(rec_array['start'], rec_array2['start'])), 'starts do not match'
    assert np.all(np.isclose(rec_array['stop'], rec_array2['stop'])), 'stops do not match'
Ejemplo n.º 3
0
def test_writeread(tmpdir):
    fname = os.path.join(tmpdir.dirname, 'temp.lbl')
    times = np.reshape(np.arange(0, 20), (-1, 2))
    labels = [chr(i) for i in np.arange(10) + 65]
    dtype = [('name', np.unicode_, max([len(x) for x in labels])),
             ('start', float), ('stop', float)]
    rec_array = np.array([(l, sta, sto)
                          for l, (sta, sto) in zip(labels, times)],
                         dtype=dtype)
    lbl.write(fname, rec_array)
    rec_array2 = lbl.read(fname)
    assert ''.join(rec_array['name']) == ''.join(
        rec_array2['name']), 'label names do not match'
    assert np.all(np.isclose(rec_array['start'],
                             rec_array2['start'])), 'starts do not match'
    assert np.all(np.isclose(rec_array['stop'],
                             rec_array2['stop'])), 'stops do not match'
Ejemplo n.º 4
0
def createtemparf(filename, datatype=0):
    root, ext = os.path.splitext(filename)
    arffile = arf.open_file(tempfile.mktemp())
    if ext == '.lbl':
        lbl_rec = lbl.read(filename)
        print(lbl_rec)
        dset = arf.create_dataset(arffile, os.path.split(filename)[-1],
                                  lbl_rec, units=['','s','s'], datatype=2002)
        dset.attrs['units'] = 's'
    elif ext == '.wav':
        wavfile = ewave.open(filename)        
        arf.create_dataset(arffile, os.path.split(filename)[-1], wavfile.read(),
                           sampling_rate=wavfile.sampling_rate, datatype=1)
    elif ext =='.pcm':
        from arfx import pcmio
        pcmfile = pcmio.open(filename)
        arf.create_dataset(arffile, os.path.split(filename)[-1], pcmfile.read(),
                           sampling_rate=pcmfile.sampling_rate, datatype=datatype)
    return arffile['/']