aspire_bilby.utils#
Classes#
Dataclass to store global functions. |
Functions#
|
Update the global functions for log likelihood and log prior. |
|
Get the log likelihood function for a bilby likelihood object. |
|
Get a dictionary of prior bounds. |
|
Determine which parameters are periodic. |
|
Get samples from a bilby result object. |
|
Get samples from a bilby prior object. |
|
Sample the missing parameters from the bilby result. |
|
Temporarily set the logger level. |
|
Load a bilby_pipe ini file and return the likelihood and priors. |
|
Get the aspire inputs from a bilby_pipe ini file. |
|
Get a function from a module path. |
Module Contents#
- aspire_bilby.utils.update_global_functions(bilby_likelihood, bilby_priors, fixed_parameters, parameters, use_ratio)[source]#
Update the global functions for log likelihood and log prior.
- Parameters:
bilby_likelihood (bilby.core.likelihood.Likelihood)
bilby_priors (bilby.core.prior.PriorDict)
fixed_parameters (dict[str, float])
parameters (list[str])
use_ratio (bool)
- aspire_bilby.utils.get_aspire_functions(bilby_likelihood, bilby_priors, parameters, use_ratio=False, likelihood_dtype='float64')[source]#
Get the log likelihood function for a bilby likelihood object.
- Parameters:
bilby_likelihood (
Likelihood) – The bilby likelihood object.bilby_priors (
PriorDict) – The bilby prior object.parameters (
list[str]) – The parameters to evaluate the log likelihood and log prior for. The order should match the order of the parameters in the aspire sampler.use_ratio (
bool) – Whether to use the log likelihood ratio function if available. If False, the log likelihood function is used instead.likelihood_dtype (
str) – The dtype to use for the log likelihood values. Default is “float64”.
- aspire_bilby.utils.get_prior_bounds(bilby_priors, parameters)[source]#
Get a dictionary of prior bounds.
- Parameters:
bilby_priors (bilby.core.prior.PriorDict)
parameters (list[str])
- Return type:
dict[str, numpy.ndarray]
- aspire_bilby.utils.get_periodic_parameters(bilby_priors)[source]#
Determine which parameters are periodic.
- Parameters:
bilby_priors (bilby.core.prior.PriorDict)
- Return type:
list[str]
- aspire_bilby.utils.samples_from_bilby_result(result, parameters=None, bilby_priors=None, sample_from_prior=None, conversion_function=None)[source]#
Get samples from a bilby result object.
- Parameters:
result (
Result) – The bilby result object.parameters (
str) – The parameters to read from the result. If None, all parameters will be read.bilby_priors (
PriorDict) – The bilby prior object. If not specified, the initial result must contain all parameters.sample_from_prior (
list[str]) – A list of parameters to explicitly sample from the prior rather reading from the result.conversion_function (Callable | None)
- aspire_bilby.utils.samples_from_bilby_priors(bilby_priors, n_samples, parameters=None)[source]#
Get samples from a bilby prior object.
- Parameters:
bilby_priors (
PriorDict) – The bilby prior object.n_samples (
int) – The number of samples to draw.parameters (
str) – The parameters to sample. If None, all parameters will be sampled.
- aspire_bilby.utils.sample_missing_parameters(bilby_result, bilby_priors, parameters=None, parameters_to_sample=None)[source]#
Sample the missing parameters from the bilby result.
- Parameters:
bilby_result (
Result) – The initial bilby result object.bilby_priors (
PriorDict) – The bilby prior object.parameters (
list[str]) – The parameters that should be present in the final set of samples. If not specified, the parameters will be inferred from the priors.parameters_to_sample (
list[str]) – A list of parameters to explicitly sample from the prior rather reading from the result. Each entry can be a regex pattern to match multiple parameters.
- Returns:
The samples from the bilby result and the missing parameters from the bilby priors. The order will be the same as
parameters.- Return type:
pd.DataFrame
- aspire_bilby.utils.temporary_logger_level(logger, level)[source]#
Temporarily set the logger level.
Example usage
```python with temporary_logger_level(logger, “DEBUG”):
# Do something
- Parameters:
level (str | None)
- aspire_bilby.utils.load_bilby_pipe_ini(config_file, data_dump_file, suppress_bilby_logger=True)[source]#
Load a bilby_pipe ini file and return the likelihood and priors.
- Parameters:
config_file (str)
data_dump_file (str)
suppress_bilby_logger (bool)
- aspire_bilby.utils.get_inputs_from_bilby_pipe_ini(config_file, data_dump_file, use_ratio=False, suppress_bilby_logger=True)[source]#
Get the aspire inputs from a bilby_pipe ini file.
- Returns:
A namedtuple with the log_likelihood and log_prior functions.
- Return type:
namedtuple- Parameters:
config_file (str)
data_dump_file (str)
use_ratio (bool)
suppress_bilby_logger (bool)