rabacus.constants package

Submodules

rabacus.constants.physical module

Physical constants from NIST (http://physics.nist.gov/cuu/Constants/index.html). We also make use of constants defined by the IAU-2009 Report (pdf included in the doc/ref directory).

class rabacus.constants.physical.PhysicalConstants[source]

Physical constants.

Attributes:

m_p: proton mass.

m_n: neutraon mass.

m_e: electron mass.

c: speed of light in vacuum.

h: Planck constant.

kb: Boltzmann constant.

Rbohr: Bohr radius.

sigma_t: Thomson cross-section.

alpha: fine-structure constant.

G: Newtonian constant of gravitation.

Ry_inf: Rydberg constant times hc.

sfkb: Stefan-Boltzmann constant.

GMsun: solar mass parameter.

Msun: solar mass.

AU: IAU defined astronomical unit.

rabacus.constants.units module

A wrapper to the quantities package (https://github.com/python-quantities/python-quantities) providing units.

class rabacus.constants.units.Units[source]

Standard units.

Attributes:

dimensionless: no units

angstrom: angstrom

nm: nanometer

um: micrometer

cm: centimeter

m: meter

km: kilometer

pc: parsec

AU: atronomical unit

kpc: kiloparsec

Mpc: megaparsec

s: second

yr: year

Myr: megayear

Gyr: gigayear

g: gram

kg: kilogram

Msun: solar mass

erg: erg

eV: electron volt

J: joule

Ry_inf: rydberg energy unit (infinite nucleus mass compared to electron)

Ry_H: rydberg energy unit (reduced mass for H electron)

K: kelvin

Hz: Hertz

sr: steradian

class rabacus.constants.units.CosmoUnits(h, a)[source]

Bases: rabacus.constants.units.Units

Provides cosmological units.

Args:

h (float): hubble parameter, H_0 = 100 h km / s / Mpc

a (float): scale factor for co-moving conversions

Module contents

The constants package provides classes which handle physical constants and units. In particular,

Units and Physical Constants

All variables in Rabacus are quantities . In other words, they have a magnitude and associated units. Whenever the module is imported an instance of both PhysicalConstants and Units will be attached as pc and u respectively.

>>> import rabacus as ra
>>> d = 100 * ra.u.kpc
>>> d
array(100.0) * kpc

Note that scalars are represented as 0-d arrays. The units of any quantity are stored as an attribute and can be changed by string assignment,

>>> d.units
array(1.0) * kpc
>>> d.units = 'cm'
>>> d
array(3.08568025e+23) * cm

Each quantity has a function called rescale that will return the quantity in a different set of units without modifying its current units.

>>> d.rescale('mile')
array(1.9173528158056945e+18) * mi
>>> d
array(3.08568025e+23) * cm

One can access just the magnitude of any quantity in its current units,

>>> d.magnitude
array(3.08568025e+23)

Attempting to take the log of a quantity with dimensions will raise a ValueError so one should always use a magnitude when calculating logarithms.

>>> import numpy as np
>>> np.log10( d.magnitude ) 
23.489350920801908

Dividing two length units will produce a hybrid unit,

>>> r = d / (10 * ra.u.kpc)
>>> r
array(3.0856802499999998e+22) * cm/kpc

that can be reduced using the attribute simplified.

>>> r.simplified
array(10.0) * dimensionless

Cosmological Units

By creating an instance of CosmoUnits one can also use the hubble parameter and scale factor as units. However one must be careful about accidentally mixing unit systems with different values for h and a. When rabacus is imported, an instance of the cosmology class is created with parameters reported by the Planck mission. The included Planck cosmology is called planck13_cosmology.

>>> import rabacus as ra
>>> ra.planck13_cosmology.H0
array(100.0) * km*hh/(s*Mpc)

Note that the h unit is indicated with a double hh. Similarly the scale factor unit is indicated with a double aa. This is because h and a are already units in the quantities package. The above statement is an expression of the fact that the Hubble parameter is always 100 in units of km/s/(Mpc/h). By requesting the quantity in units of km/s/Mpc we recover the value specific to the Planck cosmology,

>>> ra.planck13_cosmology.H0.rescale('km/s/Mpc')
array(67.11182) * km/(s*Mpc)

Suppose we create another hubble parameter,

>>> h = 0.7
>>> H0 = 100 * h * ra.u.km / ra.u.s / ra.u.Mpc
>>> H0
array(70.0) * km/(s*Mpc)

and then request it in units of km/s/(Mpc/h)

>>> H0.units = 'hh*km/s/Mpc'
>>> H0
array(104.30353401233941) * km*hh/(s*Mpc)

We don’t get the expected value of 100 because the hubble parameter associated with the set of units in ra.u is the Planck13 value. However, if we create a new instance of CosmoUnits we get the correct result,

>>> cu = ra.CosmoUnits(h=0.7,a=1.0)
>>> H0 = 100 * cu.h * cu.km / cu.s / cu.Mpc
>>> H0
array(100.0) * km*hh/(s*Mpc)
>>> H0.rescale( 'km/s/Mpc' )
array(70.0) * km/(s*Mpc)

This occurs automatically whenever an instance of the Cosmology class is created,

>>> di = {'omegam': 0.3, 'omegal': 0.7, 'omegab': 0.05}
>>> di.update( {'h': 0.7, 'sigma8': 0.8, 'ns':1.0, 'Yp':0.25} )
>>> co = ra.Cosmology(di)
>>> H0 = 100 * co.cu.h * co.cu.km / co.cu.s / co.cu.Mpc
>>> H0
array(100.0) * km*hh/(s*Mpc)
>>> H0.rescale( 'km/s/Mpc' )
array(70.0) * km/(s*Mpc)

Warning

Always create a new instance of CosmoUnits when you want a new value of the hubble parameter. This happens automatically when you create an instance of the Cosmology class.