Skip to main content
`Ctrl`+`K`

# `CurvesROIWidget`: ROI from curves

Widget to handle regions of interest (`ROI`) on curves displayed in a `PlotWindow`.

This widget is meant to work with `PlotWindow`.

You can access to the ROIWidget from a Plot window by :

- using the tool button ‘ROI’

- using the options button then by selecting region of interest.

## `ROI` class

class ROI(name, fromdata=None, todata=None, type_=None)

  Bases: `_RegionOfInterestBase`

  The Region Of Interest is defined by:

  - A name

  - A type. The type is the label of the x axis. This can be used to apply or not some ROI to a curve and do some post processing.

  - The x coordinate of the left limit (fromdata)

  - The x coordinate of the right limit (todata)

  Parameters:

    - str – name of the ROI

    - fromdata – left limit of the roi

    - todata – right limit of the roi

    - type – type of the ROI

  sigChanged

    Signal emitted when the ROI is edited

  getID()
    Return int:

      the unique ID of the ROI

  setType(type_)
    Parameters:

      type (str)

  getType()
    Return str:

      the type of the ROI.

  setFrom(frm)
    Parameters:

      frm – set x coordinate of the left limit

  getFrom()
    Returns:

      x coordinate of the left limit

  setTo(to)
    Parameters:

      to – x coordinate of the right limit

  getTo()
    Returns:

      x coordinate of the right limit

  getMiddle()
    Returns:

      middle position between ‘from’ and ‘to’ values

  toDict()
    Returns:

      dict containing the roi parameters

  isICR()
    Returns:

      True if the ROI is the ICR

  computeRawAndNetCounts(curve)

    Compute the Raw and net counts in the ROI for the given curve.

    - Raw count: Points values sum of the curve in the defined Region Of

        Interest.

    - Net count: Raw counts minus background

    Parameters:

      curve (CurveItem)

    Return tuple:

      rawCount, netCount

  computeRawAndNetArea(curve)

    Compute the Raw and net counts in the ROI for the given curve.

    - Raw area: integral of the curve between the min ROI point and the

        max ROI point to the y = 0 line.

    - Net area: Raw counts minus background

    Parameters:

      curve (CurveItem)

    Return tuple:

      rawArea, netArea

  contains(position)

    Returns True if the position is in this ROI.

    Parameters:

      position (tuple[float,float]) – position to check

    Returns:

      True if the value / point is consider to be in the region of interest.

    Return type:

      bool

## `CurvesROIWidget` class

class CurvesROIWidget(parent=None, name=None, plot=None)

  Bases: `QWidget`

  Widget displaying a table of ROI information.

  Implements also the following behavior:

  - if the roiTable has no ROI when showing create the default ICR one

  Parameters:

    - parent – See `QWidget`

    - name (str) – The title of this widget

  sigROIWidgetSignal

    Signal of ROIs modifications.

    Modification information if given as a dict with an ‘event’ key providing the type of events.

    Type of events:

    - AddROI, DelROI, LoadROI and ResetROI with keys: ‘roilist’, ‘roidict’

    - selectionChanged with keys: ‘row’, ‘col’ ‘roi’, ‘key’, ‘colheader’, ‘rowheader’

  getPlotWidget()

    Returns the associated PlotWidget or None

    Return type:

      Union[PlotWidget,None]

  property roiFileDir

    The directory from which to load/save ROI from/to files.

  load(filename)

    Load ROI widget information from a file storing a dict of ROI.

    Parameters:

      filename (str) – The file from which to load ROI

  save(filename)

    Save current ROIs of the widget as a dict of ROI to a file.

    Parameters:

      filename (str) – The file to which to save the ROIs

  setHeader(text='ROIs')

    Set the header text of this widget

  calculateRois(roiList=None, roiDict=None)

    Compute ROI information

  showEvent(self, a0: QShowEvent | None)
  hideEvent(self, a0: QHideEvent | None)

