roi

Region of interest creation

class pdsspect.roi.ROIBase(image_set, view_canvas, color='red', linewidth=1, linestyle='solid', showcap=False, fill=True, fillcolor=None, alpha=1.0, drawdims=False, font='Sans Serif', fillalpha=1.0, **kwargs)[source]

Bases: ginga.canvas.types.basic.Polygon

Base class for all ROI shapes

contains_arr(x_arr, y_arr)[source]

Determine whether the points in the ROI are in arrays

The arrays must be the same shape. The arrays should be result of np.mgrid[y1:y2:1, x1:x2:1]

Parameters:
Returns:

result – Boolean array where coordinates that are in ROI are True

Return type:

numpy.ndarray

continue_ROI(data_x, data_y)[source]

Abstract method to continue the ROI process

create_ROI(points=None)[source]

Create a Region of interest

Parameters:points (list of tuple of two int) – Points that make up the vertices of the ROI
Returns:coordinatesm x 2 array of coordinates.
Return type:numpy.ndarray
static draw_after(func)[source]

Wrapper to redraw canvas after function

extend_ROI(data_x, data_y)[source]

Abstract method to extend the ROI process

lock_coords_to_pixel(data_x, data_y)[source]

Lock the coordinates to the bottom-left corner of the pixel

The center of the pixel has integer coordinates and the edges of the pixel are 0.5 units away. We choose to lock to the bottom left corner or each pixel. If the decimal value of the coordinate is less than or equal to 0.5 then the coordinate is to the left/below the center of the pixel. To lock we round the coordinate down and add 0.5. If the decimal value is greater than 0.5 then the coordinate is to the right/above the center. To lock we round the coordinate down and subtract 0.5. For example, if the coordinate is (2.3, 4.7) the pixel coordinate is (2, 4) and the corresponding locked coordinate is (2.5, 4.5).

Parameters:
  • data_x (float) – The given x coordinate
  • data_y (float) – The given y coordinate
Returns:

  • point_x (float) – The corresponding x pixel coordinate
  • point_y (float) – The corresponding y pixel coordinate

static lock_coords_to_pixel_wrapper(func)[source]

Wrapper to lock data coordinates to the corresponding pixels

right

float – The right edge of the image

The right edge is 0.5 units before the right edge of the image.

start_ROI(data_x, data_y)[source]

Abstract method to start the ROI process

stop_ROI(data_x, data_y)[source]

Abstract method to stop the ROI process

top

float – The top edge of the image

The top edge is 1.5 units past the edge of the image due to how ginga renders the image. I feel like this is a bug but I haven’t had time to try to expose it in a simple example so working around it will have to do for now.

class pdsspect.roi.Polygon(image_set, view_canvas, color='red', linewidth=1, linestyle='solid', showcap=False, fill=True, fillcolor=None, alpha=1.0, drawdims=False, font='Sans Serif', fillalpha=1.0, **kwargs)[source]

Bases: pdsspect.roi.ROIBase

Polygon Region of Interest

continue_ROI(data_x, data_y)[source]

Create new vertex on the polygon on left click

Parameters:
  • data_x (float) – The x coordinate
  • data_y (float) – The y coordinate
extend_ROI(data_x, data_y)[source]

Extend the current edge of the polygon on mouse motion

Parameters:
  • data_x (float) – The x coordinate
  • data_y (float) – The y coordinate
start_ROI(data_x, data_y)[source]

Start the ROI process

The ROI will be a ginga.canvas.types.basic.Path object

Parameters:
  • data_x (float) – The x coordinate
  • data_y (float) – The y coordinate
stop_ROI(data_x, data_y)[source]

Close the polygon on right click

The polygon will close based on last left click and not on the right click. There must be more than 2 points to formulate a polygon

Parameters:
  • data_x (float) – The x coordinate
  • data_y (float) – The y coordinate
class pdsspect.roi.Rectangle(image_set, view_canvas, color='red', linewidth=1, linestyle='solid', showcap=False, fill=True, fillcolor=None, alpha=1.0, drawdims=False, font='Sans Serif', fillalpha=1.0, **kwargs)[source]

Bases: pdsspect.roi.ROIBase

Rectangle Region of interest

extend_ROI(data_x, data_y)[source]

Exend the rectangle on region of interest on mouse motion

Parameters:
  • data_x (float) – The x coordinate
  • data_y (float) – The y coordinate
start_ROI(data_x, data_y)[source]

Start the region of interest on left click

Parameters:
  • data_x (float) – The x coordinate
  • data_y (float) – The y coordinate
stop_ROI(data_x, data_y)[source]

Stop the region of interest on right click

Parameters:
  • data_x (float) – The x coordinate
  • data_y (float) – The y coordinate
class pdsspect.roi.Pencil(*args, **kwargs)[source]

Bases: pdsspect.roi.ROIBase

Select individual pixels

continue_ROI(data_x, data_y)[source]

Add another pixel on left click

Parameters:
  • data_x (float) – The x coordinate
  • data_y (float) – The y coordinate
move_delta(delta_x, delta_y)[source]

Override the move_delta function to move all the points

Parameters:
  • delta_x (float) – Change in the x direction
  • delta_y (float) – Change in the y direction
start_ROI(data_x, data_y)[source]

Start choosing pixels on left click

Parameters:
  • data_x (float) – The x coordinate
  • data_y (float) – The y coordinate
stop_ROI(data_x, data_y)[source]

Set all pixels as roi coordinates on right click

Parameters:
  • data_x (float) – The x coordinate
  • data_y (float) – The y coordinate
Returns:

coordinates – Coordinates of points selected

Return type:

numpy.ndarray