How to use the treecorr.config 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
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
    assert treecorr.config.get_from_list(config1, 'flip_g2', 2, bool, False) == False

    with assert_raises(IndexError):
        treecorr.config.get_from_list(config1, 'k_col', 2, int)
    with assert_raises(IndexError):
        treecorr.config.get_from_list(config1, 'flip_g1', 2, bool)
    with assert_raises(IndexError):
        treecorr.config.get_from_list(config1, 'flip_g1', 2, bool, False)
github rmjarvis / TreeCorr / tests / test_periodic.py View on Github external
with open(rand_file_name1, 'w') as fid:
        for i in range(nrand):
            fid.write(('%.20f %.20f\n')%(rx1[i],ry1[i]))
    rand_file_name2 = os.path.join('data','nn_periodic_rand2.dat')
    with open(rand_file_name2, 'w') as fid:
        for i in range(nrand):
            fid.write(('%.20f %.20f\n')%(rx2[i],ry2[i]))
    rr = treecorr.NNCorrelation(min_sep=min_sep, max_sep=max_sep, nbins=nbins, bin_slop=0,
                                verbose=0, xperiod=Lx, yperiod=Ly)
    rr.process(rcat1,rcat2, metric='Periodic')
    xi, varxi = dd.calculateXi(rr)
    print('xi = ',xi)

    # Do this via the corr2 function.
    config = treecorr.config.read_config('configs/nn_periodic.yaml')
    logger = treecorr.config.setup_logger(2)
    treecorr.corr2(config, logger)
    corr2_output = np.genfromtxt(os.path.join('output','nn_periodic.out'), names=True,
                                    skip_header=1)
    np.testing.assert_allclose(corr2_output['r_nom'], dd.rnom, rtol=1.e-3)
    np.testing.assert_allclose(corr2_output['DD'], dd.npairs, rtol=1.e-3)
    np.testing.assert_allclose(corr2_output['npairs'], dd.npairs, rtol=1.e-3)
    np.testing.assert_allclose(corr2_output['RR'], rr.npairs, rtol=1.e-3)
    np.testing.assert_allclose(corr2_output['xi'], xi, rtol=1.e-3)

    # If don't give a period, then an error.
    rr = treecorr.NNCorrelation(min_sep=min_sep, max_sep=max_sep, nbins=nbins)
    with assert_raises(ValueError):
        rr.process(rcat1,rcat2, metric='Periodic')

    # Or if only give one kind of period
    rr = treecorr.NNCorrelation(min_sep=min_sep, max_sep=max_sep, nbins=nbins, xperiod=3)
github rmjarvis / TreeCorr / tests / test_config.py View on Github external
def test_parse_variables():
    """Test parse_variables functionality
    """
    config = treecorr.read_config('configs/nn.yaml')

    # parse_variables is used by corr2 executable to add or change items in config
    # with extra command line arguments
    assert 'file_name2' not in config
    treecorr.config.parse_variable(config, 'file_name2 = data/nn_data.dat')
    assert config['file_name2'] == 'data/nn_data.dat'

    treecorr.config.parse_variable(config, 'file_name2=data/nn_data2.dat')
    assert config['file_name2'] == 'data/nn_data2.dat'

    # It's also used by params parsing, so removes trailing comments
    treecorr.config.parse_variable(config, 'file_name2=data/nn_data3.dat # The second file')
    assert config['file_name2'] == 'data/nn_data3.dat'

    # Extra whitespace is ignored
    treecorr.config.parse_variable(config, 'file_name2 = \t\tdata/nn_data4.dat       ')
    assert config['file_name2'] == 'data/nn_data4.dat'

    # Invalid if no = sign.
    with assert_raises(ValueError):
        treecorr.config.parse_variable(config, 'file_name2:data/nn_data2.dat')
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
github rmjarvis / TreeCorr / treecorr / nkcorrelation.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 / corr3.py View on Github external
"""Run the full three-point correlation function code based on the parameters in the
    given config dict.

    The function `print_corr3_params` will output information about the valid parameters
    that are expected to be in the config dict.

    Optionally a logger parameter maybe given, in which case it is used for logging.
    If not given, the logging will be based on the verbose and log_file parameters.

    :param config:  The configuration dict which defines what to do.
    :param logger:  If desired, a logger object for logging. (default: None, in which case
                    one will be built according to the config dict's verbose level.)
    """
    # Setup logger based on config verbose value
    if logger is None:
        logger = treecorr.config.setup_logger(
                treecorr.config.get(config,'verbose',int,1),
                config.get('log_file',None))

    # Check that config doesn't have any extra parameters.
    # (Such values are probably typos.)
    # Also convert the given parameters to the correct type, etc.
    config = treecorr.config.check_config(config, corr3_valid_params, corr3_aliases, logger)

    import pprint
    logger.debug('Using configuration dict:\n%s',pprint.pformat(config))

    if ( 'output_dots' not in config
          and config.get('log_file',None) is None
          and config['verbose'] >= 2 ):
        config['output_dots'] = True
github rmjarvis / TreeCorr / treecorr / gggcorrelation.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 / corr2.py View on Github external
def print_corr2_params():
    """Print information about the valid parameters that may be given to the `corr2` function.
    """
    treecorr.config.print_params(corr2_valid_params)
github rmjarvis / TreeCorr / treecorr / kkkcorrelation.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 / nncorrelation.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))