Skip to main content
`Ctrl`+`K`

# `profile`: Profile tool for PlotWidget

This module provides tools to get profiles on plot data.

It provides:

- `ScatterProfileToolBar`: a QToolBar to handle profile on scatter data

The profile package is divided into several sub-modules.

## `manager` module

This module provides a manager to compute and display profiles.

### `ProfileManager` class

class ProfileManager(parent=None, plot=None, roiManager=None)

  Bases: `QObject`

  Base class for profile management tools

  Parameters:

    - plot – `PlotWidget` on which to operate.

    - plot – `RegionOfInterestManager` on which to operate.

  setSingleProfile(enable)

    Enable or disable the single profile mode.

    In single mode, the manager enforce a single ROI at the same time. A new one will remove the previous one.

    If this mode is not enabled, many ROIs can be created, and many profile windows will be displayed.

  isSingleProfile()

    Returns true if the manager is in a single profile mode.

    Return type:

      bool

  createProfileAction(profileRoiClass, parent=None)

    Create an action from a class of ProfileRoi

    Parameters:

      - profileRoiClass (core.ProfileRoiMixIn) – A class of a profile ROI

      - parent (qt.QObject) – The parent of the created action.

    Return type:

      qt.QAction

  createClearAction(parent)

    Create an action to clean up the plot from the profile ROIs.

    Parameters:

      parent (qt.QObject) – The parent of the created action.

    Return type:

      qt.QAction

  createImageActions(parent)

    Create actions designed for image items. This actions created new ROIs.

    Parameters:

      parent (qt.QObject) – The parent of the created action.

    Return type:

      List[qt.QAction]

  createScatterActions(parent)

    Create actions designed for scatter items. This actions created new ROIs.

    Parameters:

      parent (qt.QObject) – The parent of the created action.

    Return type:

      List[qt.QAction]

  createScatterSliceActions(parent)

    Create actions designed for regular scatter items. This actions created new ROIs.

    This ROIs was designed to use the input data without interpolation, like you could do with an image.

    Parameters:

      parent (qt.QObject) – The parent of the created action.

    Return type:

      List[qt.QAction]

  createImageStackActions(parent)

    Create actions designed for stack image items. This actions created new ROIs.

    This ROIs was designed to create both profile on the displayed image and profile on the full stack (2D result).

    Parameters:

      parent (qt.QObject) – The parent of the created action.

    Return type:

      List[qt.QAction]

  createEditorAction(parent)

    Create an action containing GUI to edit the selected profile ROI.

    Parameters:

      parent (qt.QObject) – The parent of the created action.

    Return type:

      qt.QAction

  setItemType(image=False, scatter=False)

    Set the item type to use and select the active one.

    Parameters:

      - image (bool) – Image item are allowed

      - scatter (bool) – Scatter item are allowed

  setProfileWindowClass(profileWindowClass)

    Set the class which will be instantiated to display profile result.

  setActiveItemTracking(tracking)

    Enable/disable the tracking of the active item of the plot.

    Parameters:

      tracking (bool) – Tracking mode

  setDefaultColorFromCursorColor(enabled)

    Enabled/disable the use of the colormap cursor color to display the ROIs.

    If set, the manager will update the color of the profile ROIs using the current colormap cursor color from the selected item.

  clearProfile()

    Clear the associated ROI profile

  hasPendingOperations()

    Returns true if a thread is still computing or displaying a profile.

    Return type:

      bool

  requestUpdateAllProfile()

    Request to update the profile of all the managed ROIs.

  requestUpdateProfile(profileRoi)

    Request to update a specific profile ROI.

    Parameters:

      profileRoi (ProfileRoiMixIn)

  setPlotItem(item)

    Set the plot item focused by the profile manager.

    Parameters:

      item (Item) – A plot item

  getDefaultColor(item)

    Returns the default ROI color to use according to the given item.

    Parameters:

      item (Item) – AN item

    Return type:

      qt.QColor

  getPlotItem()

    Returns the item focused by the profile manager.

    Return type:

      Item

  getPlotWidget()

    The plot associated to the profile manager.

    Return type:

      PlotWidget

  getCurrentRoi()

    Returns the currently selected ROI, else None.

    Return type:

      core.ProfileRoiMixIn

  getRoiManager()

    Returns the used ROI manager

    Return type:

      RegionOfInterestManager

  createProfileWindow(plot, roi)

    Create a new profile window.

    Parameters:

      - roi (ProfileRoiMixIn) – The plot containing the raw data

      - roi – A managed ROI

    Return type:

      ~ProfileWindow

  initProfileWindow(profileWindow, roi)

    This function is called just after the profile window creation in order to initialize the window location.

    Parameters:

      profileWindow (~ProfileWindow) – The profile window to initialize.

  clearProfileWindow(profileWindow)

    Called when a profile window is not anymore needed.

    By default the window will be closed. But it can be inherited to change this behavior.

### `ProfileWindow` class

