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 |
|
A dictionary containing the state of rotation guidelines. |
|
|
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.ColorMapState[source]¶
Bases:
TypedDictA dictionary containing the colormap state of an
ImageSlicerAreainstance.
- class erlab.interactive.imagetool.viewer.GuidelineState[source]¶
Bases:
TypedDictA dictionary containing the state of rotation guidelines.
- class erlab.interactive.imagetool.viewer.PlotItemState[source]¶
Bases:
TypedDictA dictionary containing the state of a
PlotIteminstance.-
guideline_state:
NotRequired[GuidelineState]¶
-
guideline_state:
- class erlab.interactive.imagetool.viewer.ImageSlicerState[source]¶
Bases:
TypedDictA dictionary containing the state of an
ImageSlicerAreainstance.- color: ColorMapState¶
- slice: ArraySlicerState¶
- current_cursor: int¶
- manual_limits: dict[str, list[float]]¶
- cursor_colors: list[str]¶
- file_path: typing.NotRequired[str | None]¶
- load_func: typing.NotRequired[tuple[str, dict[str, typing.Any], int] | None]¶
- splitter_sizes: typing.NotRequired[list[list[int]]]¶
- plotitem_states: typing.NotRequired[list[PlotItemState]]¶
- erlab.interactive.imagetool.viewer.suppress_history(method=None)[source]¶
Ignore history changes made within the decorated method.
- erlab.interactive.imagetool.viewer.record_history(method=None)[source]¶
Log history before calling the decorated method.
- erlab.interactive.imagetool.viewer.link_slicer(func=None, *, indices=False, steps=False, color=False)[source]¶
Sync decorated methods across multiple
ImageSlicerAreainstances.- Parameters:
func (
Callable|None, default:None) – The method to sync across multiple instances ofImageSlicerArea.indices (
bool, default:False) – IfTrue, the input argument namedvaluegiven tofuncare interpreted as indices, and will be converted to appropriate values for other instances ofImageSlicerArea. The behavior of this conversion is determined bysteps. IfTrue, An input argument namedaxisof type integer must be present in the decorated method to determine the axis along which the index is to be changed.steps (
bool, default:False) – IfFalse, considersvalueas an absolute index. IfTrue, considersvalueas a relative value such as the number of steps or bins. See the implementation ofSlicerLinkProxyfor more information.color (
bool, default:False) – Boolean whether the decorated method is related to visualization, such as colormap control.
- class erlab.interactive.imagetool.viewer.SlicerLinkProxy(*slicers, link_colors=True)[source]¶
Bases:
objectInternal class for handling linked
ImageSlicerAreas.- Parameters:
*slicers (
ImageSlicerArea) – The slicers to link.link_colors (
bool, default:True) – Whether to sync color related changes, by defaultTrue.
- sync(source, funcname, arguments, indices, steps, color)[source]¶
Propagate changes across multiple
ImageSlicerAreas.This method is invoked every time a method decorated with
link_slicer()in a linkedImageSlicerAreais called.- Parameters:
source (
ImageSlicerArea) – Instance ofImageSlicerAreacorresponding to the called method.funcname (
str) – Name of the called method.arguments (
dict[str,Any]) – Arguments included in the function call.indices (
bool) – Arguments given to the decorator. Seelink_slicer()steps (
bool) – Arguments given to the decorator. Seelink_slicer()color (
bool) – Arguments given to the decorator. Seelink_slicer()
- 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, 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|str,dict[str,Any],int] |None, default:None) – 3-tuple containing the function, a dictionary of keyword arguments, and the index 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 as a string representing the loader name. If the function always returns a single DataArray, the last element should be 0.
- 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, 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¶
- 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|str,dict[str,Any],int] |None, default:None) – 3-tuple containing the function, a dictionary of keyword arguments, and the index 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 be given as a string representing the loader name. If the function always returns a single DataArray, the last element should be 0.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 data can be reloaded from the file.
The data can be reloaded if the data was loaded from a file that still exists and the data loader name is stored in the data attributes.
- reload()[source]¶
Reload the data from the file it was loaded from, using the same loader.
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.
- apply_func(func, update=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 action is not recorded in the history, and the data is not affected. Only one function can be applied at a time.
- 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]