erlab.interactive.utilities

Various helper functions and extensions to pyqtgraph.

Functions

array_rect(data)

copy_to_clipboard(content)

Copy content to the clipboard.

format_kwargs(d)

Format a dictionary of keyword arguments for a function call.

gen_function_code([copy])

Copy the Python code for function calls to the clipboard.

gen_single_function_code(funcname, *args, ...)

Generate the string for a Python function call.

parse_data(data)

Classes

AnalysisWidgetBase([orientation, num_ax, ...])

AnalysisWidgetBase.

AnalysisWindow(data[, title, layout, ...])

BetterAxisItem(*args, **kwargs)

BetterSpinBox(*args[, integer, compact, ...])

An improved spinbox.

ComparisonWidget(*args, **kwargs)

DictMenuBar([parent])

FittingParameterWidget(name[, spin_kw, ...])

ParameterGroup([widgets, ncols, groupbox_kw])

Easy creation of groupboxes with multiple varying parameters.

ROIControls(roi[, spinbox_kw])

xImageItem([image])

pyqtgraph.ImageItem with additional functionality.

class erlab.interactive.utilities.AnalysisWidgetBase(orientation='vertical', num_ax=2, link='both', cut_to_data='none', **kwargs)[source]

Bases: GraphicsLayoutWidget

AnalysisWidgetBase.

Parameters:
  • orientation (Literal['vertical', 'horizontal']) – Sets the orientation of the plots, by default “vertical”

  • num_ax (int) – Sets the number of axes.

  • link (Literal['x', 'y', 'both', 'none']) – Link axes, by default “both”

  • cut_to_data (Literal['in', 'out', 'both', 'none']) – Whether to remove outliers by adjusting color levels, by default “none”

add_roi(i)[source]
get_axis_pos(ax)[source]
get_hist_pos(ax)[source]
initialize_layout(nax)[source]
setStretchFactor(i, factor)[source]
setStretchFactors(factors)[source]
set_input(data=None)[source]
class erlab.interactive.utilities.AnalysisWindow(data, title=None, layout='horizontal', data_is_input=True, analysisWidget=None, *args, **kwargs)[source]

Bases: QMainWindow

addParameterGroup(*args, **kwargs)[source]
closeEvent(event)[source]
class erlab.interactive.utilities.BetterAxisItem(*args, **kwargs)[source]

Bases: AxisItem

labelString()[source]
setLabel(text=None, units=None, unitPrefix=None, **args)[source]
tickStrings(values, scale, spacing)[source]
updateAutoSIPrefix()[source]
class erlab.interactive.utilities.BetterSpinBox(*args, integer=False, compact=True, discrete=False, decimals=3, significant=False, scientific=False, value=0.0, **kwargs)[source]

Bases: QAbstractSpinBox

An improved spinbox.

Signals:
  • valueChanged – Emitted when the value is changed.

  • textChanged – Emitted when the text is changed.

Parameters:
  • integer (bool) – If True, the spinbox will only display integer values.

  • compact (bool) – Whether to reduce the height of the spinbox.

  • discrete (bool) –

    If True the spinbox will only step to pre-determined discrete values.

    If False, the spinbox will just add or subtract the predetermined increment when increasing or decreasing the step.

  • decimals (int) – The precision of the spinbox. See the significant argument for the meaning. When integer is True, this argument is ignored.

  • significant (bool) –

    If True, decimals will specify the total number of significant digits, before or after the decimal point, ignoring leading zeros.

    If False, decimals will specify the total number of digits after the decimal point, including leading zeros.

    When integer or scientific is True, this argument is ignored.

  • scientific (bool) – Whether to print in scientific notation.

  • value (float) – Initial value of the spinbox.

decimals()[source]
editingFinishedEvent()[source]
fixup(input)[source]
keyPressEvent(evt)[source]
maximum()[source]
minimum()[source]
setDecimals(decimals)[source]
setMaximum(mx)[source]
setMinimum(mn)[source]
setRange(mn, mx)[source]
setSingleStep(step)[source]
setValue(val)[source]
singleStep()[source]
stepBy(steps)[source]
stepEnabled()[source]
text()[source]
textFromValue(value)[source]
validate(strn, pos)[source]
value()[source]
valueFromText(text)[source]
widthFromText(text)[source]
widthFromValue(value)[source]
class erlab.interactive.utilities.DictMenuBar(parent=None, **kwargs)[source]

