utils2p/synchronization.py
def process_optical_flow_line(line):
    """
    This function converts the optical flow line
    into a step function. The value corresponds
    to the index of optical flow value at this
    time point. If the value is -9223372036854775808, no optical flow
    value was recorded for this time point.

    Note: Due to the time it takes to transfer the data
    from the Arduino to the computer it is possible that
    the last optical flow data point is missing, i.e.
    the processed optical flow line indicates one more
    data point than the text file contains. This can be
    solved by cropping all lines before the acquisition
    of the last optical flow data point. Lines can be
    cropped with :func:`crop_lines`.

    Parameters
    ----------
    line : numpy array
        Line signal for h5 file.

    Returns
    -------
    processed_optical_flow_line : numpy array
        Array with monotonically increasing step
        function.

    Examples
    --------
    >>> import utils2p
    >>> import utils2p.synchronization
    >>> import numpy as np
    >>> h5_file = utils2p.find_sync_file("data/mouse_kidney_raw")
    >>> line_names = ["OpFlow"]
    >>> (optical_flow_line,) = utils2p.synchronization.get_lines_from_h5_file(h5_file, line_names)
    >>> set(optical_flow_line)
    {0, 16}
    >>> processed_optical_flow_line = utils2p.synchronization.process_optical_flow_line(optical_flow_line)
    >>> len(set(processed_optical_flow_line))
    1409
    """
    processed_optical_flow_line = np.ones_like(line) * np.nan
    rising_edges = edges(line, (0, np.inf))[0]
    for i in range(0, len(rising_edges) - 1):
        processed_optical_flow_line[rising_edges[i]:rising_edges[i + 1]] = i
    processed_optical_flow_line[rising_edges[-1]:] = (
        processed_optical_flow_line[rising_edges[-1] - 1] + 1)
    return processed_optical_flow_line.astype(np.int)

    This function converts the optical flow line
    into a step function. The value corresponds
    to the index of optical flow value at this
    time point. If the value is -9223372036854775808, no optical flow
    value was recorded for this time point.

    Note: Due to the time it takes to transfer the data
    from the Arduino to the computer it is possible that
    the last optical flow data point is missing, i.e.
    the processed optical flow line indicates one more
    data point than the text file contains. This can be
    solved by cropping all lines before the acquisition
    of the last optical flow data point. Lines can be
    cropped with :func:`crop_lines`.

    Parameters
    ----------
    line : numpy array
        Line signal for h5 file.

    Returns
    -------
    processed_optical_flow_line : numpy array
        Array with monotonically increasing step
        function.

    Examples
    --------
    >>> import utils2p
    >>> import utils2p.synchronization
    >>> import numpy as np
    >>> h5_file = utils2p.find_sync_file("data/mouse_kidney_raw")
    >>> line_names = ["OpFlow"]
    >>> (optical_flow_line,) = utils2p.synchronization.get_lines_from_h5_file(h5_file, line_names)
    >>> set(optical_flow_line)
    {0, 16}
    >>> processed_optical_flow_line = utils2p.synchronization.process_optical_flow_line(optical_flow_line)
    >>> len(set(processed_optical_flow_line))
    1409
    
This function converts the optical flow line
into a step function. The value corresponds
to the index of optical flow value at this
time point. If the value is -9223372036854775808, no optical flow
value was recorded for this time point.

Due to the time it takes to transfer the data
from the Arduino to the computer it is possible that
the last optical flow data point is missing, i.e.
the processed optical flow line indicates one more
data point than the text file contains. This can be
solved by cropping all lines before the acquisition
of the last optical flow data point. Lines can be
cropped with :func:`crop_lines`.

Parameters

line : numpy array
Line signal for h5 file.

Returns

processed_optical_flow_line : numpy array
Array with monotonically increasing step
function.

Examples


This function converts the optical flow line into a step function . The value corresponds to the index of optical flow value at this time point . If the value is - 9223372036854775808 no optical flow value was recorded for this time point . Due to the time it takes to transfer the data from the Arduino to the computer it is possible that the last optical flow data point is missing i . e . the processed optical flow line indicates one more data point than the text file contains . This can be solved by cropping all lines before the acquisition of the last optical flow data point . Lines can be cropped with : func : ` crop_lines ` . Parameters line : numpy array Line signal for h5 file . Returns processed_optical_flow_line : numpy array Array with monotonically increasing step function . Examples
def process_optical_flow_line(line):
    processed_optical_flow_line = np.ones_like(line) * np.nan
    rising_edges = edges(line, (0, np.inf))[0]
    for i in range(0, len(rising_edges) - 1):
        processed_optical_flow_line[rising_edges[i]:rising_edges[i + 1]] = i
    processed_optical_flow_line[rising_edges[-1]:] = (
        processed_optical_flow_line[rising_edges[-1] - 1] + 1)
    return processed_optical_flow_line.astype(np.int)
def process_optical_flow_line ( line ) : processed_optical_flow_line = np . ones_like ( line ) * np . nan rising_edges = edges ( line , ( 0 , np . inf ) ) [ 0 ] for i in range ( 0 , len ( rising_edges ) - 1 ) : processed_optical_flow_line [ rising_edges [ i ] : rising_edges [ i + 1 ] ] = i processed_optical_flow_line [ rising_edges [ - 1 ] : ] = ( processed_optical_flow_line [ rising_edges [ - 1 ] - 1 ] + 1 ) return processed_optical_flow_line . astype ( np . int )
This function converts the optical flow line
into a step function.
This function converts the optical flow line into a step function .
"""
    This function converts the optical flow line
    into a step function. The value corresponds
    to the index of optical flow value at this
    time point. If the value is -9223372036854775808, no optical flow
    value was recorded for this time point.

    Note: Due to the time it takes to transfer the data
    from the Arduino to the computer it is possible that
    the last optical flow data point is missing, i.e.
    the processed optical flow line indicates one more
    data point than the text file contains. This can be
    solved by cropping all lines before the acquisition
    of the last optical flow data point. Lines can be
    cropped with :func:`crop_lines`.

    Parameters
    ----------
    line : numpy array
        Line signal for h5 file.

    Returns
    -------
    processed_optical_flow_line : numpy array
        Array with monotonically increasing step
        function.

    Examples
    --------
    >>> import utils2p
    >>> import utils2p.synchronization
    >>> import numpy as np
    >>> h5_file = utils2p.find_sync_file("data/mouse_kidney_raw")
    >>> line_names = ["OpFlow"]
    >>> (optical_flow_line,) = utils2p.synchronization.get_lines_from_h5_file(h5_file, line_names)
    >>> set(optical_flow_line)
    {0, 16}
    >>> processed_optical_flow_line = utils2p.synchronization.process_optical_flow_line(optical_flow_line)
    >>> len(set(processed_optical_flow_line))
    1409
    """
line