Namespaces#
This page contains the protocols describing the layout of a conforming cosmology library.
- class CosmologyNamespace#
Bases:
ProtocolRuntime-checkable Protocol for the Cosmology API namespace.
Notes
This is a Protocol, so it is not meant to be instantiated. It is meant to be used for static and runtime type checking. See https://docs.python.org/3/library/typing.html#typing.Protocol for more details.
When used in a runtime check, isinstance will only look for the existence of objects, not details like their type. For example,
constantsshould be a ~cosmology.api.CosmologyConstantsNamespace, but isinstance will not check this.Examples
A library can be checked for conformance with the Cosmology API namespace.
>>> from cosmology.api import CosmologyNamespace >>> from astropy import cosmology as astropy_cosmology >>> isinstance(astropy_cosmology, CosmologyNamespace) False
We can check what is missing from the library.
>>> print( ... set(n for n in dir(CosmologyNamespace) if not n.startswith('_')) ... - set(dir(astropy_cosmology))) {'constants'}
Most libraries are not yet Cosmology API compatible. There are compatibility wrappers to help with this, with documentation upcoming.
Attributes
The cosmology constants API.
- property constants: CosmologyConstantsNamespace#
The cosmology constants API.
- class CosmologyConstantsNamespace#
Bases:
ProtocolRuntime-checkable Protocol for the Cosmology API constants module.
Notes
This is a Protocol, so it is not meant to be instantiated. It is meant to be used for static and runtime type checking. See https://docs.python.org/3/library/typing.html#typing.Protocol for more details.
When used in a runtime check, isinstance will only look for the existence of objects, not details like their type. For example,
cshould be in units of kilometers per second, but isinstance will not check this.Examples
A module can be checked for conformance with the Cosmology API’s constants namespace.
>>> from types import SimpleNamespace >>> constants = SimpleNamespace(G=1, c=2) >>> isinstance(constants, CosmologyConstantsNamespace) True
>>> constants.G 1
Most cosmology libraries are not yet Cosmology API compatible. There are compatibility wrappers to help with this, with documentation upcoming.
Attributes