entry_exit_mouse_box package

Submodules

entry_exit_mouse_box.mask_from_video module

class entry_exit_mouse_box.mask_from_video.MaskFromBackground(input_video_path, output_video_path, ref, tr=75, st={}, r=None, frame_count=64)[source]

Bases: object

add_frames_to_video(frames)[source]
process_frames(batch, frames)[source]
read_frames()[source]
release_resources()[source]
start_processing(num_workers=16)[source]
worker()[source]
class entry_exit_mouse_box.mask_from_video.QtWorkerMFV(in_path, out_path, ref, t, s, r)[source]

Bases: QObject

mask_ready
run()[source]

entry_exit_mouse_box.measures module

class entry_exit_mouse_box.measures.MiceVisibilityProcessor(mask_path, areas, ma, start, duration)[source]

Bases: object

Calculates an array indicating for each box (designated by the labels in ‘areas’) if a mouse is inside or not. The process is realized on several threads. The input video was saved as a mask (0=BG, 255=FG) but it requires thresholding anyway due to compression. The areas are a grayscale image with one value per box (0=BG). To process the presence of a mouse, we use the length of the ellipse fitted to the mouse’s label. It requires the input image to be calibrated. The process doesn’t start from the frame 0 but from the frame ‘start’. We don’t need a control structure to write in the buffer as the threads are not writing in the same place.

fix_visibility()[source]
process_n_in_out()[source]
process_sessions()[source]

We call ‘session’ the span of time during which the mouse is hidden or visible. For each box, a video is a succession of sessions, alternating between hidden and visible. During a session, the mouse is either hidden or visible. A session is defined by a duration (in seconds) and a distance (in pixels).

process_visibility_pos(batch, frames)[source]
read_frames(frames_count=32)[source]
release_resources()[source]
smooth_centroids()[source]
start_processing(num_workers=4)[source]
worker()[source]
class entry_exit_mouse_box.measures.QtWorkerMVP(mask_path, areas, ma, start, duration)[source]

Bases: QObject

measures_ready
run()[source]
entry_exit_mouse_box.measures.calculate_maximal_length(mask)[source]

entry_exit_mouse_box.media_manager module

class entry_exit_mouse_box.media_manager.MediaManager(viewer)[source]

Bases: object

add_source(file_path, target_layer, img_type, process=None)[source]

Add a new video source to the manager.

Parameters:
  • file_path – Path of the video file to be opened.

  • target_layer – Name of the layer to which each frame of the video will be loaded.

  • img_type – Type of the image to be loaded (‘image’ or ‘labels’).

  • process – Function to be applied to each frame of the video before displaying it.

Raises:
  • FileNotFoundError – If the file is not found at the specified path.

  • IOError – If the file cannot be opened.

  • ValueError – If the properties of the video do not match the properties of the media already opened.

Returns:

The properties of the last video added under the form of a dictionary.

get_current_frame_number()[source]
get_fps()[source]
get_height()[source]
get_n_frames()[source]
get_n_sources()[source]
get_source_by_index(index)[source]
get_source_by_name(name)[source]
get_video_properties()[source]
get_width()[source]
release()[source]
release_source(index)[source]
set_frame(frame_target)[source]
set_logger(logger)[source]
entry_exit_mouse_box.media_manager.properties_match(p1, p2)[source]

entry_exit_mouse_box.results_table module

class entry_exit_mouse_box.results_table.FrameWiseResultsTable(data, parent=None)[source]

Bases: ResultsTable

set_data(data)[source]
class entry_exit_mouse_box.results_table.ResultsTable(data, name='Data Table', parent=None)[source]

Bases: QMainWindow

export_data()[source]
export_table_to_csv(tableWidget: QTableWidget, filename: str)[source]
init_ui()[source]
set_data(data)[source]
set_exp_name(name)[source]
class entry_exit_mouse_box.results_table.SessionsResultsTable(data, parent=None)[source]

Bases: ResultsTable

set_data(data)[source]
entry_exit_mouse_box.results_table.main_sessions()[source]
entry_exit_mouse_box.results_table.read_names(f_path)[source]

entry_exit_mouse_box.utils module

entry_exit_mouse_box.utils.apply_lut(tags, to_pass, classes)[source]

tags: Layer that will receive the LUT. to_pass: List of gray levels to which we will have to bind a color. classes: Dictionary of colors to bind to the gray levels.

entry_exit_mouse_box.utils.cast_to_pixels(unit_str_src, length_float_src, unit_str_tgt, scale_tgt)[source]

Converts a length from its unit to the viewer’s unit and then to pixels.

Args: - unit_str_src: str The unit of the length to convert (ex: the pillar’s unit). - length_float_src: float The length to convert (ex: the diameter of the pillar). - unit_str_tgt: str The unit of the viewer (ex: the calibration unit). - scale_tgt: float The scale factor to convert the length to pixels (the calibration of the scalebar).

Returns: - int The length in pixels.

entry_exit_mouse_box.utils.merge_close_points(path, min_distance, dot_threshold=-0.7)[source]

Merge points in a 2D path that are closer than a specified minimum distance. Points are merged into their average position. The operation preserves the path order and does not merge non-consecutive points if the path crosses over itself.

Parameters: - path: A list or numpy array of 2D points (e.g., [[x1, y1], [x2, y2], …]). - min_distance: The minimum allowed distance between consecutive points.

Returns: - A new list of points with no consecutive points closer than the minimum distance.

entry_exit_mouse_box.utils.setup_logger(file_path)[source]
entry_exit_mouse_box.utils.smooth_path_2d(points, window_size=3)[source]

Smooth a path of 2D points using a simple moving average with a sliding window.

