def sse_intersection(sse1, sse2, intersection='linkwise'):
    """
    Given two sequences of synchronous events (SSEs) `sse1` and `sse2`, each
    consisting of a pool of positions (iK, jK) of matrix entries and
    associated synchronous events SK, finds the intersection among them.
    The intersection can be performed 'pixelwise' or 'linkwise'.

        * if 'pixelwise', it yields a new SSE which retains only events in sse1
          whose pixel position matches a pixel position in sse2. This operation
          is not symmetric: intersection(sse1, sse2) != intersection(sse2, sse1).
        * if 'linkwise', an additional step is performed where each retained
          synchronous event SK in sse1 is intersected with the corresponding
          event in sse2. This yields a symmetric operation:
          intersection(sse1, sse2) = intersection(sse2, sse1).

    Both sse1 and sse2 must be provided as dictionaries of the type

    .. centered:: {(i1, j1): S1, (i2, j2): S2, ..., (iK, jK): SK},

    where each i, j is an integer and each S is a set of neuron ids.
    (See also: extract_sse() that extracts SSEs from given spiketrains).

    Parameters
    ----------
    sse1, sse2 : each a dict
        each is a dictionary of pixel positions (i, j) as keys, and sets S of
        synchronous events as values (see above).
    intersection : str, optional
        the type of intersection to perform among the two SSEs. Either
        'pixelwise' or 'linkwise' (see above).
        Default: 'linkwise'.

    Returns
    -------
    sse : dict
        a new SSE (same structure as sse1 and sse2) which retains only the
        events of sse1 associated to keys present both in sse1 and sse2.
        If intersection = 'linkwise', such events are additionally
        intersected with the associated events in sse2 (see above).
    """
    sse_new = sse1.copy()
    for pixel1 in sse1.keys():
        if pixel1 not in sse2.keys():
            del sse_new[pixel1]
    if intersection == 'linkwise':
        for pixel1, link1 in sse_new.items():
            sse_new[pixel1] = link1.intersection(sse2[pixel1])
            if len(sse_new[pixel1]) == 0:
                del sse_new[pixel1]
    elif intersection == 'pixelwise':
        pass
    else:
        raise ValueError('intersection (=%s) can only be' % intersection +
            " 'pixelwise' or 'linkwise'")
    return sse_new
