Skip to content

Commit

Permalink
Merge pull request #321 from LSSTDESC/readthedocs_development
Browse files Browse the repository at this point in the history
Readthedocs development
  • Loading branch information
elisachisari authored Jul 13, 2018
2 parents c52a8a7 + 9b1a3ab commit fa4f0d3
Show file tree
Hide file tree
Showing 34 changed files with 866 additions and 120 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# If CLASS was installed via our script, don't include it.
class

# Ignore RTD documentation special files
readthedocs/_build
readthedocs/*~
readthedocs/source/*~

# Ignore autoconf build files.
Makefile
config.h
Expand Down
3 changes: 3 additions & 0 deletions pyccl/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
"""The pyccl package contains all of the submodules that are implemented in individual files in CCL.
"""

# Sets the environment variable for default config path if it does not exist yet
from os import environ, path
if environ.get("CCL_PARAM_FILE") is None:
Expand Down
27 changes: 13 additions & 14 deletions pyccl/background.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

from pyccl import ccllib as lib
from pyccl.pyutils import _vectorize_fn, _vectorize_fn2, _vectorize_fn3, _vectorize_fn4

Expand All @@ -20,7 +19,7 @@ def growth_factor(cosmo, a):
a (float or array_like): Scale factor(s), normalized to 1 today.
Returns:
growth_factor (float or array_like): Growth factor.
float or array_like: Growth factor.
"""
return _vectorize_fn(lib.growth_factor,
Expand All @@ -34,7 +33,7 @@ def growth_factor_unnorm(cosmo, a):
a (float or array_like): Scale factor(s), normalized to 1 today.
Returns:
growth_factor_unnorm (float or array_like): Unnormalized growth factor, normalized to the scale factor at early times.
float or array_like: Unnormalized growth factor, normalized to the scale factor at early times.
"""
return _vectorize_fn(lib.growth_factor_unnorm,
Expand All @@ -48,7 +47,7 @@ def growth_rate(cosmo, a):
a (float or array_like): Scale factor(s), normalized to 1 today.
Returns:
growth_rate (float or array_like): Growth rate; .
float or array_like: Growth rate.
"""
return _vectorize_fn(lib.growth_rate,
Expand All @@ -62,23 +61,23 @@ def comoving_radial_distance(cosmo, a):
a (float or array_like): Scale factor(s), normalized to 1 today.
Returns:
comoving_radial_distance (float or array_like): Comoving radial distance; Mpc.
float or array_like: Comoving radial distance; Mpc.
"""
return _vectorize_fn(lib.comoving_radial_distance,
lib.comoving_radial_distance_vec, cosmo, a)

def comoving_angular_distance(cosmo, a):
"""Comoving angular distance.
NOTE this quantity is otherwise known as the transverse comoving distance, and is NOT angular diameter
distance or angular separation
.. note:: this quantity is otherwise known as the transverse comoving distance, and is NOT angular diameter distance or angular separation
Args:
cosmo (:obj:`ccl.cosmology`): Cosmological parameters.
a (float or array_like): Scale factor(s), normalized to 1 today.
Returns:
comoving_angular_distance (float or array_like): Comoving angular distance; Mpc.
float or array_like: Comoving angular distance; Mpc.
"""
return _vectorize_fn(lib.comoving_angular_distance,
Expand All @@ -92,7 +91,7 @@ def h_over_h0(cosmo, a):
a (float or array_like): Scale factor(s), normalized to 1 today.
Returns:
h_over_h0 (float or array_like): H(a)/H0.
float or array_like: H(a)/H0.
"""
return _vectorize_fn(lib.h_over_h0,
Expand All @@ -106,7 +105,7 @@ def luminosity_distance(cosmo, a):
a (float or array_like): Scale factor(s), normalized to 1 today.
Returns:
luminosity_distance (float or array_like): Luminosity distance; Mpc.
float or array_like: Luminosity distance; Mpc.
"""
return _vectorize_fn(lib.luminosity_distance,
Expand All @@ -120,7 +119,8 @@ def distance_modulus(cosmo, a):
a (float or array_like): Scale factor(s), normalized to 1 today.
Returns:
distance_modulus (float or array_like): Distance modulus at a.
float or array_like: Distance modulus at a.
"""
return _vectorize_fn(lib.distance_modulus,
lib.distance_modulus_vec, cosmo, a)
Expand All @@ -133,7 +133,7 @@ def scale_factor_of_chi(cosmo, chi):
chi (float or array_like): Comoving distance(s); Mpc.
Returns:
scale_factor_of_chi (float or array_like): Scale factor(s), normalized to 1 today.
float or array_like: Scale factor(s), normalized to 1 today.
"""
return _vectorize_fn(lib.scale_factor_of_chi,
Expand All @@ -149,8 +149,7 @@ def omega_x(cosmo, a, label):
'radiation', 'curvature', 'neutrinos_rel', and 'neutrinos_massive'
Returns:
omega_x (float or array_like): Density fraction of a given species
at a scale factor.
float or array_like: Density fraction of a given species at a scale factor.
"""
if label not in species_types.keys() :
Expand Down
80 changes: 27 additions & 53 deletions pyccl/cls.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,24 +40,9 @@
NoneArr = np.array([])

class ClTracer(object):
"""ClTracer class used to wrap the cl_tracer found
in CCL.
"""ClTracer is a general class used to wrap the cl_tracer found in CCL. A ClTracer is a data structure that contains all information describing the transfer functon of one tracer of the matter distribution. If an object has an angular power spectrum then it can be described by a tracer.
A ClTracer is a data structure that contains all information
describing the transfer functon of one tracer of the matter
distribution.
"""

def __init__(self, cosmo, tracer_type=None, has_rsd=False,
has_magnification=False, has_intrinsic_alignment=False,
z=None, n=None, bias=None, mag_bias=None, bias_ia=None,
f_red=None,z_source=1100.):
"""
ClTracer is a class for handling tracers that have an angular power
spectrum.
Note: unless otherwise stated, defaults are None.
.. note:: unless otherwise stated, defaults are None.
Args:
cosmo (:obj:`Cosmology`): Cosmology object.
Expand Down Expand Up @@ -88,7 +73,13 @@ def __init__(self, cosmo, tracer_type=None, has_rsd=False,
f_red (array_like or tuple, optional): Array of red galaxy
fractions f_red(z), or a tuple of arrays (z, f_red(z)).
z_source (float, optional): Redshift of source plane for CMB lensing.
"""
"""

def __init__(self, cosmo, tracer_type=None, has_rsd=False,
has_magnification=False, has_intrinsic_alignment=False,
z=None, n=None, bias=None, mag_bias=None, bias_ia=None,
f_red=None,z_source=1100.):
# Verify cosmo object
cosmo = _cosmology_obj(cosmo)

Expand Down Expand Up @@ -180,22 +171,14 @@ def get_internal_function(self, cosmo, function, a):

def __del__(self):
"""Free memory associated with CCL_ClTracer object.
"""
if hasattr(self, 'has_cltracer'):
if self.has_cltracer:
lib.cl_tracer_free(self.cltracer)


class ClTracerNumberCounts(ClTracer):
"""
ClTracer for galaxy number counts (galaxy clustering).
"""

def __init__(self, cosmo, has_rsd, has_magnification,
n, bias, z=None, mag_bias=None):
"""
ClTracer class for a tracer of galaxy number counts (galaxy clustering).
"""ClTracer for galaxy number counts (galaxy clustering).
Args:
cosmo (:obj:`Cosmology`): Cosmology object.
Expand All @@ -217,8 +200,11 @@ def __init__(self, cosmo, has_rsd, has_magnification,
mag_bias (array_like or tuple, optional): Array of magnification
bias s(z) sampled at the redshifts given in the z array, or a
tuple of arrays (z, s(z)).
"""
"""

def __init__(self, cosmo, has_rsd, has_magnification,
n, bias, z=None, mag_bias=None):
# Sanity check on input arguments
if has_magnification and mag_bias is None:
raise ValueError("Keyword arg 'mag_bias' must be specified if "
Expand All @@ -234,14 +220,7 @@ def __init__(self, cosmo, has_rsd, has_magnification,


class ClTracerLensing(ClTracer):
"""
ClTracer for weak lensing shear (galaxy shapes).
"""

def __init__(self, cosmo, has_intrinsic_alignment,
n, z=None, bias_ia=None, f_red=None):
"""
ClTracer class for a tracer of weak lensing shear (galaxy shapes).
"""ClTracer for weak lensing shear (galaxy shapes).
Args:
cosmo (:obj:`Cosmology`): Cosmology object.
Expand All @@ -259,8 +238,11 @@ def __init__(self, cosmo, has_intrinsic_alignment,
alignment amplitudes b_IA(z), or a tuple of arrays (z, b_IA(z)).
f_red (array_like or tuple, optional): Array of red galaxy
fractions f_red(z), or a tuple of arrays (z, f_red(z)).
"""
"""

def __init__(self, cosmo, has_intrinsic_alignment,
n, z=None, bias_ia=None, f_red=None):
# Sanity check on input arguments
if has_intrinsic_alignment \
and (bias_ia is None or f_red is None):
Expand All @@ -277,19 +259,15 @@ def __init__(self, cosmo, has_intrinsic_alignment,


class ClTracerCMBLensing(ClTracer):
"""
ClTracer for CMB lensing.
"""

def __init__(self, cosmo, z_source):
"""
ClTracer class for a tracer of CMB lensing.
"""ClTracer for CMB lensing.
Args:
cosmo (:obj:`Cosmology`): Cosmology object.
z_source (float): Redshift of source plane for CMB lensing.
"""
"""

def __init__(self, cosmo, z_source):
# Call ClTracer constructor with appropriate arguments
super(ClTracerCMBLensing, self).__init__(
cosmo=cosmo, tracer_type='cmbl',
Expand All @@ -300,9 +278,7 @@ def __init__(self, cosmo, z_source):


def _cltracer_obj(cltracer):
"""
Returns a CCL_ClTracer object, given an input object which may be
CCL_ClTracer, the ClTracer wrapper class, or an invalid type.
"""Returns a CCL_ClTracer object, given an input object which may be CCL_ClTracer, the ClTracer wrapper class, or an invalid type.
Args:
cltracer (:obj:): Either a CCL_ClTracer or the ClTracer wrapper class.
Expand All @@ -321,9 +297,7 @@ def _cltracer_obj(cltracer):


def _check_array_params(z, f_arg, f_name):
"""
Check whether an argument `f_arg` passed into the constructor of ClTracer()
is valid.
"""Check whether an argument `f_arg` passed into the constructor of ClTracer() is valid.
If the argument is set to `None`, it will be replaced with a special array
that signals to the CCL wrapper that this argument is NULL.
Expand Down Expand Up @@ -354,6 +328,7 @@ def _check_array_params(z, f_arg, f_name):
f = np.atleast_1d(f_arg)
return z_f, f


def angular_cl(cosmo, cltracer1, cltracer2, ell,
l_limber=-1.,l_logstep=1.05,l_linstep=20.,dchi=3., dlk=0.003, zmin=0.05,
non_limber_method="native"):
Expand All @@ -376,8 +351,7 @@ def angular_cl(cosmo, cltracer1, cltracer2, ell,
"native" and "angpow"
Returns:
cl (float or array_like): Angular (cross-)power spectrum values, C_ell,
for the pair of tracers, as a function of `ell`.
float or array_like: Angular (cross-)power spectrum values, :math:`C_\ell`, for the pair of tracers, as a function of :math:`\ell`.
"""
# Access ccl_cosmology object
Expand Down
2 changes: 2 additions & 0 deletions pyccl/constants.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
"""This file exposes constants present in CCL.
"""
from pyccl.ccllib import \
CCL_ClTracer, CCL_ClTracer_swigregister, \
CCL_ERROR_CLASS, CCL_ERROR_INCONSISTENT, CCL_ERROR_INTEG, CCL_ERROR_LINSPACE, \
Expand Down
Loading

0 comments on commit fa4f0d3

Please sign in to comment.