Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
assert isinstance(logger1.handlers[0], logging.StreamHandler)
logger2 = treecorr.config.setup_logger(verbose=3)
assert logger2.level == logging.DEBUG
assert logger2.name == 'treecorr'
assert len(logger2.handlers) == 1
assert isinstance(logger2.handlers[0], logging.StreamHandler)
logger3 = treecorr.config.setup_logger(verbose=2, log_file='output/test_logger.out')
assert logger3.level == logging.INFO
assert logger3.name == 'treecorr'
assert len(logger3.handlers) == 1
assert isinstance(logger3.handlers[0], logging.FileHandler)
assert logger3.handlers[0].baseFilename == os.path.abspath('output/test_logger.out')
logger4 = treecorr.config.setup_logger(verbose=1, log_file='output/test_logger.out')
assert logger4.level == logging.WARNING
assert logger4.name == 'treecorr'
assert len(logger4.handlers) == 1
assert isinstance(logger4.handlers[0], logging.FileHandler)
assert logger4.handlers[0].baseFilename == os.path.abspath('output/test_logger.out')
logger5 = treecorr.config.setup_logger(verbose=1, log_file='output/test_logger2.out')
assert logger5.level == logging.WARNING
assert logger5.name == 'treecorr'
assert len(logger5.handlers) == 1
assert isinstance(logger5.handlers[0], logging.FileHandler)
assert logger5.handlers[0].baseFilename == os.path.abspath('output/test_logger2.out')
logger6 = treecorr.config.setup_logger(verbose=1, log_file=None)
assert logger6.level == logging.WARNING
assert logger6.name == 'treecorr'
with assert_raises(TypeError):
dd.calculateXi(dr=dr, rd=rd)
rr2 = treecorr.NNCorrelation(min_sep=min_sep, max_sep=max_sep, nbins=nbins, bin_type='Linear')
with assert_raises(ValueError):
dd.calculateXi(rr=rr2, dr=dr, rd=rd)
with assert_raises(ValueError):
dd.calculateXi(rr=rr, dr=rr2, rd=rd)
with assert_raises(ValueError):
dd.calculateXi(rr=rr, dr=dr, rd=rr2)
with assert_raises(ValueError):
dd.calculateXi(rr=rr, rd=rr2)
with assert_raises(ValueError):
dd.calculateXi(rr=rr, dr=rr2)
config = treecorr.config.read_config('configs/nn_linear.yaml')
logger = treecorr.config.setup_logger(0)
treecorr.corr2(config, logger)
corr2_output = np.genfromtxt(os.path.join('output','nn_linear.out'), names=True,
skip_header=1)
print('corr2_output = ',corr2_output)
print('corr2_output.dtype = ',corr2_output.dtype)
print('rnom = ',dd.rnom)
print(' ',corr2_output['r_nom'])
np.testing.assert_allclose(corr2_output['r_nom'], dd.rnom, rtol=1.e-3)
print('DD = ',dd.npairs)
print(' ',corr2_output['DD'])
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)
print('RR = ',rr.npairs)
print(' ',corr2_output['RR'])
np.testing.assert_allclose(corr2_output['RR'], rr.npairs, rtol=1.e-3)
print('xi = ',xi)
ra = rng.normal(11.34, 0.9, (ngal,) )
dec = rng.normal(-48.12, 4.3, (ngal,) )
r = rng.normal(1024, 230, (ngal,) )
k = rng.normal(0,s, (ngal,) )
g1 = rng.normal(0,s, (ngal,) )
g2 = rng.normal(0,s, (ngal,) )
cat1 = treecorr.Catalog(x=x, y=y, z=z, g1=g1, g2=g2, k=k)
cat2 = treecorr.Catalog(ra=ra, dec=dec, ra_units='hour', dec_units='deg',
w=w, g1=g1, g2=g2, k=k)
cat2.logger = None
cat3 = treecorr.Catalog(x=x, y=y, g1=g1, g2=g2, k=k, w=w)
cat3 = cat3.copy() # This tests that post-pickled catalog still works correctly.
cat4 = treecorr.Catalog(x=x, y=y, w=w)
logger = treecorr.config.setup_logger(1)
assert cat1.field is None # Before calling get*Field, this is None.
assert cat2.field is None
assert cat3.field is None
t0 = time.time()
nfield1 = cat1.getNField()
nfield2 = cat2.getNField(0.01, 1)
nfield3 = cat3.getNField(1,300, logger=logger)
t1 = time.time()
nfield1b = cat1.getNField()
nfield2b = cat2.getNField(0.01, 1)
nfield3b = cat3.getNField(1,300, logger=logger)
t2 = time.time()
assert cat1.nfields.count == 1
assert cat2.nfields.count == 1
"""Run the full two-point correlation function code based on the parameters in the
given config dict.
The function `print_corr2_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, corr2_valid_params, corr2_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
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))
self._field = lambda : None
def __init__(self, config=None, logger=None, **kwargs):
self.config = treecorr.config.merge_config(config,kwargs,BinnedCorr3._valid_params)
if logger is None:
self.logger = treecorr.config.setup_logger(
treecorr.config.get(self.config,'verbose',int,1),
self.config.get('log_file',None))
else:
self.logger = logger
if 'output_dots' in self.config:
self.output_dots = treecorr.config.get(self.config,'output_dots',bool)
else:
self.output_dots = treecorr.config.get(self.config,'verbose',int,1) >= 2
self.bin_type = self.config.get('bin_type', None)
self._bintype = treecorr._lib.Log
self.sep_units = self.config.get('sep_units','')
self._sep_units = treecorr.config.get(self.config,'sep_units',str,'radians')
self._log_sep_units = math.log(self._sep_units)
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))
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))
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))