ROI Manager

The GUI QDockWidget that communicates with the back-end managers

ModuleGUI

class mesmerize.viewer.modules.roi_manager.ModuleGUI(parent, viewer_reference)[source]

The GUI front-end for the ROI Manager module

__init__(parent, viewer_reference)[source]

Instantiate attributes

manager = None

The back-end manager instance.

eventFilter(QObject, QEvent)[source]

Set some keyboard shortcuts

slot_delete_roi_menu()[source]

Delete the currently selected ROI

start_cnmfe_mode()[source]

Start in CNMFE mode. Creates a new back-end manager instance (uses ManagerCNMFE)

add_all_cnmfe_components(*args, **kwargs)[source]

Import CNMF(E) output data

start_manual_mode()[source]

Start in manual mode. Creates a new back-end manager instance (Uses ManagerManual)

add_manual_roi(shape: str)[source]

Add a manual ROI. Just calls ManagerManual.add_roi

package_for_project() → dict[source]

Gets all the ROI states so that they can be packaged along with the rest of the work environment to be saved as a project Sample

set_all_from_states(states: dict)[source]

Set all the ROIs from a states dict. Instantiates the appropriate back-end Manager

import_from_imagej()[source]

Import ROIs from ImageJ zip file

Managers

The back-end managers that are used by the ROI Manager ModuleGUI

The managers hold instances of ROIs in an instance of ROIList

AbstractBaseManager

class mesmerize.viewer.modules.roi_manager_modules.managers.AbstractBaseManager(parent, ui, viewer_interface: mesmerize.viewer.core.common.ViewerUtils)[source]

Base ROI Manager

__init__(parent, ui, viewer_interface: mesmerize.viewer.core.common.ViewerUtils)[source]

Set the common attributes

Parameters:
  • parent – The ModuleGUI QDockWidget instance
  • ui – The ui of the ModuleGUI QDockWidget instance,
  • viewer_interface – A ViewerUtils instance for accessing the Viewer the parent QDockWidget belongs to
roi_list = None

The ROIList instance that stores the list of ROIs

add_roi(*args, **kwargs)[source]

Method for adding an ROI, must be implemented in subclass

is_empty() → bool[source]

Return true if the ROI list is empty, else return False

get_all_states() → dict[source]

Get the ROI states for all ROIs in self.roi_list so that they can be restored. The appropriate manager is instantiated based on the ‘roi_type’ key of the returned dict

restore_from_states(states: list)[source]

Restore ROIs from their states

get_plot_item() → mesmerize.pyqtgraphCore.graphicsItems.PlotDataItem.PlotDataItem[source]

Get the viewer plot item that is associated to these ROIs

clear()[source]

Cleanup of all ROIs in the list

__del__()[source]

Cleanup of all ROIs in the list and deletes the manager instance. Used when switching modes.

__weakref__

list of weak references to the object (if defined)

ManagerManual

class mesmerize.viewer.modules.roi_manager_modules.managers.ManagerManual(parent, ui, viewer_interface)[source]

Bases: mesmerize.viewer.modules.roi_manager_modules.managers.AbstractBaseManager

The Manager for the Manual mode

__init__(parent, ui, viewer_interface)[source]

Set the common attributes

Parameters:
  • parent – The ModuleGUI QDockWidget instance
  • ui – The ui of the ModuleGUI QDockWidget instance,
  • viewer_interface – A ViewerUtils instance for accessing the Viewer the parent QDockWidget belongs to
create_roi_list()[source]

Create a new empty ROI list instance for storing Manual ROIs

add_roi(shape: str)[source]

Add an ROI to the list

Parameters:shape – either “PolyLineROI” or “EllipseROI”
restore_from_states(states: dict)[source]

Restore ROIs from states

get_all_states() → dict[source]

Get the ROI states so that they can be restored later

import_from_imagej(path: str)[source]

Uses read-roi package created by Hadrien Mary. https://pypi.org/project/read-roi/

Parameters:path – Full path to the ImageJ ROIs zip file

ManagerCNMFE

class mesmerize.viewer.modules.roi_manager_modules.managers.ManagerCNMFE(parent, ui, viewer_interface)[source]

Bases: mesmerize.viewer.modules.roi_manager_modules.managers.AbstractBaseManager

Manager for ROIs imported from CNMF or CNMFE outputs

__init__(parent, ui, viewer_interface)[source]

Instantiate necessary attributes

create_roi_list()[source]

