def get_plot_average_y_section(obj, apply_lut=False): """ Return cross section along y-axis, averaged on ROI defined by 'obj' 'obj' is an AbstractShape object supporting the 'get_rect' method (RectangleShape, AnnotatedRectangle, etc.) """ x0, y0, x1, y1 = obj.get_rect() xc0, yc0 = axes_to_canvas(obj, x0, y0) xc1, yc1 = axes_to_canvas(obj, x1, y1) invert = False ydir = obj.plot().get_axis_direction("left") if (ydir and yc0 > yc1) or (not ydir and yc0 < yc1): invert = True yc1, yc0 = yc0, yc1 if xc0 > xc1: xc1, xc0 = xc0, xc1 try: data = get_image_from_qrect(obj.plot(), QPoint(xc0, yc0), QPoint(xc1, yc1), apply_lut=apply_lut, apply_interpolation=False) except (ValueError, ZeroDivisionError, TypeError): return np.array([]), np.array([]) y = data.mean(axis=1) x = np.linspace(y0, y1, len(y)) if invert: x = x[::-1] return x, y
def get_plot_x_section(obj, apply_lut=False): """ Return plot cross section along x-axis, at the y value defined by 'obj', a Marker/AnnotatedPoint object """ _x0, y0 = get_object_coordinates(obj) plot = obj.plot() xmap = plot.canvasMap(plot.X_BOTTOM) xc0, xc1 = xmap.p1(), xmap.p2() _xc0, yc0 = axes_to_canvas(obj, 0, y0) if plot.get_axis_direction("left"): yc1 = yc0+1 else: yc1 = yc0-1 try: #TODO: eventually add an option to apply interpolation algorithm data = get_image_from_qrect(plot, QPoint(xc0, yc0), QPoint(xc1, yc1), apply_lut=apply_lut, apply_interpolation=False) except (ValueError, ZeroDivisionError, TypeError): return np.array([]), np.array([]) y = data.mean(axis=0) x0, _y0 = canvas_to_axes(obj, QPoint(xc0, yc0)) x1, _y1 = canvas_to_axes(obj, QPoint(xc1, yc1)) x = np.linspace(x0, x1, len(y)) return x, y
def get_plot_y_section(obj, apply_lut=False): """ Return plot cross section along y-axis, at the x value defined by 'obj', a Marker/AnnotatedPoint object """ x0, _y0 = get_object_coordinates(obj) plot = obj.plot() ymap = plot.canvasMap(plot.Y_LEFT) yc0, yc1 = ymap.p1(), ymap.p2() if plot.get_axis_direction("left"): yc1, yc0 = yc0, yc1 xc0, _yc0 = axes_to_canvas(obj, x0, 0) xc1 = xc0 + 1 try: data = get_image_from_qrect(plot, QPoint(xc0, yc0), QPoint(xc1, yc1), apply_lut=apply_lut, apply_interpolation=False) except (ValueError, ZeroDivisionError, TypeError): return np.array([]), np.array([]) y = data.mean(axis=1) _x0, y0 = canvas_to_axes(obj, QPoint(xc0, yc0)) _x1, y1 = canvas_to_axes(obj, QPoint(xc1, yc1)) x = np.linspace(y0, y1, len(y)) return x, y
def get_plot_x_section(obj, apply_lut=False): """ Return plot cross section along x-axis, at the y value defined by 'obj', a Marker/AnnotatedPoint object """ _x0, y0 = get_object_coordinates(obj) plot = obj.plot() xmap = plot.canvasMap(plot.X_BOTTOM) xc0, xc1 = xmap.p1(), xmap.p2() _xc0, yc0 = axes_to_canvas(obj, 0, y0) if plot.get_axis_direction("left"): yc1 = yc0 + 1 else: yc1 = yc0 - 1 try: #TODO: eventually add an option to apply interpolation algorithm data = get_image_from_qrect(plot, QPoint(xc0, yc0), QPoint(xc1, yc1), apply_lut=apply_lut, apply_interpolation=False) except (ValueError, ZeroDivisionError, TypeError): return np.array([]), np.array([]) y = data.mean(axis=0) x0, _y0 = canvas_to_axes(obj, QPoint(xc0, yc0)) x1, _y1 = canvas_to_axes(obj, QPoint(xc1, yc1)) x = np.linspace(x0, x1, len(y)) return x, y
def get_plot_y_section(obj, apply_lut=False): """ Return plot cross section along y-axis, at the x value defined by 'obj', a Marker/AnnotatedPoint object """ x0, _y0 = get_object_coordinates(obj) plot = obj.plot() ymap = plot.canvasMap(plot.Y_LEFT) yc0, yc1 = ymap.p1(), ymap.p2() if plot.get_axis_direction("left"): yc1, yc0 = yc0, yc1 xc0, _yc0 = axes_to_canvas(obj, x0, 0) xc1 = xc0+1 try: data = get_image_from_qrect(plot, QPoint(xc0, yc0), QPoint(xc1, yc1), apply_lut=apply_lut, apply_interpolation=False) except (ValueError, ZeroDivisionError, TypeError): return np.array([]), np.array([]) y = data.mean(axis=1) _x0, y0 = canvas_to_axes(obj, QPoint(xc0, yc0)) _x1, y1 = canvas_to_axes(obj, QPoint(xc1, yc1)) x = np.linspace(y0, y1, len(y)) return x, y