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 or analytic expressions using hypergeometric functions.

  • 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 the cupy backend. Units are supported with the jax backend using unxt.

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)

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


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.5.0.tar.gz (6.8 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

wcosmo-0.5.0-py3-none-any.whl (23.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: wcosmo-0.5.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.5.0.tar.gz
Algorithm Hash digest
SHA256 2f21ffc7cccb8c6f2304079ae90a7983df591d2472ad690980528133c9f5866c
MD5 e64f712b6cf5b5824b20febc970d651b
BLAKE2b-256 9ce132d8f77685a2fd83d8a59227956938daaa47aafd3aebe3316304fb7f4043

See more details on using hashes here.

Provenance

The following attestation bundles were made for wcosmo-0.5.0.tar.gz:

Publisher: release.yaml on ColmTalbot/wcosmo

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

  • Download URL: wcosmo-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 23.6 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.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3eefc0b100c9c4ec100df8ddc9de2cb7cb1dcf11cd49b13ed4de342f6110a1d9
MD5 2616fad151f8dbabb70bd02c03ffdc24
BLAKE2b-256 fa9a4d5f8de9585d4206ca8ac708783b15c176f87228a005748c2ffe844ceed9

See more details on using hashes here.

Provenance

The following attestation bundles were made for wcosmo-0.5.0-py3-none-any.whl:

Publisher: release.yaml on ColmTalbot/wcosmo

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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