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

Update codecov settings #22

Merged
merged 7 commits into from
Dec 4, 2023
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
3 changes: 3 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ comment: # this is a top-level key
require_changes: false # if true: only post the comment if coverage changes
require_base: false # [true :: must have a base report to post]
require_head: true # [true :: must have a head report to post]
ignore:
- "setup.py"
- "test/*"
25 changes: 14 additions & 11 deletions hierarc/Likelihood/KDELikelihood/chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,21 @@ def __init__(
loglsamples=None,
rescale=True,
):
"""
"""For keywords in the `kw` parameter, see
https://wiki.cosmos.esa.int/planck-legacy-archive/index.php/Cosmological_Parameters

: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 probe: (str). Planck probe combination. For example, "plikHM_TTTEEE_lowl_lowE" for default Planck results
:param kw: (str). Planck base cosmology keyword. For example, "base" or
"base_omegak".
:param probe: (str). Planck probe combination. For example,
"plikHM_TTTEEE_lowl_lowE" for default Planck results
:param params: (dictionnary). Dictionnary containing the samples.
:param default_weights: (numpy array). Default weights associated to the samples.
:param cosmology: (str). Astropy cosmology
:param loglsamples: (numpy array). Corresponding Loglikelihood of the samples (optionnal).
:param rescale: (bool). Rescale the chains between 0 and 1 for all parameters. This is absolutely necessary if you want to evaluate a KDE on these chains.
:param loglsamples: (numpy array). Corresponding Loglikelihood of the samples
(optionnal).
:param rescale: (bool). Rescale the chains between 0 and 1 for all
parameters. This is absolutely necessary if you want to evaluate a KDE on
these chains.
"""
self.kw = kw
self.probe = probe
Expand Down Expand Up @@ -142,15 +148,12 @@ def rescale_from_unity(self, verbose=False):


def import_Planck_chain(datapath, kw, probe, params, cosmology, rescale=True):
"""Special function to parse Planck files. Return a Chain object.
"""Special function to parse Planck files. Return a Chain object. For keywords in
the `kw` parameter, 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-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-
archive/index.php/Cosmological_Parameters.
"base_omegak".
:param probe: (str). Planck probe combination. For example,
"plikHM_TTTEEE_lowl_lowE" for default Planck results
:param params: (list). List of cosmological parameters. ["h0", "om"] for FLCDM.
Expand Down
8 changes: 5 additions & 3 deletions hierarc/Sampling/mcmc_sampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ class MCMCSampler(object):
"""Class which executes the different sampling methods."""

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."""
"""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.
"""
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
Loading