Create empty CNMFROI list

add_all_components(cnmA, cnmb, cnmC, cnm_f, cnmYrA, idx_components, dims, input_params_dict, dfof=False, calc_raw_min_max=False)[source]

Add all components from a CNMF(E) output. Arguments correspond to CNMF(E) outputs

add_roi()[source]

Not implemented, uses add_all_components to import all ROIs instead

restore_from_states(states: dict)[source]

Restore from states, such as when these ROIs are saved with a Project Sample

get_all_states() → dict[source]

Get all states so that they can be restored

update_idx_components(ix: int)[source]

Update idx_components if the user manually delete an ROI

ROI List

Used for holding instance of ROIs

class mesmerize.viewer.modules.roi_manager_modules.roi_list.ROIList(ui, roi_types: str, viewer_interface: mesmerize.viewer.core.common.ViewerUtils)[source]

A list for holding ROIs of one type

__init__(ui, roi_types: str, viewer_interface: mesmerize.viewer.core.common.ViewerUtils)[source]

Instantiate

Parameters:
  • ui – The ui from the parent ModuleGUI, used to interact with the ROI list widget etc.
  • roi_types – The type of ROI that this list will hold
  • viewer_interface – ViewerUtils instance for interacting with the parent Viewer
list_widget = None

ROI list widget

list_widget_tags = None

Tags list widget

vi = None

ViewrUtils instance

current_index = None

Current index (int)

previous_index = None

Previous index (int)

append(roi: Union[mesmerize.viewer.modules.roi_manager_modules.roi_types.CNMFROI, mesmerize.viewer.modules.roi_manager_modules.roi_types.ManualROI])[source]

Add an ROI instance to the list

clear_()[source]

Cleanup of the list

__delitem__(key)[source]

Delete an ROI from the list and cleanup from the viewer, reindex the colors etc.

disconnect_all()[source]

Disconnect signals from the parent GUI

_reindex_list_widget()[source]

Reindex ROI list

reindex_colormap()[source]

Reindex the colors so they sequentially follow the HSV colormap

__getitem__(item) → Union[mesmerize.viewer.modules.roi_manager_modules.roi_types.ManualROI, mesmerize.viewer.modules.roi_manager_modules.roi_types.CNMFROI][source]

Get an item (ROI) from the list

set_current_index(ix: int)[source]

Set the current index

highlight_roi(roi: Union[mesmerize.viewer.modules.roi_manager_modules.roi_types.ManualROI, mesmerize.viewer.modules.roi_manager_modules.roi_types.CNMFROI])[source]

Highlight an ROI in white, both the spatial visualization and the curve

highlight_curve(ix: int)[source]

Highlight the curve corresponding to the ROI at the passed index

set_previous_index()[source]

Set the previous_index attribute

slot_show_all_checkbox_clicked(b: bool)[source]

Show all ROIs in the viewer overlay visualization and curves

_show_graphics_object(ix: int)[source]

Show the ROI at the passed index in the viewer overlay visualization

_hide_graphics_object(ix: int)[source]

Hide the ROI at the passed index in the viewer overlay visualization

_show_all_graphics_objects()[source]

Show all ROIs in the viewer overlay visualization

_hide_all_graphics_objects()[source]

Hide all ROIs in the viewer overlay visualization

plot_manual_roi_regions()[source]

Plot the ROI curves from the regions of all ManualROI instances in the list

set_pg_roi_plot(ix: int)[source]

Plot the ROI curve from the region of the ManualROI instance at the passed index

set_list_widget_tags()[source]

Set the tags list for the ROI at the current index

update_roi_defs_from_configuration()[source]

Update ROI_DEFs in the Tags list from the project configuration

__weakref__

list of weak references to the object (if defined)

ROI Types

A list of these are held by an instance of ROIList

AbstractBaseROI

class mesmerize.viewer.modules.roi_manager_modules.roi_types._AbstractBaseROI(curve_plot_item: mesmerize.pyqtgraphCore.graphicsItems.PlotDataItem.PlotDataItem, view_box: mesmerize.pyqtgraphCore.graphicsItems.ViewBox.ViewBox.ViewBox, state: Optional[dict])[source]

Abstract base class defining an ROI that works with the ROIList and ROI Managers. Inherit from this or BaseROI to make a new ROI class

