1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
.. _astropy-cosmology-traits:
****************
Cosmology Traits
****************
.. currentmodule:: astropy.cosmology.traits
The :mod:`~astropy.cosmology.traits` module hosts various parts of cosmologies, such as
the :class:`~astropy.cosmology.traits.ScaleFactor` or
:class:`~astropy.cosmology.traits.TemperatureCMB`. These :term:`traits <trait type>` can
be used to more easily construct custom cosmologies by combining different components.
As a simple example, the :class:`~astropy.cosmology.traits.TemperatureCMB` trait
provides the ``Tcmb0`` property and
:meth:`~astropy.cosmology.traits.TemperatureCMB.Tcmb` method for computing the
cosmological CMB temperature at specified redshifts. By using this trait, you can add
temperature-related functionality to your custom cosmology class without having to
implement it from scratch.
Here is an example of how to use the :class:`~astropy.cosmology.traits.ScaleFactor` and
:class:`~astropy.cosmology.traits.TemperatureCMB` traits in a custom cosmology class:
>>> import astropy.units as u
>>> from astropy.cosmology.traits import ScaleFactor, TemperatureCMB
>>> from astropy.cosmology import Cosmology
>>>
>>> class CustomCosmology(Cosmology, ScaleFactor, TemperatureCMB):
... def __init__(self, H0, Om0, Ode0, Tcmb0=2.725):
... self.H0 = H0
... self.Om0 = Om0
... self.Ode0 = Ode0
... self.Tcmb0 = u.Quantity(Tcmb0, "K")
... super().__init__()
...
... is_flat = False
... # Additional custom methods and properties can be added here
>>> cosmo = CustomCosmology(H0=70, Om0=0.3, Ode0=0.7)
>>> cosmo.scale_factor(0)
<Quantity 1.>
>>> cosmo.Tcmb(1)
<Quantity 5.45 K>
By combining different traits, you can create fully-featured cosmology classes with
minimal effort.
Reference/API
*************
.. py:currentmodule:: astropy.cosmology.traits
.. automodapi:: astropy.cosmology.traits
:inherited-members:
|