moseq2_app.flip package


Flip - Controller Module

Interactive Flip classifier frame selection functionality.

class moseq2_app.flip.controller.FlipRangeTool(input_dir, max_frames, output_file, tail_filter_iters, prefilter_kernel_size, launch_gui=True, continuous_slider_update=True)

Bases: FlipClassifierWidgets

apply_flip_classifier(chunk_size=4000, chunk_overlap=0, smoothing=51, frame_path='frames', fps=30, write_movie=False, verbose=True)

Apply a trained flip classifier on previously extracted data to flip the mice to the correct orientation.

Args: chunk_size (int): size of frame chunks to process in batches. chunk_overlap (int): number of frames to overlap between chunks to improve classification precision between chunks. smoothing (int): kernel size of the applied median filter on the flip classifier results verbose (bool): displays the tqdm progress bars for each session.


Augment the selected correct dataset with 3 rotated versions of the truth values.

Args: plot_examples (bool): Indicates whether to display the 2x2 preview grid of dataset examples. Returns:


Apply the selected flip orientation ranges to the entire dataset to correct the incorrectly oriented frames.


display the frame to display with the selected data box.


Recursively searche for completed h5 extraction files, and loads total_frames=max_frames to include in the total dataset.


Returns: path_dict (dict): dict of session names and paths filtered for sessions missing an h5 or mp4 files.

plot_xy_examples(data_xflip, data_yflip, data_xyflip, selected_frame=0)

Plots 2 columns of examples for the correct and incorrect examples being used to train the flip classifier.

Args: data_xflip (np.ndarray): Single frame of the corrected dataset flipped on the x-axis (class 1) data_yflip (np.ndarray): Single frame of the corrected dataset flipped on the x-axis (class 0) data_xyflip (np.ndarray): Single frame of the corrected dataset flipped on the x and y-axis (class 1)


prepare_datasets(test_size, random_state=0, plot_examples=False)

correct data with user input, augment and create X,y training sets, and split the data to training and testing splits.

Args: test_size (int): Test dataset percent split size random_state (int): Seed value to randomly sort the split data plot_examples (bool): Indicates whether to display the 2x2 preview grid of dataset examples

train_and_evaluate_model(n_estimators=100, criterion='gini', n_jobs=4, max_depth=6, min_samples_split=2, min_samples_leaf=1, oob_score=False, random_state=0, verbose=0, train=True)

Train the flip classifier the pre-augmented dataset given some optionally adjustable model initialization parameters.

Args: n_estimators (int): The number of trees in the forest. criterion (str): The function to measure the quality of a split. [‘gini’, mse’, ‘mae’] n_jobs (int): The number of jobs to run in parallel for both fit and predict. max_depth (int): The maximum depth of the tree. If None, then nodes are expanded until all leaves are pure. min_samples_split (int): The minimum number of samples required to split an internal node. min_samples_leaf (int): The minimum number of samples required to be at a leaf node. oob_score (bool): whether to use out-of-bag samples to estimate the R^2 on unseen data. random_state (int): The seed used by the random number generator. verbose (int): Controls the verbosity when fitting and predicting. train (bool): If True, trains or retrains a model, if False only tests the model on the test set.

Flip - Widgets Module

Widgets module containing all the interactive components of the frame selection GUI.

class moseq2_app.flip.widgets.FlipClassifierWidgets(path_dict, max_frames, continuous_update=True, launch_gui=True)

Bases: object


load newly selected session.

Args: event (ipywidgets Event): self.session_select_dropdown.value is changed


Clear the output.

Args: b (button click): user click the button


Update the currently displayed frame when the slider is moved.

Args: event (ipywidgets Event): self.frame_num_slider.value is changed.


handle when a user clicks either of the left or right facing buttons after selecting a frame range.


delete the currently selected frame range from the list upon clicking the Delete button.

Args: b (ipywidgets.Event): Button click event.


make the delete button visible once the user selects one of the frame ranges.


start and stop the “Add Range” functionality.

Args: b (button click): User clicks on “Start or Stop” Range button.


Update the view upon a correct frame range addition (stop > start).

Args: left (bool): Indicates which direction the mouse is facing the selected range. if True, facing left, else right.

Module contents