def test_event_discrepancies(self, subject, experiment, session, rhino_root): """Test loading of known subjects with differences between session number in events.json and session number everywhere else. """ reader = CMLReader(subject, experiment, session, rootdir=rhino_root) pairs = reader.load("pairs") events = reader.load("events") reader.load_eeg(events.sample(n=1), rel_start=0, rel_stop=10, scheme=pairs)
def test_load_multisession(self, subjects, experiments, rhino_root): events = CMLReader.load_events(subjects, experiments, rootdir=rhino_root) good_sample = False while not good_sample: events = events.copy()[events["type"] == "WORD"].sample(20) good_sample = ( all([s in events.subject.values for s in subjects]) and all([e in events.experiment.values for e in experiments])) reader = CMLReader(events["subject"].unique()[0], rootdir=rhino_root) load = lambda: reader.load_eeg(events, rel_start=0, rel_stop=10 ) # noqa if len(subjects) > 1: with pytest.raises(ValueError): load() return eeg = load() assert len(eeg.epochs) == len(events) assert len(eeg.events) == len(events) for subject in subjects: assert subject in set(events["subject"]) for experiment in experiments: assert experiment in set(events["experiment"])
def test_read_whole_session(self, subject, rhino_root): reader = CMLReader(subject=subject, experiment="FR1", session=0, rootdir=rhino_root) eeg = reader.load_eeg() assert eeg.shape == (1, 70, 3304786)
def test_negative_offsets(self, rhino_root): subject, experiment = ("R1298E", "FR1") reader = CMLReader(subject=subject, experiment=experiment, session=0, rootdir=rhino_root) events = reader.load("events") events = events[events["type"] == "WORD"].iloc[:2] eeg = reader.load_eeg(events=events, rel_start=-100, rel_stop=-20) assert eeg.shape[-1] == 80
def test_eeg_reader(self, subject, index, channel, rhino_root): reader = CMLReader(subject=subject, experiment='FR1', session=0, rootdir=rhino_root) events = reader.load("events") events = events[events["type"] == "WORD"].iloc[:2] eeg = reader.load_eeg(events=events, rel_start=0, rel_stop=100) assert len(eeg.time) == 100 assert eeg.data.shape[0] == 2 assert eeg.channels[index] == channel
def load_eeg(self, subject: str, experiment: str) -> TimeSeries: """Load EEG data for all sessions of the given experiment. :param subject: subject ID :param experiment: experiment name """ logger.info("Loading EEG for %s/%s", subject, experiment) events = CMLReader.load_events(subject, experiment) words = events[events.type == "WORD"] reader = CMLReader(subject, experiment) eeg = reader.load_eeg(events=words, rel_start=0, rel_stop=1600) return eeg
def test_channel_discrepancies(self, subject, experiment, session, eeg_channels, pairs_channels, rhino_root): """Test loading of known subjects with differences between channels in pairs.json and channels actually recorded. """ reader = CMLReader(subject, experiment, session, rootdir=rhino_root) pairs = reader.load("pairs") events = reader.load("events") with pytest.warns(MissingChannelsWarning): eeg = reader.load_eeg(events.sample(n=1), rel_start=0, rel_stop=10, scheme=pairs) assert len(eeg.channels) == eeg_channels assert len(pairs) == pairs_channels
def test_filter_channels(self, subject, region_key, region_name, expected_channels, tlen, rhino_root): """Test that we can actually filter channels. This happens via rereference, so it's really just a special case check of that. """ reader = CMLReader(subject, "FR1", 0, rootdir=rhino_root) pairs = reader.load("pairs") scheme = pairs[pairs[region_key] == region_name] all_events = reader.load("events") events = all_events[all_events["type"] == "WORD"] eeg = reader.load_eeg(events, rel_start=-100, rel_stop=100, scheme=scheme) assert eeg.shape[0] == len(events) assert eeg.shape[1] == expected_channels assert eeg.shape[2] == tlen assert eeg.attrs["rereferencing_possible"] is ( True if subject != "R1384J" else False)
def test_eeg_reader_with_events(self, subject, rhino_root): """Note: R1161E is split over two separate sets of files""" reader = CMLReader(subject=subject, experiment='FR1', session=0, rootdir=rhino_root) events = reader.load('events') word_events = events[events.type == 'WORD'] eeg = reader.load_eeg(events=word_events, rel_start=-75, rel_stop=75) assert eeg.shape[0] == len(word_events) assert eeg.shape[-1] == 150 ErrorType = exc.IncompatibleParametersError with pytest.raises(ErrorType): reader.load_eeg(events=word_events, rel_start=0) with pytest.raises(ErrorType): reader.load_eeg(events=word_events, rel_stop=0) with pytest.raises(ErrorType): reader.load_eeg(events=word_events)
def test_partial_session(self, subject, experiment, session, rel_start, rel_stop, samples, rhino_root): """Test loading a partial session without giving events.""" reader = CMLReader(subject, experiment, session, rootdir=rhino_root) eeg = reader.load_eeg(rel_start=rel_start, rel_stop=rel_stop) assert eeg.shape[2] == samples