hexsample.roi — Region of interest#

This module contains all the facilities related to the concept of region of interest (ROI), encapsulated in two main classes:

Module documentation#

Description of a region of interest.

class hexsample.roi.Padding(top: int, right: int = None, bottom: int = None, left: int = None)#

Padding on the outside of the region of trigger.

This is setup so that the padding can be initialized with a single argument, assuming that it is the same on all four sides, with two arguments (bottom = top and left = right), or with the padding different on all four sides.

Parameters:
  • top (int) – Top-side padding in pixels.

  • right (int) – Right-side padding in pixels.

  • bottom (int) – Bottom-side padding in pixels.

  • left (int) – Left-side padding in pixels.

top: int#
right: int = None#
bottom: int = None#
left: int = None#
class hexsample.roi.RegionOfInterest(min_col: int, max_col: int, min_row: int, max_row: int, padding: Padding)#

Class describing a region of interest (ROI).

A region of interest is the datum of the logical coorinates of its two extreme corners, in the order (min_col, max_col, min_row, max_row).

min_col: int#
max_col: int#
min_row: int#
max_row: int#
padding: Padding#
shape() Tuple[int, int]#

Return the shape of the ROI.

Note that rows goes first and cols goes last—this is the shape that needs to be used to reshape the one-dimensional pha array so that it gets printed on the screen with the right size and orientation.

at_border(chip_size: Tuple[int, int])#

Return True if the ROI is on the border for a given chip_size.

We should consider making the chip size a class member, because it looks kind of awkward to pass it as an argument here.

col_indexes() array#

Return an array with all the valid column indexes.

row_indexes() array#

Return an array with all the valid row indexes.

serial_readout_coordinates() Tuple[array, array]#

Return two one-dimensional arrays containing the column and row indexes, respectively, in order of serial readout of the ROI.

Example

>>> col, row = RegionOfInterest(0, 4, 0, 3).serial_readout_coordinates()
>>> print(col)
>>> [0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4]
>>> print(row)
>>> [0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3]
serial_readout_indexes() array#

Return a zero-indexed, two-dimensional array containing the serial readout index for each pixel in the ROI.

Example

>>> print(RegionOfInterest(0, 4, 0, 3).serial_readout_indexes())
>>> [[ 0  1  2  3  4]
     [ 5  6  7  8  9]
     [10 11 12 13 14]
     [15 16 17 18 19]]
rot_slice() Tuple[slice, slice]#

Return a pair of slice objects that can be used to address the ROT part of a numpy array representing, e.g., the pha values of a given event.

Note this operates in relative coordinates, i.e., native numpy indexing.

rot_mask() array#

Return a two-dimensional, boolean array mask, with the same dimensions of the region of interest, that is True in the region of trigger and False in the outer, padding area.

Note this operates in relative coordinates, i.e., native numpy indexing.

in_rot(col: array, row: array) array#

Return a boolean mask indicaing whether elements of the (col, row) arrays lie into the ROT area.