Skip to content

Instantly share code, notes, and snippets.

@teonbrooks
Created September 23, 2014 13:28
Show Gist options
  • Save teonbrooks/35f09845aea3d5a7b4dc to your computer and use it in GitHub Desktop.
Save teonbrooks/35f09845aea3d5a7b4dc to your computer and use it in GitHub Desktop.
A test for mne-python bdf reader for larger files
import os.path as op
import inspect
from nose.tools import assert_equal, assert_true
from numpy.testing import assert_array_almost_equal, assert_array_equal
from numpy.testing import assert_raises
from scipy import io
import numpy as np
from mne.externals.six import iterbytes
from mne.utils import _TempDir
from mne.io import Raw
from mne.io import read_raw_edf
FILE = inspect.getfile(inspect.currentframe())
data_dir = op.join(op.dirname(op.abspath(FILE)))
bdf_path = op.join(data_dir, 'AA_136.bdf')
tempdir = _TempDir()
raw1 = read_raw_edf(bdf_path, preload=False)
raw1_file = op.join(tempdir, 'test1-raw.fif')
raw1.save(raw1_file, overwrite=True, buffer_size_sec=25)
raw11 = Raw(raw1_file, preload=True)
chunk = 25000
test_range = raw1.last_samp-chunk
for i in range(10):
start = np.random.random_integers(0,test_range)
data1, times1 = raw1[:, start:start+chunk]
data11, times11 = raw11[:, start:start+chunk]
assert_array_almost_equal(data1, data11, 8)
assert_array_almost_equal(times1, times11)
assert_equal(sorted(raw1.info.keys()), sorted(raw11.info.keys()))
del raw1, raw11
# test the _read_segment function by only loading some of the data
raw2 = read_raw_edf(bdf_path, preload=False)
raw22 = read_raw_edf(bdf_path, preload=True)
for i in range(10):
start = np.random.random_integers(0,test_range)
data2, times2 = raw2[:, start:start+chunk]
data22, times22 = raw22[:, start:start+chunk]
assert_array_equal(data2, data22)
assert_array_equal(times2, times22)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment