Skip to content

Commit

Permalink
Merge pull request #64 from /issues/56
Browse files Browse the repository at this point in the history
Adding downstream accuracy CCL params
  • Loading branch information
arthurmloureiro authored Jul 9, 2024
2 parents d393a82 + ef51ee1 commit bd2c6e0
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 1 deletion.
31 changes: 30 additions & 1 deletion augur/analyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,49 @@ def __init__(self, config, likelihood=None, tools=None, req_params=None):
fisher: np.ndarray
Output Fisher matrix
"""

_config = parse_config(config) # Load full config

# Load the likelihood if no likelihood is passed along
if likelihood is None:
likelihood, S, tools, req_params = generate(config, return_all_outputs=True)
else:
if (tools is None) or (req_params is None):
raise ValueError('If a likelihood is passed tools and req_params are required! \
Please, remove the likelihood or add tools and req_params.')
else:
# Load the ccl accuracy parameters if `generate` is not run
if 'ccl_accuracy' in config.keys():
# Pass along spline control parameters
if 'spline_params' in config['ccl_accuracy'].keys():
for key in config['ccl_accuracy']['spline_params'].keys():
try:
type_here = type(ccl.spline_params[key])
value = config['ccl_accuracy']['spline_params'][key]
ccl.spline_params[key] = type_here(value)
except KeyError:
print(f'The selected spline keyword `{key}` is not recognized.')
except ValueError:
print(f'The selected value `{value}` could not be casted to \
`{type_here}`.')
# Pass along GSL control parameters
if 'gsl_params' in config['ccl_accuracy'].keys():
for key in config['ccl_accuracy']['gsl_params'].keys():
try:
type_here = type(ccl.gsl_params[key])
value = config['ccl_accuracy']['gsl_params'][key]
ccl.gsl_params[key] = type_here(value)
except KeyError:
print(f'The selected GSL keyword `{key}` is not recognized.')
except ValueError:
print(f'The selected value `{value}` could not be casted to \
`{type_here}`.')

self.lk = likelihood # Just to save some typing
self.tools = tools
self.req_params = req_params
self.data_fid = self.lk.get_data_vector()

_config = parse_config(config) # Load full config
# Get the fiducial cosmological parameters
self.pars_fid = tools.get_ccl_cosmology().__dict__['_params_init_kwargs']

Expand Down
24 changes: 24 additions & 0 deletions augur/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,30 @@ def generate_sacc_and_stats(config):
if cosmo_cfg.get('extra_parameters') is None:
cosmo_cfg['extra_parameters'] = dict()

if 'ccl_accuracy' in config.keys():
# Pass along spline control parameters
if 'spline_params' in config['ccl_accuracy'].keys():
for key in config['ccl_accuracy']['spline_params'].keys():
try:
type_here = type(ccl.spline_params[key])
value = config['ccl_accuracy']['spline_params'][key]
ccl.spline_params[key] = type_here(value)
except KeyError:
print(f'The selected spline keyword `{key}` is not recognized.')
except ValueError:
print(f'The selected value `{value}` could not be casted to `{type_here}`.')
# Pass along GSL control parameters
if 'gsl_params' in config['ccl_accuracy'].keys():
for key in config['ccl_accuracy']['gsl_params'].keys():
try:
type_here = type(ccl.gsl_params[key])
value = config['ccl_accuracy']['gsl_params'][key]
ccl.gsl_params[key] = type_here(value)
except KeyError:
print(f'The selected GSL keyword `{key}` is not recognized.')
except ValueError:
print(f'The selected value `{value}` could not be casted to `{type_here}`.')

try:
cosmo = ccl.Cosmology(**cosmo_cfg)
except (KeyError, TypeError, ValueError) as e:
Expand Down
6 changes: 6 additions & 0 deletions examples/config_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ cosmo:
# transfer_function : 'eisenstein_hu' # If you want to specify the transfer function you can do so here
# If the transfer function is not specified, it defaults to using CAMB

ccl_accuracy: # Example of a couple of parameters to modify.
spline_params: # You can change here any pyccl.spline_params
K_MAX_SPLINE : 100
gsl_params: # You can change here any pyccl.gsl_params
INTEGRATION_EPSREL: 1e-6

sources: # Sources
nbins : 5
ndens : 10 # in arcmin^-2 (it should be a scalar with the total number density or a list with each bin's)
Expand Down

0 comments on commit bd2c6e0

Please sign in to comment.