Cosmology¶
- class astropy.cosmology.Cosmology(*args, **kwargs)[source]¶
Bases:
object
Base-class for all Cosmologies.
- Parameters
- *args
Arguments into the cosmology; used by subclasses, not this base class.
- name
python:str
orpython:None
(optional, keyword-only) The name of the cosmology.
- meta
python:dict
orpython:None
(optional, keyword-only) Metadata for the cosmology, e.g., a reference.
- **kwargs
Arguments into the cosmology; used by subclasses, not this base class.
Notes
Class instances are static – you cannot (and should not) change the values of the parameters. That is, all of the above attributes (except meta) are read only.
For details on how to create performant custom subclasses, see the documentation on Speeding up Integrals in Custom Cosmologies.
Attributes Summary
Transform object to a
Cosmology
.The name of the Cosmology instance.
Read and parse data to a
Cosmology
.Transform this Cosmology to another format.
Write this Cosmology object out in the specified format.
Methods Summary
clone
(*[, meta])Returns a copy of this object with updated parameters, as specified.
is_equivalent
(other)Check equivalence between Cosmologies.
Attributes Documentation
- from_format¶
Transform object to a
Cosmology
.This function provides the Cosmology interface to the Astropy unified I/O layer. This allows easily parsing supported data formats using syntax such as:
>>> from astropy.cosmology import Cosmology >>> cosmo1 = Cosmology.from_format(cosmo_mapping, format='mapping')
When the
from_format
method is called from a subclass the subclass will provide a keyword argumentcosmology=<class>
to the registered parser. The method uses this cosmology class, regardless of the class indicated in the data, and sets parameters’ default values from the class’ signature.Get help on the available readers using the
help()
method:>>> Cosmology.from_format.help() # Get help and list supported formats >>> Cosmology.from_format.help('<format>') # Get detailed help on a format >>> Cosmology.from_format.list_formats() # Print list of available formats
See also: https://docs.astropy.org/en/stable/io/unified.html
Note
from_format()
andread()
currently access the same registry. This will be deprecated and formats intended forread
should not be used here. UseCosmology.to_format.help()
to confirm that the format may be used to convert to a Cosmology.- Parameters
- obj
object
The object to parse according to ‘format’
- *args
Positional arguments passed through to data parser.
- format
python:str
(optional, keyword-only) Object format specifier.
- **kwargs
Keyword arguments passed through to data parser.
- obj
- Returns
- meta¶
- name¶
The name of the Cosmology instance.
- read¶
Read and parse data to a
Cosmology
.This function provides the Cosmology interface to the Astropy unified I/O layer. This allows easily reading a file in supported data formats using syntax such as:
>>> from astropy.cosmology import Cosmology >>> cosmo1 = Cosmology.read('<file name>')
When the
read
method is called from a subclass the subclass will provide a keyword argumentcosmology=<class>
to the registered read method. The method uses this cosmology class, regardless of the class indicated in the file, and sets parameters’ default values from the class’ signature.Get help on the available readers using the
help()
method:>>> Cosmology.read.help() # Get help reading and list supported formats >>> Cosmology.read.help(format='<format>') # Get detailed help on a format >>> Cosmology.read.list_formats() # Print list of available formats
See also: https://docs.astropy.org/en/stable/io/unified.html
Note
read()
andfrom_format()
currently access the same registry. This will be deprecated and formats intended forfrom_format
should not be used here. UseCosmology.read.help()
to confirm that the format may be used to read a file.- Parameters
- *args
Positional arguments passed through to data reader. If supplied the first argument is typically the input filename.
- format
python:str
(optional, keyword-only) File format specifier.
- **kwargs
Keyword arguments passed through to data reader.
- Returns
- to_format¶
Transform this Cosmology to another format.
This function provides the Cosmology interface to the astropy unified I/O layer. This allows easily transforming to supported data formats using syntax such as:
>>> from astropy.cosmology import Planck18 >>> Planck18.to_format("mapping") {'cosmology': astropy.cosmology.core.FlatLambdaCDM, 'name': 'Planck18', 'H0': <Quantity 67.66 km / (Mpc s)>, 'Om0': 0.30966, ...
Get help on the available representations for
Cosmology
using thehelp()
method:>>> Cosmology.to_format.help() # Get help and list supported formats >>> Cosmology.to_format.help('<format>') # Get detailed help on format >>> Cosmology.to_format.list_formats() # Print list of available formats
Note
to_format()
andwrite()
currently access the same registry. This will be deprecated and formats intended forwrite
should not be used here. UseCosmology.to_format.help()
to confirm that the format may be used to convert a Cosmology.- Parameters
- format
python:str
Format specifier.
- *args
Positional arguments passed through to data writer. If supplied the first argument is the output filename.
- **kwargs
Keyword arguments passed through to data writer.
- format
- write¶
Write this Cosmology object out in the specified format.
This function provides the Cosmology interface to the astropy unified I/O layer. This allows easily writing a file in supported data formats using syntax such as:
>>> from astropy.cosmology import Planck18 >>> Planck18.write('<file name>')
Get help on the available writers for
Cosmology
using thehelp()
method:>>> Cosmology.write.help() # Get help writing and list supported formats >>> Cosmology.write.help(format='<format>') # Get detailed help on format >>> Cosmology.write.list_formats() # Print list of available formats
Note
write()
andto_format()
currently access the same registry. This will be deprecated and formats intended forto_format
should not be used here. UseCosmology.write.help()
to confirm that the format may be used to write to a file.- Parameters
- *args
Positional arguments passed through to data writer. If supplied the first argument is the output filename.
- format
python:str
(optional, keyword-only) File format specifier.
- **kwargs
Keyword arguments passed through to data writer.
Methods Documentation
- clone(*, meta=None, **kwargs)[source]¶
Returns a copy of this object with updated parameters, as specified.
This cannot be used to change the type of the cosmology, so
clone()
cannot be used to change between flat and non-flat cosmologies.- Parameters
- metapython:mapping or
python:None
(optional, keyword-only) Metadata that will update the current metadata.
- **kwargs
Cosmology parameter (and name) modifications. If any parameter is changed and a new name is not given, the name will be set to “[old name] (modified)”.
- metapython:mapping or
- Returns
- newcosmo
Cosmology
subclass instance A new instance of this class with updated parameters as specified. If no modifications are requested, then a reference to this object is returned instead of copy.
- newcosmo
Examples
To make a copy of the
Planck13
cosmology with a different matter density (Om0
), and a new name:>>> from astropy.cosmology import Planck13 >>> newcosmo = Planck13.clone(name="Modified Planck 2013", Om0=0.35)
If no name is specified, the new name will note the modification.
>>> Planck13.clone(Om0=0.35).name 'Planck13 (modified)'
- is_equivalent(other)[source]¶
Check equivalence between Cosmologies.
Two cosmologies may be equivalent even if not the same class. For example, an instance of
LambdaCDM
might have \(\Omega_0=1\) and \(\Omega_k=0\) and therefore be flat, likeFlatLambdaCDM
.- Parameters
- other
Cosmology
subclass instance The object in which to compare.
- other
- Returns
- bool
True if cosmologies are equivalent, False otherwise.