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 viajax.grad. - Hybrid Evaluation: Evaluates density using
jax.scipy.ndimage.map_coordinatesfor 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)
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
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 coleman_bulge_density_model-0.3.5.tar.gz.
File metadata
- Download URL: coleman_bulge_density_model-0.3.5.tar.gz
- Upload date:
- Size: 77.4 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a622a813d91ff26ea3913301afe2329559891129642369d602f913f1d3fc9554
|
|
| MD5 |
9f7006aa1b4b6b1d93c72f569b2efaed
|
|
| BLAKE2b-256 |
476eaf551acf23fadaf683119470093fba568c650885679ebe3786d1effa2006
|
Provenance
The following attestation bundles were made for coleman_bulge_density_model-0.3.5.tar.gz:
Publisher:
publish.yml on dylannpaterson/coleman_bulge_density_model
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
coleman_bulge_density_model-0.3.5.tar.gz -
Subject digest:
a622a813d91ff26ea3913301afe2329559891129642369d602f913f1d3fc9554 - Sigstore transparency entry: 1358735913
- Sigstore integration time:
-
Permalink:
dylannpaterson/coleman_bulge_density_model@2cc15eb1522b00ab33679162d86ef395c963490c -
Branch / Tag:
refs/tags/v0.3.5 - Owner: https://github.com/dylannpaterson
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@2cc15eb1522b00ab33679162d86ef395c963490c -
Trigger Event:
release
-
Statement type:
File details
Details for the file coleman_bulge_density_model-0.3.5-py3-none-any.whl.
File metadata
- Download URL: coleman_bulge_density_model-0.3.5-py3-none-any.whl
- Upload date:
- Size: 74.1 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b698093af26ce14a57c83849bfb470cbbd394eb7236e7b6a95a9baa0e111ad5e
|
|
| MD5 |
b44ae426d5ce911e8de4858491f55ec0
|
|
| BLAKE2b-256 |
ea61dbc6ed29031a0396070516a08cd331238d37daf85d6fa05920a2949b9a7f
|
Provenance
The following attestation bundles were made for coleman_bulge_density_model-0.3.5-py3-none-any.whl:
Publisher:
publish.yml on dylannpaterson/coleman_bulge_density_model
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
coleman_bulge_density_model-0.3.5-py3-none-any.whl -
Subject digest:
b698093af26ce14a57c83849bfb470cbbd394eb7236e7b6a95a9baa0e111ad5e - Sigstore transparency entry: 1358736158
- Sigstore integration time:
-
Permalink:
dylannpaterson/coleman_bulge_density_model@2cc15eb1522b00ab33679162d86ef395c963490c -
Branch / Tag:
refs/tags/v0.3.5 - Owner: https://github.com/dylannpaterson
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@2cc15eb1522b00ab33679162d86ef395c963490c -
Trigger Event:
release
-
Statement type: