diff --git a/codecov.yml b/codecov.yml index 55e5016..088d970 100644 --- a/codecov.yml +++ b/codecov.yml @@ -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/*" diff --git a/hierarc/Likelihood/KDELikelihood/chain.py b/hierarc/Likelihood/KDELikelihood/chain.py index 9888f23..ba3dc00 100644 --- a/hierarc/Likelihood/KDELikelihood/chain.py +++ b/hierarc/Likelihood/KDELikelihood/chain.py @@ -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 @@ -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. diff --git a/hierarc/Sampling/mcmc_sampling.py b/hierarc/Sampling/mcmc_sampling.py index 5b62743..036c0fe 100644 --- a/hierarc/Sampling/mcmc_sampling.py +++ b/hierarc/Sampling/mcmc_sampling.py @@ -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 diff --git a/notebooks/double_source_plane.ipynb b/notebooks/double_source_plane.ipynb index 25c1df3..14df869 100644 --- a/notebooks/double_source_plane.ipynb +++ b/notebooks/double_source_plane.ipynb @@ -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", @@ -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)" ] }, { @@ -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", @@ -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())" ] }, { @@ -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", + "}" ] }, { @@ -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()" ] },