erlab.interactive.imagetool.viewer¶
Provides core functionality of ImageTool.
This module contains ImageSlicerArea which handles the core functionality of
ImageTool, including the slicing and plotting of data.
Functions
|
Sync decorated methods across multiple |
|
Log history before calling the decorated method. |
|
Ignore history changes made within the decorated method. |
Classes
|
A dictionary containing the colormap state of an |
|
An interactive tool based on |
|
A dictionary containing the state of an |
|
A dictionary containing the state of a |
|
Internal class for handling linked |
- class erlab.interactive.imagetool.viewer.ImageSlicerArea(parent, data, cmap=None, gamma=None, high_contrast=False, zero_centered=False, vmin=None, vmax=None, rad2deg=False, *, transpose=False, bench=False, state=None, file_path=None, load_func=None, auto_compute=True, image_cls=None, plotdata_cls=None, _in_manager=False)[source]¶
Bases:
QWidgetAn interactive tool based on
pyqtgraphfor exploring 3D data.- Parameters:
parent (
QWidget) – Parent widget.data (
DataArrayorarray-like) – Data to display. The data must have 2 to 4 dimensions.cmap (
str|ColorMap|None, default:None) – Default colormap of the data.gamma (
float, optional) – Default power law normalization of the colormap.high_contrast (
bool, default:False) – IfTrue, the colormap is displayed in high contrast mode. This changes the behavior of the exponent scaling of the colormap. Seeerlab.plotting.colorsfor a detailed explanation of the difference.zero_centered (
bool, default:False) – IfTrue, the normalization is applied symmetrically from the midpoint of the colormap.vmin (
float|None, default:None) – Minimum value of the colormap.vmax (
float|None, default:None) – Maximum value of the colormap.rad2deg (
bool|Iterable[str], default:False) – IfTrueanddatais notNone, converts some known angle coordinates to degrees. If an iterable of strings is given, only the coordinates that correspond to the given strings are converted.transpose (
bool, default:False) – IfTrue, the main image is transposed before being displayed.bench (
bool, default:False) – Prints the fps on Ctrl + drag for debugging purposes.state (
ImageSlicerState|None, default:None) – Initial state containing the settings and cursor position.file_path (
str|PathLike|None, default:None) – Path to the file from which the data was loaded. If given, the file path is used to set the window title and when reloading the data. To successfully reload the data,load_funcmust also be provided.load_func (
tuple[Callable[...,Any] |str,dict[str,Any],int|dict[str,Any] |FileDataSelection] |None, default:None) – 3-tuple containing the function, a dictionary of keyword arguments, and the selection of the data variable used when loading the data. The function is called when reloading the data. If using a data loader plugin, the function may be given as a string representing the loader name.
- Signals:
sigDataChanged()
sigCurrentCursorChanged(index)
sigViewOptionChanged()
sigHistoryChanged()
sigWriteHistory()
sigCursorColorsChanged()
sigDataEdited() – Signal to track when the data has been modified by user actions.
sigSourceDataReplaced() – Signal emitted when the underlying source data is replaced or otherwise changed at the source level, such as file open, reload, manager-driven replacement, accepted filters, or in-place console edits.
sigPointValueChanged(value) – Signal emitted when the point value at the current cursor has been computed. Only emitted for dask-backed data.
sigCursorCountChanged(n_cursors) – Inherited from
erlab.interactive.slicer.ArraySlicer.sigIndexChanged(cursor, axes) – Inherited from
erlab.interactive.slicer.ArraySlicer.sigBinChanged(cursor, axes) – Inherited from
erlab.interactive.slicer.ArraySlicer.sigShapeChanged() – Inherited from
erlab.interactive.slicer.ArraySlicer.sigTwinChanged() – Inherited from
erlab.interactive.slicer.ArraySlicer.
- property provenance_spec: ToolProvenanceSpec | None¶
Canonical replay provenance for the current ImageTool data.
- property COLORS: tuple[QColor, ...]¶
PySide6.QtGui.QColors for multiple cursors.
-
TWIN_COLORS:
tuple[QColor,...] = (<PyQt6.QtGui.QColor object>, <PyQt6.QtGui.QColor object>, <PyQt6.QtGui.QColor object>, <PyQt6.QtGui.QColor object>, <PyQt6.QtGui.QColor object>)¶ PySide6.QtGui.QColors for twin plots.
- property display_name: str¶
Generate a display name for the slicer.
Depending on the source of the data and the ‘name’ attribute of the underlying DataArray, the display name is generated differently.
If nothing can be inferred, an empty string is returned.
- property colormap_properties: ColorMapState¶
- property state: ImageSlicerState¶
- property main_image: ItoolPlotItem¶
Return the main PlotItem.
- property array_slicer: ArraySlicer¶
- displayed_live_source_spec(base_spec)[source]¶
Return live source provenance including the accepted display filter.
- go_to_history_index(index)[source]¶
Go to a specific index in the history.
- Parameters:
index (
int) – Index in the history to go to. 0 corresponds to the current state. Positive indices point to the future, while negative indices point to the past.
- refresh_actions_enabled()[source]¶
Refresh the enabled state of miscellaneous actions.
This slot is triggered from the parent widget when the menubar containing the actions is about to be shown.
- set_data(data, rad2deg=False, file_path=None, load_func=None, auto_compute=True, *, source_replaced=False)[source]¶
Set the data to be displayed.
- Parameters:
data (
DataArray|ndarray[tuple[Any,...],dtype[TypeVar(_ScalarT, bound=generic)]]) – The data to be displayed. If axarray.DataArrayis given, the dimensions and coordinates are used to determine the axes of the plots. If axarray.Datasetis given, the first data variable is used. If anumpy.ndarrayis given, it is converted to axarray.DataArraywith default dimensions.rad2deg (
bool|Iterable[str], default:False) – IfTrue, converts coords along dimensions that have angle-like names to degrees. If an iterable of strings is given, coordinates for dimensions that correspond to the given strings are converted.file_path (
str|PathLike|None, default:None) – Path to the file from which the data was loaded. If given, the file path is used to set the window title and when reloading the data. To successfully reload the data,load_funcmust also be provided.load_func (
tuple[Callable[...,Any] |str,dict[str,Any],int|dict[str,Any] |FileDataSelection] |None, default:None) – 3-tuple containing the function, a dictionary of keyword arguments, and the selection of the data variable used when loading the data. The function is called when reloading the data. If using a data loader plugin, the function may be given as a string representing the loader name.auto_compute (
bool, default:True) – IfTrueand the data is dask-backed, automatically compute the data if its size is below the threshold defined in options.
- replace_source_data(data, rad2deg=False, file_path=None, load_func=None, auto_compute=True, *, emit_edited=False)[source]¶
Replace the underlying source data and notify bound child tools.
Parameters are the same as
set_data(), with the addition ofemit_editedto indicate that the replacement should also be treated as a user edit for watcher propagation.
- property reloadable: bool¶
Check if the displayed data can be reloaded.
Direct file-backed windows reload from their stored loader. Detached file-rooted provenance reloads by replaying its self-contained code. Managed script-derived ImageTools reload through the manager from their recorded inputs.
- reload()[source]¶
Reload the displayed data from recorded source information.
Silently fails if the data cannot be reloaded. If an error occurs while reloading the data, a message is shown to the user.
See also
- update_values(values, update=True)[source]¶
Update only the values of the data.
The coords and shape of the data array are not changed.
- Parameters:
values (
ndarray[tuple[Any,...],dtype[TypeVar(_ScalarT, bound=generic)]] |DataArray) – The new values to be set. If axarray.DataArrayis given, the dimensions must match the current data array. If anumpy.ndarrayis given, the shape must match the current data array. Note that if the user has transposed the current data array, passing anumpy.ndarraywith the original shape will fail.update (
bool, default:True) – IfTrue, the plots are updated after setting the new values.
Note
This method only checks for matching dimension name and shape, and does not check for equal coordinate values.
- displayed_provenance_spec(base_spec=None)[source]¶
Return provenance for the currently displayed data values.
- apply_func(func, update=True, *, operation=None, emit_edited=False, preview=True)[source]¶
Apply a function to the data.
The function must accept the data as the first argument and return a new DataArray. The returned DataArray must have the same dimensions and coordinates as the original data.
This preview-only action is not recorded in the history, and the source data remains unchanged. Accepted filters must use
apply_filter_operation(). Only one preview function can be applied at a time.- Parameters:
func (
Callable[[DataArray],DataArray] |None) – The function to apply to the data. if None, the data is restored.update (
bool, default:True) – IfTrue, the plots are updated after setting the new values.operation (
ToolProvenanceOperation|None, default:None) – Deprecated. Accepted filters must useapply_filter_operation().emit_edited (
bool, default:False) – IfTrue, emit edit and source-change signals after updating the preview.preview (
bool, default:True) – Must beTrue. The argument is kept for existing internal callers.
- apply_filter_operation(operation, update=True, *, emit_edited=False, preview=False)[source]¶
Apply an operation-backed reversible display filter.
- set_manual_limits(manual_limits)[source]¶
Set manual limits for the axes.
Replaces the current manual limits with the given limits dictionary and updates all child axes accordingly.
- propagate_limit_change(axes)[source]¶
Propagate manual limits changes to all linked slicers.
Called when the limits of a child axes are changed by the user.
This method first propagates the limits to all linked slicers (if any), and then triggers the update of the manual limits for all other axes. This ensures that all plots share the same limits for a given dimension.
- property watched_data_name: str | None¶
Get the name of the watched data variable.
Only applicable if in an ImageTool Manager and the data is linked to a watched variable in a notebook. Returns None if otherwise.
- make_cursors(colors, *, update=True)[source]¶
Create cursors with the specified colors.
Used when restoring the state of the slicer. All existing cursors are removed.
- set_colormap(cmap=None, gamma=None, reverse=None, high_contrast=None, zero_centered=None, levels_locked=None, levels=None, update=True)[source]¶
- add_tool_window(widget, update_title=True, transfer_to_manager=True)[source]¶
Save a reference to an additional window widget.
This is mainly used for handling tool windows such as goldtool and dtool.
The tool window is cleared from memory immediately when it is closed. Closing the main window will close all associated tool windows.
Only pass widgets that are not associated with a parent widget.
If the parent ImageTool is in the manager, the widget is transferred to the manager instead
- Parameters:
widget (
QWidget) – The widget to add.update_title (
bool, default:True) – IfTrue, the window title is updated to include the parent title. IfFalse, the window title is not changed.transfer_to_manager (
bool, default:True) – IfTrue, the ownership of the widget is transferred to the manager if the parent ImageTool is in the manager. UseFalsefor dialog windows that should not be managed by the manager.
- adjust_layout(r=(1.2, 1.5, 3.0, 1.0))[source]¶
Determine the padding and aspect ratios.
- Parameters:
Notes
Axes indices and layout parameters.
┌───────────┬───────────┐ r[0] │ 1 │ 6 │ │ ├───────────┤ ├───────────┤ 3 │ r[1] │ 4 ├───────────┤ │ │ 7 │ │───────────┼───────┬───┤ │ │ │ │ r[2] │ 0 │ 5 │ 2 │ │ │ │ │ └───────────┴───────┴───┘ r[3] * r[2]