From 323eb3f7078d4daa2aa260c8041eb669c75210c2 Mon Sep 17 00:00:00 2001 From: Anowar Shajib Date: Mon, 4 Dec 2023 11:34:26 -0600 Subject: [PATCH 1/7] Update codecov.yml Remove setup.py and test files from test coverage statistics, as [recommended here](https://about.codecov.io/blog/should-i-include-test-files-in-code-coverage-calculations/). --- codecov.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/codecov.yml b/codecov.yml index 55e5016..45af80e 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" + - "tests/*" From f33767bb605edc80b109ee4f24632ff86b43790d Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 4 Dec 2023 17:35:16 +0000 Subject: [PATCH 2/7] [pre-commit.ci] auto fixes from pre-commit.com hooks --- hierarc/Likelihood/KDELikelihood/chain.py | 7 ++ hierarc/Sampling/mcmc_sampling.py | 6 +- notebooks/double_source_plane.ipynb | 83 ++++++++++++++--------- 3 files changed, 62 insertions(+), 34 deletions(-) diff --git a/hierarc/Likelihood/KDELikelihood/chain.py b/hierarc/Likelihood/KDELikelihood/chain.py index 9888f23..393a88e 100644 --- a/hierarc/Likelihood/KDELikelihood/chain.py +++ b/hierarc/Likelihood/KDELikelihood/chain.py @@ -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- diff --git a/hierarc/Sampling/mcmc_sampling.py b/hierarc/Sampling/mcmc_sampling.py index 5b62743..870e88c 100644 --- a/hierarc/Sampling/mcmc_sampling.py +++ b/hierarc/Sampling/mcmc_sampling.py @@ -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 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()" ] }, From 9d43104bef89affba932c868a43d214bb478de98 Mon Sep 17 00:00:00 2001 From: Anowar Shajib Date: Mon, 4 Dec 2023 11:36:34 -0600 Subject: [PATCH 3/7] Update hierarc/Sampling/mcmc_sampling.py --- hierarc/Sampling/mcmc_sampling.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hierarc/Sampling/mcmc_sampling.py b/hierarc/Sampling/mcmc_sampling.py index 870e88c..e7c7708 100644 --- a/hierarc/Sampling/mcmc_sampling.py +++ b/hierarc/Sampling/mcmc_sampling.py @@ -7,7 +7,7 @@ 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: + """Initialise the classes of the chain and for parameter options positional arguments for the CosmoLikelihood() instance :param kwargs: keyword arguments for the CosmoLikelihood() instance. From 4827728ae86afe9329771c0a97509c79108b300f Mon Sep 17 00:00:00 2001 From: Anowar Shajib Date: Mon, 4 Dec 2023 11:36:38 -0600 Subject: [PATCH 4/7] Update hierarc/Sampling/mcmc_sampling.py --- hierarc/Sampling/mcmc_sampling.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hierarc/Sampling/mcmc_sampling.py b/hierarc/Sampling/mcmc_sampling.py index e7c7708..8b23cfb 100644 --- a/hierarc/Sampling/mcmc_sampling.py +++ b/hierarc/Sampling/mcmc_sampling.py @@ -9,7 +9,7 @@ class MCMCSampler(object): def __init__(self, *args, **kwargs): """Initialise the classes of the chain and for parameter options - positional arguments for the CosmoLikelihood() instance + :param args: positional arguments for the CosmoLikelihood() instance :param kwargs: keyword arguments for the CosmoLikelihood() instance. """ self.chain = CosmoLikelihood(*args, **kwargs) From a5d3d2f8e8b0456a06033ba7a7ffb49857dbb59b Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 4 Dec 2023 17:36:42 +0000 Subject: [PATCH 5/7] [pre-commit.ci] auto fixes from pre-commit.com hooks --- hierarc/Likelihood/KDELikelihood/chain.py | 14 ++++++++++++++ hierarc/Sampling/mcmc_sampling.py | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/hierarc/Likelihood/KDELikelihood/chain.py b/hierarc/Likelihood/KDELikelihood/chain.py index 393a88e..cb733a1 100644 --- a/hierarc/Likelihood/KDELikelihood/chain.py +++ b/hierarc/Likelihood/KDELikelihood/chain.py @@ -147,9 +147,23 @@ 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- + :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- diff --git a/hierarc/Sampling/mcmc_sampling.py b/hierarc/Sampling/mcmc_sampling.py index 8b23cfb..036c0fe 100644 --- a/hierarc/Sampling/mcmc_sampling.py +++ b/hierarc/Sampling/mcmc_sampling.py @@ -7,7 +7,7 @@ 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 + """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. From 6defc3367eb40f76ffd5895e01ea448ce3a71513 Mon Sep 17 00:00:00 2001 From: Anowar Shajib Date: Mon, 4 Dec 2023 11:41:11 -0600 Subject: [PATCH 6/7] Update chain.py --- hierarc/Likelihood/KDELikelihood/chain.py | 48 +++++++---------------- 1 file changed, 15 insertions(+), 33 deletions(-) diff --git a/hierarc/Likelihood/KDELikelihood/chain.py b/hierarc/Likelihood/KDELikelihood/chain.py index cb733a1..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,36 +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. - - :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- - :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. + """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. + "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. From 6695d959770ac85094632fff6511680eea9183ee Mon Sep 17 00:00:00 2001 From: Anowar Shajib Date: Mon, 4 Dec 2023 13:19:35 -0600 Subject: [PATCH 7/7] Update codecov.yml --- codecov.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/codecov.yml b/codecov.yml index 45af80e..088d970 100644 --- a/codecov.yml +++ b/codecov.yml @@ -6,4 +6,4 @@ comment: # this is a top-level key require_head: true # [true :: must have a head report to post] ignore: - "setup.py" - - "tests/*" + - "test/*"