Skip to content

Commit

Permalink
Merge pull request #1217 from LSSTDESC/master
Browse files Browse the repository at this point in the history
Merge branch 'master' into SSC
  • Loading branch information
RyoTerasawa authored Dec 8, 2024
2 parents 2925dac + 406b548 commit 2f5417a
Show file tree
Hide file tree
Showing 21 changed files with 417 additions and 63 deletions.
4 changes: 1 addition & 3 deletions benchmarks/test_ptpk.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import pyccl as ccl
import pyccl.nl_pt as pt
import pytest
from contextlib import nullcontext

# Set cosmology
COSMO = ccl.Cosmology(Omega_c=0.25, Omega_b=0.05,
Expand Down Expand Up @@ -50,8 +49,7 @@ def test_pt_pk(comb):
ptt1 = ptt[t1]
ptt2 = ptt[t2]

with pytest.warns(ccl.CCLWarning) if comb[1] == "gi" else nullcontext():
pk = ptc.get_biased_pk2d(ptt1, tracer2=ptt2, return_ia_bb=return_bb)
pk = ptc.get_biased_pk2d(ptt1, tracer2=ptt2, return_ia_bb=return_bb)

for iz, z in enumerate(zs):
a = 1./(1+z)
Expand Down
6 changes: 3 additions & 3 deletions pyccl/_nonlimber_FKEM.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@
(https://jila.colorado.edu/~ajsh/FFTLog/fftlog.pdf)
to compute integrals over spherical bessel functions
"""
import warnings
import numpy as np
from . import lib, check
from .pyutils import integ_types
from scipy.interpolate import interp1d
from pyccl.pyutils import _fftlog_transform_general
import pyccl as ccl
from . import CCLWarning
from . import CCLWarning, warnings


def _get_general_params(b):
Expand Down Expand Up @@ -66,7 +65,8 @@ def _nonlimber_FKEM(
warnings.warn(
"p_of_k_a and p_of_k_a_lin must be of the same "
"type: a str in cosmo or a Pk2D object. "
"Defaulting to Limber calculation. ", CCLWarning)
"Defaulting to Limber calculation. ",
category=CCLWarning, importance='high')
return -1, np.array([]), status

psp_lin = cosmo.parse_pk2d(p_of_k_a_lin, is_linear=True)
Expand Down
12 changes: 6 additions & 6 deletions pyccl/baryons/baccoemu_baryons.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

import numpy as np
from copy import deepcopy
from warnings import warn

from .. import Pk2D
from .. import Pk2D, CCLDeprecationWarning
from . import Baryons


Expand Down Expand Up @@ -216,8 +215,9 @@ class BaccoemuBaryons(BaryonsBaccoemu):

def __init__(self, *args, **kwargs):
"""This throws a deprecation warning on initialization."""
warn(f"Class {self.__class__.__name__} will be deprecated. " +
f"Please use {BaryonsBaccoemu.__name__} instead.",
DeprecationWarning, stacklevel=2)
from .. import warnings
warnings.warn(f"Class {self.__class__.__name__} will be deprecated. " +
f"Please use {BaryonsBaccoemu.__name__} instead.",
CCLDeprecationWarning, stacklevel=2,
importance='low')
super().__init__(*args, **kwargs)
pass
2 changes: 1 addition & 1 deletion pyccl/ccl.i
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ from .errors import CCLError
%init %{
import_array();
// Tell CCL to not print to stdout/stderr for debugging.
ccl_set_debug_policy(CCL_DEBUG_MODE_ON);
ccl_set_debug_policy(CCL_DEBUG_MODE_OFF);
%}

// Automatically document arguments and output types of all functions
Expand Down
11 changes: 4 additions & 7 deletions pyccl/cells.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
__all__ = ("angular_cl",)

import warnings

import numpy as np

from . import DEFAULT_POWER_SPECTRUM, CCLWarning, check, lib
from . import DEFAULT_POWER_SPECTRUM, CCLWarning, check, lib, warnings
from .pyutils import integ_types
from ._nonlimber_FKEM import _nonlimber_FKEM

Expand Down Expand Up @@ -56,15 +54,15 @@ def angular_cl(
the kernels are defined will be used (capped to 1E-6 Mpc if this
value is zero). Users are encouraged to experiment with this parameter
and ``fkem_Nchi`` to ensure the robustness of the output
:math:`C_\\ell`s.
:math:`C_\\ell` s.
fkem_Nchi: Number of values of the comoving distance over which `FKEM`
will interpolate the radial kernels. If ``None`` the smallest number
over which the kernels are currently sampled will be used. Note that
`FKEM` will use a logarithmic sampling for distances between
``fkem_chi_min`` and the maximum distance over which the tracers
are defined. Users are encouraged to experiment with this parameter
and ``fkem_chi_min`` to ensure the robustness of the output
:math:`C_\\ell`s.
:math:`C_\\ell` s.
p_of_k_a_lin (:class:`~pyccl.pk2d.Pk2D`, :obj:`str` or :obj:`None`):
3D linear Power spectrum to project, for special use in
PT calculations using the FKEM non-limber integration technique.
Expand All @@ -84,8 +82,7 @@ def angular_cl(
warnings.warn(
"CCL does not properly use the hyperspherical Bessel functions "
"when computing angular power spectra in non-flat cosmologies!",
category=CCLWarning,
)
category=CCLWarning, importance='low')

if limber_integration_method not in integ_types:
raise ValueError(
Expand Down
52 changes: 48 additions & 4 deletions pyccl/errors.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,50 @@
__all__ = ("CCLError", "CCLWarning", "CCLDeprecationWarning",)
__all__ = ("CCLError", "CCLWarning", "CCLDeprecationWarning",
"warnings", "update_warning_verbosity")

import warnings
import warnings as warnings_builtin


_warning_importance = {'high': 10, 'low': 1}
_verbosity_thresholds = {'none': 100, 'low': 10, 'high': 1}


class warnings:
_CCL_WARN_THRESHOLD = 10 # Equivalent to "low" verbosity

def warn(*args, **kwargs):
category = kwargs.get('category')
importance = _warning_importance[kwargs.pop('importance', 'low')]

if ((category in (CCLWarning, CCLDeprecationWarning)) and
(importance < warnings._CCL_WARN_THRESHOLD)):
return

warnings_builtin.warn(*args, **kwargs)


def update_warning_verbosity(verbosity):
""" Update the level of verbosity of the CCL warnings. Available
levels are "none", "low", and "high". More warning messages will
be output for higher verbosity levels. If "none", no CCL-level
warnings will be shown. The default verbosity is "low". Note that
unless the verbosity level is "high", all C-level warnings will
be omitted.
Args:
verbosity (str): one of ``'none'``, ``'low'`` or ``'high'``.
"""

if not (verbosity in ['none', 'low', 'high']):
raise KeyError("`verbosity` must be one of {'none', 'low', 'high'}")
warnings._CCL_WARN_THRESHOLD = _verbosity_thresholds[verbosity]

# Remove C-level warnings
from . import debug_mode

if verbosity == 'high':
debug_mode(True)
else:
debug_mode(False)


class CCLError(RuntimeError):
Expand Down Expand Up @@ -40,8 +84,8 @@ def __hash__(self):

@classmethod
def enable(cls):
warnings.simplefilter("always")
warnings_builtin.simplefilter("always")

@classmethod
def disable(cls):
warnings.filterwarnings(action="ignore", category=cls)
warnings_builtin.filterwarnings(action="ignore", category=cls)
Loading

0 comments on commit 2f5417a

Please sign in to comment.