Skip to content

Commit 347bcb3

Browse files
committed
fix memory useage
1 parent b2d2420 commit 347bcb3

File tree

3 files changed

+34
-26
lines changed

3 files changed

+34
-26
lines changed

mne/evoked.py

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
_check_pandas_installed, _check_pandas_index_arguments,
2525
_convert_times, _scale_dataframe_data, _check_time_format,
2626
_check_preload, _check_fname)
27+
from .utils.mixin import _check_decim
2728
from .viz import (plot_evoked, plot_evoked_topomap, plot_evoked_field,
2829
plot_evoked_image, plot_evoked_topo)
2930
from .viz.evoked import plot_evoked_white, plot_evoked_joint
@@ -860,30 +861,6 @@ def to_data_frame(self, picks=None, index=None,
860861
return df
861862

862863

863-
def _check_decim(info, decim, offset):
864-
"""Check decimation parameters."""
865-
if decim < 1 or decim != int(decim):
866-
raise ValueError('decim must be an integer > 0')
867-
decim = int(decim)
868-
new_sfreq = info['sfreq'] / float(decim)
869-
lowpass = info['lowpass']
870-
if decim > 1 and lowpass is None:
871-
warn('The measurement information indicates data is not low-pass '
872-
'filtered. The decim=%i parameter will result in a sampling '
873-
'frequency of %g Hz, which can cause aliasing artifacts.'
874-
% (decim, new_sfreq))
875-
elif decim > 1 and new_sfreq < 3 * lowpass:
876-
warn('The measurement information indicates a low-pass frequency '
877-
'of %g Hz. The decim=%i parameter will result in a sampling '
878-
'frequency of %g Hz, which can cause aliasing artifacts.'
879-
% (lowpass, decim, new_sfreq)) # > 50% nyquist lim
880-
offset = int(offset)
881-
if not 0 <= offset < decim:
882-
raise ValueError('decim must be at least 0 and less than %s, got '
883-
'%s' % (decim, offset))
884-
return decim, offset, new_sfreq
885-
886-
887864
@fill_doc
888865
class EvokedArray(Evoked):
889866
"""Evoked object from numpy array.

mne/utils/mixin.py

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,31 @@ def metadata(self, metadata, verbose=None):
423423
self._metadata = metadata
424424

425425

426+
def _check_decim(info, decim, offset, check_filter=True):
427+
"""Check decimation parameters."""
428+
if decim < 1 or decim != int(decim):
429+
raise ValueError('decim must be an integer > 0')
430+
decim = int(decim)
431+
new_sfreq = info['sfreq'] / float(decim)
432+
offset = int(offset)
433+
if not 0 <= offset < decim:
434+
raise ValueError('decim must be at least 0 and less than %s, got '
435+
'%s' % (decim, offset))
436+
if check_filter:
437+
lowpass = info['lowpass']
438+
if decim > 1 and lowpass is None:
439+
warn('The measurement information indicates data is not low-pass '
440+
'filtered. The decim=%i parameter will result in a sampling '
441+
'frequency of %g Hz, which can cause aliasing artifacts.'
442+
% (decim, new_sfreq))
443+
elif decim > 1 and new_sfreq < 3 * lowpass:
444+
warn('The measurement information indicates a low-pass frequency '
445+
'of %g Hz. The decim=%i parameter will result in a sampling '
446+
'frequency of %g Hz, which can cause aliasing artifacts.'
447+
% (lowpass, decim, new_sfreq)) # > 50% nyquist lim
448+
return decim, offset, new_sfreq
449+
450+
426451
class EpochsTimesMixin(object):
427452
"""Class to handle times, tmin, tmax and decimation for epochs."""
428453

@@ -481,8 +506,11 @@ def decimate(self, decim, offset=0, verbose=None):
481506
----------
482507
.. footbibliography::
483508
"""
484-
from ..evoked import _check_decim
485-
decim, offset, new_sfreq = _check_decim(self.info, decim, offset)
509+
# if epochs have frequencies, they are not in time (EpochsTFR)
510+
# and so do not need to be checked whether they have been
511+
# appropriately filtered to avoid aliasing
512+
decim, offset, new_sfreq = _check_decim(
513+
self.info, decim, offset, check_filter=hasattr(self, 'freqs'))
486514
start_idx = int(round(-self._raw_times[0] * (self.info['sfreq'] *
487515
self._decim)))
488516
self._decim *= decim

tutorials/inverse/55_tfr_stc.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,9 @@
189189
# Now, we can apply the filters and compute a source time-course estimate
190190
# for each frequency.
191191

192+
# decimate for speed in this tutorial, you probably shouldn't decimate
193+
# so much in a real analysis
194+
epochs_tfr.decimate(decim=20)
192195
stc = mne.beamformer.apply_lcmv_epochs_tfr(epochs_tfr, filters)
193196
del filters
194197

0 commit comments

Comments
 (0)