Skip to content

Commit

Permalink
MRG, MAINT: Reduce memory usage of examples (mne-tools#8254)
Browse files Browse the repository at this point in the history
* MAINT: Reduce memory usage of examples

* STY: Fix [ci skip]

* FIX: verbose
  • Loading branch information
larsoner authored Sep 14, 2020
1 parent f5080a8 commit b911a76
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 26 deletions.
5 changes: 3 additions & 2 deletions mne/epochs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1488,8 +1488,8 @@ def __repr__(self):
class_name = 'Epochs' if class_name == 'BaseEpochs' else class_name
return '<%s | %s>' % (class_name, s)

@fill_doc
def crop(self, tmin=None, tmax=None, include_tmax=True):
@verbose
def crop(self, tmin=None, tmax=None, include_tmax=True, verbose=None):
"""Crop a time interval from the epochs.
Parameters
Expand All @@ -1499,6 +1499,7 @@ def crop(self, tmin=None, tmax=None, include_tmax=True):
tmax : float | None
End time of selection in seconds.
%(include_tmax)s
%(verbose_meth)s
Returns
-------
Expand Down
5 changes: 3 additions & 2 deletions mne/evoked.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,8 @@ def tmax(self):
"""
return self.times[-1]

@fill_doc
def crop(self, tmin=None, tmax=None, include_tmax=True):
@verbose
def crop(self, tmin=None, tmax=None, include_tmax=True, verbose=None):
"""Crop data to a given time interval.
Parameters
Expand All @@ -247,6 +247,7 @@ def crop(self, tmin=None, tmax=None, include_tmax=True):
tmax : float | None
End time of selection in seconds.
%(include_tmax)s
%(verbose_meth)s
Returns
-------
Expand Down
2 changes: 1 addition & 1 deletion mne/minimum_norm/inverse.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def read_inverse_operator(fname, verbose=None):
#
logger.info('Reading inverse operator decomposition from %s...'
% fname)
f, tree, _ = fiff_open(fname, preload=True)
f, tree, _ = fiff_open(fname)
with f as fid:
#
# Find all inverse operators
Expand Down
7 changes: 2 additions & 5 deletions mne/source_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -692,9 +692,6 @@ def read_source_spaces(fname, patch_stats=False, verbose=None):

def _read_one_source_space(fid, this):
"""Read one source space."""
FIFF_BEM_SURF_NTRI = 3104
FIFF_BEM_SURF_TRIANGLES = 3106

res = dict()

tag = find_tag(fid, this, FIFF.FIFF_MNE_SOURCE_SPACE_ID)
Expand Down Expand Up @@ -796,7 +793,7 @@ def _read_one_source_space(fid, this):

res['np'] = int(tag.data)

tag = find_tag(fid, this, FIFF_BEM_SURF_NTRI)
tag = find_tag(fid, this, FIFF.FIFF_BEM_SURF_NTRI)
if tag is None:
tag = find_tag(fid, this, FIFF.FIFF_MNE_SOURCE_SPACE_NTRI)
if tag is None:
Expand Down Expand Up @@ -830,7 +827,7 @@ def _read_one_source_space(fid, this):
raise ValueError('Vertex normal information is incorrect')

if res['ntri'] > 0:
tag = find_tag(fid, this, FIFF_BEM_SURF_TRIANGLES)
tag = find_tag(fid, this, FIFF.FIFF_BEM_SURF_TRIANGLES)
if tag is None:
tag = find_tag(fid, this, FIFF.FIFF_MNE_SOURCE_SPACE_TRIANGLES)
if tag is None:
Expand Down
3 changes: 1 addition & 2 deletions mne/viz/tests/test_evoked.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,8 +399,7 @@ def test_plot_compare_evokeds():
plot_compare_evokeds([list(evoked_dict.values())], picks=[0],
ci=_parametric_ci)
# smoke test for tmin >= 0 (from mailing list)
with pytest.warns(RuntimeWarning, match='Cropping removes baseline'):
red.crop(0.01, None)
red.crop(0.01, None)
assert len(red.times) > 2
plot_compare_evokeds(red)
# plot a flat channel
Expand Down
15 changes: 10 additions & 5 deletions tutorials/source-modeling/plot_forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,21 @@
# :func:`mne.setup_source_space`, while **volumetric** source space is computed
# using :func:`mne.setup_volume_source_space`.
#
# We will now compute a surface-based source space with an ``'oct6'``
# We will now compute a surface-based source space with an ``'oct4'``
# resolution. See :ref:`setting_up_source_space` for details on source space
# definition and spacing parameter.
#
# .. warning::
# ``'oct4'`` is used here just for speed, for real analyses the recommended
# spacing is ``'oct6'``.

src = mne.setup_source_space(subject, spacing='oct6', add_dist='patch',
src = mne.setup_source_space(subject, spacing='oct4', add_dist='patch',
subjects_dir=subjects_dir)
print(src)

###############################################################################
# The surface based source space ``src`` contains two parts, one for the left
# hemisphere (4098 locations) and one for the right hemisphere (4098
# hemisphere (258 locations) and one for the right hemisphere (258
# locations). Sources can be visualized on top of the BEM surfaces in purple.

mne.viz.plot_bem(subject=subject, subjects_dir=subjects_dir,
Expand Down Expand Up @@ -194,13 +198,14 @@
# parameter.

fwd = mne.make_forward_solution(raw_fname, trans=trans, src=src, bem=bem,
meg=True, eeg=False, mindist=5.0, n_jobs=2)
meg=True, eeg=False, mindist=5.0, n_jobs=2,
verbose=True)
print(fwd)

###############################################################################
# .. warning::
# Forward computation can remove vertices that are too close to (or outside)
# the inner skull surface. For example, here we have gone from 8096 to 7498
# the inner skull surface. For example, here we have gone from 516 to 474
# vertices in use. For many functions, such as
# :func:`mne.compute_source_morph`, it is important to pass ``fwd['src']``
# or ``inv['src']`` so that this removal is adequately accounted for.
Expand Down
7 changes: 3 additions & 4 deletions tutorials/source-modeling/plot_mne_solutions.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
data_path = sample.data_path()
subjects_dir = data_path + '/subjects'

# Read data
# Read data (just MEG here for speed, though we could use MEG+EEG)
fname_evoked = data_path + '/MEG/sample/sample_audvis-ave.fif'
evoked = mne.read_evokeds(fname_evoked, condition='Left Auditory',
baseline=(None, 0))
fname_fwd = data_path + '/MEG/sample/sample_audvis-meg-eeg-oct-6-fwd.fif'
fname_fwd = data_path + '/MEG/sample/sample_audvis-meg-oct-6-fwd.fif'
fname_cov = data_path + '/MEG/sample/sample_audvis-cov.fif'
fwd = mne.read_forward_solution(fname_fwd)
cov = mne.read_cov(fname_cov)
Expand All @@ -52,7 +52,6 @@
brain = stc.plot(figure=1, **kwargs)
brain.add_text(0.1, 0.9, 'MNE', 'title', font_size=14)


###############################################################################
# Next let's use the default noise normalization, dSPM:

Expand Down Expand Up @@ -82,6 +81,7 @@

inv = make_inverse_operator(evoked.info, fwd, cov, loose=1., depth=0.8,
verbose=True)
del fwd

###############################################################################
# Let's look at the current estimates using MNE. We'll take the absolute
Expand All @@ -91,7 +91,6 @@
brain = stc.plot(figure=5, **kwargs)
brain.add_text(0.1, 0.9, 'MNE', 'title', font_size=14)


###############################################################################
# Next let's use the default noise normalization, dSPM:

Expand Down
9 changes: 4 additions & 5 deletions tutorials/source-modeling/plot_visualize_stc.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
# You can also morph it to fsaverage and visualize it using a flatmap:

# sphinx_gallery_thumbnail_number = 2

stc_fs = mne.compute_source_morph(stc, 'sample', 'fsaverage', subjects_dir,
smooth=5, verbose='error').apply(stc)
brain = stc_fs.plot(subjects_dir=subjects_dir, initial_time=initial_time,
Expand Down Expand Up @@ -87,7 +86,8 @@
# Let us load the sensor-level evoked data. We select the MEG channels
# to keep things simple.
evoked = read_evokeds(fname_evoked, condition=0, baseline=(None, 0))
evoked.pick_types(meg=True, eeg=False)
evoked.pick_types(meg=True, eeg=False).crop(
0.05, 0.15, verbose='error') # 'error' here: ignore cutting off baseline

###############################################################################
# Then, we can load the precomputed inverse operator from a file.
Expand All @@ -102,7 +102,6 @@
lambda2 = 1.0 / snr ** 2
method = "dSPM" # use dSPM method (could also be MNE or sLORETA)
stc = apply_inverse(evoked, inv, lambda2, method)
stc.crop(0.0, 0.2)

###############################################################################
# This time, we have a different container
Expand Down Expand Up @@ -154,8 +153,8 @@

inv = read_inverse_operator(fname_inv)
stc = apply_inverse(evoked, inv, lambda2, 'dSPM', pick_ori='vector')
stc.plot(subject='sample', subjects_dir=subjects_dir,
initial_time=initial_time)
brain = stc.plot(subject='sample', subjects_dir=subjects_dir,
initial_time=initial_time)

###############################################################################
# Dipole fits
Expand Down

0 comments on commit b911a76

Please sign in to comment.