__init__(curve_plot_item: mesmerize.pyqtgraphCore.graphicsItems.PlotDataItem.PlotDataItem, view_box: mesmerize.pyqtgraphCore.graphicsItems.ViewBox.ViewBox.ViewBox, state: Optional[dict])[source]

Minimum required attributes

Parameters:
  • curve_plot_item – The plot item that is used for display the curves in the viewer
  • view_box – ViewBox containing the image sequence, used for overlaying the ROIs on top of the image
  • state – ROI state, used for restoring the ROIs. Pass None is not restoring an ROI from a state dict
curve_data

The curve data for this ROI

Returns:(x, y), [np.ndarray, np.ndarray]
Return type:tuple
get_roi_graphics_object() → PyQt5.QtWidgets.QGraphicsObject[source]

Get the QGraphicsObject used for visualization of the spatial localization of the ROI

set_roi_graphics_object(*args, **kwargs)[source]

Set the QGraphicsObject used for visualization of the spatial localization of the ROI

reset_color()[source]

Reset the color of this ROI back to the original color

set_original_color(color)[source]

Set the original color for this ROI

Parameters:color – 1D numpy array of 4 floating point numbers (range 0 - 255) in RBGA format, [R, G, B, A]
get_color() → numpy.ndarray[source]

Get the current color of this ROI

Returns:1D numpy array of 4 floating point numbers (range 0 - 255) in RBGA format, [R, G, B, A]
Return type:np.ndarray
set_color(color, *args, **kwargs)[source]

Set the current color of this ROI

Parameters:color – 1D numpy array of 4 floating point numbers (range 0 - 255) in RBGA format, [R, G, B, A]
set_text(text: str)[source]

Not implemented

set_tag(roi_def: str, tag: str)[source]

Set a tag for the passed roi_def

Parameters:
  • roi_def – The ROI_DEF that should be tagged
  • tag – The tag to label for the passed ROI_DEF/ROI Type
get_tag(roi_def) → str[source]

Get the tag that is set to the passed ‘roi_def’

Return type:str
get_all_tags() → dict[source]

Get all the tags for all the ROI_DEFs

Return type:dict
add_to_viewer()[source]

Add this ROI to the viewer.

remove_from_viewer()[source]

Remove this ROI from the viewer

to_state()[source]

Get the current state for this ROI so that it can be restored later

classmethod from_state(curve_plot_item: mesmerize.pyqtgraphCore.graphicsItems.PlotDataItem.PlotDataItem, view_box: mesmerize.pyqtgraphCore.graphicsItems.ViewBox.ViewBox.ViewBox, state: dict)[source]

Restore this ROI from a state

Parameters:
  • curve_plot_item – The plot item that is used for display the curves in the viewer
  • view_box – ViewBox containing the image sequence, used for overlaying the ROIs on top of the image
  • state – ROI state, used for restoring the ROIs. Pass None is not restoring an ROI from a state dict
__weakref__

list of weak references to the object (if defined)

BaseROI

class mesmerize.viewer.modules.roi_manager_modules.roi_types.BaseROI(curve_plot_item: mesmerize.pyqtgraphCore.graphicsItems.PlotDataItem.PlotDataItem, view_box: mesmerize.pyqtgraphCore.graphicsItems.ViewBox.ViewBox.ViewBox, state: Optional[dict] = None)[source]

Bases: mesmerize.viewer.modules.roi_manager_modules.roi_types._AbstractBaseROI

A base class that is used by ManualROI and CNMFEROI Inherit from this to make a new ROI class

__init__(curve_plot_item: mesmerize.pyqtgraphCore.graphicsItems.PlotDataItem.PlotDataItem, view_box: mesmerize.pyqtgraphCore.graphicsItems.ViewBox.ViewBox.ViewBox, state: Optional[dict] = None)[source]

Instantiate common attributes

Parameters:
  • curve_plot_item – The plot item that is used for display the curves in the viewer
  • view_box – ViewBox containing the image sequence, used for overlaying the ROIs on top of the image
  • state – ROI state, used for restoring the ROIs. Pass None is not restoring an ROI from a state dict
curve_data

The curve data for this ROI

Returns:(x, y), [np.ndarray, np.ndarray]
Return type:tuple
get_roi_graphics_object() → PyQt5.QtWidgets.QGraphicsObject[source]

Get the QGraphicsObject used for visualization of the spatial localization of the ROI

set_roi_graphics_object(*args, **kwargs)[source]

Set the QGraphicsObject used for visualization of the spatial localization of the ROI

