Skip to content

Commit

Permalink
rename drop_epochs to drop and drop_bad_epochs to drop_bad
Browse files Browse the repository at this point in the history
  • Loading branch information
agramfort authored and larsoner committed Apr 21, 2016
1 parent 604cf50 commit b08a56b
Show file tree
Hide file tree
Showing 14 changed files with 70 additions and 49 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*.egg*
*.tmproj
*.png
*.dat
.DS_Store
events.eve
foo-lh.label
Expand Down Expand Up @@ -59,5 +60,5 @@ cover
# PyCharm
.idea/**

# sublime
*-e
*.dat
2 changes: 1 addition & 1 deletion doc/manual/memory.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ has been loaded with ``preload=True``. Preloading is also supported for :func:`m

.. warning:: This comes with a caveat. When ``preload=False``, data rejection based on peak-to-peak thresholds is executed when the data is loaded from disk, *not* when the ``Epochs`` object is created.

To explicitly reject artifacts with ``preload=False``, use the function :func:`mne.Epochs.drop_bad_epochs`.
To explicitly reject artifacts with ``preload=False``, use the function :func:`mne.Epochs.drop_bad`.

Loading data explicitly
=======================
Expand Down
2 changes: 1 addition & 1 deletion examples/inverse/plot_tf_lcmv.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
# parameters passed here are used to create epochs from filtered data. However,
# reading epochs without preloading means that bad epoch rejection is delayed
# until later. To perform bad epoch rejection based on the reject parameter
# passed here, run epochs.drop_bad_epochs(). This is done automatically in
# passed here, run epochs.drop_bad(). This is done automatically in
# tf_lcmv to reject bad epochs based on unfiltered data.
event_id = 1
events = mne.read_events(event_fname)
Expand Down
2 changes: 1 addition & 1 deletion examples/plot_from_raw_to_epochs_to_evoked.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@

# Look at channels that caused dropped events, showing that the subject's
# blinks were likely to blame for most epochs being dropped
epochs.drop_bad_epochs()
epochs.drop_bad()
epochs.plot_drop_log(subject='sample')

# Average epochs and get evoked data corresponding to the left stimulation
Expand Down
2 changes: 1 addition & 1 deletion mne/beamformer/_lcmv.py
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ def tf_lcmv(epochs, forward, noise_covs, tmin, tmax, tstep, win_lengths,
raw_picks = [raw.ch_names.index(c) for c in ch_names]

# Make sure epochs.events contains only good events:
epochs.drop_bad_epochs()
epochs.drop_bad()

# Multiplying by 1e3 to avoid numerical issues, e.g. 0.3 // 0.05 == 5
n_time_steps = int(((tmax - tmin) * 1e3) // (tstep * 1e3))
Expand Down
2 changes: 1 addition & 1 deletion mne/beamformer/tests/test_dics.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def test_dics():
assert_array_equal(stcs[0].data, advance_iterator(stcs_).data)

# Test whether correct number of trials was returned
epochs.drop_bad_epochs()
epochs.drop_bad()
assert_true(len(epochs.events) == len(stcs))

# Average the single trial estimates
Expand Down
4 changes: 2 additions & 2 deletions mne/beamformer/tests/test_lcmv.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def test_lcmv():
reg=0.01, return_generator=True)
assert_array_equal(stcs[0].data, advance_iterator(stcs_).data)

epochs.drop_bad_epochs()
epochs.drop_bad()
assert_true(len(epochs.events) == len(stcs))

# average the single trial estimates
Expand Down Expand Up @@ -288,7 +288,7 @@ def test_tf_lcmv():
epochs = mne.Epochs(raw, events, event_id, tmin, tmax, proj=True,
baseline=None, preload=False,
reject=dict(grad=4000e-13, mag=4e-12, eog=150e-6))
epochs.drop_bad_epochs()
epochs.drop_bad()

freq_bins = [(4, 12), (15, 40)]
time_windows = [(-0.1, 0.1), (0.0, 0.2)]
Expand Down
2 changes: 1 addition & 1 deletion mne/decoding/ems.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def compute_ems(epochs, conditions=None, picks=None, n_jobs=1, verbose=None):
else:
epochs = epochs[conditions]

epochs.drop_bad_epochs()
epochs.drop_bad()

if len(conditions) != 2:
raise ValueError('Currently this function expects exactly 2 '
Expand Down
46 changes: 33 additions & 13 deletions mne/epochs.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
plot_epochs_image, plot_topo_image_epochs)
from .utils import (check_fname, logger, verbose, _check_type_picks,
_time_mask, check_random_state, object_hash, warn)
from .utils import deprecated
from .externals.six import iteritems, string_types
from .externals.six.moves import zip

Expand Down Expand Up @@ -1070,9 +1071,18 @@ def plot_topo_image(self, layout=None, sigma=0., vmin=None, vmax=None,
border=border, fig_facecolor=fig_facecolor, font_color=font_color,
show=show)

@deprecated('drop_bad_epochs method has been renamed drop_bad. '
'drop_bad_epochs method will be removed in 0.14')
def drop_bad_epochs(self, reject='existing', flat='existing'):
"""Drop bad epochs without retaining the epochs data.
.. Warning:: This method has been renamed. See drop_bad
"""
return self.drop_bad(reject, flat)

def drop_bad(self, reject='existing', flat='existing'):
"""Drop bad epochs without retaining the epochs data.
Should be used before slicing operations.
.. Warning:: Operation is slow since all epochs have to be read from
Expand Down Expand Up @@ -1164,7 +1174,7 @@ def plot_drop_log(self, threshold=0, n_max_plot=20, subject='Unknown',
if not self._bad_dropped:
raise ValueError("You cannot use plot_drop_log since bad "
"epochs have not yet been dropped. "
"Use epochs.drop_bad_epochs().")
"Use epochs.drop_bad().")

from .viz import plot_drop_log
return plot_drop_log(self.drop_log, threshold, n_max_plot, subject,
Expand Down Expand Up @@ -1233,16 +1243,26 @@ def plot_image(self, picks=None, sigma=0., vmin=None,
cmap=cmap, fig=fig,
overlay_times=overlay_times)

@deprecated('drop_bad method has been renamed drop_bad. '
'drop_bad method will be removed in 0.14')
@verbose
def drop_epochs(self, indices, reason='USER', verbose=None):
"""Drop epochs based on indices or boolean mask
Deprecated: See the drop method.
"""
return self.drop(indices, reason, verbose)

@verbose
def drop(self, indices, reason='USER', verbose=None):
"""Drop epochs based on indices or boolean mask
Note that the indices refer to the current set of undropped epochs
rather than the complete set of dropped and undropped epochs.
They are therefore not necessarily consistent with any external indices
(e.g., behavioral logs). To drop epochs based on external criteria,
do not use the preload=True flag when constructing an Epochs object,
and call this method before calling the drop_bad_epochs method.
and call this method before calling the drop_bad method.
Parameters
----------
Expand Down Expand Up @@ -1340,7 +1360,7 @@ def _get_data(self, out=True, verbose=None):
data[idx] = epoch_out
else:
# bads need to be dropped, this might occur after a preload
# e.g., when calling drop_bad_epochs w/new params
# e.g., when calling drop_bad w/new params
good_idx = []
n_out = 0
assert n_events == len(self.selection)
Expand Down Expand Up @@ -1408,7 +1428,7 @@ def __len__(self):
raise RuntimeError('Since bad epochs have not been dropped, the '
'length of the Epochs is not known. Load the '
'Epochs with preload=True, or call '
'Epochs.drop_bad_epochs(). To find the number '
'Epochs.drop_bad(). To find the number '
'of events in the Epochs, use '
'len(Epochs.events).')
return len(self.events)
Expand Down Expand Up @@ -1682,7 +1702,7 @@ def save(self, fname, split_size='2GB'):

# to know the length accurately. The get_data() call would drop
# bad epochs anyway
self.drop_bad_epochs()
self.drop_bad()
total_size = self[0].get_data().nbytes * len(self)
n_parts = int(np.ceil(total_size / float(split_size)))
epoch_idxs = np.array_split(np.arange(len(self)), n_parts)
Expand Down Expand Up @@ -1756,7 +1776,7 @@ def equalize_event_counts(self, event_ids, method='mintime', copy=True):
if len(event_ids) == 0:
raise ValueError('event_ids must have at least one element')
if not epochs._bad_dropped:
epochs.drop_bad_epochs()
epochs.drop_bad()
# figure out how to equalize
eq_inds = list()

Expand Down Expand Up @@ -1810,7 +1830,7 @@ def equalize_event_counts(self, event_ids, method='mintime', copy=True):
indices = _get_drop_indices(event_times, method)
# need to re-index indices
indices = np.concatenate([e[idx] for e, idx in zip(eq_inds, indices)])
epochs.drop_epochs(indices, reason='EQUALIZED_COUNT')
epochs.drop(indices, reason='EQUALIZED_COUNT')
# actually remove the indices
return epochs, indices

Expand Down Expand Up @@ -1964,7 +1984,7 @@ class Epochs(_BaseEpochs):
'NO_DATA' or 'TOO_SHORT' if epoch didn't contain enough data;
names of channels that exceeded the amplitude threshold;
'EQUALIZED_COUNTS' (see equalize_event_counts);
or 'USER' for user-defined reasons (see drop_epochs).
or 'USER' for user-defined reasons (see drop method).
verbose : bool, str, int, or None
See above.
Expand Down Expand Up @@ -2148,7 +2168,7 @@ def __init__(self, data, info, events, tmin=0, event_id=None,
for ii, e in enumerate(self._data):
# This is safe without assignment b/c there is no decim
self._detrend_offset_decim(e)
self.drop_bad_epochs()
self.drop_bad()


def combine_event_ids(epochs, old_event_ids, new_event_id, copy=True):
Expand Down Expand Up @@ -2242,11 +2262,11 @@ def equalize_epoch_counts(epochs_list, method='mintime'):
# make sure bad epochs are dropped
for e in epochs_list:
if not e._bad_dropped:
e.drop_bad_epochs()
e.drop_bad()
event_times = [e.events[:, 0] for e in epochs_list]
indices = _get_drop_indices(event_times, method)
for e, inds in zip(epochs_list, indices):
e.drop_epochs(inds, reason='EQUALIZED_COUNT')
e.drop(inds, reason='EQUALIZED_COUNT')


def _get_drop_indices(event_times, method):
Expand Down Expand Up @@ -2604,7 +2624,7 @@ def __init__(self, fname, proj=True, add_eeg_ref=True, preload=True,
name=name, proj=proj, add_eeg_ref=add_eeg_ref,
preload_at_end=False, on_missing='ignore', selection=selection,
drop_log=drop_log, verbose=verbose)
# use the private property instead of drop_bad_epochs so that epochs
# use the private property instead of drop_bad so that epochs
# are not all read from disk for preload=False
self._bad_dropped = True

Expand Down Expand Up @@ -2804,7 +2824,7 @@ def _finish_concat(info, data, events, event_id, tmin, tmax, baseline,
baseline=baseline, add_eeg_ref=False,
selection=selection, drop_log=drop_log,
proj=False, on_missing='ignore', verbose=verbose)
out.drop_bad_epochs()
out.drop_bad()
return out


Expand Down
2 changes: 1 addition & 1 deletion mne/minimum_norm/tests/test_time_frequency.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def test_source_psd_epochs():
baseline=(None, 0), reject=reject)

# only look at one epoch
epochs.drop_bad_epochs()
epochs.drop_bad()
one_epochs = epochs[:1]

inv = prepare_inverse_operator(inverse_operator, nave=1,
Expand Down
2 changes: 1 addition & 1 deletion mne/preprocessing/ssp.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def _compute_exg_proj(mode, raw, raw_event, tmin, tmax,
epochs = Epochs(raw, events, None, tmin, tmax, baseline=None, preload=True,
picks=picks, reject=reject, flat=flat, proj=True)

epochs.drop_bad_epochs()
epochs.drop_bad()
if epochs.events.shape[0] < 1:
warn('No good epochs found, returning None for projs')
return None, events
Expand Down
Loading

0 comments on commit b08a56b

Please sign in to comment.