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

Issue/654/redshift to utils #655

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion .github/workflows/build_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion clmm/cosmology/cluster_toolkit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 2 additions & 3 deletions clmm/cosmology/parent_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion clmm/dataops/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion clmm/galaxycluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
compute_background_probability,
)
from .theory import compute_critical_surface_density_eff
from .plotting import plot_profiles
from .utils import (
validate_argument,
_validate_ra,
_validate_dec,
_draw_random_points_from_tab_distribution,
_validate_coordinate_system,
)
from .utils.plotting import plot_profiles


class GalaxyCluster:
Expand Down
8 changes: 0 additions & 8 deletions clmm/redshift/__init__.py

This file was deleted.

2 changes: 1 addition & 1 deletion clmm/support/mock_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 0 additions & 2 deletions clmm/theory/parent_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
from ..utils import (
validate_argument,
compute_beta_s_func,
)
from ..redshift import (
_integ_pzfuncs,
compute_for_good_redshifts,
)
Expand Down
7 changes: 7 additions & 0 deletions clmm/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion clmm/utils/beta_lens.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 3 additions & 1 deletion clmm/utils/validation.py
Original file line number Diff line number Diff line change
@@ -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=""):
Expand Down Expand Up @@ -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.

Expand All @@ -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)"""

Expand Down
3 changes: 0 additions & 3 deletions docs/doc-config.ini
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
APIDOC
clusterensemble
constants
cosmology
dataops
galaxycluster
gcdata
redshift
theory
plotting
utils
support

Expand Down
2 changes: 1 addition & 1 deletion examples/demo_theory_functionality.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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]"
]
},
Expand Down
2 changes: 1 addition & 1 deletion examples/demo_theory_functionality_diff_z_types.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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 *"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion examples/demo_theory_functionality_oo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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]"
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion tests/test_cosmo_parent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ---------------

Expand Down
10 changes: 3 additions & 7 deletions tests/test_mockdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}

Expand Down Expand Up @@ -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)

Expand Down
9 changes: 5 additions & 4 deletions tests/test_theory.py
Original file line number Diff line number Diff line change
@@ -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}

Expand Down Expand Up @@ -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
Expand Down
8 changes: 3 additions & 5 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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():
Expand Down Expand Up @@ -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
Expand Down
Loading