def test_read_raw(): """Test the raw reading.""" # Use a file ending that does not exist f = 'file.bogus' with pytest.raises(ValueError, match='file name extension must be one of'): _read_raw(f)
def interpolate(self): """ Interpolates bad channels to create new data and updates info Parameters ---------- none Returns ------- none """ result_filename = self.unique_name + "_results.json" result_file_overall = os.path.join(self.result_path, result_filename) processed_filename = self.unique_name + "_raw.fif" processed_file_overall = os.path.join(self.result_path, processed_filename) if os.path.isfile(result_file_overall) and os.path.isfile( processed_file_overall): eeg = _read_raw(processed_file_overall) with open(result_file_overall) as json_file: automagic = json.load(json_file) else: raise (ValueError, "The block has not been preprocessed yet.") return interpolate_chans = self.to_be_interpolated if interpolate_chans == []: raise ( ValueError, "The block is rated to be interpolated but no channels chosen", ) return if (self.params == [] or not "interpolation_params" in self.params or self.params["interpolation_params"] == []): default_params = self.config["default_params"] interpolation_params = default_params["interpolation_params"] else: interpolation_params = self.params["interpolation_params"] eeg.load_data() eeg.info["dig"] = mne.channels.make_standard_montage(self.montage) interpolated = eeg.interpolate_bads( ) # (origin=interpolation_params['origin']) overall_thresh = self.project.quality_thresholds["overall_thresh"] time_thresh = self.project.quality_thresholds["time_thresh"] chan_thresh = self.project.quality_thresholds["chan_thresh"] apply_common_avg = self.project.quality_thresholds["apply_common_avg"] quality_scores = calcQuality( interpolated.get_data(), interpolate_chans, overall_thresh, time_thresh, chan_thresh, apply_common_avg, ) update_to_be_stored = { "rate": "not rated", "is_manually_rated": False, "to_be_interpolated": [], "final_bad_chans": interpolate_chans, "is_interpolated": True, "quality_scores": quality_scores, } self.update_rating(update_to_be_stored) automagic.update({ "interpolation": { "channels": interpolate_chans, "params": interpolation_params, }, "quality_scores": self.quality_scores, "rate": self.rate, }) results = {"preprocessed": interpolated, "automagic": automagic} self.write_log(automagic) automagic.update({ "to_be_interpolated": self.to_be_interpolated, "rate": self.rate, "quality_scores": self.quality_scores, "is_manually_rated": self.is_manually_rated, "is_interpolated": self.is_interpolated, }) main_result_file = results["automagic"] result_filename = self.unique_name + "_results.json" result_file_overall = os.path.join(self.result_path, result_filename) _write_json(result_file_overall, main_result_file, overwrite=True, verbose=True) processed = results["preprocessed"] processed.info["dig"] = None processed_filename = self.unique_name + "_raw.fif" processed_file_overall = os.path.join(self.result_path, processed_filename) processed.save(processed_file_overall, overwrite=True) return results
def run(): """Run the raw_to_bids command.""" from mne.commands.utils import get_optparser parser = get_optparser(__file__, usage="usage: %prog options args", prog_prefix='mne_bids', version=mne_bids.__version__) parser.add_option('--subject_id', dest='subject_id', help=('subject name in BIDS compatible format ' '(01, 02, etc.)')) parser.add_option('--task', dest='task', help='name of the task the data is based on') parser.add_option('--raw', dest='raw_fname', help='path to the raw MEG file') parser.add_option('--bids_root', dest='bids_root', help='The path of the BIDS compatible folder.') parser.add_option('--session_id', dest='session_id', help='session name in BIDS compatible format') parser.add_option('--run', dest='run', help='run number for this dataset') parser.add_option('--acq', dest='acq', help='acquisition parameter for this dataset') parser.add_option('--events_data', dest='events_data', help='events file (events.tsv)') parser.add_option('--event_id', dest='event_id', help='event id dict', metavar='eid') parser.add_option('--hpi', dest='hpi', help='path to the MEG marker points') parser.add_option('--electrode', dest='electrode', help='path to head-native digitizer points') parser.add_option('--hsp', dest='hsp', help='path to headshape points') parser.add_option('--config', dest='config', help='path to the configuration file') parser.add_option('--overwrite', dest='overwrite', help="whether to overwrite existing data (BOOLEAN)") parser.add_option('--line_freq', dest='line_freq', help="The frequency of the line noise in Hz " "(e.g. 50 or 60). If unknown, pass None") opt, args = parser.parse_args() if len(args) > 0: parser.print_help() parser.error('Do not specify arguments without flags. Found: "{}".\n' .format(args)) if not all([opt.subject_id, opt.task, opt.raw_fname, opt.bids_root]): parser.print_help() parser.error('Arguments missing. You need to specify at least the' 'following: --subject_id, --task, --raw, --bids_root.') bids_path = BIDSPath( subject=opt.subject_id, session=opt.session_id, run=opt.run, acquisition=opt.acq, task=opt.task, root=opt.bids_root) allow_maxshield = False if opt.raw_fname.endswith('.fif'): allow_maxshield = 'yes' raw = _read_raw(opt.raw_fname, hpi=opt.hpi, electrode=opt.electrode, hsp=opt.hsp, config_path=opt.config, allow_maxshield=allow_maxshield) if opt.line_freq is not None: line_freq = None if opt.line_freq == "None" else opt.line_freq raw.info['line_freq'] = line_freq write_raw_bids(raw, bids_path, event_id=opt.event_id, events_data=opt.events_data, overwrite=opt.overwrite, verbose=True)
def run(): """Run the raw_to_bids command.""" from mne.commands.utils import get_optparser parser = get_optparser(__file__, usage="usage: %prog options args", prog_prefix='mne_bids', version=mne_bids.__version__) parser.add_option('--subject_id', dest='subject_id', help=('subject name in BIDS compatible format ' '(01, 02, etc.)')) parser.add_option('--task', dest='task', help='name of the task the data is based on') parser.add_option('--raw', dest='raw_fname', help='path to the raw MEEG file') parser.add_option('--output_path', dest='output_path', help='path to the BIDS compatible folder') parser.add_option('--session_id', dest='session_id', help='session name in BIDS compatible format') parser.add_option('--run', dest='run', help='run number for this dataset') parser.add_option('--acq', dest='acq', help='acquisition parameter for this dataset') parser.add_option('--events_data', dest='events_data', help='events file (events.tsv)') parser.add_option('--event_id', dest='event_id', help='event id dict', metavar='eid') parser.add_option('--hpi', dest='hpi', help='path to the MEG marker points') parser.add_option('--electrode', dest='electrode', help='path to head-native digitizer points') parser.add_option('--hsp', dest='hsp', help='path to headshape points') parser.add_option('--config', dest='config', help='path to the configuration file') parser.add_option('--overwrite', dest='overwrite', help="whether to overwrite existing data (BOOLEAN)") parser.add_option('--allow_maxshield', dest='allow_maxshield', help="whether to allow non maxfiltered data (BOOLEAN)", action='store_true') opt, args = parser.parse_args() if len(args) > 0: parser.print_help() parser.error( 'Do not specify arguments without flags. Found: "{}".\n'.format( args)) if not all([opt.subject_id, opt.task, opt.raw_fname, opt.output_path]): parser.print_help() parser.error('Arguments missing. You need to specify at least the' 'following: --subject_id, --task, --raw, --output_path.') bids_basename = make_bids_basename(subject=opt.subject_id, session=opt.session_id, run=opt.run, acquisition=opt.acq, task=opt.task) raw = _read_raw(opt.raw_fname, hpi=opt.hpi, electrode=opt.electrode, hsp=opt.hsp, config=opt.config, allow_maxshield=opt.allow_maxshield) write_raw_bids(raw, bids_basename, opt.output_path, event_id=opt.event_id, events_data=opt.events_data, overwrite=opt.overwrite, verbose=True)