image_panels.py

Module implementing plots and interactive elements of the DataViewers.

class image_panels.Sliders[source]

Object defining draggable lines allowing user to choose exact position of a slice.

__init__(image_plot, pos=(0, 0), mainplot=True, orientation='horizontal')[source]

Initialize two draggable sliders.

Parameters:
  • image_plot (ImagePlot) – ImagePlot on which sliders are displayed

  • pos (Iterable) – initial position of the sliders

  • mainplot (bool) – if True register signals for both sliders. Different behavior is expected for ImagePlot s being horizontal and vertical cuts

  • orientation (str) –

    relative orientation of the image, when vertical the actual orientation of sliders is flipped. Default is horizontal.

    Note

    Actually, it’s easier to define sliders in coordinate system of the data, where horizontal always corresponds to slicing along momentum.

Return type:

None

add_to(widget)[source]

Add these sliders to a pyqtgraph widget.

Parameters:

widget (Any) – widget to which sliders are added

Return type:

None

remove_from(widget)[source]

Remove these sliders from a pyqtgraph widget.

Parameters:

widget (Any) – widget to which sliders are removed

Return type:

None

set_color(linecolor=(255, 255, 0, 255), hover_color=(195, 155, 0, 255))[source]

Set the color and hover color of both sliders that make up. The arguments can be any pyqtgraph compatible color specifiers.

Parameters:
  • linecolor (Any) – can be any pyqtgraph compatible color specifiers

  • hover_color (Any) – can be any pyqtgraph compatible color specifiers

Return type:

None

set_movable(movable=True)[source]

Define whether these sliders can be dragged by the mouse or not.

Parameters:

movable (bool) – if True, make sliders movable

Return type:

None

update_position_h()[source]

Update position of the horizontal slider.

Return type:

None

update_position_v()[source]

Update position of the vertical slider.

Return type:

None

on_dragged_h()[source]

Callback for dragging horizontal slider changing value of the connected CustomTracedVariable.

on_dragged_v()[source]

Callback for dragging vertical slider changing value of the connected CustomTracedVariable.

Return type:

None

set_bounds(xmin, xmax, ymin, ymax)[source]

Set boundaries within which sliders can be dragged.

Parameters:
  • xmin (int) – lowest value along horizontal direction

  • xmax (int) – highest value along horizontal direction

  • ymin (int) – lowest value along vertical direction

  • ymax (int) – highest value along vertical direction

Return type:

None

class image_panels.ImagePlot[source]

Object displaying 2D color-scaled data using different colormaps. It treats data as a regular rectangular images, which allows for time efficient slicing and updating displayed cuts. Inherits from pyqtgraph.PlotWidget which gives access to additional plotty features like displaying custom scales instead of just pixels.

__init__(image=None, background=(64, 64, 64), name=None, mainplot=True, orientation='horizontal', **kwargs)[source]

Initialize color-scaled plot.

Parameters:
  • image (ndarray | None) – 2D array with data

  • background (Any) – color of the background, can be any pyqtgraph compatible color specifier

  • mainplot (bool) – specifies behavior of the draggable sliders. See Sliders for more details

  • orientation (str) – orientation of the image. Default is ‘horizontal

  • kwargs (dict) – kwargs passed to parent pg.PlotWidget

  • name (str | None)

Return type:

None

update_allowed_values()[source]

Update the allowed values of the sliders. This assumes that the displayed image is in pixel coordinates and sets the allowed values to the available pixels.

Return type:

None

set_bounds(xmin, xmax, ymin, ymax)[source]

Set both, the displayed area of the axes and the range in which sliders can be dragged.

Parameters:
  • xmin (int) – lowest value along horizontal direction

  • xmax (int) – highest value along horizontal direction

  • ymin (int) – lowest value along vertical direction

  • ymax (int) – highest value along vertical direction

Return type:

None

orient()[source]

Configure plot’s layout depending on its orientation.

Return type:

None

remove_image()[source]

Remove currently displayed image.

Return type:

None

set_image(image, emit=True, *args, **kwargs)[source]

Set/update displayed image. Also make sure the old one has been removed.

Parameters:
  • image (ndarray) – 2D array with data

  • emit (bool) – if True, emmit signal that image has been changed

  • args (dict) – additional arguments for a parent ImageItem

  • kwargs (dict) – additional keyword arguments for a parent ImageItem

Return type:

None

set_xscale(scale)[source]

Set custom values of the xscale.

Parameters:

scale (ndarray) – 1D array with axis values

Return type:

None

set_yscale(scale)[source]

Set custom values of the yscale.

Parameters:

scale (ndarray) – 1D array with axis values

Return type:

None

set_ticks(min_val, max_val, axis)[source]

Set customized axis’ ticks to reflect the dimensions of the physical data.