reset_color()[source]

Reset the color of this ROI back to the original color

set_original_color(color)[source]

Set the original color for this ROI

Parameters:color – 1D numpy array of 4 floating point numbers (range 0 - 255) in RBGA format, [R, G, B, A]
get_color()[source]

Get the current color of this ROI

Returns:1D numpy array of 4 floating point numbers (range 0 - 255) in RBGA format, [R, G, B, A]
Return type:np.ndarray
set_color(color: Union[numpy.ndarray, str], *args, **kwargs)[source]

Set the current color of this ROI

Parameters:color – 1D numpy array of 4 floating point numbers (range 0 - 255) in RBGA format, [R, G, B, A]
set_text(text: str)[source]

Not implemented

set_tag(roi_def: str, tag: str)[source]

Set a tag for the passed roi_def

Parameters:
  • roi_def – The ROI_DEF that should be tagged
  • tag – The tag to label for the passed ROI_DEF/ROI Type
get_tag(roi_def) → str[source]

Get the tag that is set to the passed ‘roi_def’

Return type:str
get_all_tags() → dict[source]

Get all the tags for all the ROI_DEFs

Return type:dict
add_to_viewer()[source]

Add this ROI to the viewer.

remove_from_viewer()[source]

Remove this ROI from the viewer

to_state()[source]

Must be implemented in subclass

classmethod from_state(curve_plot_item: mesmerize.pyqtgraphCore.graphicsItems.PlotDataItem.PlotDataItem, view_box: mesmerize.pyqtgraphCore.graphicsItems.ViewBox.ViewBox.ViewBox, state: dict)[source]

Restore this ROI from a state

Parameters:
  • curve_plot_item – The plot item that is used for display the curves in the viewer
  • view_box – ViewBox containing the image sequence, used for overlaying the ROIs on top of the image
  • state – ROI state, used for restoring the ROIs. Pass None is not restoring an ROI from a state dict

ManualROI

class mesmerize.viewer.modules.roi_manager_modules.roi_types.ManualROI(curve_plot_item: mesmerize.pyqtgraphCore.graphicsItems.PlotDataItem.PlotDataItem, roi_graphics_object: mesmerize.pyqtgraphCore.graphicsItems.ROI.ROI, view_box: mesmerize.pyqtgraphCore.graphicsItems.ViewBox.ViewBox.ViewBox, state: Optional[dict] = None)[source]

Bases: mesmerize.viewer.modules.roi_manager_modules.roi_types.BaseROI

A class manually drawn ROIs

__init__(curve_plot_item: mesmerize.pyqtgraphCore.graphicsItems.PlotDataItem.PlotDataItem, roi_graphics_object: mesmerize.pyqtgraphCore.graphicsItems.ROI.ROI, view_box: mesmerize.pyqtgraphCore.graphicsItems.ViewBox.ViewBox.ViewBox, state: Optional[dict] = None)[source]
get_roi_graphics_object() → mesmerize.pyqtgraphCore.graphicsItems.ROI.ROI[source]

Get the QGraphicsObject used for visualization of the spatial localization of the ROI

set_roi_graphics_object(graphics_object: mesmerize.pyqtgraphCore.graphicsItems.ROI.ROI)[source]

Set the QGraphicsObject used for visualization of the spatial localization of the ROI

to_state()[source]

Must be implemented in subclass

classmethod from_state(curve_plot_item: mesmerize.pyqtgraphCore.graphicsItems.PlotDataItem.PlotDataItem, view_box: mesmerize.pyqtgraphCore.graphicsItems.ViewBox.ViewBox.ViewBox, state: dict)[source]

Restore this ROI from a state

Parameters:
  • curve_plot_item – The plot item that is used for display the curves in the viewer
  • view_box – ViewBox containing the image sequence, used for overlaying the ROIs on top of the image
  • state – ROI state, used for restoring the ROIs. Pass None is not restoring an ROI from a state dict
add_to_viewer()

Add this ROI to the viewer.

curve_data

The curve data for this ROI

Returns:(x, y), [np.ndarray, np.ndarray]
Return type:tuple
get_all_tags() → dict

Get all the tags for all the ROI_DEFs

Return type:dict
get_color()

Get the current color of this ROI

Returns:1D numpy array of 4 floating point numbers (range 0 - 255) in RBGA format, [R, G, B, A]
Return type:np.ndarray
get_tag(roi_def) → str

Get the tag that is set to the passed ‘roi_def’

