Skip to main content

A vectorized implementation of the Coleman et al. (2020) Milky Way bulge density model.

Project description

Coleman Bulge Density Model

A JAX-based, differentiable implementation of the Coleman et al. (2020) Milky Way bulge density model.

Features

  • JAX Backend & Auto-Diff: Built on jax.numpy, allowing for gradient computations via jax.grad.
  • Hybrid Evaluation: Evaluates density using jax.scipy.ndimage.map_coordinates for coordinates within a pre-computed grid. It falls back to an analytical model for extrapolation outside the grid bounds.
  • Vectorized & JIT-Compiled: Vectorized and JIT-compiled (@jax.jit) to process large arrays of coordinates on CPU, GPU, or TPU.
  • Flexible Coordinates: Accepts inputs in either Sun-centered spherical coordinates (r, lat, lon) or Galactic Cartesian coordinates (x, y, z).

Requirements

  • Python >= 3.8
  • JAX >= 0.4.0
  • NumPy >= 1.20.0
  • SciPy >= 1.7.0

Installation

This package can be installed using pip:

pip install coleman-bulge-density-model

Usage

To use the model, import the pre-instantiated bulge_density_model.

The returned densities are in units of stars per pc^3, normalised to match the observed VVV star counts in the Ks band.

Basic Evaluation

import jax.numpy as jnp
from coleman_bulge_density import bulge_density_model

# 1. Using Galactic Cartesian coordinates (x, y, z)
density, in_bounds = bulge_density_model(x=8.0, y=0.0, z=0.0)

# 2. Processing large arrays
x_arr = jnp.linspace(0, 15, 100)
y_arr = jnp.zeros(100)
z_arr = jnp.zeros(100)
densities, bounds = bulge_density_model(x=x_arr, y=y_arr, z=z_arr)

Hexagonal bin plot showing the spatial distribution of Milky Way bulge density samples across the celestial sphere.

HMC & Gradients

The model is compatible with JAX operations, allowing for gradient calculations for use in physics simulations and HMC samplers.

import jax
import jax.numpy as jnp
from coleman_bulge_density import bulge_density_model

def log_prob(position_vector):
    """Calculates the log-probability for a given (x, y, z) position."""
    density, _ = bulge_density_model(
        x=position_vector[0], 
        y=position_vector[1], 
        z=position_vector[2]
    )
    return jnp.log(density)

# Generate the gradient function
grad_log_prob = jax.grad(log_prob)

# Evaluate the gradient at a given position
position = jnp.array([8.0, 0.0, 0.0])
gradient = grad_log_prob(position)

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

coleman_bulge_density_model-0.3.4.tar.gz (77.4 MB view details)

Uploaded Source

Built Distribution

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

coleman_bulge_density_model-0.3.4-py3-none-any.whl (74.1 MB view details)

Uploaded Python 3

File details

Details for the file coleman_bulge_density_model-0.3.4.tar.gz.

File metadata

File hashes

Hashes for coleman_bulge_density_model-0.3.4.tar.gz
Algorithm Hash digest
SHA256 3af183672110cc53827c5fd9dea563c54feaae2fa07a33dbc2094c3e757e7ccb
MD5 040a900c731d899cc727bf5158ab62d8
BLAKE2b-256 484536859270f174341e2b338fae6aad95d303d8f008fc1d64a99e2abf765612

See more details on using hashes here.

Provenance

The following attestation bundles were made for coleman_bulge_density_model-0.3.4.tar.gz:

Publisher: publish.yml on dylannpaterson/coleman_bulge_density_model

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

File details

Details for the file coleman_bulge_density_model-0.3.4-py3-none-any.whl.

File metadata

File hashes

Hashes for coleman_bulge_density_model-0.3.4-py3-none-any.whl
Algorithm Hash digest
SHA256 3b72968162d94cb368b165d62b79bfc0bbd9be5b43c5f63e81db7282cf48f7ac
MD5 f1df03d2d90b3f195b0e87d56ab9e922
BLAKE2b-256 ef052a209b9168d574b797eaa1153ff2a21aa41d61179d70946963c7505eeb37

See more details on using hashes here.

Provenance

The following attestation bundles were made for coleman_bulge_density_model-0.3.4-py3-none-any.whl:

Publisher: publish.yml on dylannpaterson/coleman_bulge_density_model

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