moseq2_app.roi package

Submodules

ROI - Controller Module

Interactive ROI detection and extraction preview functionalities.

class moseq2_app.roi.controller.InteractiveExtractionViewer(data_path, flipped=False)

Bases: object

clear_on_click(b=None)

Clear the cell output

Args: b (button click)

get_extraction(input_file)

Returns a div containing a video object to display.

Args: input_file (str): Path to session extraction video to view.

ROI - Validation Module

The module contains extraction validation functions that test extractions’ scalar values timestamps, and position heatmaps.

moseq2_app.roi.validation.check_timestamp_error_percentage(timestamps, fps=30, scaling_factor=1000)

Return the proportion of dropped frames relative to the respective recorded timestamps and frames per second.

Args: timestamps (numpy.array): Session’s recorded timestamp array. fps (int): Frames per second scaling_factor (float): factor to divide timestamps by to convert timestamp milliseconds into seconds.

Returns: percentError (float): Percentage of frames that were dropped/missed during acquisition.

moseq2_app.roi.validation.count_frames_with_small_areas(scalar_df)

Count the number of frames where the mouse area is smaller than 2 standard deviations of all mouse areas.

Args: scalar_df (pd.DataFrame): dataframe that contains frame by frame scalar and syllable data (moseq_df/scalar_df)

Returns: corrupt_frames (int): Number of frames where the recorded mouse area is too small

moseq2_app.roi.validation.count_missing_mouse_frames(scalar_df)

Count the number of frames where the mouse is not found.

Args: scalar_df (pd.DataFrame): dataframe that contains frame by frame scalar and syllable data (moseq_df/scalar_df)

Returns: missing_mouse_frames (int): Number of frames with recorded mouse area ~= 0

moseq2_app.roi.validation.count_nan_rows(scalar_df)

Count the number of rows with NaN scalar values.

Args: scalar_df (pd.DataFrame): dataframe that contains frame by frame scalar and syllable data (moseq_df/scalar_df)

Returns: n_missing_frames (int): Number of frames with NaN computed scalar values.

moseq2_app.roi.validation.count_stationary_frames(scalar_df)

Count the number of frames where mouse is not moving.

Args: scalar_df (pd.DataFrame): dataframe that contains frame by frame scalar and syllable data (moseq_df/scalar_df)

Returns: motionless_frames (int): Number of frames where the mouse is not moving

moseq2_app.roi.validation.get_scalar_anomaly_sessions(scalar_df, status_dicts)

Detect outlier sessions using an EllipticEnvelope model based on a subset of their mean scalar values.

Args: scalar_df (pd.DataFrame): dataframe that contains frame by frame scalar and syllable data (moseq_df/scalar_df) status_dicts (dict): stacked dictionary object containing all the sessions’ flag status dicts.

Returns: status_dicts (dict): stacked dictionary object containing updated scalar_anomaly flags.

moseq2_app.roi.validation.get_scalar_df(path_dict)

Compute a scalar dataframe that contains all the extracted sessions recorded scalar values along with their metadata.

Args: path_dict (dict): dictionary of session folder names paired with their extraction paths

Returns: scalar_df (pd.DataFrame): Ddataframe that contains frame by frame scalar and syllable data (moseq_df/scalar_df)

moseq2_app.roi.validation.make_session_status_dicts(paths)

Return the flag status dicts for all the found completed extracted sessions. Additionally performs dropped frames test on all sessions.

Args: paths (dict): path dict of session names paired wit their mp4 paths.

Returns: status_dicts (dict): stacked dictionary object containing all the sessions’ flag status dicts.

moseq2_app.roi.validation.print_validation_results(scalar_df, status_dicts)

Display all the outlier sessions flag names and values. Additionally plots the flagged position heatmap.

Args: anomaly_dict (dict): Dict object containing specific session flags to print

moseq2_app.roi.validation.run_validation_tests(scalar_df, status_dicts)

run all the available extraction validation tests and updates the status_dicts flags accordingly.

Args: scalar_df (pd.DataFrame): dataframe that contains frame by frame scalar and syllable data (moseq_df/scalar_df) status_dicts (dict): stacked dictionary object containing all the sessions’ flag status dicts.

Returns: status_dicts (dict): stacked dictionary object containing all the sessions’ updated flag status dicts.

ROI - View Module

Interactive ROI/Extraction Bokeh visualization functions.

moseq2_app.roi.view.bokeh_plot_helper(bk_fig, image)

create the Bokeh image gylphs in the created canvases/figures.

Args: bk_fig (Bokeh figure): figure canvas to draw image/glyph on image (2D np.array): image to draw.

moseq2_app.roi.view.show_extraction(input_file, video_file)

display manually triggered extraction.s

Args: input_file (str): session name to display. video_file (str): path to video to display

Returns: output (ipywidgets.Output widget): HTML canvas where the video is being displayed.

Module contents