Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
pre-commit-ci[bot] committed Dec 4, 2023
1 parent 323eb3f commit f33767b
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 34 deletions.
7 changes: 7 additions & 0 deletions hierarc/Likelihood/KDELikelihood/chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,13 @@ def import_Planck_chain(datapath, kw, probe, params, cosmology, rescale=True):
:param datapath: (str). Path to the Planck chain :param kw: (str). Planck base
cosmology keyword. For example, "base" or "base_omegak". See
https://wiki.cosmos.esa.int/planck-legacy-archive/index.php/Cosmological_Parameters.
:param datapath: (str). Path to the Planck chain :param kw: (str). Planck base
cosmology keyword. For example, "base" or "base_omegak". See
https://wiki.cosmos.esa.int/planck-legacy-
:param datapath: (str). Path to the Planck chain
:param kw: (str). Planck base cosmology keyword. For example, "base" or
"base_omegak". See https://wiki.cosmos.esa.int/planck-legacy-
archive/index.php/Cosmological_Parameters.
:param datapath: (str). Path to the Planck chain
:param kw: (str). Planck base cosmology keyword. For example, "base" or
"base_omegak". See https://wiki.cosmos.esa.int/planck-legacy-
Expand Down
6 changes: 4 additions & 2 deletions hierarc/Sampling/mcmc_sampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ class MCMCSampler(object):

