Ejemplo n.º 1
0
def save_evoked_to_blender(mri_subject, events, args, evoked=None):
    fol = op.join(MMVT_DIR, mri_subject, 'eeg')
    utils.make_dir(fol)
    if '{cond}' in meg.EVO:
        for event_ind, event_id in enumerate(events.keys()):
            if evoked is None:
                evo = mne.read_evokeds(meg.get_cond_fname(meg.EVO, event_id))
            else:
                evo = evoked[event_id]
            if event_ind == 0:
                ch_names = np.array(evo[0].ch_names)
                dt = np.diff(evo[0].times[:2])[0]
                data = np.zeros((evo[0].data.shape[0], evo[0].data.shape[1], 2))
            data[:, :, event_ind] = evo[0].data
    else:
        if evoked is None:
            evoked = mne.read_evokeds(meg.EVO)
        data = evoked[0].data
        data = data[..., np.newaxis]
        ch_names = np.array(evoked[0].ch_names)
        dt = np.diff(evoked[0].times[:2])[0]
    if 'Event' in ch_names:
        event_ind = np.where(ch_names == 'Event')[0]
        ch_names = np.delete(ch_names, event_ind)
        data = np.delete(data, event_ind, 0)
    data_max, data_min = utils.get_data_max_min(data, args.norm_by_percentile, args.norm_percs)
    max_abs = utils.get_max_abs(data_max, data_min)
    if args.normalize_evoked:
        data = data / max_abs
    np.save(op.join(fol, 'eeg_data.npy'), data)
    np.savez(op.join(fol, 'eeg_data_meta.npz'), names=ch_names, conditions=list(events.keys()), dt=dt,
             minmax=(-max_abs, max_abs))
    return True
Ejemplo n.º 2
0
def save_evoked_to_blender(mri_subject, events, args, evoked=None):
    fol = op.join(MMVT_DIR, mri_subject, 'eeg')
    utils.make_dir(fol)
    if '{cond}' in meg.EVO:
        for event_ind, event_id in enumerate(events.keys()):
            if evoked is None:
                evo = mne.read_evokeds(meg.get_cond_fname(meg.EVO, event_id))
            else:
                evo = evoked[event_id]
            if event_ind == 0:
                ch_names = np.array(evo[0].ch_names)
                dt = np.diff(evo[0].times[:2])[0]
                data = np.zeros((evo[0].data.shape[0], evo[0].data.shape[1], 2))
            data[:, :, event_ind] = evo[0].data
    else:
        if evoked is None:
            evoked = mne.read_evokeds(meg.EVO)
        data = evoked[0].data
        data = data[..., np.newaxis]
        ch_names = np.array(evoked[0].ch_names)
        dt = np.diff(evoked[0].times[:2])[0]
    if 'Event' in ch_names:
        event_ind = np.where(ch_names == 'Event')[0]
        ch_names = np.delete(ch_names, event_ind)
        data = np.delete(data, event_ind, 0)
    if args.normalize_evoked:
        data_max, data_min = utils.get_data_max_min(data, args.norm_by_percentile, args.norm_percs)
        max_abs = utils.get_max_abs(data_max, data_min)
        data = data / max_abs
    np.save(op.join(fol, 'eeg_data.npy'), data)
    np.savez(op.join(fol, 'eeg_data_meta.npz'), names=ch_names, conditions=list(events.keys()), dt=dt)
    return True
Ejemplo n.º 3
0
def save_evoked_to_blender(mri_subject,
                           events,
                           evoked=None,
                           norm_by_percentile=True,
                           norm_percs=(1, 99)):
    fol = op.join(MMVT_DIR, mri_subject, 'eeg')
    utils.make_dir(fol)
    if '{cond}' in meg.EVO:
        for event_ind, event_id in enumerate(events.keys()):
            if evoked is None:
                evo = mne.read_evokeds(meg.get_cond_fname(meg.EVO, event_id))
            else:
                evo = evoked[event_id]
            if event_ind == 0:
                ch_names = evo[0].ch_names
                data = np.zeros(
                    (evo[0].data.shape[0], evo[0].data.shape[1], 2))
            data[:, :, event_ind] = evo[0].data
    else:
        if evoked is None:
            evoked = mne.read_evokeds(meg.EVO)
        data = evoked.data
    data_max, data_min = utils.get_data_max_min(data, norm_by_percentile,
                                                norm_percs)
    max_abs = utils.get_max_abs(data_max, data_min)
    data = data / max_abs
    np.save(op.join(fol, 'eeg_data.npy'), data)
    np.savez(op.join(fol, 'eeg_data_meta.npz'),
             names=ch_names,
             conditions=list(events.keys()))
    return True
