mousestyles.path_diversity package

Submodules

mousestyles.path_diversity.clean_movements module

mousestyles.path_diversity.clean_movements.clean_movements(movements, keep_index=False)[source]

Returns a list of cleaned movement objects.

For each element of the input movements object, detects the existence of adjacent rows which have i) same x,y-coordinates, or ii) same timestamps. For case i), and removes the duplicated rows except for the first. For case ii), raises value error.

Parameters:
  • movements (list) – each element is pandas.DataFrame containing CT, CX, CY coordinates. Should have length greater than 1.
  • keep_index (boolean) – whether or not keep the original index. Deafalt is False. If false, cleaned movement object is re-indexed.
Returns:

cleaned-movements – each element is cleaned movement object.

Return type:

list

Examples

>>> strain_nums = [0,0,1,1,2,2]
>>> mouse_nums = [0,0,1,1,2,2]
>>> day_nums = [0,11,0,11,0,11]
>>> movements = [data.load_movement(strain_num, mouse_num, day_num)
                 for strain_num, mouse_num, day_num in
                 zip(strain_nums, mouse_nums, day_nums)]
>>> cleaned_movements = clean_movements(movements)

mousestyles.path_diversity.detect_noise module

mousestyles.path_diversity.detect_noise.detect_noise(movement, paths, angle_threshold, delta_t)[source]

Return a list object containing boolean values at points where measurement noise is detected and will be passed to a smoothing function

Parameters:
  • movement (pandas.DataFrame) – CT, CX, CY coordinates and homebase status for the unique combination of strain, mouse and day
  • index (paths) –
  • angle_threshold (float) – positive number indicating the minimum turning angle to flag as noise
  • delta_t (float) – positive number indicating the delta_time interval
Returns:

  • noise index (a pandas series containing the indices at which)
  • noise, as defined by input parameters, is detected

Examples

>>> movement = data.load_movement(1, 2, 1)
>>> paths = path_diversity.path_index(movement, 1, 1)
>>> noise = detect_noise(movement, paths, 135, .1)

mousestyles.path_diversity.filter_path module

mousestyles.path_diversity.filter_path.filter_path(movement, paths, time_threshold)[source]

Return a list object containing start and end indices for movements lasting equal to or longer than the specified time threshold

Parameters:
  • movement (pandas.DataFrame) – CT, CX, CY coordinates and homebase status for the unique combination of strain, mouse and day
  • paths (list) – a list containing the indices for all paths
  • time_threshold (float) – positive number indicating the time threshold
Returns:

  • paths index (a list containing the indices for all paths)
  • that the spending times are larger than a time threshold

Examples

