A package for cosmology calculations with arbitrary numpy-like APIs
Project description
An efficient implementation of astropy-like cosmology compatible
with numpy-like backends, e.g., jax and cupy.
There are two main features leading to superior efficiency to astropy:
Integrals of \(E(z)\) and related functions are performed analytically with Pade approximations or analytic expressions using hypergeometric functions.
Support for
jaxandcupybackends allow hardware acceleration, just-in-time compilation, and automatic differentiation.
The primary limitations are:
Only flat cosmologies are supported with two components with constant equations of state, e.g.,
FlatwCDM.Approximations to the various integrals generally agree with
astropyat the <0.1% level.The
astropyunits are incompatible with thecupybackend. Units are supported with thejaxbackend usingunxt.
Installation and contribution
wcosmo can be installed via conda-forge, pypi or from
source.
$ mamba install -c conda-forge wcosmo
$ pip install wcosmo
$ pip install git+https://github.com/ColmTalbot/wcosmo.git
for development you should follow a standard fork-and-pull workflow.
First create a new fork at
github.com/UserName/wcosmo.Clone your fork
$ git clone git@github.com:UserName/wcosmo.gitor use a GitHub codespace.
Install the local version with
$ python -m pip install .Make any desired edits and push to your fork.
Open a pull request into
git@github.com:ColmTalbot/wcosmo.git.
Basic usage
To import an astropy-like cosmology
>>> from wcosmo import FlatwCDM
>>> cosmology = FlatwCDM(H0=70, Om0=0.3, w0=-1)
>>> cosmology.luminosity_distance(1)
The built-in cosmologies in astropy are all available, e.g.,
>>> from wcosmo import Planck18
>>> Planck18.luminosity_distance(1)
<Quantity 6797.43628659 Mpc>
they can also be accessed using wcosmo.available
>>> from wcosmo import available
>>> available["Planck18"].luminosity_distance(1)
<Quantity 6797.43628659 Mpc>
Explicit usage of astropy units can be freely enabled/disabled.
In this case, the values will have the default units for each method.
>>> from wcosmo import FlatwCDM
>>> from wcosmo.utils import disable_units, enable_units
>>> cosmology = FlatwCDM(H0=70, Om0=0.3, w0=-1)
>>> disable_units()
>>> cosmology.luminosity_distance(1)
6607.657732077576
>>> enable_units()
>>> cosmology.luminosity_distance(1)
<Quantity 6607.65773208 Mpc>
Changing backend
wcosmo mostly relies on implicit backend switching. The backend is
determined automatically based on the input arguments. When an input value is
a Python built-in type, the default backend is chosen using the
environment variable WCOSMO_ARRAY_API. The default is numpy.
GWPopulation
The original intention for this package was for use with GWPopulation.
This code is automatically used in GWPopulation when using either
gwpopulation.experimental.cosmo_models.CosmoModel and/or
PowerLawRedshift
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file wcosmo-0.5.4.tar.gz.
File metadata
- Download URL: wcosmo-0.5.4.tar.gz
- Upload date:
- Size: 6.8 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
79b84e82d0d54646798957aa1ff6e355c11d838dfab0ba6641cf1f04e07f72a7
|
|
| MD5 |
f0472b68e635206c118fb3e5e1206fe7
|
|
| BLAKE2b-256 |
a11116f0dc0e0678973d659c489d32847df8ca133e1f3839fcd1afb69a509cc4
|
Provenance
The following attestation bundles were made for wcosmo-0.5.4.tar.gz:
Publisher:
release.yaml on ColmTalbot/wcosmo
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
wcosmo-0.5.4.tar.gz -
Subject digest:
79b84e82d0d54646798957aa1ff6e355c11d838dfab0ba6641cf1f04e07f72a7 - Sigstore transparency entry: 484516220
- Sigstore integration time:
-
Permalink:
ColmTalbot/wcosmo@6e5be029d84114c921302a2957ce67cecf1eb7fe -
Branch / Tag:
refs/tags/v0.5.4 - Owner: https://github.com/ColmTalbot
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yaml@6e5be029d84114c921302a2957ce67cecf1eb7fe -
Trigger Event:
push
-
Statement type:
File details
Details for the file wcosmo-0.5.4-py3-none-any.whl.
File metadata
- Download URL: wcosmo-0.5.4-py3-none-any.whl
- Upload date:
- Size: 24.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9a015ea174890c4782685e53bc60d76d8bc94d8463e718bdf3e88f993de706c8
|
|
| MD5 |
4baccbbe307f854ceb542de453e7cac4
|
|
| BLAKE2b-256 |
35ce8ff783458a766e81e2b8828966c148fb669c694f6fd4022a99d209d2b489
|
Provenance
The following attestation bundles were made for wcosmo-0.5.4-py3-none-any.whl:
Publisher:
release.yaml on ColmTalbot/wcosmo
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
wcosmo-0.5.4-py3-none-any.whl -
Subject digest:
9a015ea174890c4782685e53bc60d76d8bc94d8463e718bdf3e88f993de706c8 - Sigstore transparency entry: 484516238
- Sigstore integration time:
-
Permalink:
ColmTalbot/wcosmo@6e5be029d84114c921302a2957ce67cecf1eb7fe -
Branch / Tag:
refs/tags/v0.5.4 - Owner: https://github.com/ColmTalbot
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yaml@6e5be029d84114c921302a2957ce67cecf1eb7fe -
Trigger Event:
push
-
Statement type: