How to use the treecorr.config.get function in TreeCorr

To help you get started, we’ve selected a few TreeCorr 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 rmjarvis / TreeCorr / tests / test_config.py View on Github external
def test_get():
    """Test getting a parameter from a config dict
    """
    config1 = treecorr.read_config('configs/kg.yaml')
    assert treecorr.config.get(config1, 'x_col', int) == 1
    assert treecorr.config.get(config1, 'x_col', str) == '1'
    assert treecorr.config.get(config1, 'x_col') == '1'
    assert treecorr.config.get(config1, 'x_col', int, 2) == 1
    assert treecorr.config.get(config1, 'ra_col', int) == None
    assert treecorr.config.get(config1, 'ra_col', int, 2) == 2

    config1['flip_g1'] = True
    assert treecorr.config.get(config1, 'flip_g1', bool) == True
    assert treecorr.config.get(config1, 'flip_g1', bool, False) == True
    assert treecorr.config.get(config1, 'flip_g2', bool, False) == False
    assert treecorr.config.get(config1, 'flip_g2', bool) == None

    assert treecorr.config.get_from_list(config1, 'k_col', 0, int) == 3
    assert treecorr.config.get_from_list(config1, 'k_col', 0, str) == '3'
    assert treecorr.config.get_from_list(config1, 'k_col', 0) == '3'
    assert treecorr.config.get_from_list(config1, 'k_col', 0, int, 2) == 3
github rmjarvis / TreeCorr / tests / test_config.py View on Github external
def test_get():
    """Test getting a parameter from a config dict
    """
    config1 = treecorr.read_config('configs/kg.yaml')
    assert treecorr.config.get(config1, 'x_col', int) == 1
    assert treecorr.config.get(config1, 'x_col', str) == '1'
    assert treecorr.config.get(config1, 'x_col') == '1'
    assert treecorr.config.get(config1, 'x_col', int, 2) == 1
    assert treecorr.config.get(config1, 'ra_col', int) == None
    assert treecorr.config.get(config1, 'ra_col', int, 2) == 2

    config1['flip_g1'] = True
    assert treecorr.config.get(config1, 'flip_g1', bool) == True
    assert treecorr.config.get(config1, 'flip_g1', bool, False) == True
    assert treecorr.config.get(config1, 'flip_g2', bool, False) == False
    assert treecorr.config.get(config1, 'flip_g2', bool) == None

    assert treecorr.config.get_from_list(config1, 'k_col', 0, int) == 3
    assert treecorr.config.get_from_list(config1, 'k_col', 0, str) == '3'
    assert treecorr.config.get_from_list(config1, 'k_col', 0) == '3'
    assert treecorr.config.get_from_list(config1, 'k_col', 0, int, 2) == 3
    assert treecorr.config.get_from_list(config1, 'k_col', 1, int) == 0
    assert treecorr.config.get_from_list(config1, 'k_col', 1, int, 2) == 0
    assert treecorr.config.get_from_list(config1, 'ra_col', 1, int, 2) == 2
    assert treecorr.config.get_from_list(config1, 'ra_col', 1, int) == None

    config1['flip_g1'] = [True, False]
    assert treecorr.config.get_from_list(config1, 'flip_g1', 0, bool) == True
    assert treecorr.config.get_from_list(config1, 'flip_g1', 1, bool) == False
    assert treecorr.config.get_from_list(config1, 'flip_g1', 0, bool, False) == True
    assert treecorr.config.get_from_list(config1, 'flip_g2', 1, bool) == None
    assert treecorr.config.get_from_list(config1, 'flip_g2', 1, bool, False) == False
