class astropy.cosmology.connect.CosmologyFromFormat(instance: Cosmology, cosmo_cls: type[Cosmology])[source]#

Bases: UnifiedReadWrite

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 argument cosmology=<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:

>>>  # Get help and list supported formats
>>>'<format>')  # Get detailed help on a format
>>> Cosmology.from_format.list_formats()  # Print list of available formats

See also:


The object to parse according to ‘format’


Positional arguments passed through to data parser.

formatstr or None, optional keyword-only

Object format specifier. For None (default) CosmologyFromFormat tries to identify the correct format.


Keyword arguments passed through to data parser. Parsers should accept the following keyword arguments:

  • cosmologythe class (or string name thereof) to use / check when

    constructing the cosmology instance.

outCosmology subclass instance

Cosmology corresponding to obj contents.

Methods Summary


Call self as a function.

Methods Documentation

__call__(obj: _CosmoT, *args: Any, format: Literal['astropy.cosmology'] | None, **kwargs: Any) _CosmoT[source]#
__call__(obj: _CosmologyModel, *args: Any, format: Literal['astropy.model'] | None, **kwargs: Any) Cosmology
__call__(obj: Row, *args: Any, format: Literal['astropy.row'] | None, **kwargs: Any) Cosmology
__call__(obj: Table, *args: Any, format: Literal['astropy.table'] | None, **kwargs: Any) Cosmology
__call__(obj: Mapping[str, Any], *args: Any, format: Literal['mapping'] | None, **kwargs: Any) Cosmology
__call__(obj: str, *args: Any, format: Literal['yaml'], **kwargs: Any) Cosmology
__call__(obj: Any, *args: Any, format: str | None = None, **kwargs: Any) Cosmology

Call self as a function.