deepof.utils

Functions and general utilities for the deepof package.

Functions

align_trajectories(data[, mode, run_numba])

Remove rotational variance on the trajectories.

angle(bpart_array)

Return a numpy.ndarray with the angles between the provided instances.

binary_moving_median_numba(time_series, lag)

will applay a moving median like filter on a binary signal, i.e. if a window of size lag has more 1s than 0s set the frame to 1 for that window, set it to 0 otherwise.

bp2polar(tab)

Return the DataFrame in polar coordinates.

bpart_distance(dataframe)

Return a pandas.DataFrame with the scaled distances between all pairs of body parts.

cluster_transition_matrix(cluster_sequence, ...)

Compute the transition matrix between clusters and the autocorrelation in the sequence.

compute_animal_presence_mask(quality[, ...])

Compute a mask of the animal presence in the video.

compute_areas(polygon_xy_stack)

Compute polygon areas for the provided stack of sets of data point-xy coordinates.

compute_areas_numba(polygon_xy_stack)

Compute polygon areas for the provided stack of sets of data point-xy coordinates.

compute_dist(pair_array)

Return a pandas.DataFrame with the scaled distances between a pair of body parts.

connect_mouse([animal_ids, ...])

Create a nx.Graph object with the connectivity of the bodyparts in the DLC topview model for a single mouse.

count_events(binary_behavior[, ...])

Counts the number of continuous blocks of 1s in a binary behavior vector in different ways

count_transitions(tab_dict, exp_conditions)

Count transitions between successive behaviors for all experiments in tab_dict.

edges_to_weighted_adj(adj, edges)

Convert an edge feature matrix to a weighted adjacency matrix.

enforce_skeleton_constraints_numba(data, ...)

Adjusts the positions of body parts in each frame to ensure that the distances between connected parts adhere to predefined skeleton constraints within a specified tolerance.

enumerate_all_bridges(G)

Enumerate all 3-node connected sequences in the given graph.

extend_behaviors_numba(behaviors[, delta_T, ...])

Takes a booelan array of behavior detections and extends each behavior detection by delta_T.

extract_windows(to_window, window_size, ...)

Apply the rupture method independently to each experiment, and concatenate into a single dataset at the end.

filter_animal_id_in_table(table[, ...])

Filter a DataFrame to keep only those columns related to the selected id.

filter_columns(columns, selected_id[, ...])

Given a set of TableDict columns, returns those that correspond to a given animal, specified in selected_id.

filter_short_bouts(cluster_assignments, ...)

Filter out cluster assignment bouts shorter than min_bout_duration.

filter_short_true_segments(array, min_length)

Filters out sahort "True" sections from boolean array "array"

filter_short_true_segments_numba(array, ...)

Filters out sahort "True" sections from boolean array "array"

full_outlier_mask(experiment, likelihood, ...)

Iterate over all body parts of experiment, and outputs a dataframe where all x, y positions are replaced by a boolean mask, where True indicates an outlier.

get_behavior_mask_and_confidence(tab, ...)

Generates a boolean mask and a confidence dataframe for given behaviors.

get_point_polygon_distance(points, polygon)

Calculates array of distances between 2D points and a polygon (roi)

get_point_polygon_distance_numba(points, poly_xy)

get_total_Frames(video_paths)

Get the number of all frames in all videos listed in the input dictionary

gmm_compute(x, n_components, cv_type)

Fit a Gaussian Mixture Model to the provided data and returns evaluation metrics.

gmm_model_selection(x, n_components_range, ...)

Run GMM clustering model selection on the specified X dataframe.

in_field_of_view(mouse_pts, fov_angle_deg, roi)

mouse_pts: (N, 3, 2) or (3, 2), order [left_ear, nose, right_ear] Returns float array of shape (N,): 1.0 -> ROI intersects FOV 0.0 -> ROI does not intersect FOV np.nan -> cannot be calculated (invalid/degenerate geometry or non-finite points) Apex of FOV triangle is midpoint between ears.

in_field_of_view_numba(mouse_pts, ...[, eps])

Numba version of in_field_of_view (no plotting, no shapely).

infer_column_types(df)

Identify coord, speed, distance, and angle columns from a pose table.

infer_scalar_cols(df)

iterative_imputation(project, tab_dict, lik_dict)

Perform iterative imputation on occluded body parts.

kleinberg(offsets[, s, gamma, n, T, k])

Apply Kleinberg's algorithm (described in 'Bursty and Hierarchical Structure in Streams').

kleinberg_core_numba(gaps, s, gamma, n, T, k)

Computation intensive core part of Kleinberg's algorithm (described in 'Bursty and Hierarchical Structure in Streams').

load_precompiled_model(path, download_path, ...)

Loads model for automatic arena segmentation

load_table(tab, table_path, table_format[, ...])

Loads a table into a structured pandas data frame.

mask_outliers(time_series, likelihood, ...)

Return a mask over the bivariate trajectory of a body part, identifying as True all detected outliers.

mouse_in_roi(tab, aid, in_roi_criterion, ...)

Checks if a given animal for a given table is in a given roi by given criterion.

moving_average(time_series[, lag])

Fast implementation of a moving average function.

multi_step_paired_smoothing(behavior_in[, ...])

This filtering approach will first gradually merge together very close behavioral instances (how close is regulated by min_length), then filter out remaining short instances.

point_in_polygon(points, polygon)

Check if a set of points is inside a polygon.

point_in_polygon_numba(points, polygon)

This function was generated by Perplexity.ai Check if a set of points is inside a polygon.

polygon_area_numba(vertices)

Calculate the area of a single polygon given its vertices.

remove_outliers(experiment, likelihood, ...)

Mark all outliers in experiment and replaces them using a uni-variate linear interpolation approach.

rename_track_bps(loaded_tab, ...)

Renames all body parts in the provided dataframe.

rolling_speed(dframe[, frame_rate, window, ...])

Return the average speed over n frames in millimeters per second.

rolling_window(a, window_size, window_step)

Return a 3D numpy.array with a sliding-window extra dimension.

rotate(p, angles[, origin])

Return a 2D numpy.ndarray with the initial values rotated by angles radians.

rotate_all_numba(data, angles)

Rotates Return a 2D numpy.ndarray with the initial values rotated by angles radians.

rotate_numba(p, angles[, origin])

Return a 2D numpy.ndarray with the initial values rotated by angles radians.

row_nanargmax(arr)

argmax per row, ignoring NaNs.

rts_smoother_numba(measurements, F, H, Q, R)

Implements the Rauch-Tung-Striebel (RTS) smoother for state estimation.

scale_table(df[, scale, animal_ids, ...])

set_missing_animals(coordinates, tab_dict, ...)

Set the coordinates of the missing animals to NaN.

signed_angle(bpart_array)

Return a numpy.ndarray with the signed angles between the provided instances.

smooth_boolean_array(a[, scale, sigma, ...])

LEGACY FILTER FOR BEHAVIORAL ANALYSIS.

smooth_mult_trajectory(series[, alpha, w_length])

Return a smoothed a trajectory using a Savitzky-Golay 1D filter.

str2bool(v)

Return the passed string as a boolean.

tab2polar(cartesian_df)

Return a pandas.DataFrame in which all the coordinates are polar.

validate_parameter(param_name, param_value, ...)

A generic helper to validate a single parameter against a list of valid options.

Classes

KeyErrorMessage

MouseTrackingImputer([n_iterations, ...])

A class for imputing and processing mouse tracking data.