Ejemplo n.º 4
0
def calc_minmax(mri_subject, args):
    #todo: merge into save_evoked_to_blender
    fol = op.join(MMVT_DIR, mri_subject, 'eeg')
    data = np.load(op.join(fol, 'eeg_data.npy'))
    data_max, data_min = utils.get_data_max_min(np.diff(data), args.norm_by_percentile, args.norm_percs)
    max_abs = utils.get_max_abs(data_max, data_min)
    np.save(op.join(fol, 'eeg_data_minmax.npy'), [-max_abs, max_abs])
    return op.isfile(op.join(fol, 'eeg_data_minmax.npy'))
Ejemplo n.º 5
0
def plot_color_bar(ax, graph_data, cb_title, data_type='', cb_min_max_eq=True, color_map='jet'):
    if data_type == '':
        return
    import matplotlib as mpl
    data_max = max([max(v) for v in graph_data[data_type].values()])
    data_min = min([min(v) for v in graph_data[data_type].values()])
    if cb_min_max_eq:
        data_max_min = utils.get_max_abs(data_max, data_min)
        vmin, vmax = -data_max_min, data_max_min
    else:
        vmin, vmax = data_min, data_max
    # cmap = color_map # mpl.cm.jet
    norm = mpl.colors.Normalize(vmin=vmin, vmax=vmax)
    cb = mpl.colorbar.ColorbarBase(ax, cmap=color_map, norm=norm, orientation='vertical')#, ticks=color_map_bounds)
    cb.set_label(cb_title)
Ejemplo n.º 6
0
def plot_color_bar(ax,
                   graph_data,
                   cb_title,
                   data_type='',
                   cb_min_max_eq=True,
                   color_map='jet'):
    if data_type == '':
        return
    import matplotlib as mpl
    data_max = max([max(v) for v in graph_data[data_type].values()])
    data_min = min([min(v) for v in graph_data[data_type].values()])
    if cb_min_max_eq:
        data_max_min = utils.get_max_abs(data_max, data_min)
        vmin, vmax = -data_max_min, data_max_min
    else:
        vmin, vmax = data_min, data_max
    # cmap = color_map # mpl.cm.jet
    norm = mpl.colors.Normalize(vmin=vmin, vmax=vmax)
    cb = mpl.colorbar.ColorbarBase(
        ax, cmap=color_map, norm=norm,
        orientation='vertical')  #, ticks=color_map_bounds)
    cb.set_label(cb_title)
Ejemplo n.º 7
0
def plot_color_bar(ax,
                   graph_data,
                   cb_title,
                   data_type='',
                   cb_min_max_eq=True,
                   cb_norm_percs=None,
                   color_map='jet',
                   position='right'):
    if data_type == '':
        return
    import matplotlib as mpl
    if cb_norm_percs is None:
        data_max = max([max(v) for v in graph_data[data_type].values()])
        data_min = min([min(v) for v in graph_data[data_type].values()])
    else:
        data_max = max([
            np.percentile(v, cb_norm_percs[1])
            for v in graph_data[data_type].values()
        ])
        data_min = min([
            np.percentile(v, cb_norm_percs[0])
            for v in graph_data[data_type].values()
        ])
    if cb_min_max_eq:
        data_max_min = utils.get_max_abs(data_max, data_min)
        vmin, vmax = -data_max_min, data_max_min
    else:
        vmin, vmax = data_min, data_max
    # cmap = color_map # mpl.cm.jet
    norm = mpl.colors.Normalize(vmin=vmin, vmax=vmax)
    color_map = fu.find_color_map(color_map)
    cb = mpl.colorbar.ColorbarBase(
        ax, cmap=color_map, norm=norm,
        orientation='vertical')  #, ticks=color_map_bounds)
    if position == 'left':
        ax.yaxis.set_ticks_position('left')
        ax.yaxis.set_label_position('left')
    cb.set_label(cb_title)