Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 17 additions & 10 deletions autogalaxy/profiles/light_and_mass_profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,13 @@ def __init__(
effective_radius
The radius containing half the light of this light profile.
mass_to_light_ratio_base
The base mass-to-light ratio of the profile, which is the mass-to-light ratio of the Gaussian before it
is scaled by values that adjust its mass-to-light ratio based on the reference radius and gradient.
The mass-to-light ratio of a Gaussian whose `sigma` equals `mass_to_light_radius`.
mass_to_light_gradient
The mass-to-light radial gradient of the profile, whereby positive values means there is more mass
per unit light within the reference radius.
The power-law slope of the mass-to-light ratio with `sigma`, M/L proportional to
`(sigma / mass_to_light_radius) ** -mass_to_light_gradient`: positive values mean the mass-to-light
ratio falls outward (more mass per unit light within the reference radius).
mass_to_light_radius
The radius where the mass-to-light ratio is equal to the base mass-to-light ratio, such that there will be
more of less mass per unit light within this radius depending on the mass-to-light gradient.
The reference radius at which the mass-to-light ratio equals `mass_to_light_ratio_base`.
"""
lp.Gaussian.__init__(
self,
Expand Down Expand Up @@ -370,7 +369,9 @@ def __init__(
mass_to_light_ratio
The mass-to-light ratio of the light profiles.
mass_to_light_gradient
The mass-to-light radial gradient.
The power-law slope of the mass-to-light ratio with radius, M/L proportional to
`(R / effective_radius) ** -mass_to_light_gradient`: positive values mean the mass-to-light ratio
falls outward, and it equals `mass_to_light_ratio` on the ellipse of the effective radius.
"""
lp.Sersic.__init__(
self,
Expand Down Expand Up @@ -420,7 +421,9 @@ def __init__(
mass_to_light_ratio
The mass-to-light ratio of the light profiles
mass_to_light_gradient
The mass-to-light radial gradient.
The power-law slope of the mass-to-light ratio with radius, M/L proportional to
`(R / effective_radius) ** -mass_to_light_gradient`: positive values mean the mass-to-light ratio
falls outward, and it equals `mass_to_light_ratio` on the ellipse of the effective radius.
"""

SersicGradient.__init__(
Expand Down Expand Up @@ -463,7 +466,9 @@ def __init__(
mass_to_light_ratio
The mass-to-light ratio of the light profiles
mass_to_light_gradient
The mass-to-light radial gradient.
The power-law slope of the mass-to-light ratio with radius, M/L proportional to
`(R / effective_radius) ** -mass_to_light_gradient`: positive values mean the mass-to-light ratio
falls outward, and it equals `mass_to_light_ratio` on the ellipse of the effective radius.
"""

SersicGradient.__init__(
Expand Down Expand Up @@ -505,7 +510,9 @@ def __init__(
mass_to_light_ratio
The mass-to-light ratio of the light profiles
mass_to_light_gradient
The mass-to-light radial gradient.
The power-law slope of the mass-to-light ratio with radius, M/L proportional to
`(R / effective_radius) ** -mass_to_light_gradient`: positive values mean the mass-to-light ratio
falls outward, and it equals `mass_to_light_ratio` on the ellipse of the effective radius.
"""

SersicGradientSph.__init__(
Expand Down
27 changes: 17 additions & 10 deletions autogalaxy/profiles/light_linear_and_mass_profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,13 @@ def __init__(
effective_radius
The radius containing half the light of this light profile.
mass_to_light_ratio_base
The base mass-to-light ratio of the profile, which is the mass-to-light ratio of the Gaussian before it
is scaled by values that adjust its mass-to-light ratio based on the reference radius and gradient.
The mass-to-light ratio of a Gaussian whose `sigma` equals `mass_to_light_radius`.
mass_to_light_gradient
The mass-to-light radial gradient of the profile, whereby positive values means there is more mass
per unit light within the reference radius.
The power-law slope of the mass-to-light ratio with `sigma`, M/L proportional to
`(sigma / mass_to_light_radius) ** -mass_to_light_gradient`: positive values mean the mass-to-light
ratio falls outward (more mass per unit light within the reference radius).
mass_to_light_radius
The radius where the mass-to-light ratio is equal to the base mass-to-light ratio, such that there will be
more of less mass per unit light within this radius depending on the mass-to-light gradient.
The reference radius at which the mass-to-light ratio equals `mass_to_light_ratio_base`.
"""
lp_linear.Gaussian.__init__(
self,
Expand Down Expand Up @@ -359,7 +358,9 @@ def __init__(
mass_to_light_ratio
The mass-to-light ratio of the light profiles.
mass_to_light_gradient
The mass-to-light radial gradient.
The power-law slope of the mass-to-light ratio with radius, M/L proportional to
`(R / effective_radius) ** -mass_to_light_gradient`: positive values mean the mass-to-light ratio
falls outward, and it equals `mass_to_light_ratio` on the ellipse of the effective radius.
"""
lp_linear.Sersic.__init__(
self,
Expand Down Expand Up @@ -408,7 +409,9 @@ def __init__(
mass_to_light_ratio
The mass-to-light ratio of the light profiles
mass_to_light_gradient
The mass-to-light radial gradient.
The power-law slope of the mass-to-light ratio with radius, M/L proportional to
`(R / effective_radius) ** -mass_to_light_gradient`: positive values mean the mass-to-light ratio
falls outward, and it equals `mass_to_light_ratio` on the ellipse of the effective radius.
"""

SersicGradient.__init__(
Expand Down Expand Up @@ -451,7 +454,9 @@ def __init__(
mass_to_light_ratio
The mass-to-light ratio of the light profiles
mass_to_light_gradient
The mass-to-light radial gradient.
The power-law slope of the mass-to-light ratio with radius, M/L proportional to
`(R / effective_radius) ** -mass_to_light_gradient`: positive values mean the mass-to-light ratio
falls outward, and it equals `mass_to_light_ratio` on the ellipse of the effective radius.
"""

SersicGradient.__init__(
Expand Down Expand Up @@ -493,7 +498,9 @@ def __init__(
mass_to_light_ratio
The mass-to-light ratio of the light profiles
mass_to_light_gradient
The mass-to-light radial gradient.
The power-law slope of the mass-to-light ratio with radius, M/L proportional to
`(R / effective_radius) ** -mass_to_light_gradient`: positive values mean the mass-to-light ratio
falls outward, and it equals `mass_to_light_ratio` on the ellipse of the effective radius.
"""

SersicGradientSph.__init__(
Expand Down
34 changes: 19 additions & 15 deletions autogalaxy/profiles/mass/stellar/gaussian_gradient.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,24 @@ def __init__(
mass_to_light_radius: float = 1.0,
):
r"""
The elliptical Gaussian light profile with a gradient in its mass to light conversion.
The elliptical Gaussian mass profile with a gradient in its mass-to-light conversion.

$\Psi (r) = \Psi_{o} \frac{(\sigma + 0.01)}{R_{ref}}^{\Tau}$
Each Gaussian takes a single mass-to-light ratio set by its `sigma`, following a power law in radius:

$\Upsilon(\sigma) = \Upsilon_{0} \left( \frac{\sigma}{R_{\rm ref}} \right)^{-\Gamma}$

Where:

$\Psi (r)$ is the 1D convergence profile of the Gaussian [dimensionless].
$\Psi_{o}$ is the base mass-to-light ratio of the profile [dimensionless].
$\Upsilon(\sigma)$ is the mass-to-light ratio of the Gaussian [dimensionless].
$\Upsilon_{0}$ is `mass_to_light_ratio_base`, the mass-to-light ratio at the reference radius [dimensionless].
$\sigma$ is the sigma value of the Gaussian [arc-seconds].
$r$ is the radius from the centre of the profile [arc-seconds].
$R_{ref}$ is the reference radius where the mass-to-light ratio is equal to $\Psi_{o} [arc-seconds].
$\Tau$ is the mass-to-light gradient of the profile [dimensionless].
$R_{\rm ref}$ is `mass_to_light_radius`, the reference radius [arc-seconds].
$\Gamma$ is `mass_to_light_gradient` [dimensionless].

A positive `mass_to_light_gradient` means the mass-to-light ratio falls outward: Gaussians with
`sigma` below the reference radius carry more mass per unit light than those above it. This is the
same convention as `SersicGradient`, so the same positive gradient makes both profiles' mass-to-light
ratio fall with radius.

Parameters
----------
Expand All @@ -40,23 +46,21 @@ def __init__(
sigma
The sigma value of the Gaussian.
mass_to_light_ratio_base
The base mass-to-light ratio of the profile, which is the mass-to-light ratio of the Gaussian before it
is scaled by values that adjust its mass-to-light ratio based on the reference radius and gradient.
The mass-to-light ratio of a Gaussian whose `sigma` equals `mass_to_light_radius`.
mass_to_light_gradient
The mass-to-light radial gradient of the profile, whereby positive values means there is more mass
per unit light within the reference radius.
The power-law slope of the mass-to-light ratio with `sigma`, M/L proportional to
`(sigma / mass_to_light_radius) ** -mass_to_light_gradient`: positive values mean the mass-to-light
ratio falls outward.
mass_to_light_radius
The radius where the mass-to-light ratio is equal to the base mass-to-light ratio, such that there will be
more of less mass per unit light within this radius depending on the mass-to-light gradient.
The reference radius at which the mass-to-light ratio equals `mass_to_light_ratio_base`.
"""

self.mass_to_light_ratio_base = mass_to_light_ratio_base
self.mass_to_light_gradient = mass_to_light_gradient
self.mass_to_light_radius = mass_to_light_radius
mass_to_light_ratio = (
self.mass_to_light_ratio_base
* ((sigma + 0.01) / self.mass_to_light_radius)
** self.mass_to_light_gradient
* (sigma / self.mass_to_light_radius) ** -self.mass_to_light_gradient
)

super().__init__(
Expand Down
142 changes: 62 additions & 80 deletions autogalaxy/profiles/mass/stellar/sersic.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,89 +23,71 @@ def cse_settings_from(
decomposition resolution (``total_cses`` / ``sample_points``) used to decompose
a Sersic convergence profile into cored steep ellipsoids.

The standard (``mass_to_light_gradient <= 0.5``) path is written branch-free
using ``xp`` (``jnp.where`` / ``jnp.log10`` under JAX) so it traces cleanly
inside ``jax.jit`` when ``sersic_index`` / ``effective_radius`` are tracers:
Python ``if`` statements cannot branch on a tracer value, and ``jax.jit``
requires static array shapes, so ``total_cses`` / ``sample_points`` are frozen
to the conservative maximum previously used (50 / 80) rather than tuned per
Sersic index. The per-index ``upper_dex`` / ``lower_dex`` *ranges* are preserved
exactly via ``xp.where`` so accuracy is unchanged (only the CSE count can rise).

The ``mass_to_light_gradient > 0.5`` path (radial-gradient Sersic profiles) is
left as the original NumPy branching — it is only reached with a concrete
gradient value and is not part of the standard JAX-traced Sersic path.
Both the standard (``mass_to_light_gradient <= 0.5``) ranges and the steep-gradient
(``mass_to_light_gradient > 0.5``, radial-gradient Sersic profiles) ranges are written
branch-free using ``xp`` (``jnp.where`` / ``jnp.log10`` under JAX), and the two are
selected with ``xp.where`` on the gradient. This lets the profile trace inside
``jax.jit`` when ``sersic_index``, ``effective_radius`` or ``mass_to_light_gradient``
are tracers: Python ``if`` statements cannot branch on a tracer value. ``jax.jit``
also requires static array shapes, so ``total_cses`` / ``sample_points`` are frozen
to the conservative maximum previously used on either path (50 / 80) rather than
tuned per Sersic index. The per-index ``upper_dex`` / ``lower_dex`` *ranges* are
preserved exactly, so accuracy is unchanged (only the CSE count can rise).
"""
if mass_to_light_gradient > 0.5:
if effective_radius > 0.2:
lower_dex = 6.0
upper_dex = np.min(
[np.log10((18.0 / sersic_constant) ** sersic_index), 1.1]
)

if sersic_index <= 1.2:
total_cses = 50
sample_points = 80
elif sersic_index > 3.8:
total_cses = 40
sample_points = 50
lower_dex = 6.5
else:
total_cses = 30
sample_points = 50

else:
if sersic_index <= 1.2:
upper_dex = 1.0
total_cses = 50
sample_points = 80
lower_dex = 4.5

elif sersic_index > 3.8:
total_cses = 40
sample_points = 50
lower_dex = 6.0
upper_dex = 1.5
else:
upper_dex = 1.1
lower_dex = 6.0
total_cses = 30
sample_points = 50
else:
# Static shapes for jax.jit: frozen to the former per-index maximum.
total_cses = 50
sample_points = 80

log_effective_radius = xp.log10(effective_radius)
base_upper_dex = xp.minimum(
xp.log10((23.0 / sersic_constant) ** sersic_index),
0.85 - log_effective_radius,
)

# upper_dex / lower_dex select the same per-index ranges as the original
# if/elif ladder, expressed branch-free so a tracer sersic_index traces.
upper_dex = xp.where(
sersic_index <= 0.8,
xp.log10((16.0 / sersic_constant) ** sersic_index),
# Static shapes for jax.jit: frozen to the former per-index maximum.
total_cses = 50
sample_points = 80

# Standard ranges (mass_to_light_gradient <= 0.5).
log_effective_radius = xp.log10(effective_radius)
base_upper_dex = xp.minimum(
xp.log10((23.0 / sersic_constant) ** sersic_index),
0.85 - log_effective_radius,
)

# upper_dex / lower_dex select the same per-index ranges as the original
# if/elif ladder, expressed branch-free so a tracer sersic_index traces.
standard_upper_dex = xp.where(
sersic_index <= 0.8,
xp.log10((16.0 / sersic_constant) ** sersic_index),
xp.where(
sersic_index <= 0.9,
xp.log10((18.0 / sersic_constant) ** sersic_index),
base_upper_dex,
),
)
standard_lower_dex = xp.where(
sersic_index <= 0.8,
4.0 + log_effective_radius,
xp.where(
sersic_index <= 0.9,
4.3 + log_effective_radius,
xp.where(
sersic_index <= 0.9,
xp.log10((18.0 / sersic_constant) ** sersic_index),
base_upper_dex,
sersic_index > 3.8,
4.5 + log_effective_radius,
3.5 + log_effective_radius,
),
)
lower_dex = xp.where(
sersic_index <= 0.8,
4.0 + log_effective_radius,
xp.where(
sersic_index <= 0.9,
4.3 + log_effective_radius,
xp.where(
sersic_index > 3.8,
4.5 + log_effective_radius,
3.5 + log_effective_radius,
),
),
)
),
)

# Steep-gradient ranges (mass_to_light_gradient > 0.5), the same values as the
# former nested if/else on effective_radius > 0.2 and the Sersic index.
large_upper_dex = xp.minimum(
xp.log10((18.0 / sersic_constant) ** sersic_index), 1.1
)
large_lower_dex = xp.where(sersic_index > 3.8, 6.5, 6.0)
small_upper_dex = xp.where(
sersic_index <= 1.2, 1.0, xp.where(sersic_index > 3.8, 1.5, 1.1)
)
small_lower_dex = xp.where(sersic_index <= 1.2, 4.5, 6.0)

is_large = effective_radius > 0.2
gradient_upper_dex = xp.where(is_large, large_upper_dex, small_upper_dex)
gradient_lower_dex = xp.where(is_large, large_lower_dex, small_lower_dex)

is_steep_gradient = mass_to_light_gradient > 0.5
upper_dex = xp.where(is_steep_gradient, gradient_upper_dex, standard_upper_dex)
lower_dex = xp.where(is_steep_gradient, gradient_lower_dex, standard_lower_dex)

return upper_dex, lower_dex, total_cses, sample_points

Expand Down
Loading
Loading