Parameters:
  • min_val (float) – lowest axis’ value

  • max_val (float) – highest axis’ value

  • axis (str) – concerned axis, can be [bottom, left, etc]

Return type:

None

set_secondary_axis(min_val, max_val)[source]

Set/update a second x-axis on the top.

Parameters:
  • min_val (float) – lowest axis’ value

  • max_val (float) – highest axis’ value

Return type:

None

get_limits()[source]

Get limits of the image data.

Returns:

list of lists in a format: [[x_min, x_max], [y_min, y_max]]

Return type:

list

fix_viewrange()[source]

Prevent zooming out by fixing the limits of the QViewBox.

Return type:

None

add_binning_lines(pos, width, orientation='horizontal')[source]

Add not-movable lines around the specified sliders. The lines indicate integration area for a corresponding cut.

Parameters:
  • pos (int) – position of the slider

  • width (int) – number of left and right steps from the slider position

  • orientation (str) – orientation of the slider

Return type:

None

remove_binning_lines(orientation='horizontal')[source]

Remove binning lines from the ImagePlot.

Parameters:

orientation (str) – orientation of the slider

Return type:

None

register_momentum_slider(traced_variable)[source]

Register vertical slider draggable along momentum in the cut plots.

Parameters:

traced_variable (TracedVariable) – connected traced variable

Return type:

None

set_position()[source]

Set the position of the momentum sliders whenever the value of connected CustomTracedVariable has changed.

Return type:

None

on_allowed_values_change()[source]

Set new momentum slider bounds after changing allowed values of the connected CustomTracedVariable, e.g. after setting binning lines.

Return type:

None

class image_panels.CurvePlot[source]

Object displaying basic 1D curves with a draggable slider.

__init__(background=(64, 64, 64), name=None, orientation='horizontal', slider_width=1, z_plot=False, **kwargs)[source]

Initialize simple 1D plot panel.

Parameters:
  • background (Any) – color of the background, can be any pyqtgraph compatible color specifier

  • orientation (str) – orientation of the plot. Default is ‘horizontal

  • slider_width (int) – width of the draggable slider

  • z_plot (bool) – if True, plot is a main energy plot of the DataViewer3D GUI

  • kwargs (dict) – kwargs passed to parent PlotWidget

  • name (str | None)

Return type:

None

get_data()[source]

Get the currently displayed data as a tuple of arrays.

Returns:

(x_data, y_data)

Return type:

tuple

orient()[source]

Configure plot’s layout depending on its orientation.

Return type:

None

register_traced_variable(traced_variable)[source]

Register CustomTracedVariable connected to the slider.

Parameters:

traced_variable (TracedVariable)

Return type:

None

on_position_change()[source]

Callback for dragging slider changing value of the connected CustomTracedVariable.

Return type:

None

on_allowed_values_change()[source]

Set new momentum slider bounds after changing allowed values of the connected CustomTracedVariable, e.g. after setting binning lines.

Return type:

None

set_position()[source]

Set the position of the sliders whenever the value of connected CustomTracedVariable has changed.

Return type:

None

add_binning_lines(pos, width)[source]

Add not-movable lines around the specified sliders. The lines indicate integration area for a corresponding cut.

Parameters:
  • pos (int) – position of the slider

  • width (int) – number of left and right steps from the slider position

Return type:

None

remove_binning_lines()[source]

Remove binning lines from the ImagePlot.

Return type:

None

set_bounds(lower, upper)[source]

Set both, the displayed area of the axes and the range in which sliders can be dragged.

Parameters:
  • lower (int) – lowest value

  • upper (int) – highest value

Return type:

None

set_secondary_axis(min_val, max_val)[source]

Set/update a second x-axis on the top.

Parameters:
  • min_val (float) – lowest axis’ value

  • max_val (float) – highest axis’ value

Return type:

None

set_ticks(min_val, max_val, axis)[source]

Set customized axis’ ticks to reflect the dimensions of the physical data.

Parameters:
  • min_val (float) – lowest axis’ value

  • max_val (float) – highest axis’ value

  • axis (str) – concerned axis, can be [bottom, left, etc]

Return type:

None

set_slider_pen(color=None, width=None, hover_color=None)[source]

Set a color and thickness of the slider.

Parameters:
  • color (Any | None) – color of the slider, can be any pyqtgraph compatible color specifier

  • width (int | None) – width of the slider

  • hover_color (Any | None) – hover color of the slider, can be any pyqtgraph compatible color specifier

Return type:

None

class image_panels.CustomTracedVariable[source]

Wrapper around data_slicer.imageplot.TracedVariable (see for more details).

In short, object taking care of traced variables using signalling mechanism.

__init__(value=None, name=None)[source]

Initialize traced variable.

Parameters:
  • value (Any | None) – initial value of the variable

  • name (str | None) – name of the variable

Return type:

None