Esempio n. 1
0
def _get_data():
    """Helper to get some starting data"""
    # raw with ECG channel
    raw = Raw(raw_fname).crop(0.0, 5.0).load_data()
    data_picks = pick_types(raw.info, meg=True, eeg=True)
    other_picks = pick_types(raw.info, meg=False, stim=True, eog=True)
    picks = np.sort(np.concatenate((data_picks[::16], other_picks)))
    raw = raw.pick_channels([raw.ch_names[p] for p in picks])
    ecg = RawArray(np.zeros((1, len(raw.times))), create_info(["ECG 063"], raw.info["sfreq"], "ecg"))
    for key in ("dev_head_t", "buffer_size_sec", "highpass", "lowpass", "filename", "dig"):
        ecg.info[key] = raw.info[key]
    raw.add_channels([ecg])

    src = read_source_spaces(src_fname)
    trans = read_trans(trans_fname)
    sphere = make_sphere_model("auto", "auto", raw.info)
    stc = _make_stc(raw, src)
    return raw, src, stc, trans, sphere
Esempio n. 2
0
def _get_data():
    """Helper to get some starting data"""
    # raw with ECG channel
    raw = Raw(raw_fname).crop(0., 5.0).load_data()
    data_picks = pick_types(raw.info, meg=True, eeg=True)
    other_picks = pick_types(raw.info, meg=False, stim=True, eog=True)
    picks = np.sort(np.concatenate((data_picks[::16], other_picks)))
    raw = raw.pick_channels([raw.ch_names[p] for p in picks])
    ecg = RawArray(np.zeros((1, len(raw.times))),
                   create_info(['ECG 063'], raw.info['sfreq'], 'ecg'))
    for key in ('dev_head_t', 'buffer_size_sec', 'highpass', 'lowpass',
                'filename', 'dig'):
        ecg.info[key] = raw.info[key]
    raw.add_channels([ecg])

    src = read_source_spaces(src_fname)
    trans = read_trans(trans_fname)
    sphere = make_sphere_model('auto', 'auto', raw.info)
    stc = _make_stc(raw, src)
    return raw, src, stc, trans, sphere
Esempio n. 3
0
def _get_data():
    """Helper to get some starting data"""
    # raw with ECG channel
    raw = Raw(raw_fname).crop(0., 5.0, copy=False).load_data()
    data_picks = pick_types(raw.info, meg=True, eeg=True)
    other_picks = pick_types(raw.info, meg=False, stim=True, eog=True)
    picks = np.sort(np.concatenate((data_picks[::16], other_picks)))
    raw = raw.pick_channels([raw.ch_names[p] for p in picks])
    ecg = RawArray(np.zeros((1, len(raw.times))),
                   create_info(['ECG 063'], raw.info['sfreq'], 'ecg'))
    for key in ('dev_head_t', 'buffer_size_sec', 'highpass', 'lowpass',
                'filename', 'dig'):
        ecg.info[key] = raw.info[key]
    raw.add_channels([ecg])

    src = read_source_spaces(src_fname)
    trans = read_trans(trans_fname)
    sphere = make_sphere_model('auto', 'auto', raw.info)
    stc = _make_stc(raw, src)
    return raw, src, stc, trans, sphere
Esempio n. 4
0
 def save_setup(self):
     de = self.data_entries.copy()
     raw_fname = de.pop('New File').get()
     loc_fname = de.pop('Loc File').get()
     suffix = raw_fname.split('.')[-1]
     if suffix == 'fif':
         try:
             raw = Raw(raw_fname, preload=False)
         except Exception as e:
             print(e)
             messagebox.showerror('Error', 'Failed to read fif')
             return
         if loc_fname:
             messagebox.showwarning('Warning',
                                    'Ignoring location file given')
     elif suffix == 'vhdr':
         if not loc_fname:
             messagebox.showerror('Error', 'Location file not specified')
         try:
             raw = read_raw_brainvision(raw_fname,
                                        preload=os.path.join(
                                            self.sub_dirs['tmp'],
                                            'raw_tmp'))
         except Exception as e:
             print(e)
             messagebox.showerror('Error',
                                  'Failed to read BrainVision raw file')
             return
         try:
             montage = read_dig_montage(bvct=loc_fname)
             ref_name = [
                 ch for ch in montage.dig_ch_pos
                 if not ch in raw.info['ch_names']
             ]
             if len(ref_name) != 1:
                 ref_name = simpledialog.askstring(
                     'Reference Channel',
                     'What is the reference channel name?',
                     parent=self.root)
             else:
                 ref_name = ref_name[0]
             info = create_info([ref_name], raw.info['sfreq'], ['eeg'])
             ref = RawArray(np.zeros((1, len(raw.times))), info)
             ref.info['lowpass'] = raw.info['lowpass']
             raw = raw.add_channels([ref])  #, force_update_info=True)
             #
             for ch_type in ['eog', 'ecg', 'emg', 'stim']:
                 chs = [
                     ch for ch in raw.info['ch_names']
                     if ch_type in ch.lower()
                 ]
                 for ch in chs:
                     ch_ix = raw.ch_names.index(ch)
                     raw._data[ch_ix, :] *= 1e-6
                     raw.set_channel_types({ch: ch_type})
             raw = raw.set_montage(montage, verbose=False)
         except Exception as e:
             print(e)
             messagebox.showerror(
                 'Error', 'Failed to read BrainVision location file')
             return
     else:
         messagebox.showerror('Error', 'Unrecognized raw file format')
         return
     self.save_exp(raw)
