lightcurvelynx.astro_utils.milky_way_density

Milky Way stellar density models for sampling sky positions.

This module provides density models that describe the spatial distribution of stars in the Milky Way. These models can be used to generate realistic sky positions for simulated stellar populations.

This module is adapted from: https://github.com/uiucsn/ztf-dr-vars/blob/master/ch_vars/spatial_distr.py

References

Classes

MilkyWayDensityBase

Abstract base class for Milky Way stellar density models.

MilkyWayDensityJuric2008

Milky Way stellar density model from Juric et al. (2008).

Module Contents

class MilkyWayDensityBase(n_grid=1024)[source]

Bases: abc.ABC

Abstract base class for Milky Way stellar density models.

Subclasses must implement the dens() method which returns the unnormalised stellar number density at a given cylindrical galactocentric position (rho, phi, z).

The constructor precomputes a 2-D grid over (rho, z) and a flat cumulative distribution that is used for fast inverse-transform sampling.

sun_z_kpc[source]

Height of the Sun above the Galactic mid-plane in kpc.

Type:

float

sun_rho_kpc[source]

Galactocentric distance of the Sun in the mid-plane in kpc.

Type:

float

rho_min_kpc[source]

Minimum cylindrical radius for the sampling grid in kpc.

Type:

float

rho_max_kpc[source]

Maximum cylindrical radius for the sampling grid in kpc.

Type:

float

z_min_kpc[source]

Minimum height above/below the mid-plane for the sampling grid in kpc.

Type:

float

z_max_kpc[source]

Maximum height above/below the mid-plane for the sampling grid in kpc.

Type:

float

n_grid[source]

Number of grid points per axis.

Type:

int

Parameters:

n_grid (int, optional) – Number of grid points along each axis of the (rho, z) grid. Larger values give more accurate sampling at the cost of memory and initialisation time. Default: 1024

sun_z_kpc = None[source]
sun_rho_kpc = None[source]
rho_min_kpc = 0.0[source]
rho_max_kpc = 20.0[source]
z_min_kpc = -20.0[source]
z_max_kpc = 20.0[source]
n_grid = 1024[source]
abstractmethod dens(rho, phi, z)[source]

Return the unnormalised stellar density at cylindrical position.

Parameters:
  • rho (float or numpy.ndarray) – Cylindrical galactocentric radius in kpc.

  • phi (float or numpy.ndarray) – Azimuthal angle in radians (0 toward Sun).

  • z (float or numpy.ndarray) – Height above the Galactic mid-plane in kpc.

Returns:

density – Unnormalised stellar density (arbitrary units).

Return type:

float or numpy.ndarray

sample_galactic_cylindrical(n_samples=1, rng=None)[source]

Sample positions in cylindrical Galactic coordinates.

Uses inverse-transform sampling on the precomputed cumulative distribution to draw (rho, phi, z) positions.

Parameters:
  • n_samples (int, optional) – Number of positions to draw. Default: 1

  • rng (numpy.random.Generator, optional) – Random number generator to use. If None a fresh generator is created with numpy.random.default_rng().

Returns:

  • rho (numpy.ndarray) – Cylindrical galactocentric radii in kpc, shape (n_samples,).

  • phi (numpy.ndarray) – Azimuthal angles in radians, shape (n_samples,).

  • z (numpy.ndarray) – Heights above the Galactic mid-plane in kpc, shape (n_samples,).

sample_icrs(n_samples=1, rng=None)[source]

Sample sky positions distributed according to the density model.

Positions are drawn from the precomputed distribution and converted from Galactocentric cylindrical coordinates to ICRS (RA, dec).

Parameters:
  • n_samples (int, optional) – Number of positions to draw. Default: 1

  • rng (numpy.random.Generator, optional) – Random number generator to use. If None a fresh generator is created with numpy.random.default_rng().

Returns:

coords – ICRS sky coordinates for the sampled positions.

Return type:

astropy.coordinates.ICRS

class MilkyWayDensityJuric2008(*, n_grid=1024, thin_disk_weight=1.0, thick_disk_weight=1.0, halo_weight=1.0, sun_rho_kpc=8.0, sun_z_kpc=0.024, l_thin_kpc=2.6, h_thin_kpc=0.3, dens_thick_to_thin=0.12, l_thick_kpc=3.6, h_thick_kpc=0.9, dens_halo_to_thin=0.0051, ellipticity_halo=0.64, power_order_halo=2.77)[source]

Bases: MilkyWayDensityBase

Milky Way stellar density model from Juric et al. (2008).

Implements the smooth stellar number-density model described in Table 10 of Juric et al. (2008), composed of a thin disk, a thick disk, and a spherical halo component.

References

sun_rho_kpc[source]

Galactocentric distance of the Sun, 8 kpc.

Type:

float

sun_z_kpc[source]

Height of the Sun above the Galactic mid-plane, 0.024 kpc.

Type:

float

l_thin_kpc[source]

Scale length of the thin disk in kpc.

Type:

float

h_thin_kpc[source]

Scale height of the thin disk in kpc.

Type:

float

dens_thick_to_thin[source]

Local normalisation of the thick disk relative to the thin disk.