class ProfileWindow(parent=None, backend=None)

  Bases: `QMainWindow`

  Display a computed profile.

  The content can be described using `setRoiProfile()` if the source of the profile is a profile ROI, and `setProfile()` for the data content.

  sigClose

    Emitted by `closeEvent()` (e.g. when the window is closed through the window manager’s close icon).

  prepareWidget(roi)

    Called before the show to prepare the window to use with a specific ROI.

  createPlot1D(parent, backend)

    Inherit this function to create your own plot to render 1D profiles. The default value is a Plot1D.

    Parameters:

      - parent – The parent of this widget or None.

      - backend – The backend to use for the plot. See `PlotWidget` for the list of supported backend.

    Return type:

      PlotWidget

  createPlot2D(parent, backend)

    Inherit this function to create your own plot to render 2D profiles. The default value is a Plot2D.

    Parameters:

      - parent – The parent of this widget or None.

      - backend – The backend to use for the plot. See `PlotWidget` for the list of supported backend.

    Return type:

      PlotWidget

  getPlot1D(init=True)

    Return the current plot used to display curves and create it if it does not yet exists and init is True. Else returns None.

  getPlot2D(init=True)

    Return the current plot used to display image and create it if it does not yet exists and init is True. Else returns None.

  closeEvent(self, a0: QCloseEvent | None)
  setRoiProfile(roi)

    Set the profile ROI which it the source of the following data to display.

    Parameters:

      roi (ProfileRoiMixIn) – The profile ROI data source

  clear()

    Clear the window profile

  getProfile()

    Returns the profile data which is displayed

  setProfile(data)

    Setup the window to display a new profile data.

    This method dispatch the result to a specific method according to the data type.

    Parameters:

      data – Computed data profile

## `editors` module

This module provides editors which are used to custom profile ROI properties.

### `ProfileRoiEditorAction` class

class ProfileRoiEditorAction(parent=None)

  Bases: `QWidgetAction`

  Action displaying GUI to edit the selected ROI.

  Parameters:

    parent (qt.QWidget) – Parent widget

  createWidget(parent)

    Inherit the method to create a new editor

  deleteWidget(widget)

    Inherit the method to delete an editor

  setRoiManager(roiManager)

    Connect this action to a ROI manager.

    Parameters:

      roiManager (RegionOfInterestManager) – A ROI manager

  setProfileRoi(roi)

    Set a profile ROI to edit.

    Parameters:

      roi (ProfileRoiMixIn) – A profile ROI

  getRoiProfile()

    Returns the edited profile ROI.

    Return type:

      ProfileRoiMixIn

  getEditorClass(roi)

    Returns the editor class to use according to the ROI.

## `core` module

This module define core objects for profile tools.

### `ProfileRoiMixIn` class

class ProfileRoiMixIn(parent=None)

  Bases: `object`

  Base mix-in for ROI which can be used to select a profile.

  This mix-in have to be applied to a `RegionOfInterest` in order to be usable by a `ProfileManager`.

  ITEM_KIND = None

    Define the plot item which can be used with this profile ROI

  sigProfilePropertyChanged

    Emitted when a property of this profile have changed

  sigPlotItemChanged

    Emitted when the plot item linked to this profile have changed

  invalidateProfile()

    Must be called by the implementation when the profile have to be recomputed.

  invalidateProperties()

    Must be called when a property of the profile have changed.

  getPlotItem()

    Returns the plot item used by this profile

    Return type:

      ~silx.gui.plot.items.Item

  getProfileManager()

    Returns the profile manager connected to this ROI.

    Return type:

      ProfileManager

  getProfileWindow()

    Returns the windows associated to this ROI, else None.

    Return type:

      ProfileWindow

  setProfileWindow(profileWindow)

    Associate a window to this ROI. Can be None.

    Parameters:

      profileWindow (ProfileWindow) – A main window to display the profile.

  computeProfile(item)

    Compute the profile which will be displayed.

    This method is not called from the main Qt thread, but from a thread pool.

    Parameters:

      item (`Item`) – A plot item

    Return type:

      `CurveProfileData` | `ImageProfileData` | `RgbaProfileData` | `CurvesProfileData`

### `CurveProfileData` class

class CurveProfileData(coords, profile, title, xLabel, yLabel)

  Bases: `NamedTuple`

  coords: ndarray

    Alias for field number 0

  profile: ndarray

    Alias for field number 1

  title: str

    Alias for field number 2

  xLabel: str

    Alias for field number 3

  yLabel: str

    Alias for field number 4

### `ImageProfileData` class

class ImageProfileData(coords, profile, title, xLabel, yLabel, colormap)

  Bases: `NamedTuple`

  coords: ndarray

    Alias for field number 0

  profile: ndarray

    Alias for field number 1

  title: str

    Alias for field number 2

  xLabel: str

    Alias for field number 3

  yLabel: str

    Alias for field number 4

  colormap: Colormap

    Alias for field number 5

## `ScatterProfileToolBar` module

This module profile tools for scatter plots.

### `ScatterProfileToolBar`

class ScatterProfileToolBar(parent=None, plot=None)

  Bases: `ProfileToolBar`

  QToolBar providing scatter plot profiling tools

  Parameters:

    - parent – See `QToolBar`.

    - plot – `PlotWidget` on which to operate.

## `rois` module

This module define ROIs for profile tools.