Bases: QMenuBar

add_items(**kwargs)[source]
static parse_action(actopts)[source]
parse_menu(parent, **kwargs)[source]
class erlab.interactive.utilities.ParameterGroup(widgets=None, ncols=1, groupbox_kw=None, **widgets_kwargs)[source]

Bases: QGroupBox

Easy creation of groupboxes with multiple varying parameters.

Can be used in many different interactive tools for dynamic data analysis.

Parameters:
Signals:

sigParameterChanged(dict)

Examples

>>> ParameterGroup(
    **{
        "a": QtWidgets.QDoubleSpinBox(range=(0, 1), singleStep=0.01, value=0.2),
        "b": dict(qwtype="dblspin", range=(0, 2), singleStep=0.04),
        "c": QtWidgets.QSlider(range=(0, 10000))
    }
)
static getParameterWidget(qwtype=None, **kwargs)[source]

Initialize the PySide6.QtWidgets.QWidget corresponding to qwtype.

Parameters:

qwtype (Literal['spin', 'dblspin', 'btspin', 'slider', 'chkbox', 'pushbtn', 'chkpushbtn', 'combobox', 'fitparam'] | None) – Type of the widget, must a key of ParameterGroup.VALID_QWTYPE.

global_connect()[source]
set_values(**kwargs)[source]
widget_change_signal(widget)[source]
widget_value(widget)[source]
widgets_of_type(widgetclass)[source]
VALID_QWTYPE: Mapping[str, type[QWidget]] = mappingproxy({'spin': <class 'PyQt6.QtWidgets.QSpinBox'>, 'dblspin': <class 'PyQt6.QtWidgets.QDoubleSpinBox'>, 'btspin': <class 'erlab.interactive.utilities.BetterSpinBox'>, 'slider': <class 'PyQt6.QtWidgets.QSlider'>, 'chkbox': <class 'PyQt6.QtWidgets.QCheckBox'>, 'pushbtn': <class 'PyQt6.QtWidgets.QPushButton'>, 'chkpushbtn': <class 'PyQt6.QtWidgets.QPushButton'>, 'combobox': <class 'PyQt6.QtWidgets.QComboBox'>, 'fitparam': <class 'erlab.interactive.utilities.FittingParameterWidget'>})
property values: dict[str, float | int | bool]
class erlab.interactive.utilities.xImageItem(image=None, **kwargs)[source]

Bases: BetterImageItem

pyqtgraph.ImageItem with additional functionality.

This class provides xarray.DataArray support and auto limits based on histogram analysis.

Parameters:
  • image (npt.NDArray | None) – Image data.

  • **kwargs – Additional arguments to pyqtgraph.ImageItem.

Signals:

sigToleranceChanged()

data_cut_levels(data=None)[source]

Return appropriate levels estimated from the data.

getMenu()[source]
getPlotItem()[source]
open_itool()[source]
setDataArray(data, update_labels=True, **kargs)[source]
setImage(image=None, autoLevels=None, cut_to_data=False, **kargs)[source]
set_cut_tolerance(cut_tolerance)[source]
erlab.interactive.utilities.copy_to_clipboard(content)[source]

Copy content to the clipboard.

Parameters:

content (str | list[str]) – The content to be copied.

Returns:

The copied content.

Return type:

str

erlab.interactive.utilities.gen_function_code(copy=True, **kwargs)[source]

Copy the Python code for function calls to the clipboard.

The result can be copied to your clipboard in a form that can be pasted into an interactive Python session or Jupyter notebook cell.

Parameters:
  • copy (bool) – If True, the code string is copied.

  • **kwargs – Dictionary where the keys are the string of the function call and the values are a list of function arguments. The last item, if a dictionary, is interpreted as keyword arguments.

erlab.interactive.utilities.gen_single_function_code(funcname, *args, **kwargs)[source]

Generate the string for a Python function call.

The first argument is the name of the function, and subsequent arguments are passed as positional arguments. Keyword arguments are also supported. For strings in arguments and keyword arguments, surrounding the string with vertical bars (|) will prevent the string from being quoted.

Parameters:
  • funcname (str) – Name of the function.

  • *args (tuple) – Mandatory arguments passed onto the function.

  • **kwargs – Keyword arguments passed onto the function.

Returns:

code – generated code.

Return type:

str

erlab.interactive.utilities.parse_data(data)[source]