Beispiel #1
0
def test_create_collapse_intervals1():

    # Checking intervals are being correctly loaded for a particular
    # activity type and mouse-day

    # More specifically this is testing 'Food' Consumption
    # for strain=0, mouse=0, day=0
    load_ints1 = metrics.create_intervals('F', strain=0, mouse=0, day=0)

    # Collapse the intervals within a given threshold
    cp = behavior.create_collapsed_intervals(load_ints1, bout_threshold=0.001)

    # Calculate the sum of the loaded intervals
    ints1_sum_collapsed = sum(cp)

    # We now do the above calculations using a manual query
    l_ints_manual = data.load_intervals('F')
    l_ints_manual = l_ints_manual.query('strain == 0 and mouse == 0 and \
                                         day == 0')[['start', 'stop']]

    ints_manual = intervals.Intervals(l_ints_manual)

    # Collapse the intervals within a given threshold
    ints_man_collapsed = ints_manual.copy().connect_gaps(eps=0.001)
    ints_man_sum_collapsed = sum(ints_man_collapsed)

    # Check that the sum of total values from manual query and
    # function output match for every value
    assert (ints1_sum_collapsed == ints_man_sum_collapsed).all()
Beispiel #2
0
def test_process_raw_intervals():
    ints_raw = np.array([[1, 2], [2.5, 3]])
    ints = intervals.Intervals(ints_raw)
    consump = 100
    active_time = 4
    total_time = 5
    eps = 1
    tree = behavior.process_raw_intervals('F', consump, ints, active_time,
                                          total_time, eps)
    assert len(tree.contents) == 9
    assert tree['Consumption Rate'] == consump / total_time
    assert tree['AS Prob'] == active_time / total_time
Beispiel #3
0
def test_create_intervals():

    # Checking intervals are being correctly loaded for a particular
    # activity type and mouse-day
    load_ints1 = metrics.create_intervals('F', strain=0, mouse=0, day=0)

    # Calculate the sum of the loaded intervals
    ints1_sum = sum(load_ints1)

    # We now do the above calculations using a manual query
    l_ints_manual = data.load_intervals('F')
    l_ints_manual = l_ints_manual.query('strain == 0 and mouse == 0 and \
                                         day == 0')[['start', 'stop']]
    ints_manual = intervals.Intervals(l_ints_manual)
    ints_manual_sum = sum(ints_manual)

    assert ints1_sum.all() == ints_manual_sum.all()
Beispiel #4
0
def create_intervals(activity_type, strain, mouse, day):
    r"""Returns an interval object on a certain mouse-strain-day
    for a given activity type.

    Parameters
    ----------
    activity_type : str
        String specifying activity type {"AS", "F", "IS", "M_AS", "M_IS", "W"}
    strain : int
        Integer representing the strain of the mouse
    mouse : int
        Integer representing the specific mouse
    day : int
        Integer representing the day to produce the metrics for
    bout_threshold: : float
        Float representing the time threshold to use for collapsing separate
        events into bouts

    Returns
    -------
    An intervals object `intervals` for the given activity type and
    mouse-strain-day within a bout threshold

    Examples
    --------

    >>> ints=behavior.create_intervals(activity_type = 'F', strain = 0
                                       , mouse = 0, day = 0
                                       , bout_threshold = 0.001)
    >>> print(sum(ints))

    """

    # Load intervals by activity type
    l_ints = data.load_intervals(activity_type)

    # Subset to M*2 array of  (start, stop) intervals based on
    # specific mouse, strain and day
    l_ints = _select_strain_mouse_day_in_data_frame(l_ints, strain, mouse, day)
    l_ints = l_ints[['start', 'stop']]

    # Create and return the intervals object
    return intervals.Intervals(l_ints)
Beispiel #5
0
def test_create_intervals2():

    # Checking intervals are being correctly loaded for a particular
    # activity type and mouse-day

    # More specifically this is testing 'Water' Consumption
    # for strain=0, mouse=1, day=1
    load_ints1 = metrics.create_intervals('W', strain=0, mouse=1, day=1)

    # Calculate the sum of the loaded intervals
    ints1_sum = sum(load_ints1)

    # We now do the above calculations using a manual query
    l_ints_manual = data.load_intervals('W')
    l_ints_manual = l_ints_manual.query('strain == 0 and mouse == 1 and \
                                         day == 1')[['start', 'stop']]
    ints_manual = intervals.Intervals(l_ints_manual)
    ints_manual_sum = sum(ints_manual)

    # Check that the sum of total values from manual query and
    # function output match for every value
    assert (ints1_sum == ints_manual_sum).all()