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.

roiWidgetImage

ROI class

class ROI(name, fromdata=None, todata=None, type_=None)[source]

Bases: PyQt5.QtCore.QObject

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()[source]
Return int

the unique ID of the ROI

setType(type_)[source]
Parameters

type (str) –

getType()[source]
Return str

the type of the ROI.

setName(name)[source]

Set the name of the ROI

Parameters

name (str) –

getName()[source]
Return str

name of the ROI

setFrom(frm)[source]
Parameters

frm – set x coordinate of the left limit

getFrom()[source]
Returns

x coordinate of the left limit

setTo(to)[source]
Parameters

to – x coordinate of the right limit

getTo()[source]
Returns

x coordinate of the right limit

getMiddle()[source]
Returns

middle position between ‘from’ and ‘to’ values

toDict()[source]
Returns

dict containing the roi parameters

isICR()[source]
Returns

True if the ROI is the ICR

computeRawAndNetCounts(curve)[source]

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.

    ../../../_images/rawCounts.png
  • Net count: Raw counts minus background

    ../../../_images/netCounts.png
Parameters

curve (CurveItem) –

Return tuple

rawCount, netCount

computeRawAndNetArea(curve)[source]

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.

    ../../../_images/rawArea.png
  • Net area: Raw counts minus background

    ../../../_images/netArea.png
Parameters

curve (CurveItem) –

Return tuple

rawArea, netArea

CurvesROIWidget class

class CurvesROIWidget(parent=None, name=None, plot=None)[source]

Bases: PyQt5.QtWidgets.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()[source]

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)[source]

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

Parameters

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

save(filename)[source]

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')[source]

Set the header text of this widget

calculateRois(roiList=None, roiDict=None)[source]

Compute ROI information

showEvent(self, QShowEvent)[source]
hideEvent(self, QHideEvent)[source]

ROITable class

class ROITable(parent=None, plot=None, rois=None)[source]

Bases: silx.gui.widgets.TableWidget.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()[source]

Note

clear the interface only. keep the roidict…

setRois(rois, order=None)[source]

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 roidict if provided as an OrderedDict.

addRoi(roi)[source]

:param ROI roi: roi to add to the table

deleteActiveRoi()[source]

remove the current active roi

removeROI(roi)[source]

remove the requested roi

Parameters

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

setActiveRoi(roi)[source]

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, QModelIndex, QModelIndex)[source]
getROIListAndDict()[source]
Returns

the list of roi objects and the dictionary of roi name to roi object.

calculateRois(roiList=None, roiDict=None)[source]

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

Parameters
  • roiList – deprecated parameter

  • roiDict – deprecated parameter

getRois(order)[source]

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)[source]

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)[source]

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)[source]
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)[source]

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, QShowEvent)[source]
hideEvent(self, QHideEvent)[source]
setCountsVisible(visible)[source]

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)[source]

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)[source]

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)