Package cosmolopy :: Module utils :: Class PiecewisePowerlaw

Class PiecewisePowerlaw

source code

object --+
         |
        PiecewisePowerlaw

A piecewise powerlaw function.

You can specify the intervals and power indices, and this class will figure out the coefficients needed to make the function continuous and normalized to unit integral.

Notes

Intervals are defined by an array l

Powerlaw indicies by and array p

a_n are the coefficients.

f(x) = a_n x^{p_n} for l_{n-1} <= x < l_n

Recursion relation for continuity:

a_n = a_{n-1} l_n^{p_{n-1} - p_n}

Integral of a piece:

I_n = a_n p_n (l_{n+1}^{p_n - 1} - l_n^{p_n - 1})

Total integral:

I_tot = Sum_0^N I_n

Instance Methods
 
__init__(self, limits, powers, coefficients=None, externalval=0.0, norm=True)
Defined a piecewise powerlaw.
source code
 
__call__(self, x)
Evaluate the powerlaw at values x.
source code
 
integrate(self, low, high, weight_power=None)
Integrate the function from low to high.
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Properties

Inherited from object: __class__

Method Details

__init__(self, limits, powers, coefficients=None, externalval=0.0, norm=True)
(Constructor)

source code 

Defined a piecewise powerlaw.

If coefficients is None then the coefficients are determined by requiring the function to be continuous and normalized to an integral of one.

The function is composed of N powerlaws, where N = len(powers).

len(limits) must be one greated than len(powers)

Parameters

limits: array (length n+1)
boundaries of the specified powerlaws. Must be one greater in length than coefficents and powers. Specify -numpy.infty for the first limit or numpy.infty for the last limit for unbounded powerlaws.
coefficients: optional array (length n)
values of the coefficient a_i
powers: array (length n)
values of the powerlaw indices p_i
externalval: scalar
Value to return outside the defined domain. None correspons to 'NaN'.
norm: boolean
Whether to normalize the integral of the function over the defined domain to unity.

The resulting function takes a single, one-dimensional array of values on which to operate.

Overrides: object.__init__

integrate(self, low, high, weight_power=None)

source code 

Integrate the function from low to high.

Optionally weight the integral by x^weight_power.