erlab.interactive.imagetool.core¶
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 interactive tool based on |
A dictionary containing the state of an |
|
|
|
|
|
|
A subclass of |
|
|
|
Parent class for sliced data. |
|
|
|
Display a 2D slice of data as an image. |
|
Display a 1D slice of data in a plot. |
|
A subclass of |
A dictionary containing the state of a |
|
|
Internal class for handling linked |
- class erlab.interactive.imagetool.core.ColorMapState[source]¶
Bases:
TypedDictA dictionary containing the colormap state of an
ImageSlicerAreainstance.
- class erlab.interactive.imagetool.core.PlotItemState[source]¶
Bases:
TypedDictA dictionary containing the state of a
PlotIteminstance.
- class erlab.interactive.imagetool.core.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]¶
- splitter_sizes: typing.NotRequired[list[list[int]]]¶
- plotitem_states: typing.NotRequired[list[PlotItemState]]¶
- class erlab.interactive.imagetool.core.ItoolGraphicsLayoutWidget(slicer_area, display_axis, axis_enabled, image=False, **item_kw)[source]¶
Bases:
PlotWidget
- erlab.interactive.imagetool.core.suppress_history(method=None)[source]¶
Ignore history changes made within the decorated method.
- erlab.interactive.imagetool.core.record_history(method=None)[source]¶
Log history before calling the decorated method.
- erlab.interactive.imagetool.core.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.core.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.core.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, image_cls=None, plotdata_cls=None, _in_manager=False, _disable_reload=False)[source]¶
Bases:
QWidgetA 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) – If the data has been loaded from a file, the path to the file. This is used to set the window title.
- Signals:
sigDataChanged()
sigCurrentCursorChanged(index)
sigViewOptionChanged()
sigHistoryChanged()
sigWriteHistory()
sigCursorColorsChanged()
sigDataEdited() – Signal to track when the data has been modified by user actions.
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 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 slices: tuple[ItoolPlotItem, ...]¶
- property profiles: tuple[ItoolPlotItem, ...]¶
- property main_image: ItoolPlotItem¶
Return the main PlotItem.
- property images: tuple[ItoolPlotItem, ...]¶
- property axes: tuple[ItoolPlotItem, ...]¶
Currently valid subset of self._plots.
- property array_slicer: ArraySlicer¶
- 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, auto_compute=True)[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.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.
- 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)[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]
- class erlab.interactive.imagetool.core.ItoolCursorLine(*args, **kargs)[source]¶
Bases:
InfiniteLineA subclass of
pyqtgraph.InfiniteLineused in ImageTool.- property plotItem: ItoolPlotItem¶
- class erlab.interactive.imagetool.core.ItoolCursorSpan(*args, **kargs)[source]¶
Bases:
LinearRegionItem
- class erlab.interactive.imagetool.core.ItoolDisplayObject(axes, cursor=None)[source]¶
Bases:
objectParent class for sliced data.
Stores the axes and cursor index for the object, and retrieves the sliced data from
erlab.interactive.imagetool.slicer.ArraySlicerwhen needed.- property display_axis¶
- property slicer_area: ImageSlicerArea¶
- property array_slicer: ArraySlicer¶
- property cursor_index¶
- class erlab.interactive.imagetool.core.ItoolPlotDataItem(axes, cursor=None, is_vertical=False, **kargs)[source]¶
Bases:
ItoolDisplayObject,PlotDataItemDisplay a 1D slice of data in a plot.
- class erlab.interactive.imagetool.core.ItoolImageItem(axes, cursor=None, **kargs)[source]¶
Bases:
ItoolDisplayObject,BetterImageItemDisplay a 2D slice of data as an image.
- class erlab.interactive.imagetool.core.ItoolPlotItem(slicer_area, display_axis, axis_enabled, image=False, image_cls=None, plotdata_cls=None, **item_kw)[source]¶
Bases:
PlotItemA subclass of
pyqtgraph.PlotItemused in ImageTool.This class tracks axes and cursors for the data displayed in the plot, and provides context menu actions for interacting with the data.
- property axis_dims: tuple[str | None, str | None]¶
Get the names of the data dimensions plotted on each axis.
Removes ‘_idx’ suffix for non-uniform axes.
- property axis_dims_uniform: tuple[str | None, str | None]¶
Get the names of the data dimensions plotted on each axis.
Retains ‘_idx’ suffix for non-uniform axes.
- property is_view_cropped: bool¶
Whether the current view limits are smaller than the full data range.
- property current_data: DataArray¶
Data in the current plot item, optionally cropped to view limits.
If accessed while the Alt (Option) key is pressed, the data is cropped to the current axes view limits.
- property selection_code: str¶
Get the selection code for the data.
Returns a string that looks like
.sel(...)or.qsel(...)that selects the current slice of data based on the current cursor location and bin size.
- get_selection_code(placeholder='data')[source]¶
Get selection code for the current cursor and display axis.
Adds a placeholder data name as a prefix to the selection code returned by
selection_code. If the data is linked to a watched variable in a notebook through the ImageTool manager, the variable name in the notebook is used instead.- Parameters:
placeholder (
str, optional) – Name to fall back to if the data is not linked to a watched variable in a notebook. By default, uses “data”.
- normalize_to_current_view()[source]¶
Adjust color limits to the currently visible area.
Only available for image plots.
Sets the color limits of the slicer area to the min and max of the currently visible area of this image (similar to AdjustCT in ImageTool).
- range_changed_manually()[source]¶
Propagate manual range changes to other plots.
This slot propagates the limit change to related other plots in the same slicer area, and to other linked slicer areas.
- refresh_manual_range()[source]¶
Store manual limit changes in the parent slicer area.
This slot ensures that the manual limits stored in the parent slicer area are always up to date with the current view range.
When a user manually changes the view range, this slot is called before
range_changed_manuallyis called.
- property slicer_area: ImageSlicerArea¶
- property array_slicer: ArraySlicer¶
- class erlab.interactive.imagetool.core.ItoolColorBarItem(slicer_area, **kwargs)[source]¶
Bases:
BetterColorBarItem- property slicer_area: ImageSlicerArea¶
- property images¶
- property primary_image¶
- class erlab.interactive.imagetool.core.ItoolColorBar(slicer_area, **cbar_kw)[source]¶
Bases:
PlotWidget- property cb: ItoolColorBarItem¶