moseq2_app.flip package
Submodules
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_dataset(plot_examples=False)
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:
- get_corrected_data()
Apply the selected flip orientation ranges to the entire dataset to correct the incorrectly oriented frames.
- interactive_launch_frame_selector()
display the frame to display with the selected data box.
- load_sessions()
Recursively searche for completed h5 extraction files, and loads total_frames=max_frames to include in the total dataset.
Args:
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)
Returns:
- 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
- changed_selected_session(event=None)
load newly selected session.
Args: event (ipywidgets Event): self.session_select_dropdown.value is changed
- clear_on_click(b=None)
Clear the output.
Args: b (button click): user click the button
- curr_frame_update(event)
Update the currently displayed frame when the slider is moved.
Args: event (ipywidgets Event): self.frame_num_slider.value is changed.
- facing_range_callback(event)
handle when a user clicks either of the left or right facing buttons after selecting a frame range.
- on_delete_selection_clicked(b=None)
delete the currently selected frame range from the list upon clicking the Delete button.
Args: b (ipywidgets.Event): Button click event.
- on_selected_range_value(event=None)
make the delete button visible once the user selects one of the frame ranges.
- start_stop_frame_range(b=None)
start and stop the “Add Range” functionality.
Args: b (button click): User clicks on “Start or Stop” Range button.
- update_state_on_selected_range(left)
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.