def _pixel_coordinate(line: list, x_1d: np.array, y_1d: np.array, k: int = None): """Gets the pixel coordinate of the value x or y, in order to get posterior conditional probability given a KDE. :param line: Coordinates of the line we'd like to sample along [(x1, y1), (x2, y2)] :param x_1d: List of x coordinates along the axis :param y_1d: List of y coordinates along the axis :param k: Used to set number of rows/columns :return: (rows, columns) """ if k is None: num = 200 else: num = k # https://stackoverflow.com/questions/18920614/plot-cross-section-through-heat-map # Convert the line to pixel/index coordinates x_world, y_world = np.array(list(zip(*line))) col = y_1d.shape * (x_world - min(x_1d)) / x_1d.ptp() row = x_1d.shape * (y_world - min(y_1d)) / y_1d.ptp() # Interpolate the line at "num" points... row, col = [np.linspace(item[0], item[1], num) for item in [row, col]] return row, col
def qpixmap_from(image: np.array): dwidth, dheight = image.shape # map the data range to 0 - 255 img_8bit = ((image - image.min()) / (image.ptp() / 255.0)).astype(np.uint8) # qimg = QImage(img_8bit.repeat(4), dwidth, dheight, QImage.Format_RGB32) qimg = QImage(img_8bit.repeat(3), dwidth, dheight, QImage.Format_RGB888) return QPixmap(qimg)
def find_pctile(self, data: np.array, terminal_days: int, spline_knots_type: str) -> Tuple[float, float]: data = np.sort(data) if spline_knots_type == 'domain': #start_boundary_pctile = (data[terminal_days - 1] - data[0]) / data.ptp() end_boundary_pctile = (data[-terminal_days] - data[0]) / data.ptp() elif spline_knots_type == 'frequency': #start_boundary_pctile = terminal_days / data.size end_boundary_pctile = 1. - terminal_days / data.size return end_boundary_pctile # start_boundary_pctile,