radioviz.tools.region_tool
Region tool module for radioviz application.
This module provides functionality for selecting regions of interest in images, calculating statistics for those regions, and displaying histograms of the selected regions. It includes tools for rectangle, circle, ellipse, and polygon selection types, along with associated UI components and data management.
The module defines controllers, views, models, and utility functions for handling region selection and analysis operations within the radioviz application framework.
Typical Workflow for Region Creation: 1. User clicks “Add Region” button in the tool dock and selects a region type 2. A RegionSelectionDialog appears with options for region type, rotation, and enclosure 3. The RegionToolController creates a RegionToolSession with an ImageWindowController 4. A RegionSelector is initialized on the image canvas based on the selected region type 5. User performs selection on the image canvas (drag for rectangles/ellipses, click for polygons) 6. Once valid selection is made, the RegionSelectionDialog enables the “Done” button 7. User clicks “Done” which triggers RegionToolSession.start_region_computation() 8. A worker is created in a separate thread to compute statistics 9. The worker calculates histogram, mean, std dev, min, max, and area values 10. Results are returned to the RegionToolSession which finalizes the region creation 11. The new RegionData is added to the item store and displayed in the table
Typical Workflow for Region Removal: 1. User selects a region in the table view 2. User clicks the “Delete Region” button 3. RegionToolController.on_delete_clicked() is called 4. The selected RegionData is passed to RegionToolController.remove_item() 5. The item is marked as being removed to prevent re-entrancy 6. Associated overlay elements are removed from the image canvas 7. If a RegionWindowController exists, it is closed 8. The RegionData is removed from the item store
Typical Workflow for Workspace Serialization: 1. The to_workspace method is called to generate a workspace specification. 2. A ToolWorkspace object is created, capturing the current state and items of the tool. 3. The workspace specification includes optional data based on the include_data parameter. 4. The current selected item and all items in the item store are serialized into the workspace.
Typical Workflow for Workspace Restoration: 1. The from_workspace method is invoked with a ToolWorkspace specification. 2. The tool’s state is reconstructed using the workspace specification. 3. Each item in the specification is restored, resolving references using the provided context. 4. The item store is reordered based on the order specified in the workspace. 5. The selected item is restored to match the workspace state.
Key Actors: - ToolDockWidget: Provides UI controls and manages table interactions - RegionToolController: Coordinates between UI and backend logic - RegionSelectionDialog: Handles user configuration of region parameters - RegionToolSession: Manages the lifecycle of a region selection operation - RegionSelector: Handles the actual selection on the image canvas - RegionData: Stores region information and statistics - RegionWindowController: Manages the region detail window
Module Attributes
Dictionary mapping region types to their corresponding icons. |
|
Type alias for ItemStore with RegionData elements. |
Functions
|
Treat a region as complete without runtime checks. |
|
|
|
Draw a highlighted region overlay. |
|
Draw a permanent region overlay. |
|
Draw a region label.h5 overlay. |
|
Draw a region overlay on matplotlib axes. |
|
Draw a temporary region overlay. |
Classes
|
Request for region computation. |
|
Data class representing a region of interest. |
|
Protocol describing a region with fully populated histogram data. |
|
|
|
Dialog for selecting region parameters. |
|
Temporary, editable selector for region selection. |
|
Sub-window for displaying region histograms. |
|
Table model for displaying region data in a table view. |
|
Controller for the region tool. |
|
Dock widget for the region tool. |
|
Session for region tool operations. |
|
Controller for the region sub-window. |
- class radioviz.tools.region_tool.RegionComputationRequest(session_id: UUID, image: ndarray, mask: ndarray, enclosure: ROIEnclosure, bins: int | str)[source]
Bases:
objectRequest for region computation.
Contains all the information needed to compute statistics for a region.
- bins: int | str
Number of bins or bin specification for histogram.
- enclosure: ROIEnclosure
Enclosure type (Inside/Outside).
- image: ndarray
Image data.
- mask: ndarray
Binary mask of the region.
- session_id: UUID
Unique identifier for the session.
- class radioviz.tools.region_tool.RegionData(name: str, color: Color, selection_type: ROIType = ROIType.RECTANGLE, region_controller: RegionWindowController | None = None, image_controller: ImageWindowController | None = None, region_geometry: dict[str, Any] | None = None, mask: ndarray | None = None, session_id: UUID | None = None, region_id: UUID | None = None, enclosure: ROIEnclosure | None = None, histogram: ndarray | None = None, bin_edges: ndarray | None = None, bins: int | str | None = None, mean_value: float | None = None, std_dev_value: float | None = None, max_value: float | None = None, min_value: float | None = None, area: float | None = None, show_overlay: bool | None = True, show_label: bool | None = True)[source]
Bases:
objectData class representing a region of interest.
Stores information about a selected region including its properties, statistics, and associated controllers.
Initialize a RegionData instance.
- Parameters:
name (str) – Name of the region
color (Color) – Color of the region
selection_type (ROIType) – Type of selection (default: RECTANGLE)
region_controller (Optional[RegionWindowController]) – Controller for the region window
image_controller (Optional[ImageWindowController]) – Controller for the image window
mask (Optional[np.ndarray]) – Binary mask of the region
session_id (Optional[UUID]) – Session identifier
region_id (Optional[UUID]) – Unique identifier for the region
enclosure (Optional[ROIEnclosure]) – Enclosure type (Inside/Outside)
histogram (Optional[np.ndarray]) – Histogram data
bin_edges (Optional[np.ndarray]) – Bin edges for histogram
bins (Optional[Union[int, str]]) – Number of bins or bin specification
mean_value (Optional[float]) – Mean value of region
std_dev_value (Optional[float]) – Standard deviation of region
max_value (Optional[float]) – Maximum value in region
min_value (Optional[float]) – Minimum value in region
area (Optional[float]) – Area of the region
- assign_kwargs(**kwargs: Any) None[source]
Assign keyword arguments to instance attributes.
- Parameters:
kwargs (dict) – Keyword arguments to assign
- require_image_controller() ImageWindowController[source]
Return the image controller or raise if missing.
- Returns:
Associated image window controller
- Return type:
- Raises:
RuntimeError – If no image controller is linked
- require_region_controller() RegionWindowController[source]
Return the region controller or raise if missing.
- Returns:
Associated region window controller
- Return type:
- Raises:
RuntimeError – If no region controller is linked
- class radioviz.tools.region_tool.RegionDataCompleteProtocol(*args, **kwargs)[source]
Bases:
ProtocolProtocol describing a region with fully populated histogram data.
This protocol expresses the invariant that histogram arrays are available after a session completes, without adding runtime checks.
- class radioviz.tools.region_tool.RegionDataWorkspaceSpec(id: 'UUID', name: 'str', image_controller_id: 'Optional[UUID]' = None, region_controller_id: 'Optional[UUID]' = None, color: 'tuple[float, float, float]' = (0.0, 0.0, 0.0), selection_type: 'str' = 'Rectangle', enclosure: 'str' = 'Inside', bins: 'Optional[Union[int, str]]' = None, region_geometry: 'dict[str, Any]' = <factory>, show_overlay: 'bool' = True, show_label: 'bool' = True, mask: 'Optional[np.ndarray]' = None, histogram: 'Optional[np.ndarray]' = None, bin_edges: 'Optional[np.ndarray]' = None, mean_value: 'Optional[float]' = None, std_dev_value: 'Optional[float]' = None, max_value: 'Optional[float]' = None, min_value: 'Optional[float]' = None, area: 'Optional[float]' = None)[source]
Bases:
object
- class radioviz.tools.region_tool.RegionSelectionDialog(selection_type: ROIType, parent: QWidget | None = None)[source]
Bases:
QDialogDialog for selecting region parameters.
Provides UI for configuring region selection parameters like type, rotation, and enclosure.
Initialize the region selection dialog.
- Parameters:
selection_type (ROIType) – Initial selection type
parent (QWidget) – Parent widget
- is_rotation_meaningful() bool[source]
Check if rotation is meaningful for the current selection type.
- Returns:
True if rotation is meaningful
- Return type:
bool
- on_region_changed(region_type: ROIType) None[source]
Handle region type changes.
- Parameters:
region_type (ROIType) – New region type
- change_rotation
Signal emitted when rotation is changed.
- region_type_changed
Signal emitted when region type is changed.
- update_params
Signal emitted when parameters are updated.
- class radioviz.tools.region_tool.RegionSelector(ax: Axes, region_type: ROIType)[source]
Bases:
QObjectTemporary, editable selector for region selection.
Lives only for the duration of a ToolSession.
Initialize the region selector.
- Parameters:
ax (Axes) – Matplotlib axes to draw on
region_type (ROIType) – Type of region to select
- _on_polygon_select(verts: list[tuple[float, float]]) None[source]
Handle polygon selection.
- Parameters:
verts (list) – Vertices of the polygon
- _on_select(eclick: MouseEvent, erelease: MouseEvent) None[source]
Handle mouse selection for rectangle and ellipse.
- Parameters:
eclick (MouseEvent) – Mouse click event
erelease (MouseEvent) – Mouse release event
- activate() None[source]
Activate the region selector.
Sets up the appropriate matplotlib selector based on region type.
- deactivate() None[source]
Deactivate the region selector.
Cleans up resources and removes the selector from the canvas.
- geometry() tuple[float, float, float, float] | list[tuple[float, float]] | None[source]
Get the geometry of the current selection.
- Returns:
Selection geometry
- Return type:
Union[tuple, list, None]
- Raises:
RuntimeError – If region type is unsupported
- on_key_pressed(event: KeyEvent) None[source]
Handle key press events.
- Parameters:
event (KeyEvent) – Key press event
- has_valid_selection
Action descriptor for valid selection state.
- valid_selection
Signal emitted when selection validity changes.
- class radioviz.tools.region_tool.RegionSubWindow(controller: RegionWindowController, parent: QWidget | None = None)[source]
Bases:
CanvasWindow[RegionWindowController,SimpleCanvas]Sub-window for displaying region histograms.
This window shows the histogram of a selected region of interest.
Initialize the region sub-window.
- Parameters:
controller (RegionWindowController) – The region window controller
parent (QWidget) – Parent widget
- create_canvas() SimpleCanvas[source]
Create the canvas used for region histograms.
- Returns:
A configured
SimpleCanvasinstance for region plots.- Return type:
- export_to_path(path: Path) None[source]
Export the current image display to a file.
Saves the current figure displayed in the canvas to the specified path using matplotlib’s savefig functionality.
- Parameters:
path (pathlib.Path) – The file path where the image should be saved
- on_data_state_changed() None[source]
Update the window title when data state changes.
This method is called when the underlying data state changes, such as when the data is modified or saved. It updates the window title to reflect the current persistence status.
See also
- on_name_changed(new_name: str) None[source]
Handle a change of region name.
- Parameters:
new_name (str) – The new region name
- plot_histogram() None[source]
Plot the histogram of the region data.
Clears the current canvas and draws the histogram with appropriate labels and styling based on the region data.
- class radioviz.tools.region_tool.RegionTableModel(store: ItemStore[RegionData], parent: QObject | None = None)[source]
Bases:
ItemModelTable model for displaying region data in a table view.
Provides data for displaying region information in a QTableView.
Initialize the region table model.
- Parameters:
store (RegionStore) – Store containing region data
parent (QObject) – Parent object
- data_for(item: RegionData, column: int, role: int = ItemDataRole.DisplayRole) Any[source]
Get data for a specific cell in the table.
- Parameters:
item (RegionData) – Region data item
column (int) – Column index
role (Qt.ItemDataRole) – Item data role
- Returns:
Data for the cell
- Return type:
Any
- flags(index: QModelIndex | QPersistentModelIndex, /) ItemFlag[source]
Return the item flags for the given index.
- Parameters:
index (QModelIndex) – Index of the item
- Returns:
Item flags for the specified index
- Return type:
Qt.ItemFlag
- set_data_for(item: RegionData, column: int, value: Any, role: int = ItemDataRole.DisplayRole) bool[source]
Set data for a specific region cell.
- Parameters:
item (RegionData) – Region data object
column (int) – Column index
value (Any) – Value to set
role (Qt.ItemDataRole) – Item data role
- Returns:
True if successful, False otherwise
- Return type:
bool
- class radioviz.tools.region_tool.RegionTool[source]
Bases:
Tool[RegionToolController]- _increment_item_counter(item_count: int) None[source]
Increment the item counter by a specified count.
Updates the item counter to reflect the number of items being restored or added.
- Parameters:
item_count (int) – Number of items to increment the counter by
- _on_item_restore_completed() None[source]
Handle completion of item restoration.
Reorders the item store and restores the selected item based on the workspace specification.
- _reorder_store() None[source]
Reorder the item store based on the workspace specification.
Adjusts the order of items in the store to match the order specified in the workspace.
- _restore_completed() None[source]
Signal that the workspace restoration process has been completed.
Emits the restore_completed signal to notify observers that the profile tool restoration process is finished and all profiles have been properly restored from the workspace specification.
This method is called internally by the workspace restoration mechanism to indicate completion of the restoration sequence.
- _restore_selected_item() None[source]
Restore the selected item from the workspace specification.
Sets the selection in the table model to the item specified in the workspace state.
- create_controller(ctx: ToolContext) RegionToolController[source]
Create a controller for this tool.
- Parameters:
ctx (ToolContext) – Tool context
- Returns:
New region tool controller
- Return type:
- from_workspace(spec: ToolWorkspace, context: WorkspaceReferenceManager) None[source]
Restore the tool’s state from a workspace specification.
Reconstructs the tool’s state and items from the given ToolWorkspace specification, using the provided context to resolve references.
- Parameters:
spec (ToolWorkspace) – Workspace specification to restore from
context (WorkspaceReferenceManager) – Reference manager for resolving workspace references
- Raises:
RuntimeError – If no controller is available for the tool
- to_workspace(include_data: bool) ToolWorkspace[source]
Generate a workspace specification for the tool.
Creates a ToolWorkspace object containing the current state and items of the tool, optionally including data. This specification can be used for saving or restoring the tool’s state.
- Parameters:
include_data (bool) – Whether to include data in the workspace specification
- Returns:
Workspace specification for the tool
- Return type:
- description: str = 'A tool to analyse region of interests'
Tooltip or description
- name: str = 'Region Tool'
Human-readable name
- overlays_to_be_registered: list[OverlaySpec] = [OverlaySpec(overlay_type='rectangle', overlay_role=<OverlayRole.Permanent: 'permanent'>, renderer=<function draw_region_overlay>), OverlaySpec(overlay_type='rectangle', overlay_role=<OverlayRole.Highlight: 'highlight'>, renderer=<function draw_highlight_region_overlay>), OverlaySpec(overlay_type='rectangle', overlay_role=<OverlayRole.Temporary: 'temporary'>, renderer=<function draw_temporary_region_overlay>), OverlaySpec(overlay_type='ellipse', overlay_role=<OverlayRole.Permanent: 'permanent'>, renderer=<function draw_region_overlay>), OverlaySpec(overlay_type='ellipse', overlay_role=<OverlayRole.Highlight: 'highlight'>, renderer=<function draw_highlight_region_overlay>), OverlaySpec(overlay_type='ellipse', overlay_role=<OverlayRole.Temporary: 'temporary'>, renderer=<function draw_temporary_region_overlay>), OverlaySpec(overlay_type='polygon', overlay_role=<OverlayRole.Permanent: 'permanent'>, renderer=<function draw_region_overlay>), OverlaySpec(overlay_type='polygon', overlay_role=<OverlayRole.Highlight: 'highlight'>, renderer=<function draw_highlight_region_overlay>), OverlaySpec(overlay_type='polygon', overlay_role=<OverlayRole.Temporary: 'temporary'>, renderer=<function draw_temporary_region_overlay>), OverlaySpec(overlay_type='region_label', overlay_role=<OverlayRole.Label: 'label'>, renderer=<function draw_region_label>)]
List of overlay specifications to register
- tool_id: str = 'region'
Unique identifier of the tool
- windows_to_be_registered: list[WindowSpec] = [WindowSpec(window_type='region', view_cls=<class 'radioviz.tools.region_tool.RegionSubWindow'>, overwrite=False)]
List of window specifications to register
- class radioviz.tools.region_tool.RegionToolController(tool_ctx: ToolContext, tool: Tool[RegionToolController])[source]
Bases:
ToolController[ImageWindowController,RegionToolSession]Controller for the region tool.
Manages the interaction between the UI and the underlying region processing logic.
Initialize the region tool controller.
- Parameters:
tool_ctx (ToolContext) – Tool context
tool (Tool) – Tool instance
- _activate_region_window(window_controller: RegionWindowController) None[source]
Activate the region window for the given controller.
- Parameters:
window_controller (RegionWindowController) – The region window controller to activate
- _on_active_image_changed(new_window_controller: SubWindowController[Any] | None) None[source]
Handle changes to the active image window controller.
Updates the add enabled state based on whether the new controller is an image controller.
- Parameters:
new_window_controller (SubWindowController) – The new window controller
- _on_image_about_to_close(image_controller: ImageWindowController) None[source]
Handle image window closing event.
Removes all regions associated with the closing image controller.
- Parameters:
image_controller (ImageWindowController) – The image controller that is about to close
- _sync_region(region_data: RegionData) None[source]
Synchronize region data with its associated controllers and overlays.
Updates the region name in the controller and label.h5 overlay, and synchronizes the visibility settings for permanent, highlight, and label.h5 overlays. If the region is currently selected, ensures the highlight overlay is properly managed.
- activate_rotation(active: bool) None[source]
Activate or deactivate rotation for the current selection.
- Parameters:
active (bool) – Whether to activate rotation
- count_dependencies_for_image(window_controller: SubWindowController[Any]) int[source]
Count region items attached to window_controller.
- create_dock(parent_window: QWidget) RegionToolDock[source]
Create and configure a dock widget for the region tool.
- Parameters:
parent_window (QWidget) – Parent window for the dock widget
- Returns:
Configured region tool dock widget
- Return type:
- create_session(window_controller: ImageWindowController, input_data: RegionData | None = None) RegionToolSession[source]
Create a new region tool session.
- Parameters:
window_controller (ImageWindowController) – Window controller
input_data (RegionData) – Input data in case of workspace restore
- Returns:
New region tool session
- Return type:
- finalize_region(session_result: ToolSessionResult) None[source]
Finalize the creation of a new region.
Creates a region window controller, connects signals, and emits a window request. Adds the region to the item store.
- invalidate_dependencies_for_image(window_controller: SubWindowController[Any]) int[source]
Remove region items attached to window_controller.
Get the menu specifications for the region tool.
- Returns:
List of menu specifications
- Return type:
List[ToolMenuSpec]
- on_cancelled_region_definition() None[source]
Handle cancellation of region definition.
Cancels the active session if one exists.
- on_confirmed_region_definition() None[source]
Handle confirmation of region definition.
Starts region computation if an active session exists.
- on_delete_clicked() None[source]
Handle delete button click event.
Removes the currently selected region item.
- on_dock_event(event: ToolEvent) None[source]
Handle events from the dock widget.
- Parameters:
event (ToolEvent) – The tool event
- on_item_selection_changed(selected: RegionData | None, deselected: RegionData | None) None[source]
Handle changes to item selection in the table.
Removes highlight from deselected item and adds highlight to selected item. Activates the region window for the selected item.
- Parameters:
selected (RegionData | None) – The newly selected region data
deselected (RegionData | None) – The previously selected region data
- on_region_type_change(new_region_type: ROIType) None[source]
Handle changes to the region type during selection.
- Parameters:
new_region_type (ROIType) – The new region type
- remove_item(item: RegionData) None[source]
Remove a region item from the store and clean up associated resources.
- Parameters:
item (RegionData) – The region data item to remove
- require_region_requested_type() ROIType[source]
Return the requested region type or raise if missing.
- Returns:
Requested region type
- Return type:
- Raises:
RuntimeError – If the region type has not been set
- set_parameters(params: dict[str, Any]) None[source]
Set region parameters.
- Parameters:
params (dict[str, Any]) – Dictionary of parameters to update
- start_add_item(region_type: ROIType) None[source]
Start adding a new item of the specified region type.
- Parameters:
region_type (ROIType) – The type of region to add
- update_editable_fields(data: RegionData, index: int = 0) None[source]
Update editable fields when a region is updated in the store.
This method is triggered by update events and synchronizes the region data with its associated controllers and overlays.
- ack_session_completed
Signal emitted when the results of the tool session are committed.
- add_enabled_changed
Signal emitted when add enabled state changes.
- can_add
Action descriptor for add enabled state.
- can_remove
Action descriptor for remove enabled state.
- remove_enabled_changed
Signal emitted when remove enabled state changes.
- request_to_change_selection
Signal emitted when the controller request a change in the selected element
- restore_completed
Signal emitted when the restore of the tool is completed.
- class radioviz.tools.region_tool.RegionToolDock(parent: QWidget, controller: RegionToolController)[source]
Bases:
ToolDockWidget[RegionToolController]Dock widget for the region tool.
Provides UI controls for adding and managing regions.
Initialize the region tool dock.
- Parameters:
parent (QWidget) – Parent widget
controller (RegionToolController) – Region tool controller
- _set_default_region_action(region_type: ROIType) None[source]
Set the default region action.
- Parameters:
region_type (ROIType) – Default region type
- handle_event(event: ToolEvent) None[source]
Handle tool events.
- Parameters:
event (ToolEvent) – Tool event
- on_item_selected(selected: QItemSelection, deselected: QItemSelection) None[source]
Handle item selection changes.
- Parameters:
selected (QItemSelection) – Selected indexes
deselected (QItemSelection) – Deselected indexes
- on_request_to_change_selection(index: QModelIndex, flags: SelectionFlag) None[source]
Change the selection in the table view.
Selects the specified index in the table view using the provided selection flags and scrolls to the selected index to ensure it is visible.
- Parameters:
index (QModelIndex) – The index to select
flags (QItemSelectionModel.SelectionFlag) – Flags specifying how the selection should be changed
- on_window_controller_changed(is_image_controller: bool) None[source]
Handle window controller changes.
- Parameters:
is_image_controller (bool) – Whether the controller is an image controller
- set_can_remove(delete_enable: bool) None[source]
Set whether deletion is enabled.
- Parameters:
delete_enable (bool) – Whether deletion is enabled
- start_add_new_region(region_type: ROIType) None[source]
Start adding a new region of specified type.
- Parameters:
region_type (ROIType) – Type of region to add
- dock_position = 8
Position of the dock widget.
- enable_for_window_type = 15
Window types where this dock is enabled.
- initial_visibility = True
Initial visibility of the dock widget.
- item_selection_changed
Signal emitted when item selection changes.
- class radioviz.tools.region_tool.RegionToolSession(tool_controller: RegionToolController, window_controller: ImageWindowController, input_data: RegionData | None = None)[source]
Bases:
BaseToolSession[RegionToolController,ImageWindowController]Session for region tool operations.
Manages the lifecycle of a region selection operation.
Initialize the region tool session.
- Parameters:
tool_controller (RegionToolController) – Tool controller
window_controller (ImageWindowController) – Window controller
- _define_initial_condition() None[source]
Define initial conditions for the not interactive region tool session.
Sets up the region parameters and assigns the input data to the current region.
- _on_interactive_definition() None[source]
Define region interactively.
Initiates the interactive region selection process by creating a new region and setting up the selector on the image canvas.
- _require_current_region() RegionData[source]
Return the current region or raise if missing.
- Returns:
Current region data
- Return type:
- Raises:
RuntimeError – If no current region is set
- _require_input_data() RegionData[source]
Return the input data provided to the session or raise if missing.
- Returns:
Input region data
- Return type:
- Raises:
RuntimeError – If no input data has been provided
- _require_overlay_model() OverlayModel[source]
Return the overlay model or raise if missing.
- Returns:
The overlay model associated with the current region
- Return type:
- Raises:
RuntimeError – If the overlay model is not available
- _require_region_selector() RegionSelector[source]
Return the region selector or raise if missing.
- Returns:
The active region selector
- Return type:
- Raises:
RuntimeError – If no selector is active
- _require_region_type() ROIType[source]
Return the currently requested region type or raise if missing.
- Returns:
The requested region type
- Return type:
- Raises:
RuntimeError – If no region type is set
- create_label_overlay() OverlayModel[source]
Create an overlay for the region label.h5.
- create_selector() None[source]
Create a new region selector.
Recreates the selector with the current region type.
- on_cancel(reason: str) None[source]
Handle cancellation of the session.
- Parameters:
reason (str) – Reason for cancellation
- on_computation_completed(results: dict[str, Any]) None[source]
Handle completed computation.
- Parameters:
results (dict[str, Any]) – Computation results
- on_computation_failed(e: Exception) None[source]
Handle computation failure.
- Parameters:
e (Exception) – Exception that occurred
- Raises:
Exception – Re-raises the exception
- on_finish() None[source]
Handle completion of the session.
Cleans up resources and notifies the controller.
- on_start() None[source]
Start the region tool session.
Initializes the session by either defining an interactive region selection or setting initial conditions based on input data. If data is already available, it triggers computation completion directly.
- on_valid_selection_change(valid: bool) None[source]
Handle selection validity changes.
- Parameters:
valid (bool) – Whether selection is valid
- overlay_from_geometry() OverlayModel[source]
Create an overlay model from the current geometry.
- Returns:
Overlay model representing the selection
- Return type:
- Raises:
TypeError – If selection type is unsupported
- class radioviz.tools.region_tool.RegionWindowController(source: DataSource, region_data: RegionData, storage: DataStorage | None = None, view: RegionSubWindow | None = None)[source]
Bases:
SubWindowController[RegionSubWindow]Controller for the region sub-window.
Manages the interaction between the region sub-window view and the underlying region data model.
Initialize the region window controller.
- Parameters:
region_data (RegionData) – The region data to display
view (Optional[RegionSubWindow]) – Optional view instance
- _save_region_data_csv(path: Path) None[source]
Save region data to CSV format.
Writes metadata and histogram data to a CSV file with bin centers and histogram values.
- Parameters:
path (pathlib.Path) – Path to save the CSV file
- _save_region_data_hdf5(path: Path) None[source]
Save region data to HDF5 format.
Creates an HDF5 file with dataset containing bin edges and histogram values, along with attributes for region metadata.
- Parameters:
path (pathlib.Path) – Path to save the HDF5 file
- can_export_as() bool[source]
Check if the current image can be exported.
- Returns:
True if the image can be exported, False otherwise
- Return type:
bool
- default_file_name() str[source]
Get the default file name for saving region data.
- Returns:
Default file name based on region name
- Return type:
str
- export_to_path(path: Path) None[source]
Export the current view to the specified path.
- Parameters:
path (Path) – The file path where the export will be saved
- get_export_specs() list[ExportSpec][source]
Get the list of available export specifications for the image.
- Returns:
List of export specifications or empty list if no image data exists
- Return type:
list[ExportSpec]
- get_save_specs() list[SaveSpec][source]
Get the available save specifications for this region window controller.
- Returns:
List of save specifications
- Return type:
list[SaveSpec]
- on_view_closed() None[source]
Handle view closure event.
Emits a signal indicating that the region should be removed.
- save_region_data(path: Path) None[source]
Save region data to the specified path.
Dispatches to appropriate save methods based on file extension.
- Parameters:
path (pathlib.Path) – Path to save the data
- Raises:
Exception – If saving fails
- set_view(view: RegionSubWindow) None[source]
Set the view associated with this controller.
Connects the view’s context menu signal to the controller’s signal.
- Parameters:
view (T_SubWindow) – The view to associate with this controller
- radioviz.tools.region_tool.assume_complete_region(region: RegionData) RegionDataCompleteProtocol[source]
Treat a region as complete without runtime checks.
- Parameters:
region (RegionData) – The region data assumed to be complete
- Returns:
A view of the region with non-optional histogram arrays
- Return type:
- radioviz.tools.region_tool.draw_highlight_region_overlay(overlay: OverlayModel, axes: Axes) list[Artist][source]
Draw a highlighted region overlay.
Draws a highlighted version of the region with special styling for highlighting.
- Parameters:
overlay (OverlayModel) – The overlay model containing drawing information
axes (Axes) – Matplotlib axes to draw on
- Returns:
List of artists created
- Return type:
list[Artist]
- Raises:
TypeError – If overlay type is unknown
- radioviz.tools.region_tool.draw_permanent_region_overlay(overlay: OverlayModel, axes: Axes) list[Artist][source]
Draw a permanent region overlay.
This is a wrapper around draw_region_overlay for permanent overlays.
- Parameters:
overlay (OverlayModel) – The overlay model containing drawing information
axes (Axes) – Matplotlib axes to draw on
- Returns:
List of artists created
- Return type:
list[Artist]
- radioviz.tools.region_tool.draw_region_label(overlay: OverlayModel, axes: Axes) list[Artist][source]
Draw a region label.h5 overlay.
- Parameters:
overlay (OverlayModel) – The overlay model containing label.h5 configuration
axes (Axes) – The matplotlib axes to draw on
- Returns:
List of artists created for the overlay
- Return type:
list[Artist]
- radioviz.tools.region_tool.draw_region_overlay(overlay: OverlayModel, axes: Axes) list[Artist][source]
Draw a region overlay on matplotlib axes.
Creates and adds a patch to the axes based on the overlay type and geometry.
- Parameters:
overlay (OverlayModel) – The overlay model containing drawing information
axes (Axes) – Matplotlib axes to draw on
- Returns:
List of artists created
- Return type:
list[Artist]
- Raises:
TypeError – If overlay type is unknown
- radioviz.tools.region_tool.draw_temporary_region_overlay(overlay: OverlayModel, axes: Axes) list[Artist][source]
Draw a temporary region overlay.
Draws a dashed line representation of a temporary selection.
- Parameters:
overlay (OverlayModel) – The overlay model containing drawing information
axes (Axes) – Matplotlib axes to draw on
- Returns:
List of artists created
- Return type:
list[Artist]
- radioviz.tools.region_tool.RegionStore
Type alias for ItemStore with RegionData elements.
alias of
ItemStore[RegionData]
- radioviz.tools.region_tool.region_type_icons = {ROIType.CIRCLE: 'tabler:player-record', ROIType.ELLIPSE: 'tabler:oval-vertical', ROIType.POLYGON: 'tabler:polygon', ROIType.RECTANGLE: 'tabler:rectangle'}
Dictionary mapping region types to their corresponding icons.