github rmjarvis / TreeCorr / treecorr / binnedcorr2.py View on Github external
def _set_metric(self, metric, coords1, coords2=None):
        if metric is None:
            metric = treecorr.config.get(self.config,'metric',str,'Euclidean')
        if metric not in ['Rperp', 'OldRperp', 'FisherRperp', 'Rlens', 'Arc']:
            if self.min_rpar != -sys.float_info.max:
                raise ValueError("min_rpar is not valid for %s metric."%metric)
            if self.max_rpar != sys.float_info.max:
                raise ValueError("max_rpar is not valid for %s metric."%metric)
        coords, metric = treecorr.util.parse_metric(metric, coords1, coords2)
        if self.sep_units != '' and coords == '3d' and metric != 'Arc':
            raise ValueError("sep_units is invalid with 3d coordinates. "
                             "min_sep and max_sep should be in the same units as r (or x,y,z).")
        if self.coords != None or self.metric != None:
            if coords != self.coords:
                self.logger.warning("Detected a change in catalog coordinate systems.\n"+
                                    "This probably doesn't make sense!")
            if metric != self.metric:
                self.logger.warning("Detected a change in metric.\n"+
                                    "This probably doesn't make sense!")
github rmjarvis / TreeCorr / treecorr / catalog.py View on Github external
columns.append(self.wpos)
        if self.g1 is not None:
            col_names.append('g1')
            columns.append(self.g1)
        if self.g2 is not None:
            col_names.append('g2')
            columns.append(self.g2)
        if self.k is not None:
            col_names.append('k')
            columns.append(self.k)
        if self._patch is not None:
            col_names.append('patch')
            columns.append(self.patch)

        if cat_precision is None:
            cat_precision = treecorr.config.get(self.config,'cat_precision',int,16)

        treecorr.util.gen_write(file_name, col_names, columns, precision=cat_precision,
                                file_type=file_type, logger=self.logger)
        return col_names
github rmjarvis / TreeCorr / treecorr / binnedcorr3.py View on Github external
(self.nbins, 1, 2*self.nvbins))
        self.v = np.tile(self.v1d[np.newaxis, np.newaxis, :],
                            (self.nbins, self.nubins, 1))
        self.rnom = np.exp(self.logr)
        self.rnom1d = np.exp(self.logr1d)
        self.brute = treecorr.config.get(self.config,'brute',bool,False)
        if self.brute:
            self.logger.info("Doing brute force calculation.",)
        self.coords = None
        self.metric = None
        self.min_rpar = treecorr.config.get(self.config,'min_rpar',float,-sys.float_info.max)
        self.max_rpar = treecorr.config.get(self.config,'max_rpar',float,sys.float_info.max)
        period = treecorr.config.get(self.config,'period',float,0)
        self.xperiod = treecorr.config.get(self.config,'xperiod',float,period)
        self.yperiod = treecorr.config.get(self.config,'yperiod',float,period)
        self.zperiod = treecorr.config.get(self.config,'zperiod',float,period)

        self.var_method = treecorr.config.get(self.config,'var_method',str,'shot')
        self.results = {}  # for jackknife, etc. store the results of each pair of patches.