def __init__(self, *args, **kwargs):
"""Initialise the classes of the chain and for parameter options :param args:
positional arguments for the CosmoLikelihood() instance :param kwargs: keyword
arguments for the CosmoLikelihood() instance."""
positional arguments for the CosmoLikelihood() instance
:param kwargs: keyword arguments for the CosmoLikelihood() instance.
"""
self.chain = CosmoLikelihood(*args, **kwargs)
self.param = self.chain.param

Expand Down
83 changes: 51 additions & 32 deletions notebooks/double_source_plane.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"import copy\n",
"import matplotlib.pyplot as plt\n",
"import matplotlib.patches as mpatches\n",
"\n",
"%matplotlib inline\n",
"\n",
"# import lenstronomy and hierArc modules\n",
Expand All @@ -30,9 +31,10 @@
"\n",
"# matplotlib configs\n",
"from pylab import rc\n",
"rc('axes', linewidth=2)\n",
"rc('xtick',labelsize=15)\n",
"rc('ytick',labelsize=15)"
"\n",
"rc(\"axes\", linewidth=2)\n",
"rc(\"xtick\", labelsize=15)\n",
"rc(\"ytick\", labelsize=15)"
]
},
{
Expand All @@ -52,12 +54,14 @@
"metadata": {},
"outputs": [],
"source": [
"from hierarc.Likelihood.LensLikelihood.double_source_plane import beta_double_source_plane\n",
"from hierarc.Likelihood.LensLikelihood.double_source_plane import (\n",
" beta_double_source_plane,\n",
")\n",
"\n",
"# define a cosmology\n",
"cosmology = 'FLCDM' # Flat LCDM cosmology \n",
"cosmology = \"FLCDM\" # Flat LCDM cosmology\n",
"# other options are: \"FwCDM\", \"w0waCDM\", \"oLCDM\"\n",
"kwargs_cosmo_true = {'h0': 70, 'om': 0.3} # cosmological model of the forecast\n",
"kwargs_cosmo_true = {\"h0\": 70, \"om\": 0.3} # cosmological model of the forecast\n",
"\n",
"# create astropy.cosmology instance of input cosmology\n",
"cosmo_param = CosmoParam(cosmology=cosmology)\n",
Expand All @@ -73,26 +77,31 @@
"\n",
"sigma_beta = 0.05 # relative precision on Einstein radius ratio\n",
"\n",
"\n",
"def draw_lens():\n",
" \"\"\"\n",
" draw the likelihood object of a double source plane lens\n",
" \"\"\"\n",
" z_lens = np.random.uniform(low=0.2, high=0.5) \n",
" z_source1 = np.random.uniform(low=z_lens+0.2, high=3)\n",
" z_lens = np.random.uniform(low=0.2, high=0.5)\n",
" z_source1 = np.random.uniform(low=z_lens + 0.2, high=3)\n",
" z_source2 = np.random.uniform(low=z_source1, high=5)\n",
" beta = beta_double_source_plane(z_lens, z_source1, z_source2, cosmo_true)\n",
" beta_measured = beta + np.random.normal(loc=0, scale=sigma_beta * beta)\n",
" kwargs_likelihood = {'z_lens': z_lens, 'z_source_1': z_source1, 'z_source_2': z_source2, \n",
" 'beta_dspl': beta_measured, 'sigma_beta_dspl': sigma_beta * beta,\n",
" 'likelihood_type': 'DSPL'}\n",
" kwargs_likelihood = {\n",
" \"z_lens\": z_lens,\n",
" \"z_source_1\": z_source1,\n",
" \"z_source_2\": z_source2,\n",
" \"beta_dspl\": beta_measured,\n",
" \"sigma_beta_dspl\": sigma_beta * beta,\n",
" \"likelihood_type\": \"DSPL\",\n",
" }\n",
" return kwargs_likelihood\n",
"\n",
"\n",
"kwargs_dspl_list = []\n",
"\n",
"for i in range(num_dspl):\n",
" kwargs_dspl_list.append(draw_lens())\n",
"\n"
" kwargs_dspl_list.append(draw_lens())"
]
},
{
Expand All @@ -115,30 +124,36 @@
"n_run = 200\n",
"n_burn = 200\n",
"\n",
"cosmology = 'FwCDM'\n",
"\n",
"kwargs_mean_start = {'kwargs_cosmo': {'h0': 70, 'om': 0.3, 'w': -1}}\n",
"\n",
"kwargs_sigma_start = {'kwargs_cosmo': {'h0': 10, 'om': 0.05, 'w': 0.2}}\n",
"cosmology = \"FwCDM\"\n",
"\n",
"kwargs_mean_start = {\"kwargs_cosmo\": {\"h0\": 70, \"om\": 0.3, \"w\": -1}}\n",
"\n",
"kwargs_bounds = {'kwargs_lower_cosmo': {'h0': 0, 'om': 0, 'w': -2},\n",
" 'kwargs_upper_cosmo': {'h0': 200, 'om': 1, 'w': 0},\n",
" 'kwargs_fixed_cosmo': {'h0': kwargs_cosmo_true['h0']}}\n",
"kwargs_sigma_start = {\"kwargs_cosmo\": {\"h0\": 10, \"om\": 0.05, \"w\": 0.2}}\n",
"\n",
"\n",
"kwargs_bounds = {\n",
" \"kwargs_lower_cosmo\": {\"h0\": 0, \"om\": 0, \"w\": -2},\n",
" \"kwargs_upper_cosmo\": {\"h0\": 200, \"om\": 1, \"w\": 0},\n",
" \"kwargs_fixed_cosmo\": {\"h0\": kwargs_cosmo_true[\"h0\"]},\n",
"}\n",
"\n",
"\n",
"# joint options for hierArc sampling\n",
"kwargs_sampler = {'cosmology': cosmology, 'kwargs_bounds': kwargs_bounds,\n",
" 'lambda_mst_sampling': False, \n",
" 'anisotropy_sampling': False,\n",
" 'kappa_ext_sampling': False, 'kappa_ext_distribution': 'NONE', \n",
" 'alpha_lambda_sampling': False, 'sigma_v_systematics': False,\n",
" 'log_scatter': False, \n",
" 'custom_prior': None, 'interpolate_cosmo': False,\n",
" 'num_redshift_interp': 100, 'cosmo_fixed': None}\n",
"\n"
"kwargs_sampler = {\n",
" \"cosmology\": cosmology,\n",
" \"kwargs_bounds\": kwargs_bounds,\n",
" \"lambda_mst_sampling\": False,\n",
" \"anisotropy_sampling\": False,\n",
" \"kappa_ext_sampling\": False,\n",
" \"kappa_ext_distribution\": \"NONE\",\n",
" \"alpha_lambda_sampling\": False,\n",
" \"sigma_v_systematics\": False,\n",
" \"log_scatter\": False,\n",
" \"custom_prior\": None,\n",
" \"interpolate_cosmo\": False,\n",
" \"num_redshift_interp\": 100,\n",
" \"cosmo_fixed\": None,\n",
"}"
]
},
{
Expand All @@ -149,9 +164,13 @@
"outputs": [],
"source": [
"mcmc_sampler = MCMCSampler(kwargs_dspl_list, **kwargs_sampler)\n",
"mcmc_samples, log_prob = mcmc_sampler.mcmc_emcee(n_walkers, n_burn, n_run, kwargs_mean_start, kwargs_sigma_start)\n",
"mcmc_samples, log_prob = mcmc_sampler.mcmc_emcee(\n",
" n_walkers, n_burn, n_run, kwargs_mean_start, kwargs_sigma_start\n",
")\n",
"\n",
"corner.corner(mcmc_samples, show_titles=True, labels=mcmc_sampler.param_names(latex_style=True))\n",
"corner.corner(\n",
" mcmc_samples, show_titles=True, labels=mcmc_sampler.param_names(latex_style=True)\n",
")\n",
"plt.show()"
]
},
Expand Down

0 comments on commit f33767b

Please sign in to comment.