Esempio n. 5
0
    def save_setup(self):
        de = self.data_entries.copy()
        raw_fname = de.pop('Load New File').get()
        loc_fname = de.pop('Load Location File').get()
        suffix = raw_fname.split('.')[-1]
        if suffix == 'fif':
            try:
                raw = Raw(raw_fname,preload=False)
            except Exception as e:
                print(e)
                messagebox.showerror('Error','Failed to read fif')
                return
            if loc_fname:
                messagebox.showwarning('Warning','Ignoring location file given')
        elif suffix == 'vhdr':
            if not loc_fname:
               messagebox.showerror('Error','Location file not specified')
            try:
                raw = read_raw_brainvision(raw_fname,
                    preload=op.join(self.sub_dirs['tmp'],'raw_tmp'))
            except Exception as e:
                print(e)
                messagebox.showerror('Error','Failed to read BrainVision raw file')
                return
            try:
                montage = read_dig_montage(bvct=loc_fname)
                ref_name = [ch for ch in montage.dig_ch_pos if not
                            ch in raw.info['ch_names']]
                if len(ref_name) != 1:
                    ref_name = simpledialog.askstring('Reference Channel',
                                                      'What is the reference channel name?',
                                                      parent=self.root)
                else:
                    ref_name = ref_name[0]
                info = create_info([ref_name], raw.info['sfreq'], ['eeg'])
                ref = RawArray(np.zeros((1, len(raw.times))), info)
                ref.info['lowpass'] = raw.info['lowpass']
                raw = raw.add_channels([ref]) #, force_update_info=True)
                #
                for ch_type in ['eog','ecg','emg','stim']:
                    chs = [ch for ch in raw.info['ch_names']
                           if ch_type in ch.lower()]
                    for ch in chs:
                        ch_ix = raw.ch_names.index(ch)
                        raw._data[ch_ix, :] *= 1e-6
                        raw.set_channel_types({ch:ch_type})
                raw = raw.set_montage(montage,verbose=False)
            except Exception as e:
                print(e)
                messagebox.showerror('Error','Failed to read BrainVision location file')
                return
        else:
            messagebox.showerror('Error','Unrecognized raw file format')
            return
        self.save_exp(raw)
        transf = self.data_entries['Coord Trans fname'].get() 
        if not op.isfile(transf):
            subject = self.data_entries['Subject'].get()
            os.environ['SUBJECT'] = subject
            fs_dir = self.data_entries['FS Dir'].get()
            os.environ['SUBJECTS_DIR'] = fs_dir
            messagebox.showinfo(
                'Coregistration','In this next interactive GUI, will need to\n' +
                '1. Load the pial surface file -> Load Surface -> Select Pial Surface\n' +
                '2. Load the subject\'s digitization data: File -> Load digitizer data ->' +
                ' Select the raw data file for this session\n' + 
                '3. Open the coordinate alignment window: Adjust -> Coordinate Alignment\n' + 
                '4. Open the viewer window: View -> Show viewer\n' +
                '5. In the coordinate alignment window, click RAP, LAP and Naision, ' + 
                'and then after clicking each of those click on the corresponing ' +
                'fiducial points on the reconstructed head model\n' +
                '6. Click align using fiducials\n' +
                '7. In the View window: select Options -> Show digitizer data\n'
                '8. Adjust the x, y and z coordinates and rotation until ' +
                'the alignment is as close to the ground truth as possible\n' +
                'If you don\'t know these instructions, feel free to copy and paste')

            self.output_to_terminal('mne_analyze')