diff --git a/meggie/actions/evoked_group_average/controller/evoked.py b/meggie/actions/evoked_group_average/controller/evoked.py index aa964182..60d030ef 100644 --- a/meggie/actions/evoked_group_average/controller/evoked.py +++ b/meggie/actions/evoked_group_average/controller/evoked.py @@ -34,6 +34,36 @@ def group_average_evoked(experiment, evoked_name, groups, new_name): assert_arrays_same(time_arrays) + # handle channel differences + ch_names = [] + for group_key, group_subjects in groups.items(): + for subject_name in group_subjects: + try: + subject = experiment.subjects.get(subject_name) + evoked = subject.evoked.get(evoked_name) + + mne_evokeds = evoked.content + for mne_evoked in mne_evokeds.values(): + ch_idxs = mne.pick_types(mne_evoked.info, meg=True, eeg=True) + ch_names.append(tuple( + [ch_name for ch_idx, ch_name + in enumerate(mne_evoked.info['ch_names']) + if ch_idx in ch_idxs] + )) + except Exception as exc: + continue + + if len(set(ch_names)) != 1: + logging.getLogger('ui_logger').debug( + "Evokeds contain different sets of good channels. Identifying common ones..") + + common_ch_names = list(set.intersection(*map(set, ch_names))) + + logging.getLogger('ui_logger').debug( + str(len(common_ch_names)) + ' common channels found.') + else: + common_ch_names = ch_names[0] + grand_evokeds = {} for group_key, group_subjects in groups.items(): for subject in experiment.subjects.values(): @@ -51,7 +81,9 @@ def group_average_evoked(experiment, evoked_name, groups, new_name): if grand_key not in grand_evokeds: grand_evokeds[grand_key] = [] - grand_evokeds[grand_key].append(evoked_item) + grand_evokeds[grand_key].append( + evoked_item.copy().pick(common_ch_names) + ) grand_averages = {} new_keys = [] @@ -63,10 +95,13 @@ def group_average_evoked(experiment, evoked_name, groups, new_name): grand_averages[new_key] = mne.grand_average(grand_evoked) new_keys.append(new_key) - subject = experiment.active_subject + # to avoid mne complaints, set dev_head_t manually to same for all + keys = sorted(grand_averages.keys()) + for key in keys: + grand_averages[key].info['dev_head_t'] = grand_averages[keys[0]].info['dev_head_t'] + subject = experiment.active_subject evoked_directory = subject.evoked_directory - params = {'conditions': new_keys, 'groups': groups} diff --git a/meggie/actions/tfr_plot_tse/controller/tfr.py b/meggie/actions/tfr_plot_tse/controller/tfr.py index 3e19dec3..907a2aab 100644 --- a/meggie/actions/tfr_plot_tse/controller/tfr.py +++ b/meggie/actions/tfr_plot_tse/controller/tfr.py @@ -95,10 +95,14 @@ def individual_plot(ax, info_idx, names_idx): ax.legend() ax.set_xlabel('Time (s)') - ax.set_ylabel('Power ({})'.format(get_power_unit( - mne.io.pick.channel_type(info, info_idx), - False - ))) + + if blmode and blmode != "mean": + ax.set_ylabel('Power') + else: + ax.set_ylabel('Power ({})'.format(get_power_unit( + mne.io.pick.channel_type(info, info_idx), + log=False + ))) plt.show() @@ -158,8 +162,12 @@ def plot_fun(ax_idx, ax): ch_group = ch_groups[ax_idx] ax.set_title(ch_group) ax.set_xlabel('Time (s)') - ax.set_ylabel('Power ({})'.format(get_power_unit( - ch_type, False))) + + if blmode and blmode != "mean": + ax.set_ylabel('Power') + else: + ax.set_ylabel('Power ({})'.format(get_power_unit( + ch_type, log=False))) for color_idx, (key, times, curve) in enumerate(averages[(ch_type, ch_group)]): ax.plot(times, curve, color=colors[color_idx], label=key)