Package cosmolopy :: Module utils

Module utils

source code

Some utilities used by various CosmoloPy modules.
Classes
  AgeSpacedRedshift
Set up uniform time array and corresponding redshift array.
  Extrapolate1d
Interpolate/Extrapolate 1d data.
  PiecewisePowerlaw
A piecewise powerlaw function.
  Normalize
A decorator that normalizes a function.
Functions
 
ccumulate(function, x, max=None, **kwargs)
Integrate a function from x to max, where x can be an array.
source code
 
integrate_piecewise(function, x, method='romberg', return_pieces=False, **kwargs)
Integrate function and return the integral at a sequence of points.
source code
 
vecquad(function, low, high, **kwargs)
Integrate a function from low to high (vectorized).
source code
 
logquad(function, low, high, **kwargs)
Integrate a function from low to high using a log transform (vectorized).
source code
Variables
  __package__ = 'cosmolopy'
Function Details

ccumulate(function, x, max=None, **kwargs)

source code 

Integrate a function from x to max, where x can be an array.

Parameters

function: callable

x: array-like

max: float
defaults to max(x)

Notes

This can be used to find the complementary cumulative distribution function (CCDF) given the probability distribution function (PDF).

Unlike integrate_piecewise, the x values don't have to be in order, though a warning will be issued if any are greater than max, if max is specified.

integrate_piecewise(function, x, method='romberg', return_pieces=False, **kwargs)

source code 

Integrate function and return the integral at a sequence of points.

Useful when you want to efficiently calculate a cumulative integral.

Also useful for piecewise-defined functions where discontinuities or critical points cause quadrature routines to complain or become inaccurate.

Integration methods available are: quad, romberg.

Parameters

function : callable
User defined function. Should take a single vector argument and return q vector of the same shape.
x : array_like
Array of points at which to evaluate the integral.
method : str, optional
Name of the method to use to integrate each segment. 'quad' or 'romberg'.
return_pieces : bool, optional
Return the individual segments rather than the sum of all preceding segments.

Returns

integral : ndarray
The value of the integral at each x. The first value is always zero.

vecquad(function, low, high, **kwargs)

source code 

Integrate a function from low to high (vectorized).

Vectorized convenience function.

logquad(function, low, high, **kwargs)

source code 

Integrate a function from low to high using a log transform (vectorized).

The log transform is applied to the variable over which the integration is being performed.