>>> movement = data.load_movement(1, 2, 1)
>>> paths = path_index(movement, 1, 1)
>>> filter_path(movement, paths, 20)
[[26754, 26897], [28538, 28627]

mousestyles.path_diversity.get_dist_speed module

mousestyles.path_diversity.get_dist_speed.get_dist_speed(movement, start, end, return_array=True)[source]

Return a list containing distance(s) covered in a path and average speed(s) within a path.

Parameters:
  • movement (pandas.DataFrame) – CT, CX, CY coordinates and homebase status for the unique combination of strain, mouse, and day
  • start (int) – positive integer indicating the starting index of a path
  • end (int) – positive integer indicating the end index of a path
  • return_array (bool) – boolean indicating whether an array of distances and average speeds are returned or the summation of those distances and speeds
Returns:

  • dist (distance(s) travelled along a path)
  • speed (average speed(s) along a path)

Examples

>>> movement = data.load_movement(1, 2, 1)
>>> dist, speed = get_dist_speed(movement, 0, 3)
>>> print(dist)
[0.0, 0.17999999999999972, 0.19446593532030554]
>>> print(speed)
[0.0, 0.9999999999983815, 0.055246004352409776]
>>> dist, speed = get_dist_speed(movement, 0, 3, return_array=False)
>>> print(dist)
0.37446593532030525
>>> print(speed)
0.096661315260887087

mousestyles.path_diversity.path_features module

mousestyles.path_diversity.path_features.angle_between(v1, v2)[source]

Returns the angle in radians between vectors v1 and v2. Both vectors must have same length.

Parameters:v2 (v1,) – Vectors whose angle would be calculated. Should have same lengths. Should not be zero vector.
Returns:angle – nan if either of v1 or v2 is zero vector,
Return type:numpy float object

Examples

>>> angle_between([1, 0],[1, 0])
0.0
>>> angle_between([1, 0],[0, 1])
1.5707963267948966
>>> angle_between([1, 0],[-1, 0])
3.1415926535897931
mousestyles.path_diversity.path_features.compute_accelerations(speeds, timestamps)[source]

Returns a list of the accelerations along the path. Each element of the list is the ratio of the speed to the time difference. The length of the list is equal to the length of speeds minus 1.

Parameters:
  • speeds (list) – the traveled distances along the path. Expecting the output of compute_distances.
  • timestamps (list) – the time difference within the path. Its length must be equal to the length of speeds plus 1. Should not contain same time in adjacent rows; otherwise output would contain inf.
Returns:

accel – contains the speeds along the path.

Return type:

list

Examples

>>> compute_accelerations([1, 2, 0], [3, 4, 5, 6])
[0.5, -1.0]
mousestyles.path_diversity.path_features.compute_angles(path_obj, radian=False)[source]

Returns a list of the angles in the path. Each element of the list is the angle between the adjacent vectors in the path. The length of the list is equal to the length of speeds minus 2.

Parameters:
  • path_obj (pandas.DataFrame) – CT, CX, CY coordinates and homebase status. Must have length greater than 3.
  • radian (boolean) – True for the output in radians. False for in turns (i.e. 360 for a full turn). Default is False.
Returns:

angles – contains the angles in the path. The first and last elements are None.

Return type:

list

Examples

>>> path = pd.DataFrame({'t':[2, 4.5, 10.5], 'x':[0, 1, 1],\
'y':[0, 0, 1], 'isHB':[True, True, False]})
>>> compute_angles(path)
[None, 90.0, None]

mousestyles.path_diversity.path_features_advanced module

mousestyles.path_diversity.path_features_advanced.compute_advanced(path_obj)[source]

Returns dictionary containing several advanced features of path.

The features are the radius, center angles, area covered by the path, area of the rectangle spanned by the path, and absolute distance between start and end points.

Parameters:path_obj (pandas.DataFrame) – CX and CY must be contained. The length must be greater than 2.
Returns:
  • radius (list) – each element is the distance between center point and each point in the path. The length equals to the length of the path_obj.
  • center_angles (list) – each element is the center angle generated by 2 adjacent radius. The length equals to the length of the radius minus 1.
  • area_cov (numpy float object) – area covered by the path. Computed by radius and center angles.
  • area_rec (numpy float object) – area of the rectangle spanned by the path.
  • abs_distance (numpy float object) – the distance between the start and end points in a path.

Examples

>>> movement = data.load_movement(1,2,1)
>>> adv_features = compute_advanced(movement[5:10])

mousestyles.path_diversity.path_index module

mousestyles.path_diversity.path_index.path_index(movement, stop_threshold, min_path_length)[source]

Return a list object containing start and end indices for a specific movement. Each element in the list is a list containing two indices: the first element is the start index and the second element is the end index.

Parameters:
  • movement (pandas.DataFrame) – CT, CX, CY coordinates and homebase status for the unique combination of strain, mouse and day
  • stop_threshold (float) – positive number indicating the path cutoff criteria if the time difference between two observations is less than this threhold, they will be in the same path
  • min_path_length (int) – positive integer indicating how many observations in a path
Returns:

paths index

Return type:

a list containing the indices for all paths

Examples

>>> movement = data.load_movement(1, 2, 1)
>>> paths = path_index(movement, 1, 1)[:5]
>>> paths
[[0, 2], [6, 8], [107, 113], [129, 131], [144, 152]]

mousestyles.path_diversity.smooth_noise module

mousestyles.path_diversity.smooth_noise.smooth_noise(movement, paths, angle_threshold, delta_t)[source]

Return a new smoothed movement pandas DataFrame object containing CT, CX, CY coordinates.

The inputted movement DataFrame is passed through a noise detection function. At points where noise is detected, as defined by the input parameters (i.e., angle_threshold and delta_t), this function returns a new movement DataFrame by averaging points where noise is detected.

Parameters:
  • movement (pandas.DataFrame) – CT, CX, CY coordinates and homebase status for the unique combination of strain, mouse and day
  • index (paths) –
  • angle_threshold (float) – positive number indicating the minimum turning angle to flag as noise
  • delta_t (float) – positive number indicating the delta_time interval
Returns:

smoothed movement – CT, CX, CY coordinates and homebase status for the unique combination of strain, mouse and day

Return type:

pandas.DataFrame

Examples

>>> movement = data.load_movement(1, 2, 1)
>>> paths = path_index(movement, 1, 1)
>>> smoothed_movement = smooth_noise(movement, paths, 135, .1)

Module contents