Return type:str
remove_from_viewer()

Remove this ROI from the viewer

reset_color()

Reset the color of this ROI back to the original color

set_color(color: Union[numpy.ndarray, str], *args, **kwargs)

Set the current color of this ROI

Parameters:color – 1D numpy array of 4 floating point numbers (range 0 - 255) in RBGA format, [R, G, B, A]
set_original_color(color)

Set the original color for this ROI

Parameters:color – 1D numpy array of 4 floating point numbers (range 0 - 255) in RBGA format, [R, G, B, A]
set_tag(roi_def: str, tag: str)

Set a tag for the passed roi_def

Parameters:
  • roi_def – The ROI_DEF that should be tagged
  • tag – The tag to label for the passed ROI_DEF/ROI Type
set_text(text: str)

Not implemented

CNMFROI

class mesmerize.viewer.modules.roi_manager_modules.roi_types.CNMFROI(curve_plot_item: mesmerize.pyqtgraphCore.graphicsItems.PlotDataItem.PlotDataItem, view_box: mesmerize.pyqtgraphCore.graphicsItems.ViewBox.ViewBox.ViewBox, cnmf_idx: int = None, curve_data=None, contour=None, state: Optional[dict] = None, **kwargs)[source]

Bases: mesmerize.viewer.modules.roi_manager_modules.roi_types.BaseROI

A class for ROIs imported from CNMF(E) output data

__init__(curve_plot_item: mesmerize.pyqtgraphCore.graphicsItems.PlotDataItem.PlotDataItem, view_box: mesmerize.pyqtgraphCore.graphicsItems.ViewBox.ViewBox.ViewBox, cnmf_idx: int = None, curve_data=None, contour=None, state: Optional[dict] = None, **kwargs)[source]

Instantiate attributes.

Type:

curve_data: np.ndarray

Parameters:
  • curve_data – 1D numpy array of y values
  • cnmf_idx – original index of the ROI from cnmf idx_components
add_to_viewer()

Add this ROI to the viewer.

curve_data

The curve data for this ROI

Returns:(x, y), [np.ndarray, np.ndarray]
Return type:tuple
get_all_tags() → dict

Get all the tags for all the ROI_DEFs

Return type:dict
get_color()

Get the current color of this ROI

Returns:1D numpy array of 4 floating point numbers (range 0 - 255) in RBGA format, [R, G, B, A]
Return type:np.ndarray
get_tag(roi_def) → str

Get the tag that is set to the passed ‘roi_def’

Return type:str
remove_from_viewer()

Remove this ROI from the viewer

reset_color()

Reset the color of this ROI back to the original color

set_color(color: Union[numpy.ndarray, str], *args, **kwargs)

Set the current color of this ROI

Parameters:color – 1D numpy array of 4 floating point numbers (range 0 - 255) in RBGA format, [R, G, B, A]
set_original_color(color)

Set the original color for this ROI

Parameters:color – 1D numpy array of 4 floating point numbers (range 0 - 255) in RBGA format, [R, G, B, A]
set_tag(roi_def: str, tag: str)

Set a tag for the passed roi_def

Parameters:
  • roi_def – The ROI_DEF that should be tagged
  • tag – The tag to label for the passed ROI_DEF/ROI Type
set_text(text: str)

Not implemented

set_curve_data(y_vals)[source]

Set the curve data

get_roi_graphics_object() → mesmerize.pyqtgraphCore.graphicsItems.ScatterPlotItem.ScatterPlotItem[source]

Get the QGraphicsObject used for visualization of the spatial localization of the ROI

set_roi_graphics_object(contour: dict)[source]

Set the QGraphicsObject used for visualization of the spatial localization of the ROI

_create_scatter_plot()[source]

Create the scatter plot that is used for visualization of the spatial localization

to_state() → dict[source]

Must be implemented in subclass

classmethod from_state(curve_plot_item: mesmerize.pyqtgraphCore.graphicsItems.PlotDataItem.PlotDataItem, view_box: mesmerize.pyqtgraphCore.graphicsItems.ViewBox.ViewBox.ViewBox, state: dict)[source]

Restore this ROI from a state

Parameters:
  • curve_plot_item – The plot item that is used for display the curves in the viewer
  • view_box – ViewBox containing the image sequence, used for overlaying the ROIs on top of the image
  • state – ROI state, used for restoring the ROIs. Pass None is not restoring an ROI from a state dict