Skip to content

Commit

Permalink
Lightweight docs revamp for v2.last (#1082)
Browse files Browse the repository at this point in the history
* Cleaned docs
  • Loading branch information
damonge authored May 18, 2023
1 parent 0264d66 commit edcfac3
Show file tree
Hide file tree
Showing 85 changed files with 2,362 additions and 2,117 deletions.
2 changes: 1 addition & 1 deletion pyccl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

from . import ccllib as lib
from .errors import *
from .base import *
from ._core import *
from .pyutils import *

from .background import *
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
100 changes: 100 additions & 0 deletions pyccl/_core/parameters/fftlog_params.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
__all__ = ("FFTLogParams",)


class FFTLogParams:
"""Objects of this class store the FFTLog accuracy parameters.
See documentation in :meth:`update_parameters` for a full
description of all allowed parameters.
"""
#: Anti-aliasing. Factor mulitplying the lower boundary.
padding_lo_fftlog = 0.1
#: Anti-aliasing. Factor mulitplying the upper boundary.
padding_hi_fftlog = 10.

#: Samples per decade for the Hankel transforms.
n_per_decade = 100
#: Extrapolation type (`linx_liny`, `linx_logy` etc.).
extrapol = "linx_liny"

#: Padding for intermediate transforms (lower bound).
padding_lo_extra = 0.1
#: Padding for intermediate transforms (upper bound).
padding_hi_extra = 10.
#: If True, high precision intermediate transforms.
large_padding_2D = False

#: Power law index used to prewhiten data before transform.
plaw_fourier = -1.5
#: Pre-whitening power law index for 2D and cumulative profiles.
plaw_projected = -1.0

@property
def params(self):
return ["padding_lo_fftlog", "padding_hi_fftlog", "n_per_decade",
"extrapol", "padding_lo_extra", "padding_hi_extra",
"large_padding_2D", "plaw_fourier", "plaw_projected"]

def to_dict(self):
""" Returns a dictionary containing this object's parameters.
"""
return {param: getattr(self, param) for param in self.params}

def __getitem__(self, name):
return getattr(self, name)

def __setattr__(self, name, value):
raise AttributeError("FFTLogParams can only be updated via "
"`updated_parameters`.")

def __repr__(self):
return repr(self.to_dict())

def __eq__(self, other):
if self is other:
True
if type(self) != type(other):
return False
return self.to_dict() == other.to_dict()

def update_parameters(self, **kwargs):
"""Update the precision of FFTLog for the Hankel transforms.
Arguments
---------
padding_lo_fftlog: :obj:`float`
Factor by which the minimum scale is multiplied to avoid
aliasing. Default: 0.1.
padding_hi_fftlog: :obj:`float`
Factor by which the maximum scale is multiplied to avoid
aliasing. Default: 10.
n_per_decade : :obj:`float`
Samples per decade for the Hankel transforms. Default: 100.
extrapol : {'linx_liny', 'linx_logy'}
Extrapolation type when FFTLog has narrower output support.
Default ``'linx_liny'``.
padding_lo_extra: :obj:`float`
Additional minimum scale padding for double Hankel transforms,
used when computing 2D projected and cumulative profiles. In
these, the first transform goes from 3D real space to
Fourier, and the second transform goes from Fourier to 2D
real space.
Default: 0.1.
padding_hi_extra: :obj:`float`
As ``padding_lo_extra`` for the maximum scale.
Default: 10.
large_padding_2D : :obj:`bool`
Override ``padding_xx_extra`` in the intermediate transform,
and use ``padding_xx_fftlog``. The default is False.
plaw_fourier: :obj:`float`
FFTLog pre-whitens its arguments (makes them flatter) to avoid
aliasing. The ``plaw_fourier`` parameter describes the tilt of
the profile, :math:`P(r) \\propto r^{\\mathrm{tilt}}`, for
standard 3D transforms. Default: -1.5
plaw_fourier_projected: :obj:`float`
As ``plaw_fourier`` for 2D transforms (when computing 2D
projected or cumulative profiles. Default: -1.0.
"""
for name, value in kwargs.items():
if name not in self.params:
raise AttributeError(f"Parameter {name} does not exist.")
object.__setattr__(self, name, value)
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,14 @@


class DefaultParams:
"""Default cosmological parameters used throughout the library."""
"""Default cosmological parameters used throughout the library.
.. warning:: The default values of ``T_CMB`` and ``T_ncdm`` will change
in v3 of CCL.
"""
#: Mean CMB temperature in Kelvin.
T_CMB = 2.725
#: Non-CDM temperature in units of ``T_CMB``.
T_ncdm = 0.71611

warnings.warn(
Expand Down
File renamed without changes.
File renamed without changes.
134 changes: 67 additions & 67 deletions pyccl/background.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@
CCL defines seven species types:
- 'matter': cold dark matter and baryons
- 'dark_energy': cosmological constant or otherwise
- 'radiation': relativistic species besides massless neutrinos (i.e.,
only photons)
- 'curvature': curvature density
- 'neutrinos_rel': relativistic neutrinos
- 'neutrinos_massive': massive neutrinos
* 'matter': cold dark matter and baryons
* 'dark_energy': cosmological constant or otherwise
* 'radiation': relativistic species besides massless neutrinos (i.e., only photons)
* 'curvature': curvature density
* 'neutrinos_rel': relativistic neutrinos
* 'neutrinos_massive': massive neutrinos
These strings define the `species` inputs to the functions below.
"""
""" # noqa
__all__ = (
"Species", "h_over_h0", "comoving_radial_distance", "scale_factor_of_chi",
"comoving_angular_distance", "angular_diameter_distance",
Expand Down Expand Up @@ -53,11 +52,11 @@ def h_over_h0(cosmo, a):
"""Ratio of Hubble constant at `a` over Hubble constant today.
Args:
cosmo (:class:`~pyccl.core.Cosmology`): Cosmological parameters.
a (float or array_like): Scale factor(s), normalized to 1 today.
cosmo (:class:`~pyccl.cosmology.Cosmology`): Cosmological parameters.
a (:obj:`float` or `array`): Scale factor(s), normalized to 1 today.
Returns:
float or array_like: H(a)/H0.
(:obj:`float` or `array`): H(a)/H0.
"""
cosmo.compute_distances()
return _vectorize_fn(lib.h_over_h0,
Expand All @@ -68,11 +67,11 @@ def comoving_radial_distance(cosmo, a):
"""Comoving radial distance.
Args:
cosmo (:class:`~pyccl.core.Cosmology`): Cosmological parameters.
a (float or array_like): Scale factor(s), normalized to 1 today.
cosmo (:class:`~pyccl.cosmology.Cosmology`): Cosmological parameters.
a (:obj:`float` or `array`): Scale factor(s), normalized to 1 today.
Returns:
float or array_like: Comoving radial distance; Mpc.
(:obj:`float` or `array`): Comoving radial distance; Mpc.
"""
cosmo.compute_distances()
return _vectorize_fn(lib.comoving_radial_distance,
Expand All @@ -83,11 +82,11 @@ def scale_factor_of_chi(cosmo, chi):
"""Scale factor, a, at a comoving radial distance chi.
Args:
cosmo (:class:`~pyccl.core.Cosmology`): Cosmological parameters.
chi (float or array_like): Comoving radial distance(s); Mpc.
cosmo (:class:`~pyccl.cosmology.Cosmology`): Cosmological parameters.
chi (:obj:`float` or `array`): Comoving radial distance(s); Mpc.
Returns:
float or array_like: Scale factor(s), normalized to 1 today.
(:obj:`float` or `array`): Scale factor(s), normalized to 1 today.
"""
cosmo.compute_distances()
return _vectorize_fn(lib.scale_factor_of_chi,
Expand All @@ -106,11 +105,11 @@ def comoving_angular_distance(cosmo, a):
:math:`r_{A}(a)` is the comoving angular distance.
Args:
cosmo (:class:`~pyccl.core.Cosmology`): Cosmological parameters.
a (float or array_like): Scale factor(s), normalized to 1 today.
cosmo (:class:`~pyccl.cosmology.Cosmology`): Cosmological parameters.
a (:obj:`float` or `array`): Scale factor(s), normalized to 1 today.
Returns:
float or array_like: Comoving angular distance; Mpc.
(:obj:`float` or `array`): Comoving angular distance; Mpc.
"""
cosmo.compute_distances()
return _vectorize_fn(lib.comoving_angular_distance,
Expand All @@ -131,13 +130,13 @@ def angular_diameter_distance(cosmo, a1, a2=None):
sources at `a2` by passing a scalar `a1`.
Args:
cosmo (:class:`~pyccl.core.Cosmology`): Cosmological parameters.
a1 (float or array_like): Scale factor(s), normalized to 1 today.
a2 (float or array_like): Scale factor(s), normalized to 1 today,
optional.
cosmo (:class:`~pyccl.cosmology.Cosmology`): Cosmological parameters.
a1 (:obj:`float` or `array`): Scale factor(s), normalized to 1 today.
a2 (:obj:`float` or `array`): Scale factor(s), normalized to 1 today,
optional.
Returns:
float or array_like: angular diameter distance; Mpc.
(:obj:`float` or `array`): angular diameter distance; Mpc.
"""
cosmo.compute_distances()
if (a2 is not None):
Expand All @@ -162,11 +161,11 @@ def luminosity_distance(cosmo, a):
"""Luminosity distance.
Args:
cosmo (:class:`~pyccl.core.Cosmology`): Cosmological parameters.
a (float or array_like): Scale factor(s), normalized to 1 today.
cosmo (:class:`~pyccl.cosmology.Cosmology`): Cosmological parameters.
a (:obj:`float` or `array`): Scale factor(s), normalized to 1 today.
Returns:
float or array_like: Luminosity distance; Mpc.
(:obj:`float` or `array`): Luminosity distance; Mpc.
"""
cosmo.compute_distances()
return _vectorize_fn(lib.luminosity_distance,
Expand All @@ -181,11 +180,11 @@ def distance_modulus(cosmo, a):
is the apparent magnitude and M is the absolute magnitude.
Args:
cosmo (:class:`~pyccl.core.Cosmology`): Cosmological parameters.
a (float or array_like): Scale factor(s), normalized to 1 today.
cosmo (:class:`~pyccl.cosmology.Cosmology`): Cosmological parameters.
a (:obj:`float` or `array`): Scale factor(s), normalized to 1 today.
Returns:
float or array_like: Distance modulus at a.
(:obj:`float` or `array`): Distance modulus at a.
"""
cosmo.compute_distances()
return _vectorize_fn(lib.distance_modulus,
Expand All @@ -206,12 +205,12 @@ def sigma_critical(cosmo, *, a_lens, a_source):
to the source, lens, and between source and lens, respectively.
Args:
cosmo (:class:`~pyccl.core.Cosmology`): A Cosmology object.
a_lens (float): lens' scale factor.
a_source (float or array_like): source's scale factor.
cosmo (:class:`~pyccl.cosmology.Cosmology`): A Cosmology object.
a_lens (:obj:`float`): lens' scale factor.
a_source (:obj:`float` or `array`): source's scale factor.
Returns:
float or array_like: :math:`\\Sigma_{\\mathrm{crit}}` in units
(:obj:`float` or `array`): :math:`\\Sigma_{\\mathrm{crit}}` in units
of :math:`\\M_{\\odot}/Mpc^2`
"""
Ds = angular_diameter_distance(cosmo, a_source, a2=None)
Expand All @@ -232,20 +231,20 @@ def omega_x(cosmo, a, species):
"""Density fraction of a given species at a redshift different than z=0.
Args:
cosmo (:class:`~pyccl.core.Cosmology`): Cosmological parameters.
a (float or array_like): Scale factor(s), normalized to 1 today.
species (string): species type. Should be one of
- 'matter': cold dark matter, massive neutrinos, and baryons
- 'dark_energy': cosmological constant or otherwise
- 'radiation': relativistic species besides massless neutrinos
- 'curvature': curvature density
- 'neutrinos_rel': relativistic neutrinos
- 'neutrinos_massive': massive neutrinos
- 'critical'
cosmo (:class:`~pyccl.cosmology.Cosmology`): Cosmological parameters.
a (:obj:`float` or `array`): Scale factor(s), normalized to 1 today.
species (:obj:`str`): species type. Should be one of
* 'matter': cold dark matter, massive neutrinos, and baryons
* 'dark_energy': cosmological constant or otherwise
* 'radiation': relativistic species besides massless neutrinos
* 'curvature': curvature density
* 'neutrinos_rel': relativistic neutrinos
* 'neutrinos_massive': massive neutrinos
* 'critical'
Returns:
float or array_like: Density fraction of a given species at a \
(:obj:`float` or `array`): Density fraction of a given species at a \
scale factor.
"""
# TODO: Replace docstring enum with ref to Species.
Expand All @@ -261,9 +260,9 @@ def rho_x(cosmo, a, species, *, is_comoving=False):
"""Physical or comoving density as a function of scale factor.
Args:
cosmo (:class:`~pyccl.core.Cosmology`): Cosmological parameters.
a (float or array_like): Scale factor(s), normalized to 1 today.
species (string): species type. Should be one of
cosmo (:class:`~pyccl.cosmology.Cosmology`): Cosmological parameters.
a (:obj:`float` or `array`): Scale factor(s), normalized to 1 today.
species (:obj:`str`): species type. Should be one of
- 'matter': cold dark matter, massive neutrinos, and baryons
- 'dark_energy': cosmological constant or otherwise
Expand All @@ -273,10 +272,11 @@ def rho_x(cosmo, a, species, *, is_comoving=False):
- 'neutrinos_massive': massive neutrinos
- 'critical'
is_comoving (bool): either physical (False, default) or comoving (True)
is_comoving (:obj:`bool`): either physical (False, default) or
comoving (True)
Returns:
rho_x (float or array_like): Physical density of a given species
rho_x (:obj:`float` or `array`): Physical density of a given species
at a scale factor, in units of Msun / Mpc^3.
"""
# TODO: Replace docstring enum with ref to Species.
Expand All @@ -291,15 +291,15 @@ def rho_x(cosmo, a, species, *, is_comoving=False):
def growth_factor(cosmo, a):
"""Growth factor.
.. note:: CCL is not able to compute the scale-dependent growth
factor for cosmologies with massive neutrinos.
.. warning:: CCL is not able to compute the scale-dependent growth
factor for cosmologies with massive neutrinos.
Args:
cosmo (:class:`~pyccl.core.Cosmology`): Cosmological parameters.
a (float or array_like): Scale factor(s), normalized to 1 today.
cosmo (:class:`~pyccl.cosmology.Cosmology`): Cosmological parameters.
a (:obj:`float` or `array`): Scale factor(s), normalized to 1 today.
Returns:
float or array_like: Growth factor, normalized to unity today.
(:obj:`float` or `array`): Growth factor, normalized to unity today.
"""
cosmo.compute_growth()
return _vectorize_fn(lib.growth_factor,
Expand All @@ -309,15 +309,15 @@ def growth_factor(cosmo, a):
def growth_factor_unnorm(cosmo, a):
"""Unnormalized growth factor.
.. note:: CCL is not able to compute the scale-dependent growth
factor for cosmologies with massive neutrinos.
.. warning:: CCL is not able to compute the scale-dependent growth
factor for cosmologies with massive neutrinos.
Args:
cosmo (:class:`~pyccl.core.Cosmology`): Cosmological parameters.
a (float or array_like): Scale factor(s), normalized to 1 today.
cosmo (:class:`~pyccl.cosmology.Cosmology`): Cosmological parameters.
a (:obj:`float` or `array`): Scale factor(s), normalized to 1 today.
Returns:
float or array_like: Unnormalized growth factor, normalized to \
(:obj:`float` or `array`): Unnormalized growth factor, normalized to \
the scale factor at early times.
"""
cosmo.compute_growth()
Expand All @@ -329,15 +329,15 @@ def growth_rate(cosmo, a):
"""Growth rate defined as the logarithmic derivative of the
growth factor, dlnD/dlna.
.. note:: CCL is not able to compute the scale-dependent growth
rate for cosmologies with massive neutrinos.
.. warning:: CCL is not able to compute the scale-dependent growth
rate for cosmologies with massive neutrinos.
Args:
cosmo (:class:`~pyccl.core.Cosmology`): Cosmological parameters.
a (float or array_like): Scale factor(s), normalized to 1 today.
cosmo (:class:`~pyccl.cosmology.Cosmology`): Cosmological parameters.
a (:obj:`float` or `array`): Scale factor(s), normalized to 1 today.
Returns:
float or array_like: Growth rate.
(:obj:`float` or `array`): Growth rate.
"""
cosmo.compute_growth()
Expand Down
Loading

0 comments on commit edcfac3

Please sign in to comment.