Ejemplo n.º 1
0
def contour_to_roi(x, y, data):
    """
    Return a PolygonalROI for the contour that passes through (x,y) in data

    Parameters
    ----------
    x, y : float
        x and y coordinate of the point
    data : `numpy.ndarray`
        The data

    Returns
    -------
    :class:`~glue.core.roi.PolygonalROI`
        A new ROI made by the (single) contour that passes through the
        mouse location (and `None` if this could not be calculated)
    """

    if x is None or y is None:
        return None

    xy = point_contour(x, y, data)
    if xy is None:
        return None

    p = roi.PolygonalROI(vx=xy[:, 0], vy=xy[:, 1])
    return p
Ejemplo n.º 2
0
def ginga_graphic_to_roi(obj):
    if obj.kind == 'rectangle':
        # make sure x2, y2 are the upper right corner
        x1, y1, x2, y2 = obj.swapxy(obj.x1, obj.y1, obj.x2, obj.y2)
        roi = roimod.RectangularROI(xmin=x1, xmax=x2, ymin=y1, ymax=y2)
    elif obj.kind == 'circle':
        roi = roimod.CircularROI(xc=obj.x, yc=obj.y, radius=obj.radius)
    elif obj.kind in ('polygon', 'freepolygon'):
        vx, vy = zip(*obj.points)
        roi = roimod.PolygonalROI(vx=vx, vy=vy)

    elif obj.kind in ('path', 'freepath', 'line'):
        vx, vy = zip(*obj.points)
        roi = roimod.Path(vx=vx, vy=vy)

    elif obj.kind == 'xrange':
        x1, y1, x2, y2 = obj.swapxy(obj.x1, 0, obj.x2, 0)
        roi = roimod.XRangeROI(min=x1, max=x2)

    elif obj.kind == 'yrange':
        x1, y1, x2, y2 = obj.swapxy(0, obj.y1, 0, obj.y2)
        roi = roimod.YRangeROI(min=y1, max=y2)

    elif obj.kind == 'point':
        roi = roimod.PointROI(x=obj.x, y=obj.y)

    else:
        raise Exception("Don't know how to convert shape '%s' to a ROI" %
                        (obj.kind))

    return roi
Ejemplo n.º 3
0
def ginga_graphic_to_roi(obj):
    if obj.kind == 'rectangle':
        roi = roimod.RectangularROI(xmin=obj.x1,
                                    xmax=obj.x2,
                                    ymin=obj.y1,
                                    ymax=obj.y2)
    elif obj.kind == 'circle':
        roi = roimod.CircularROI(xc=obj.x, yc=obj.y, radius=obj.radius)
    elif obj.kind == 'polygon':
        vx = map(lambda xy: xy[0], obj.points)
        vy = map(lambda xy: xy[1], obj.points)
        roi = roimod.PolygonalROI(vx=vx, vy=vy)

    else:
        raise Exception("Don't know how to convert shape '%s' to a ROI" %
                        (obj.kind))

    return roi