Skip to content

Commit

Permalink
FIX: Fix grand average
Browse files Browse the repository at this point in the history
  • Loading branch information
larsoner committed Jan 5, 2015
1 parent 73fde83 commit a92af47
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 13 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ doc/build/
doc/auto_examples/
doc/modules/generated/
doc/source/generated/
doc/source/modules
pip-log.txt
.coverage
tags
Expand Down
10 changes: 9 additions & 1 deletion doc/sphinxext/gen_rst.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ def execfile(filename, global_vars=None, local_vars=None):


import joblib
MAX_NB_LINES_STDOUT = 20


###############################################################################
# A tee object to redict streams to multiple outputs
Expand Down Expand Up @@ -945,8 +947,12 @@ def generate_file_rst(fname, target_dir, src_dir, root_dir, plot_gallery):
'')
my_stdout = my_stdout.strip().expandtabs()
if my_stdout:
output_lines = my_stdout.split('\n')
if len(output_lines) > MAX_NB_LINES_STDOUT:
output_lines = output_lines[:MAX_NB_LINES_STDOUT]
output_lines.append('...')
stdout = '**Script output**::\n\n %s\n\n' % (
'\n '.join(my_stdout.split('\n')))
'\n '.join(output_lines))
open(stdout_path, 'w').write(stdout)
open(time_path, 'w').write('%f' % time_elapsed)
os.chdir(cwd)
Expand Down Expand Up @@ -976,6 +982,7 @@ def generate_file_rst(fname, target_dir, src_dir, root_dir, plot_gallery):
scale_image(image_path % fig_mngr.num, 850)
figure_list.append(image_fname % fig_mngr.num)
last_fig_num = fig_mngr.num
plt.close('all')
e = mlab.get_engine()
for scene in e.scenes:
last_fig_num += 1
Expand All @@ -984,6 +991,7 @@ def generate_file_rst(fname, target_dir, src_dir, root_dir, plot_gallery):
scale_image(image_path % last_fig_num, 850)
figure_list.append(image_fname % last_fig_num)
mlab.close(scene)
mlab.close(all=True)

except Exception:
print(80 * '_')
Expand Down
3 changes: 2 additions & 1 deletion examples/inverse/plot_gamma_map_inverse.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@
scale_factors = np.max(np.abs(stc.data), axis=1)
scale_factors = 0.5 * (1 + scale_factors / np.max(scale_factors))

plot_sparse_source_estimates(forward['src'], stc, bgcolor=(1, 1, 1),
plot_sparse_source_estimates(
forward['src'], stc, bgcolor=(1, 1, 1),
modes=['sphere'], opacity=0.1, scale_factors=(scale_factors, None),
fig_name="Gamma-MAP")

Expand Down
18 changes: 9 additions & 9 deletions mne/evoked.py
Original file line number Diff line number Diff line change
Expand Up @@ -938,7 +938,7 @@ def _get_evoked_node(fname):
return evoked_node


def grand_average(all_evokeds, interpolate_bads='eeg'):
def grand_average(all_evoked, interpolate_bads='eeg'):
"""Make grand average of a list evoked data
The function interpolates bad channels based on `interpolate_bads`
Expand Down Expand Up @@ -968,29 +968,29 @@ def grand_average(all_evokeds, interpolate_bads='eeg'):
The grand average data.
"""
# check if all elements in the given list are evoked data
if not all(isinstance(e, Evoked) for e in all_evokeds):
if not all(isinstance(e, Evoked) for e in all_evoked):
raise ValueError("Not all the elements in list are evoked data")

if interpolate_bads != 'eeg':
raise ValueError('Only EEG channels can be interpolated currently.')

# Copy channels to leave the original evoked datasets intact.
all_evokeds = [e.copy() for e in all_evokeds]
all_evoked = [e.copy() for e in all_evoked]

# Interpolates if necessary
if interpolate_bads == 'eeg':
all_evokeds = [e.interpolate_bads_eeg() if len(e.info['bads']) > 0
else e for e in all_evokeds]
all_evoked = [e.interpolate_bads_eeg() if len(e.info['bads']) > 0
else e for e in all_evoked]

# change and ignore the nave for all evoked datasets.
for e in all_evokeds:
for e in all_evoked:
e.nave = 1

equalize_channels(all_evokeds) # apply equalize_channels
equalize_channels(all_evoked) # apply equalize_channels
# make grand_average object using merge_evoked
grand_average = merge_evoked(all_evokeds)
grand_average = merge_evoked(all_evoked)
# change the grand_average.nave to the number of Evokeds
grand_average.nave = len(all_evokeds)
grand_average.nave = len(all_evoked)
# change comment field
grand_average.comment = "Grand average (n = %d)" % grand_average.nave
return grand_average
Expand Down
14 changes: 12 additions & 2 deletions mne/viz/_3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,8 @@ def plot_sparse_source_estimates(src, stcs, colors=None, linewidth=2,
opacity=0.2, brain_color=(0.7,) * 3,
show=True, high_resolution=False,
fig_name=None, fig_number=None, labels=None,
modes=('cone', 'sphere'),
scale_factors=(1, 0.6),
verbose=None, **kwargs):
"""Plot source estimates obtained with sparse solver
Expand Down Expand Up @@ -555,13 +557,21 @@ def plot_sparse_source_estimates(src, stcs, colors=None, linewidth=2,
label and the waveforms within each cluster are presented in
the same color. labels should be a list of ndarrays when
stcs is a list ie. one label for each stc.
modes : list
Should be a list, with each entry being ``'cone'`` or ``'sphere'``
to specify how the dipoles should be shown.
scale_factros : list
List of floating point scale factors for the markers.
verbose : bool, str, int, or None
If not None, override default verbose level (see mne.verbose).
kwargs : kwargs
Keyword arguments to pass to mlab.triangular_mesh.
"""
modes = ['cone', 'sphere']
scale_factors = [1, 0.6]
known_modes = ['cone', 'sphere']
if not isinstance(modes, (list, tuple)) or \
not all(mode in known_modes for mode in modes):
raise ValueError('mode must be a list containing only '
'"cone" or "sphere"')
if not isinstance(stcs, list):
stcs = [stcs]
if labels is not None and not isinstance(labels, list):
Expand Down

0 comments on commit a92af47

Please sign in to comment.