diff --git a/.github/workflows/build_check.yml b/.github/workflows/build_check.yml index 8658316f5..87ce6723b 100644 --- a/.github/workflows/build_check.yml +++ b/.github/workflows/build_check.yml @@ -16,7 +16,7 @@ jobs: - name: Install prereq and NumCosmo using conda run: | echo "$CONDA/bin" >> $GITHUB_PATH - conda install -c conda-forge gobject-introspection pygobject numcosmo cmake swig setuptools_scm sphinx sphinx_rtd_theme nbconvert pandoc ipython + conda install -c conda-forge gobject-introspection pygobject 'numcosmo<=0.22.0' cmake swig setuptools_scm sphinx sphinx_rtd_theme nbconvert pandoc ipython - name: Install prereq using pip run: | pip install -r requirements.txt diff --git a/clmm/cosmology/cluster_toolkit.py b/clmm/cosmology/cluster_toolkit.py index 69193f246..ede3c34f9 100644 --- a/clmm/cosmology/cluster_toolkit.py +++ b/clmm/cosmology/cluster_toolkit.py @@ -6,7 +6,7 @@ from astropy import units from astropy.cosmology import LambdaCDM, FlatLambdaCDM -from ..constants import Constants as const +from ..utils.constants import Constants as const from .parent_class import CLMMCosmology diff --git a/clmm/cosmology/parent_class.py b/clmm/cosmology/parent_class.py index e970b4245..ea42f674f 100644 --- a/clmm/cosmology/parent_class.py +++ b/clmm/cosmology/parent_class.py @@ -3,9 +3,8 @@ """ # CLMM Cosmology object abstract superclass import numpy as np -from ..utils import validate_argument -from ..redshift import compute_for_good_redshifts -from ..constants import Constants as const +from ..utils import validate_argument, compute_for_good_redshifts +from ..utils.constants import Constants as const class CLMMCosmology: diff --git a/clmm/dataops/__init__.py b/clmm/dataops/__init__.py index eab62c280..726b530c3 100644 --- a/clmm/dataops/__init__.py +++ b/clmm/dataops/__init__.py @@ -14,8 +14,8 @@ _validate_dec, _validate_is_deltasigma_sigma_c, _validate_coordinate_system, + _integ_pzfuncs, ) -from ..redshift import _integ_pzfuncs def compute_tangential_and_cross_components( diff --git a/clmm/galaxycluster.py b/clmm/galaxycluster.py index 35b4f44c6..d71a47dc2 100644 --- a/clmm/galaxycluster.py +++ b/clmm/galaxycluster.py @@ -12,7 +12,6 @@ compute_background_probability, ) from .theory import compute_critical_surface_density_eff -from .plotting import plot_profiles from .utils import ( validate_argument, _validate_ra, @@ -20,6 +19,7 @@ _draw_random_points_from_tab_distribution, _validate_coordinate_system, ) +from .utils.plotting import plot_profiles class GalaxyCluster: diff --git a/clmm/redshift/__init__.py b/clmm/redshift/__init__.py deleted file mode 100644 index 29628d52a..000000000 --- a/clmm/redshift/__init__.py +++ /dev/null @@ -1,8 +0,0 @@ -"""@file __init__.py -Redshift utilities package -""" -from . import distributions -from .tools import ( - _integ_pzfuncs, - compute_for_good_redshifts, -) diff --git a/clmm/support/mock_data.py b/clmm/support/mock_data.py index 27858b822..52f3d4e9c 100644 --- a/clmm/support/mock_data.py +++ b/clmm/support/mock_data.py @@ -17,8 +17,8 @@ _draw_random_points_from_distribution, gaussian, _validate_coordinate_system, + redshift_distributions as zdist, ) -from ..redshift import distributions as zdist def generate_galaxy_catalog( diff --git a/clmm/theory/parent_class.py b/clmm/theory/parent_class.py index 758db702c..5b31c4540 100644 --- a/clmm/theory/parent_class.py +++ b/clmm/theory/parent_class.py @@ -21,8 +21,6 @@ from ..utils import ( validate_argument, compute_beta_s_func, -) -from ..redshift import ( _integ_pzfuncs, compute_for_good_redshifts, ) diff --git a/clmm/utils/__init__.py b/clmm/utils/__init__.py index a2c0854bb..53fdd1bad 100644 --- a/clmm/utils/__init__.py +++ b/clmm/utils/__init__.py @@ -1,5 +1,7 @@ """General utility functions that are used in multiple modules""" +from . import redshift_distributions, constants, plotting + from .beta_lens import ( compute_beta, compute_beta_s, @@ -33,6 +35,11 @@ gaussian, ) +from .redshift_tools import ( + _integ_pzfuncs, + compute_for_good_redshifts, +) + from .validation import ( arguments_consistency, _patch_rho_crit_to_cd2018, diff --git a/clmm/utils/beta_lens.py b/clmm/utils/beta_lens.py index 26ce410f7..584f5e572 100644 --- a/clmm/utils/beta_lens.py +++ b/clmm/utils/beta_lens.py @@ -2,7 +2,7 @@ import numpy as np from scipy.integrate import quad -from ..redshift import distributions as zdist +from . import redshift_distributions as zdist def compute_beta(z_src, z_cl, cosmo): diff --git a/clmm/constants.py b/clmm/utils/constants.py similarity index 100% rename from clmm/constants.py rename to clmm/utils/constants.py diff --git a/clmm/plotting/__init__.py b/clmm/utils/plotting.py similarity index 100% rename from clmm/plotting/__init__.py rename to clmm/utils/plotting.py diff --git a/clmm/redshift/distributions.py b/clmm/utils/redshift_distributions.py similarity index 100% rename from clmm/redshift/distributions.py rename to clmm/utils/redshift_distributions.py diff --git a/clmm/redshift/tools.py b/clmm/utils/redshift_tools.py similarity index 100% rename from clmm/redshift/tools.py rename to clmm/utils/redshift_tools.py diff --git a/clmm/utils/validation.py b/clmm/utils/validation.py index 1002ed222..e55b07c86 100644 --- a/clmm/utils/validation.py +++ b/clmm/utils/validation.py @@ -1,7 +1,7 @@ """General utility functions that are used in multiple modules""" import numpy as np -from ..constants import Constants as const +from ..utils.constants import Constants as const def arguments_consistency(arguments, names=None, prefix=""): @@ -226,6 +226,7 @@ def _validate_is_deltasigma_sigma_c(is_deltasigma, sigma_c): if not is_deltasigma and sigma_c is not None: raise TypeError(f"sigma_c (={sigma_c}) must be None when is_deltasigma=False") + def _validate_coordinate_system(loc, coordinate_system, valid_type): r"""Validate the coordinate system. @@ -245,6 +246,7 @@ def _validate_coordinate_system(loc, coordinate_system, valid_type): if loc[coordinate_system] not in ["celestial", "euclidean"]: raise ValueError(f"{coordinate_system} must be 'celestial' or 'euclidean'.") + class DiffArray: """Array where arr1==arr2 is actually all(arr1==arr)""" diff --git a/docs/doc-config.ini b/docs/doc-config.ini index cb9d24c5c..8b693f145 100644 --- a/docs/doc-config.ini +++ b/docs/doc-config.ini @@ -1,13 +1,10 @@ APIDOC clusterensemble -constants cosmology dataops galaxycluster gcdata -redshift theory -plotting utils support diff --git a/examples/demo_theory_functionality.ipynb b/examples/demo_theory_functionality.ipynb index 393606340..b9951fa48 100644 --- a/examples/demo_theory_functionality.ipynb +++ b/examples/demo_theory_functionality.ipynb @@ -111,7 +111,7 @@ "\n", "# source properties\n", "z_src = 2.0 # all sources in the same plan\n", - "z_distrib_func = clmm.redshift.distributions.chang2013 # sources redshift following a distribution\n", + "z_distrib_func = clmm.utils.redshift_distributions.chang2013 # sources redshift following a distribution\n", "alpha = [2, -0.5]" ] }, diff --git a/examples/demo_theory_functionality_diff_z_types.ipynb b/examples/demo_theory_functionality_diff_z_types.ipynb index 04e6bfafa..4b228ac93 100644 --- a/examples/demo_theory_functionality_diff_z_types.ipynb +++ b/examples/demo_theory_functionality_diff_z_types.ipynb @@ -90,7 +90,7 @@ "source": [ "from clmm.support import mock_data as mock\n", "from clmm import Cosmology\n", - "from clmm.redshift.distributions import *" + "from clmm.utils.redshift_distributions import *" ] }, { diff --git a/examples/demo_theory_functionality_oo.ipynb b/examples/demo_theory_functionality_oo.ipynb index b0d773f0b..814bd3938 100644 --- a/examples/demo_theory_functionality_oo.ipynb +++ b/examples/demo_theory_functionality_oo.ipynb @@ -106,7 +106,7 @@ "\n", "# source properties\n", "z_src = 2.0 # all sources in the same plane\n", - "z_distrib_func = clmm.redshift.distributions.chang2013 # sources redshift following a distribution\n", + "z_distrib_func = clmm.utils.redshift_distributions.chang2013 # sources redshift following a distribution\n", "alpha = [2, -0.5]" ] }, diff --git a/examples/mass_fitting/Example3_Fit_Halo_Mass_to_Shear_Catalog.ipynb b/examples/mass_fitting/Example3_Fit_Halo_Mass_to_Shear_Catalog.ipynb index 993d839ff..2f7327588 100644 --- a/examples/mass_fitting/Example3_Fit_Halo_Mass_to_Shear_Catalog.ipynb +++ b/examples/mass_fitting/Example3_Fit_Halo_Mass_to_Shear_Catalog.ipynb @@ -453,7 +453,7 @@ " #'delta_z_cut': delta_z_cut,\n", " #'zmin': None,\n", " # We provide the redshift distribution (default: Chang et al. 2013) for calculating the beta_s statistics\n", - " \"z_distrib_func\": clmm.redshift.distributions.chang2013,\n", + " \"z_distrib_func\": clmm.utils.redshift_distributions.chang2013,\n", " }\n", " beta_s_mean = clmm.utils.compute_beta_s_mean_from_distribution(**beta_kwargs)\n", " beta_s_square_mean = clmm.utils.compute_beta_s_square_mean_from_distribution(**beta_kwargs)\n", diff --git a/tests/test_cosmo_parent.py b/tests/test_cosmo_parent.py index 67de814db..d2956917e 100644 --- a/tests/test_cosmo_parent.py +++ b/tests/test_cosmo_parent.py @@ -4,7 +4,7 @@ from numpy.testing import assert_raises, assert_allclose, assert_equal import clmm.theory as theo from clmm.cosmology.parent_class import CLMMCosmology -from clmm.constants import Constants as const +from clmm.utils.constants import Constants as const # ----------- Some Helper Functions for the Validation Tests --------------- diff --git a/tests/test_mockdata.py b/tests/test_mockdata.py index edb202410..48c07df29 100644 --- a/tests/test_mockdata.py +++ b/tests/test_mockdata.py @@ -7,7 +7,7 @@ import clmm.dataops as da from clmm.support import mock_data as mock from clmm.support.sampler import fitters -from clmm.redshift import distributions as zdist +from clmm.utils import redshift_distributions as zdist TOLERANCE = {"rtol": 5.0e-4, "atol": 1.0e-4} @@ -257,17 +257,13 @@ def test_shapenoise(): # Verify that the shape noise is Gaussian around 0 (for the very small shear here) sigma = 0.25 - data = mock.generate_galaxy_catalog( - 10**12.0, 0.3, 4, cosmo, 0.8, ngals=50000, shapenoise=sigma - ) + data = mock.generate_galaxy_catalog(10**12.0, 0.3, 4, cosmo, 0.8, ngals=50000, shapenoise=sigma) # Check that there are no galaxies with |e|>1 assert_equal(np.count_nonzero((data["e1"] > 1) | (data["e1"] < -1)), 0) assert_equal(np.count_nonzero((data["e2"] > 1) | (data["e2"] < -1)), 0) # Check that shape noise is Guassian with correct std dev bins = np.arange(-1, 1.1, 0.1) - gauss = ( - 5000 * np.exp(-0.5 * (bins[:-1] + 0.05) ** 2 / sigma**2) / (sigma * np.sqrt(2 * np.pi)) - ) + gauss = 5000 * np.exp(-0.5 * (bins[:-1] + 0.05) ** 2 / sigma**2) / (sigma * np.sqrt(2 * np.pi)) assert_allclose(np.histogram(data["e1"], bins=bins)[0], gauss, atol=50, rtol=0.05) assert_allclose(np.histogram(data["e2"], bins=bins)[0], gauss, atol=50, rtol=0.05) diff --git a/tests/test_theory.py b/tests/test_theory.py index 6a5a7f96d..14b14ea07 100644 --- a/tests/test_theory.py +++ b/tests/test_theory.py @@ -1,18 +1,19 @@ """Tests for theory/""" + import json import numpy as np from numpy.testing import assert_raises, assert_allclose, assert_equal from astropy.cosmology import FlatLambdaCDM, LambdaCDM import clmm.theory as theo -from clmm.constants import Constants as clc +from clmm.utils.constants import Constants as clc from clmm.galaxycluster import GalaxyCluster from clmm import GCData from clmm.utils import ( compute_beta_s_square_mean_from_distribution, compute_beta_s_mean_from_distribution, compute_beta_s_func, + redshift_distributions as zdist, ) -from clmm.redshift.distributions import chang2013, desc_srd TOLERANCE = {"rtol": 1.0e-8} @@ -565,8 +566,8 @@ def test_shear_convergence_unittests(modeling_data, profile_init): gammat_inf = theo.compute_tangential_shear(cosmo=cosmo, **cfg_inf["GAMMA_PARAMS"]) kappa_inf = theo.compute_convergence(cosmo=cosmo, **cfg_inf["GAMMA_PARAMS"]) - # test z_src = chang2013 distribution - cfg_inf["GAMMA_PARAMS"]["z_src"] = chang2013 + # test z_src = zdist.chang2013 distribution + cfg_inf["GAMMA_PARAMS"]["z_src"] = zdist.chang2013 cfg_inf["GAMMA_PARAMS"]["z_src_info"] = "distribution" # store original values diff --git a/tests/test_utils.py b/tests/test_utils.py index f4d41f2cb..2bd7aeb4d 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -12,8 +12,8 @@ arguments_consistency, validate_argument, DiffArray, + redshift_distributions as zdist, ) -from clmm.redshift import distributions as zdist TOLERANCE = {"rtol": 1.0e-6, "atol": 0} @@ -90,9 +90,7 @@ def test_correct_with_boost_model(): ) # Test requesting unsupported boost model - assert_raises( - KeyError, utils.correct_with_boost_model, rvals, sigma_vals, "glue", boost_rscale - ) + assert_raises(KeyError, utils.correct_with_boost_model, rvals, sigma_vals, "glue", boost_rscale) def test_compute_radial_averages(): @@ -578,7 +576,7 @@ def test_beta_functions(modeling_data): # beta mean from distributions for model in (None, zdist.chang2013, zdist.desc_srd): - # None defaults to chang2013 for compute_beta* functions + # None defaults to chang2013 for compute_beta* functions. if model is None: model = zdist.chang2013