Type:

float

l_thick_kpc[source]

Scale length of the thick disk in kpc.

Type:

float

h_thick_kpc[source]

Scale height of the thick disk in kpc.

Type:

float

dens_halo_to_thin[source]

Local normalisation of the halo relative to the thin disk.

Type:

float

ellipticity_halo[source]

Axis ratio (c/a) of the halo.

Type:

float

power_order_halo[source]

Power-law index of the halo density profile.

Type:

float

thin_disk_weight[source]

Multiplicative weight applied to the thin disk component. Default: 1.0

Type:

float

thick_disk_weight[source]

Multiplicative weight applied to the thick disk component. Default: 1.0

Type:

float

halo_weight[source]

Multiplicative weight applied to the halo component. Default: 1.0

Type:

float

Parameters:
  • n_grid (int, optional) – Number of grid points along each axis of the (rho, z) grid. Default: 1024

  • sun_rho_kpc (float) – Galactocentric distance of the Sun. Default: 8 kpc.

  • sun_z_kpc (float) – Height of the Sun above the Galactic mid-plane. Default: 0.024 kpc.

  • l_thin_kpc (float) – Scale length of the thin disk in kpc.

  • h_thin_kpc (float) – Scale height of the thin disk in kpc.

  • dens_thick_to_thin (float) – Local normalisation of the thick disk relative to the thin disk.

  • l_thick_kpc (float) – Scale length of the thick disk in kpc.

  • h_thick_kpc (float) – Scale height of the thick disk in kpc.

  • dens_halo_to_thin (float) – Local normalisation of the halo relative to the thin disk.

  • ellipticity_halo (float) – Axis ratio (c/a) of the halo.

  • power_order_halo (float) – Power-law index of the halo density profile.

  • thin_disk_weight (float, optional) – Multiplicative weight applied to the thin disk component. Default: 1.0

  • thick_disk_weight (float, optional) – Multiplicative weight applied to the thick disk component. Default: 1.0

  • halo_weight (float, optional) – Multiplicative weight applied to the halo component. Default: 1.0

Examples

>>> import numpy as np
>>> model = MilkyWayDensityJuric2008(n_grid=64)
>>> rho, phi, z = model.sample_galactic_cylindrical(n_samples=10, rng=np.random.default_rng(42))
>>> len(rho)
10
rho_min_kpc = 1.0[source]
rho_max_kpc = 20.0[source]
z_min_kpc = -10.0[source]
z_max_kpc = 10.0[source]
thin_disk_weight = 1.0[source]
thick_disk_weight = 1.0[source]
halo_weight = 1.0[source]
sun_rho_kpc = 8.0[source]
sun_z_kpc = 0.024[source]
l_thin_kpc = 2.6[source]
h_thin_kpc = 0.3[source]
dens_thick_to_thin = 0.12[source]
l_thick_kpc = 3.6[source]
h_thick_kpc = 0.9[source]
dens_halo_to_thin = 0.0051[source]
ellipticity_halo = 0.64[source]
power_order_halo = 2.77[source]
thin_disk_dens(rho, phi, z)[source]

Return the thin disk component of the density.

Parameters:
  • rho (float or numpy.ndarray) – Cylindrical galactocentric radius in kpc.

  • phi (float or numpy.ndarray) – Azimuthal angle in radians (unused; model is axisymmetric).

  • z (float or numpy.ndarray) – Height above the Galactic mid-plane in kpc.

Returns:

density – Thin disk density (normalised to 1 at the Sun’s position).

Return type:

float or numpy.ndarray

thick_disk_dens(rho, phi, z)[source]

Return the thick disk component of the density.

Parameters:
  • rho (float or numpy.ndarray) – Cylindrical galactocentric radius in kpc.

  • phi (float or numpy.ndarray) – Azimuthal angle in radians (unused; model is axisymmetric).

  • z (float or numpy.ndarray) – Height above the Galactic mid-plane in kpc.

Returns:

density – Thick disk density (normalised to dens_thick_to_thin at the Sun’s position relative to the thin disk).

Return type:

float or numpy.ndarray

halo_dens(rho, phi, z)[source]

Return the stellar halo component of the density.

Parameters:
  • rho (float or numpy.ndarray) – Cylindrical galactocentric radius in kpc.

  • phi (float or numpy.ndarray) – Azimuthal angle in radians (unused; model is axisymmetric).

  • z (float or numpy.ndarray) – Height above the Galactic mid-plane in kpc.

Returns:

density – Halo density (normalised to dens_halo_to_thin at the Sun’s position relative to the thin disk).

Return type:

float or numpy.ndarray

dens(rho, phi, z)[source]

Return the total stellar density at a given position.

The total density is the weighted sum of the thin disk, thick disk, and halo components.

Parameters:
  • rho (float or numpy.ndarray) – Cylindrical galactocentric radius in kpc.

  • phi (float or numpy.ndarray) – Azimuthal angle in radians (unused; model is axisymmetric).

  • z (float or numpy.ndarray) – Height above the Galactic mid-plane in kpc.

Returns:

density – Total unnormalised stellar density.

Return type:

float or numpy.ndarray