Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding downstream accuracy CCL params #64

Merged
merged 2 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading