How to use the getdist.densities.Density2D function in getdist

To help you get started, we’ve selected a few getdist examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cmbant / getdist / getdist / plots.py View on Github external
def load_2d(self, root, param1, param2, ext='', no_axes=False):
        fname, transpose = self.plot_data_file_2D(root, param1.name, param2.name)
        if not os.path.exists(fname + ext): return None
        pts = np.loadtxt(fname + ext)
        if transpose: pts = pts.transpose()
        if no_axes: return pts
        x = np.loadtxt(fname + '_x')
        y = np.loadtxt(fname + '_y')
        if transpose:
            return Density2D(y, x, pts)
        else:
            return Density2D(x, y, pts)
github cmbant / getdist / getdist / plots.py View on Github external
:param samples_per_std: if evaluation array not specified, number of grid points per standard deviation
        :param kwargs: keyword arguments for :func:`~GetDistPlotter.add_2D_contours`
        """

        cov = np.asarray(cov)
        assert (cov.shape[0] == 2 and cov.shape[1] == 2)
        if xvals is None:
            err = np.sqrt(cov[0, 0])
            xvals = np.arange(means[0] - def_width * err, means[0] + def_width * err, err / samples_per_std)
        if yvals is None:
            err = np.sqrt(cov[1, 1])
            yvals = np.arange(means[1] - def_width * err, means[1] + def_width * err, err / samples_per_std)
        x, y = np.meshgrid(xvals - means[0], yvals - means[1])
        inv_cov = np.linalg.inv(cov)
        like = x ** 2 * inv_cov[0, 0] + 2 * x * y * inv_cov[0, 1] + y ** 2 * inv_cov[1, 1]
        density = Density2D(xvals, yvals, np.exp(-like / 2))
        density.contours = [0.32, 0.05]
        return self.add_2d_density_contours(density, **kwargs)
github cmbant / getdist / getdist / mcsamples.py View on Github external
raise SettingError('unknown boundary_correction_order (expected 0 or 1)')

        if mult_bias_correction_order:
            prior_mask = np.ones((ysize + 2 * winw, xsize + 2 * winw))
            self._setEdgeMask2D(parx, pary, prior_mask, winw, alledge=True)
            a00 = convolve2D(prior_mask, Win, 'valid', largest_size=convolvesize, cache=cache, cache_args=[2])
            for _ in range(mult_bias_correction_order):
                box = histbins.copy()
                ix2 = bins2D > np.max(bins2D) * 1e-8
                box[ix2] /= bins2D[ix2]
                bins2D *= convolve2D(box, Win, 'same', largest_size=convolvesize, cache=cache, cache_args=[2])
                bins2D /= a00

        x = np.linspace(xbinmin, xbinmax, xsize)
        y = np.linspace(ybinmin, ybinmax, ysize)
        density = Density2D(x, y, bins2D,
                            view_ranges=[(parx.range_min, parx.range_max), (pary.range_min, pary.range_max)])
        density.normalize('max', in_place=True)
        if get_density:
            return density

        ncontours = len(self.contours)
        if num_plot_contours: ncontours = min(num_plot_contours, ncontours)
        contours = self.contours[:ncontours]

        logging.debug('time 2D convolutions: %s', time.time() - start)

        # Get contour containing contours(:) of the probability
        density.contours = density.getContourLevels(contours)

        if meanlikes:
            bin2Dlikes /= np.max(bin2Dlikes)
github cmbant / getdist / getdist / gaussian_mixtures.py View on Github external
def _density2D(self, num_points=1024, xmin=None, xmax=None, ymin=None, ymax=None, sigma_max=5):
        lims = self._updateLimits(self.lims, xmin, xmax, ymin, ymax)
        (xmin, xmax), (ymin, ymax) = self.autoRanges(sigma_max, lims=lims)
        x = np.linspace(xmin, xmax, num_points)
        y = np.linspace(ymin, ymax, num_points)
        xx, yy = np.meshgrid(x, y)
        like = self.pdf(xx, yy)
        return Density2D(x, y, like)
github cmbant / getdist / getdist / plots.py View on Github external
def load_2d(self, root, param1, param2, ext='', no_axes=False):
        fname, transpose = self.plot_data_file_2D(root, param1.name, param2.name)
        if not os.path.exists(fname + ext): return None
        pts = np.loadtxt(fname + ext)
        if transpose: pts = pts.transpose()
        if no_axes: return pts
        x = np.loadtxt(fname + '_x')
        y = np.loadtxt(fname + '_y')
        if transpose:
            return Density2D(y, x, pts)
        else:
            return Density2D(x, y, pts)