Skip to content

Commit

Permalink
update boost correction function names
Browse files Browse the repository at this point in the history
  • Loading branch information
combet committed Oct 3, 2024
1 parent 71d1c50 commit bba860e
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 31 deletions.
4 changes: 2 additions & 2 deletions clmm/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
from .boost import (
compute_nfw_boost,
compute_powerlaw_boost,
correct_sigma_with_boost_values,
correct_sigma_with_boost_model,
correct_with_boost_values,
correct_with_boost_model,
boost_models,
)

Expand Down
39 changes: 20 additions & 19 deletions clmm/utils/boost.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""General utility functions that are used in multiple modules"""

import numpy as np


Expand Down Expand Up @@ -54,8 +55,8 @@ def _calc_finternal(r_norm):


def compute_powerlaw_boost(rvals, rscale, boost0=0.1, alpha=-1):
r"""Computes the boost factor at radii rvals using a power-law parametric form
r"""Computes the boost factor at radii rvals using a power-law parametric form
.. math::
B(R) = 1 + B_0 \left(\frac{R}{R_s}\right)^\alpha
Expand Down Expand Up @@ -87,35 +88,35 @@ def compute_powerlaw_boost(rvals, rscale, boost0=0.1, alpha=-1):
}


def correct_sigma_with_boost_values(sigma_vals, boost_factors):
"""Given a list of boost values and sigma profile, compute corrected sigma
def correct_with_boost_values(profile_vals, boost_factors):
"""Given a list of profile (shear or DeltaSigma) values and boost values, compute corrected profile
Parameters
----------
sigma_vals : array_like
uncorrected sigma with cluster member dilution
profile_vals : array_like
Uncorrected profile values
boost_factors : array_like
Boost values pre-computed
Boost values, pre-computed
Returns
-------
sigma_corrected : numpy.ndarray
correted radial profile
profile_vals_corrected : numpy.ndarray
Corrected radial profile
"""

sigma_corrected = np.array(sigma_vals) / np.array(boost_factors)
return sigma_corrected
profile_vals_corrected = np.array(profile_vals) / np.array(boost_factors)
return profile_vals_corrected


def correct_sigma_with_boost_model(rvals, sigma_vals, boost_model, boost_rscale, **boost_model_kw):
def correct_with_boost_model(rvals, profile_vals, boost_model, boost_rscale, **boost_model_kw):
"""Given a boost model and sigma profile, compute corrected sigma
Parameters
----------
rvals : array_like
radii
sigma_vals : array_like
uncorrected sigma with cluster member dilution
Radii
profile_vals : array_like
Uncorrected profile values
boost_model : str, optional
Boost model to use for correcting sigma
Expand All @@ -124,14 +125,14 @@ def correct_sigma_with_boost_model(rvals, sigma_vals, boost_model, boost_rscale,
Returns
-------
sigma_corrected : numpy.ndarray
correted radial profile
profile_vals_corrected : numpy.ndarray
Correted radial profile
"""
boost_model_func = boost_models[boost_model]
boost_factors = boost_model_func(rvals, boost_rscale, **boost_model_kw)

sigma_corrected = np.array(sigma_vals) / boost_factors
return sigma_corrected
profile_vals_corrected = np.array(profile_vals) / boost_factors
return profile_vals_corrected


boost_models = {
Expand Down
10 changes: 5 additions & 5 deletions examples/demo_boost_factors.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -333,10 +333,10 @@
"metadata": {},
"outputs": [],
"source": [
"Sigma_corrected_powerlaw_boost = u.correct_sigma_with_boost_values(\n",
"Sigma_corrected_powerlaw_boost = u.correct_with_boost_values(\n",
" cl.DeltaSigma_profile[\"DeltaSigma_tan\"], powerlaw_boost\n",
")\n",
"Sigma_corrected_nfw_boost = u.correct_sigma_with_boost_values(\n",
"Sigma_corrected_nfw_boost = u.correct_with_boost_values(\n",
" cl.DeltaSigma_profile[\"DeltaSigma_tan\"], nfw_boost\n",
")"
]
Expand Down Expand Up @@ -394,7 +394,7 @@
"id": "67c5e14a",
"metadata": {},
"source": [
"Now the same again but with `correct_sigma_with_boost_model`"
"Now the same again but with `correct_with_boost_model`"
]
},
{
Expand All @@ -404,13 +404,13 @@
"metadata": {},
"outputs": [],
"source": [
"Sigma_corrected_powerlaw_boost = u.correct_sigma_with_boost_model(\n",
"Sigma_corrected_powerlaw_boost = u.correct_with_boost_model(\n",
" cl.DeltaSigma_profile[\"radius\"],\n",
" cl.DeltaSigma_profile[\"DeltaSigma_tan\"],\n",
" \"powerlaw_boost\", # boost_model\n",
" 1000, # boost_rscale (in units of cl.DeltaSigma_profile[\"radius\"])\n",
")\n",
"Sigma_corrected_nfw_boost = u.correct_sigma_with_boost_model(\n",
"Sigma_corrected_nfw_boost = u.correct_with_boost_model(\n",
" cl.DeltaSigma_profile[\"radius\"],\n",
" cl.DeltaSigma_profile[\"DeltaSigma_tan\"],\n",
" \"nfw_boost\", # boost_model\n",
Expand Down
12 changes: 7 additions & 5 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,19 @@ def test_compute_powerlaw_boost():
assert_allclose(boost_factors, test_boost_factors)


def test_correct_sigma_with_boost_values():
def test_correct_with_boost_values():
""" """
# Make test data
rvals = np.arange(1, 11)
sigma_vals = (2 ** np.arange(10)).tolist()

test_unit_boost_factors = np.ones(rvals.shape).tolist()

corrected_sigma = utils.correct_sigma_with_boost_values(sigma_vals, test_unit_boost_factors)
corrected_sigma = utils.correct_with_boost_values(sigma_vals, test_unit_boost_factors)
assert_allclose(sigma_vals, corrected_sigma)


def test_correct_sigma_with_boost_model():
def test_correct_with_boost_model():
""" """
# Make test data
rvals = np.arange(1, 11).tolist()
Expand All @@ -85,12 +85,14 @@ def test_correct_sigma_with_boost_model():
# Check for no nans or inf with positive-definite rvals and sigma vals
assert np.all(
np.isfinite(
utils.correct_sigma_with_boost_model(rvals, sigma_vals, boost_model, boost_rscale)
utils.correct_with_boost_model(rvals, sigma_vals, boost_model, boost_rscale)
)
)

# Test requesting unsupported boost model
assert_raises(KeyError, utils.correct_sigma_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

0 comments on commit bba860e

Please sign in to comment.