github rmjarvis / TreeCorr / treecorr / gggcorrelation.py View on Github external
Parameters:
            file_name (str):    The name of the file to write to.
            R (array):          The R values at which to calculate the statistics.
                                (default: None, which means use self.rnom)
            file_type (str):    The type of file to write ('ASCII' or 'FITS').  (default: determine
                                the type automatically from the extension of file_name.)
            precision (int):    For ASCII output catalogs, the desired precision. (default: 4;
                                this value can also be given in the constructor in the config dict.)
        """
        self.logger.info('Writing Map^3 from GGG correlations to %s',file_name)

        if R is None:
            R = self.rnom1d
        stats = self.calculateMap3(R)
        if precision is None:
            precision = treecorr.config.get(self.config,'precision',int,4)

        treecorr.util.gen_write(
            file_name,
            ['R','Map3','Map2Mx', 'MapMx2', 'Mx3','sig_map'],
            [ R, stats[0], stats[1], stats[4], stats[7], np.sqrt(stats[8]) ],
            precision=precision, file_type=file_type, logger=self.logger)
github rmjarvis / TreeCorr / treecorr / kkcorrelation.py View on Github external
def __setstate__(self, d):
        self.__dict__ = d
        self.logger = treecorr.config.setup_logger(
                treecorr.config.get(self.config,'verbose',int,1),
                self.config.get('log_file',None))
github rmjarvis / TreeCorr / treecorr / catalog.py View on Github external
if self.npatch < 1:
                raise ValueError("npatch must be >= 1")
        else:
            self.npatch = 1

        try:
            self._single_patch = int(patch)
        except TypeError:
            pass
        else:
            patch = None
            self._npatch = 1

        if patch_centers is None and 'patch_centers' in self.config:
            # file name version may be in a config dict, rather than kwarg.
            patch_centers = treecorr.config.get(self.config,'patch_centers',str)

        if patch_centers is not None:
            if patch is not None or self.config.get('patch_col',0) not in (0,'0'):
                raise ValueError("Cannot provide both patch and patch_centers")
            if 'npatch' in self.config and self.config['npatch'] != 1:
                raise ValueError("Cannot provide both npatch and patch_centers")
            if isinstance(patch_centers, np.ndarray):
                self._centers = patch_centers
            else:
                self._centers = self.read_patch_centers(patch_centers)

        self.save_patch_dir = self.config.get('save_patch_dir',None)
        allow_xyz = self.config.get('allow_xyz', False)

        # First style -- read from a file
        if file_name is not None:
github rmjarvis / TreeCorr / treecorr / binnedcorr3.py View on Github external
self.u = np.tile(self.u1d[np.newaxis, :, np.newaxis],
                            (self.nbins, 1, 2*self.nvbins))
        self.v = np.tile(self.v1d[np.newaxis, np.newaxis, :],
                            (self.nbins, self.nubins, 1))
        self.rnom = np.exp(self.logr)
        self.rnom1d = np.exp(self.logr1d)
        self.brute = treecorr.config.get(self.config,'brute',bool,False)
        if self.brute:
            self.logger.info("Doing brute force calculation.",)
        self.coords = None
        self.metric = None
        self.min_rpar = treecorr.config.get(self.config,'min_rpar',float,-sys.float_info.max)
        self.max_rpar = treecorr.config.get(self.config,'max_rpar',float,sys.float_info.max)
        period = treecorr.config.get(self.config,'period',float,0)
        self.xperiod = treecorr.config.get(self.config,'xperiod',float,period)
        self.yperiod = treecorr.config.get(self.config,'yperiod',float,period)
        self.zperiod = treecorr.config.get(self.config,'zperiod',float,period)

        self.var_method = treecorr.config.get(self.config,'var_method',str,'shot')
        self.results = {}  # for jackknife, etc. store the results of each pair of patches.
github rmjarvis / TreeCorr / treecorr / catalog.py View on Github external
split_method (str): Which split method to use ('mean', 'median', 'middle', or 'random')
                                (default: 'mean'; this value can also be given in the Catalog
                                constructor in the config dict.)
            brute (bool):       Whether to force traversal to the leaves. (default: False)
            min_top (int):      The minimum number of top layers to use when setting up the
                                field. (default: :math:`\\max(3, \\log_2(N_{\\rm cpu}))`)
            max_top (int):      The maximum number of top layers to use when setting up the
                                field. (default: 10)
            coords (str):       The kind of coordinate system to use. (default self.coords)
            logger:             A Logger object if desired (default: self.logger)

        Returns:
            A `GField` object
        """
        if split_method is None:
            split_method = treecorr.config.get(self.config,'split_method',str,'mean')
        if self.g1 is None or self.g2 is None:
            raise TypeError("g1,g2 are not defined.")
        if logger is None:
            logger = self.logger
        field = self.gfields(min_size, max_size, split_method, brute, min_top, max_top, coords,
                             logger=logger)
        self._field = weakref.ref(field)
        return field