Skip to main content

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.

  • Support for jax and cupy backends 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 astropy at the <0.1% level.

  • The astropy units are incompatible with non-numpy backends.

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.git

    or 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)

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>

GWPopulation

The primary intention for this package is for use with GWPopulation. This code is automatically used in GWPopulation when using either gwpopulation.experimental.cosmo_models.CosmoModel and/or PowerLawRedshift

Changing backend

The backend can be switched automatically using, e.g.,

>>> import gwpopulation
>>> gwpopulation.backend.set_backend("jax")

Manual backend setting can be done as follows:

>>> import jax.numpy as jnp
>>> from jax.scipy.linalg.toeplitz import toeplitz

>>> from wcosmo import wcosmo, utils
>>> wcosmo.xp = jnp
>>> utils.xp = jnp
>>> utils.toeplitz = toeplitz

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

wcosmo-0.4.0.tar.gz (6.8 MB view details)

Uploaded Source

Built Distribution

wcosmo-0.4.0-py3-none-any.whl (22.0 kB view details)

Uploaded Python 3

File details

Details for the file wcosmo-0.4.0.tar.gz.

File metadata

  • Download URL: wcosmo-0.4.0.tar.gz
  • Upload date:
  • Size: 6.8 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for wcosmo-0.4.0.tar.gz
Algorithm Hash digest
SHA256 72ee7be051d68ba33b7ee888d6d3a86ecf9a53e743c5354f8c7e1024502c3ebc
MD5 1b38e091bd7f8e68f63bd115a3ccc683
BLAKE2b-256 e35d83ab7d4cae360aeaef97d700bb89088a8f68749ee6b35abf73e9ebd3ade0

See more details on using hashes here.

File details

Details for the file wcosmo-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: wcosmo-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 22.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for wcosmo-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 db41f63cb2a1530ab87527e92eb1102340a3b1e82ec8baa2bd995cb88d0d8996
MD5 1aba341923b6443e4b0ce3da7c650078
BLAKE2b-256 36c23a43db0de178316866fd2216ae7e3346c1b52e2f7d6f40cd37bfec9f7b73

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page