## `ROITable` class

class ROITable(parent=None, plot=None, rois=None)

  Bases: `TableWidget`

  Table widget displaying ROI information.

  See `QTableWidget` for constructor arguments.

  Behavior: listen at the active curve changed only when the widget is visible. Otherwise won’t compute the row and net counts…

  activeROIChanged

    Signal emitted when the active roi changed or when the value of the active roi are changing

  clear()

    Note

    clear the interface only. keep the roidict…

  setRois(rois, order=None)

    Set the ROIs by providing a dictionary of ROI information.

    The dictionary keys are the ROI names. Each value is a sub-dictionary of ROI info with the following fields:

    - `"from"`: x coordinate of the left limit, as a float

    - `"to"`: x coordinate of the right limit, as a float

    - `"type"`: type of ROI, as a string (e.g “channels”, “energy”)

    Parameters:

      - roidict – Dictionary of ROIs

      - order (str) – Field used for ordering the ROIs. One of “from”, “to”, “type”. None (default) for no ordering, or same order as specified in parameter `rois` if provided as a dict.

  addRoi(roi)

    :param `ROI` roi: roi to add to the table

  deleteActiveRoi()

    remove the current active roi

  removeROI(roi)

    remove the requested roi

    Parameters:

      name (str) – the name of the roi to remove from the table

  setActiveRoi(roi)

    Define the given roi as the active one.

    Warning

    this roi should already be registred / added to the table

    :param `ROI` roi: the roi to defined as active

  currentChanged(self, current: QModelIndex, previous: QModelIndex)
  calculateRois()

    Update values of all registred rois (raw and net counts in particular)

  getRois(order)

    Return the currently defined ROIs, as an ordered dict.

    The dictionary keys are the ROI names. Each value is a `ROI` object..

    Parameters:

      order – Field used for ordering the ROIs. One of “from”, “to”, “type”, “netcounts”, “rawcounts”. None (default) to get the same order as displayed in the widget.

    Returns:

      Ordered dictionary of ROI information

  save(filename)

    Save current ROIs of the widget as a dict of ROI to a file.

    Parameters:

      filename (str) – The file to which to save the ROIs

  load(filename)

    Load ROI widget information from a file storing a dict of ROI.

    Parameters:

      filename (str) – The file from which to load ROI

  showAllMarkers(_show=True)
    Parameters:

      _show (bool) – if true show all the markers of all the ROIs boundaries otherwise will only show the one of the active ROI.

  setMiddleROIMarkerFlag(flag=True)

    Activate or deactivate middle marker.

    This allows shifting both min and max limits at once, by dragging a marker located in the middle.

    Parameters:

      flag (bool) – True to activate middle ROI marker

  showEvent(self, a0: QShowEvent | None)
  hideEvent(self, a0: QHideEvent | None)
  setCountsVisible(visible)

    Display the columns relative to areas or not

    Parameters:

      visible (bool) – True if the columns ‘Raw Area’ and ‘Net Area’ should be visible.

  setAreaVisible(visible)

    Display the columns relative to areas or not

    Parameters:

      visible (bool) – True if the columns ‘Raw Area’ and ‘Net Area’ should be visible.

  fillFromROIDict(roilist=(), roidict=None, currentroi=None)

    This function API is kept for compatibility. But setRois should be preferred.

    Set the ROIs by providing a list of ROI names and a dictionary of ROI information for each ROI. The ROI names must match an existing dictionary key. The name list is used to provide an order for the ROIs. The dictionary’s values are sub-dictionaries containing 3 mandatory fields:

    - `"from"`: x coordinate of the left limit, as a float

    - `"to"`: x coordinate of the right limit, as a float

    - `"type"`: type of ROI, as a string (e.g “channels”, “energy”)

    Parameters:

      - roilist (List) – List of ROI names (keys of roidict)

      - roidict (dict) – Dict of ROI information

      - currentroi – Name of the selected ROI or None (no selection)