utils2p/synchronization.py
def correct_split_edges(line):
    """
    This function corrects edges that are spread over multiple ticks.

    Parameters
    ----------
    line : numpy array
        The line for which the edges should be corrected.

    Returns
    -------
    line : numpy array
        Line with corrected edges.

    Examples
    --------
    >>> import numpy as np
    >>> import utils2p.synchronization
    >>> line = np.array([0, 0, 0, 1, 2, 3, 3, 3, 2, 1, 0, 0, 0])
    >>> utils2p.synchronization.correct_split_edges(line)
    array([0, 0, 0, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0])
    """
    rising_edges = np.where(np.diff(line) > 0)[0] + 1
    falling_edges = np.where(np.diff(line) < 0)[0]

    split_rising_edges = np.where(np.diff(rising_edges) == 1)[0]
    split_falling_edges = np.where(np.diff(falling_edges) == 1)[0]

    if len(split_rising_edges) == 0 and len(split_falling_edges) == 0:
        return line

    first_halfs_rising = rising_edges[split_rising_edges]
    second_halfs_rising = rising_edges[split_rising_edges + 1]
    line[first_halfs_rising] = line[second_halfs_rising]

    first_halfs_falling = falling_edges[split_falling_edges]
    second_halfs_falling = falling_edges[split_falling_edges + 1]
    line[second_halfs_falling] = line[first_halfs_falling]

    # Recursive to get edges spread over more than two ticks
    return correct_split_edges(line)

    This function corrects edges that are spread over multiple ticks.

    Parameters
    ----------
    line : numpy array
        The line for which the edges should be corrected.

    Returns
    -------
    line : numpy array
        Line with corrected edges.

    Examples
    --------
    >>> import numpy as np
    >>> import utils2p.synchronization
    >>> line = np.array([0, 0, 0, 1, 2, 3, 3, 3, 2, 1, 0, 0, 0])
    >>> utils2p.synchronization.correct_split_edges(line)
    array([0, 0, 0, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0])
    
This function corrects edges that are spread over multiple ticks.
Parameters

line : numpy array
The line for which the edges should be corrected.

Returns

line : numpy array
Line with corrected edges.

Examples


This function corrects edges that are spread over multiple ticks . Parameters line : numpy array The line for which the edges should be corrected . Returns line : numpy array Line with corrected edges . Examples
def correct_split_edges(line):
    rising_edges = np.where(np.diff(line) > 0)[0] + 1
    falling_edges = np.where(np.diff(line) < 0)[0]
    split_rising_edges = np.where(np.diff(rising_edges) == 1)[0]
    split_falling_edges = np.where(np.diff(falling_edges) == 1)[0]
    if len(split_rising_edges) == 0 and len(split_falling_edges) == 0:
        return line
    first_halfs_rising = rising_edges[split_rising_edges]
    second_halfs_rising = rising_edges[split_rising_edges + 1]
    line[first_halfs_rising] = line[second_halfs_rising]
    first_halfs_falling = falling_edges[split_falling_edges]
    second_halfs_falling = falling_edges[split_falling_edges + 1]
    line[second_halfs_falling] = line[first_halfs_falling]
    return correct_split_edges(line)
def correct_split_edges ( line ) : rising_edges = np . where ( np . diff ( line ) > 0 ) [ 0 ] + 1 falling_edges = np . where ( np . diff ( line ) < 0 ) [ 0 ] split_rising_edges = np . where ( np . diff ( rising_edges ) == 1 ) [ 0 ] split_falling_edges = np . where ( np . diff ( falling_edges ) == 1 ) [ 0 ] if len ( split_rising_edges ) == 0 and len ( split_falling_edges ) == 0 : return line first_halfs_rising = rising_edges [ split_rising_edges ] second_halfs_rising = rising_edges [ split_rising_edges + 1 ] line [ first_halfs_rising ] = line [ second_halfs_rising ] first_halfs_falling = falling_edges [ split_falling_edges ] second_halfs_falling = falling_edges [ split_falling_edges + 1 ] line [ second_halfs_falling ] = line [ first_halfs_falling ] return correct_split_edges ( line )
This function corrects edges that are spread over multiple ticks.
This function corrects edges that are spread over multiple ticks .
"""
    This function corrects edges that are spread over multiple ticks.

    Parameters
    ----------
    line : numpy array
        The line for which the edges should be corrected.

    Returns
    -------
    line : numpy array
        Line with corrected edges.

    Examples
    --------
    >>> import numpy as np
    >>> import utils2p.synchronization
    >>> line = np.array([0, 0, 0, 1, 2, 3, 3, 3, 2, 1, 0, 0, 0])
    >>> utils2p.synchronization.correct_split_edges(line)
    array([0, 0, 0, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0])
    """ # Recursive to get edges spread over more than two ticks
line