Parameters: - points: A NumPy array of 2D points, shape (n_points, 2). - window_size: The size of the sliding window for the moving average.

Returns: - A NumPy array of the smoothed 2D points.

entry_exit_mouse_box.video_mean_processor module

class entry_exit_mouse_box.video_mean_processor.QtWorkerVMP(video_path, shape)[source]

Bases: QObject

bg_ready
run()[source]
class entry_exit_mouse_box.video_mean_processor.VideoMeanProcessor(video_path, shape)[source]

Bases: object

process_frames(frames)[source]
read_frames(frames_count=32)[source]
release_resources()[source]
start_processing(num_workers=16)[source]
worker()[source]

Module contents

class entry_exit_mouse_box.MediaManager(viewer)[source]

Bases: object

add_source(file_path, target_layer, img_type, process=None)[source]

Add a new video source to the manager.

Parameters:
  • file_path – Path of the video file to be opened.

  • target_layer – Name of the layer to which each frame of the video will be loaded.

  • img_type – Type of the image to be loaded (‘image’ or ‘labels’).

  • process – Function to be applied to each frame of the video before displaying it.

Raises:
  • FileNotFoundError – If the file is not found at the specified path.

  • IOError – If the file cannot be opened.

  • ValueError – If the properties of the video do not match the properties of the media already opened.

Returns:

The properties of the last video added under the form of a dictionary.

get_current_frame_number()[source]
get_fps()[source]
get_height()[source]
get_n_frames()[source]
get_n_sources()[source]
get_source_by_index(index)[source]
get_source_by_name(name)[source]
get_video_properties()[source]
get_width()[source]
release()[source]
release_source(index)[source]
set_frame(frame_target)[source]
set_logger(logger)[source]
class entry_exit_mouse_box.MouseInOutWidget(napari_viewer: Viewer)[source]

Bases: QWidget

add_calibration_ui()[source]
add_media_control_ui()[source]
add_row()[source]
add_tracking_ui()[source]
add_video_control_ui()[source]
apply_calibration()[source]
background_ready
build_labels_from_polygon()[source]
calibrate_results()[source]

Applies the calibration to the distance traveled by the mice, stored in the sessions table.

clear_state()[source]

Resets the state of the widget to its initial state.

create_temp_dir(root=None)[source]
dump_table()[source]

Dumps the content of the table in a dictionary.

duration_to_frames()[source]
experiment_duration_ui()[source]
export_results()[source]
extract_classes()[source]
extract_measures()[source]
hide_paths(state)[source]
init_ui()[source]
jump_backward()[source]
jump_forward()[source]
launch_mask_processing()[source]
launch_tracking()[source]
make_start_frame(row, button)[source]

Sets the frame at which we start measures from the current frame being displayed. The saved index is the one displayed on the screen. (The real one + 1). A source is required before we can set the start frame.

measures_ready
on_slider_change(value)[source]
on_spinbox_change(value)[source]
on_table_item_changed(item)[source]

Called when the user modifies an existing line of the table containing the colors and names of the boxes. The new name is processed here before it is provided by the user. Both the layer’s name and the box’s name are updated.

on_threshold_update(value)[source]

Creates a preview layer showing what the mask would be for the current frame for a given threshold. Updates are made only when the threshold is edited. The background reference is required. The produced layer is named ‘threshold_preview’ and is temporary, it will be discarded. This function is the callback for the threshold spinbox.

Parameters:

value – int - The threshold value to use for the preview.

remove_row()[source]
select_color(row, button, k=None)[source]
select_file()[source]
set_calibration(pixelSize, unit)[source]
set_frame(n)[source]
set_media(file_path)[source]
set_min_area()[source]

Uses a polygon drawn by the user over the head of a mouse to define the minimal area to consider that a mouse is present. When summoned, this function must find a shape layer as the active layer, and extract the area of the polygon. The shape layer is then deleted. The value extracted is not stored, it is written in the spinbox.

start_extract_background()[source]
switch_log_file(new_file_name)[source]

Creates a new log file when we switch to a new experiment video.

terminate_extract_background(ref, src_path)[source]
terminate_mask_processing(mask_path)[source]
terminate_measures(visibility, in_out_count, sessions, centroids)[source]
toggle_inputs(t)[source]

Used to disable the inputs (buttons and text fields) when a long process is running.

Parameters:

t – bool - True to enable the inputs, False to disable them.

tracking_ready
update_boxes()[source]
update_calibration(event)[source]
update_centroids()[source]
update_face_color()[source]
update_mice_path()[source]
update_playback_info()[source]
class entry_exit_mouse_box.QtWorkerMFV(in_path, out_path, ref, t, s, r)[source]

Bases: QObject

mask_ready
run()[source]
class entry_exit_mouse_box.QtWorkerMVP(mask_path, areas, ma, start, duration)[source]

Bases: QObject

measures_ready
run()[source]
class entry_exit_mouse_box.QtWorkerVMP(video_path, shape)[source]

Bases: QObject

bg_ready
run()[source]
class entry_exit_mouse_box.ResultsTable(data, name='Data Table', parent=None)[source]

Bases: QMainWindow

export_data()[source]
export_table_to_csv(tableWidget: QTableWidget, filename: str)[source]
init_ui()[source]
set_data(data)[source]
set_exp_name(name)[source]
entry_exit_mouse_box.napari_get_reader(path)[source]

A basic implementation of a Reader contribution.

Parameters:

path (str or list of str) – Path to file, or list of paths.

Returns:

If the path is a recognized format, return a function that accepts the same path or list of paths, and returns a list of layer data tuples.

Return type:

function or None

entry_exit_mouse_box.setup_logger(file_path)[source]