def test_infer_eeg_placement_scheme(): """Test inferring a correct EEG placement scheme.""" # no eeg channels case (e.g., MEG data) data_path = op.join(base_path, 'bti', 'tests', 'data') raw_fname = op.join(data_path, 'test_pdf_linux') config_fname = op.join(data_path, 'test_config_linux') headshape_fname = op.join(data_path, 'test_hs_linux') raw = mne.io.read_raw_bti(raw_fname, config_fname, headshape_fname) placement_scheme = _infer_eeg_placement_scheme(raw) assert placement_scheme == 'n/a' # 1020 case data_path = op.join(base_path, 'brainvision', 'tests', 'data') raw_fname = op.join(data_path, 'test.vhdr') raw = mne.io.read_raw_brainvision(raw_fname) placement_scheme = _infer_eeg_placement_scheme(raw) assert placement_scheme == 'based on the extended 10/20 system' # Unknown case, use raw from 1020 case but rename a channel raw.rename_channels({'P3': 'foo'}) placement_scheme = _infer_eeg_placement_scheme(raw) assert placement_scheme == 'n/a'
def _sidecar_json(raw, task, manufacturer, fname, kind, overwrite=False, verbose=True): """Create a sidecar json file depending on the kind and save it. The sidecar json file provides meta data about the data of a certain kind. Parameters ---------- raw : instance of Raw The data as MNE-Python Raw object. task : str Name of the task the data is based on. manufacturer : str Manufacturer of the acquisition system. For MEG also used to define the coordinate system for the MEG sensors. fname : str Filename to save the sidecar json to. kind : str Type of the data as in ALLOWED_KINDS. overwrite : bool Whether to overwrite the existing file. Defaults to False. verbose : bool Set verbose output to true or false. Defaults to true. """ sfreq = raw.info['sfreq'] powerlinefrequency = raw.info.get('line_freq', None) if powerlinefrequency is None: warn('No line frequency found, defaulting to 50 Hz') powerlinefrequency = 50 if isinstance(raw, BaseRaw): rec_type = 'continuous' elif isinstance(raw, Epochs): rec_type = 'epoched' else: rec_type = 'n/a' # determine whether any channels have to be ignored: n_ignored = len([ch_name for ch_name in IGNORED_CHANNELS.get(manufacturer, list()) if ch_name in raw.ch_names]) # all ignored channels are trigger channels at the moment... n_megchan = len([ch for ch in raw.info['chs'] if ch['kind'] == FIFF.FIFFV_MEG_CH]) n_megrefchan = len([ch for ch in raw.info['chs'] if ch['kind'] == FIFF.FIFFV_REF_MEG_CH]) n_eegchan = len([ch for ch in raw.info['chs'] if ch['kind'] == FIFF.FIFFV_EEG_CH]) n_ecogchan = len([ch for ch in raw.info['chs'] if ch['kind'] == FIFF.FIFFV_ECOG_CH]) n_seegchan = len([ch for ch in raw.info['chs'] if ch['kind'] == FIFF.FIFFV_SEEG_CH]) n_eogchan = len([ch for ch in raw.info['chs'] if ch['kind'] == FIFF.FIFFV_EOG_CH]) n_ecgchan = len([ch for ch in raw.info['chs'] if ch['kind'] == FIFF.FIFFV_ECG_CH]) n_emgchan = len([ch for ch in raw.info['chs'] if ch['kind'] == FIFF.FIFFV_EMG_CH]) n_miscchan = len([ch for ch in raw.info['chs'] if ch['kind'] == FIFF.FIFFV_MISC_CH]) n_stimchan = len([ch for ch in raw.info['chs'] if ch['kind'] == FIFF.FIFFV_STIM_CH]) - n_ignored # Define modality-specific JSON dictionaries ch_info_json_common = [ ('TaskName', task), ('Manufacturer', manufacturer), ('PowerLineFrequency', powerlinefrequency), ('SamplingFrequency', sfreq), ('SoftwareFilters', 'n/a'), ('RecordingDuration', raw.times[-1]), ('RecordingType', rec_type)] ch_info_json_meg = [ ('DewarPosition', 'n/a'), ('DigitizedLandmarks', False), ('DigitizedHeadPoints', False), ('MEGChannelCount', n_megchan), ('MEGREFChannelCount', n_megrefchan)] ch_info_json_eeg = [ ('EEGReference', 'n/a'), ('EEGGround', 'n/a'), ('EEGPlacementScheme', _infer_eeg_placement_scheme(raw)), ('Manufacturer', manufacturer)] ch_info_json_ieeg = [ ('iEEGReference', 'n/a'), ('ECOGChannelCount', n_ecogchan), ('SEEGChannelCount', n_seegchan)] ch_info_ch_counts = [ ('EEGChannelCount', n_eegchan), ('EOGChannelCount', n_eogchan), ('ECGChannelCount', n_ecgchan), ('EMGChannelCount', n_emgchan), ('MiscChannelCount', n_miscchan), ('TriggerChannelCount', n_stimchan)] # Stitch together the complete JSON dictionary ch_info_json = ch_info_json_common if kind == 'meg': append_kind_json = ch_info_json_meg elif kind == 'eeg': append_kind_json = ch_info_json_eeg elif kind == 'ieeg': append_kind_json = ch_info_json_ieeg ch_info_json += append_kind_json ch_info_json += ch_info_ch_counts ch_info_json = OrderedDict(ch_info_json) _write_json(fname, ch_info_json, overwrite, verbose) return fname