'Get averaging parameters for a condition (averaging category).
Output is designed to be used with the Epochs class to extract the
corresponding epochs.
Parameters
raw : Raw object
An instance of Raw.
condition : None | str | dict | list of dict
Condition or a list of conditions. Conditions can be strings
(DACQ comment field, e.g. \'Auditory left\') or category dicts
(e.g. acqp[\'Auditory left\'], where acqp is an instance of
AcqParserFIF). If None, get all conditions marked active in
DACQ.
stim_channel : None | string | list of string
Name of the stim channel or all the stim channels
affected by the trigger. If None, the config variables
\'MNE_STIM_CHANNEL\', \'MNE_STIM_CHANNEL_1\', \'MNE_STIM_CHANNEL_2\',
etc. are read. If these are not found, it will fall back to
\'STI101\' or \'STI 014\' if present, then fall back to the first
channel of type \'stim\', if present.
mask : int | None
The value of the digital mask to apply to the stim channel values.
If None (default), no masking is performed.
uint_cast : bool
If True (default False), do a cast to ``uint16`` on the channel
data. This can be used to fix a bug with STI101 and STI014 in
Neuromag acquisition setups that use channel STI016 (channel 16
turns data into e.g. -32768), similar to ``mne_fix_stim14 --32``
in MNE-C.
mask_type: \'and\' | \'not_and\'
The type of operation between the mask and the trigger.
Choose \'and\' for MNE-C masking behavior.
delayed_lookup: bool
If True, use the \'delayed lookup\' procedure implemented in Elekta
software. When a trigger transition occurs, the lookup of
the new trigger value will not happen immediately at the following
sample, but with a 1-sample delay. This allows a slight
asynchrony between trigger onsets, when they are intended to be
synchronous. If you have accurate hardware and want to detect
transitions with a resolution of one sample, use
delayed_lookup=False.
Returns
conds_data : dict or list of dict, each with following keys:
events : array, shape (n_epochs_out, 3)
List of zero time points (t0) for the epochs matching the
condition. Use as the ``events`` parameter to Epochs. Note
that these are not (necessarily) actual events.
event_id : dict
Name of condition and index compatible with ``events``.
Should be passed as the ``event_id`` parameter to Epochs.
tmin : float
Epoch starting time relative to t0. Use as the ``tmin``
parameter to Epochs.
tmax : float
Epoch ending time relative to t0. Use as the ``tmax``
parameter to Epochs.'

def get_condition(self, raw, condition=None, stim_channel=None, mask=None, uint_cast=None, mask_type='and', delayed_lookup=True):

    if (condition is None):
        condition = self.categories
    if (not isinstance(condition, list)):
        condition = [condition]
    conds_data = list()
    for cat in condition:
        if isinstance(cat, str):
            cat = self[cat]
        mne_events = find_events(raw, stim_channel=stim_channel, mask=mask, mask_type=mask_type, output='step', uint_cast=uint_cast, consecutive=True, verbose=False, shortest_event=1)
        if delayed_lookup:
            ind = np.where((np.diff(mne_events[:, 0]) == 1))[0]
            if (1 in np.diff(ind)):
                raise ValueError('There    are    several    subsequent    transitions    on    the    trigger    channel.    This    will    not    work    well    with    delayed_lookup=True.    You    may    want    to    check    your    trigger    data    and    set    delayed_lookup=False.')
            mne_events[(ind, 2)] = mne_events[((ind + 1), 2)]
            mne_events = np.delete(mne_events, (ind + 1), axis=0)
        sfreq = raw.info['sfreq']
        cat_t0_ = self._mne_events_to_category_t0(cat, mne_events, sfreq)
        cat_t0 = np.c_[(cat_t0_, np.zeros(cat_t0_.shape), (cat['index'] * np.ones(cat_t0_.shape)))].astype(np.uint32)
        cat_id = {cat['comment']: cat['index']}
        (tmin, tmax) = (cat['start'], cat['end'])
        conds_data.append(dict(events=cat_t0, event_id=cat_id, tmin=tmin, tmax=tmax))
    return (conds_data[0] if (len(conds_data) == 1) else conds_data)
