Skip to content

Feature/cored nfw#266

Merged
NiekWielders merged 40 commits intomainfrom
feature/cored_NFW
Jan 28, 2026
Merged

Feature/cored nfw#266
NiekWielders merged 40 commits intomainfrom
feature/cored_NFW

Conversation

@NiekWielders
Copy link
Copy Markdown
Collaborator

Inclusing of the cored NFW in profiles/mass/dark/ together with a cored NFW msr calculation (including a new function in msr_util).

@Jammy2211 Jammy2211 requested review from Jammy2211 and Copilot and removed request for Copilot January 28, 2026 11:01
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds support for a spherical cored NFW (cNFW) mass profile and a corresponding Ludlow-based mass–concentration–radius mapping, together with tests and prior configuration. The new profile is wired into the existing dark-matter mass profile API and cosmology utilities.

Changes:

  • Introduces a cNFWSph mass profile with analytic deflection formula and placeholder convergence/potential methods.
  • Adds cNFWMCRLudlowSph plus kappa_s_scale_radius_and_core_radius_for_ludlow to derive cNFW parameters from M200 using a Penarrubia-based mass–concentration relation.
  • Wires the new classes into autogalaxy.profiles.mass.dark and autogalaxy.profiles.mass, adds YAML priors, and creates tests validating deflections and consistency with existing NFW MCR machinery.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 12 comments.

Show a summary per file
File Description
test_autogalaxy/profiles/mass/dark/test_nfw_mcr.py Adds a cored-NFW MCR test mirroring existing NFW MCR tests, and tweaks a comment around the consistency check.
test_autogalaxy/profiles/mass/dark/test_cnfw.py Adds unit tests for cNFWSph deflections, convergence, and potential at a specific radius.
autogalaxy/profiles/mass/dark/mcr_util.py Introduces kappa_s_scale_radius_and_core_radius_for_ludlow to compute (kappa_s, scale_radius, core_radius) from M200 using Ludlow cosmology plus a Penarrubia-style mass–concentration relation.
autogalaxy/profiles/mass/dark/cnfw_mcr.py Implements cNFWMCRLudlowSph that wraps the MCR utility and instantiates a cNFWSph with derived parameters.
autogalaxy/profiles/mass/dark/cnfw.py Adds the cNFWSph cored NFW spherical profile with its analytic radial deflection, helper functions F_func / dev_F_func, and stubbed convergence/potential methods.
autogalaxy/profiles/mass/dark/__init__.py Exposes cNFWSph and cNFWMCRLudlowSph in the dark-profile public API.
autogalaxy/profiles/mass/__init__.py Re-exports cNFWSph and cNFWMCRLudlowSph at the higher-level mass API namespace.
autogalaxy/config/priors/mass/dark/cnfw_mcr.yaml Defines sampling priors for cNFWMCRLudlowSph, including mass_at_200, f_c, and redshifts.
autogalaxy/config/priors/mass/dark/cnfw.yaml Adds priors for the direct cNFWSph parameters kappa_s, scale_radius, and core_radius.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +261 to +268
mcr_penarrubia = ((f_c**2 * xp.log(1 + concentration / f_c) + (1 - 2 * f_c) * xp.log(1 + concentration)) / (1 + f_c)**2
- concentration / ((1+concentration) * (1-f_c))) #mass concentration relation (Penarrubia+2012)

scale_radius_kpc = radius_at_200 / concentration # scale radius in kpc
rho_0 = mass_at_200 / (4 * xp.pi * scale_radius_kpc**3 * mcr_penarrubia)
kappa_s = rho_0 * scale_radius_kpc / critical_surface_density # kappa_s
scale_radius = scale_radius_kpc / kpc_per_arcsec # scale radius in arcsec
core_radius = f_c * scale_radius # core radius in arcsec
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mcr_penarrubia and rho_0 use f_c in log(1 + concentration / f_c) and in a (1 - f_c) denominator, so f_c=0 (allowed by callers and priors) will produce divisions by zero / log(0) and NaNs; this function should guard against f_c<=0 (and f_c>=1 for the (1-f_c) term) or enforce a strictly positive, bounded prior for f_c.

Copilot uses AI. Check for mistakes.
Comment on lines +71 to +77
deflection_r = (
factor
* (self.F_func(theta, self.scale_radius, xp=xp) - self.F_func(theta, self.core_radius, xp=xp)
- (self.scale_radius - self.core_radius) * self.dev_F_func(theta, self.scale_radius, xp=xp)
)
/ (theta * (self.scale_radius - self.core_radius)**2)
)
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The deflection formula divides by (self.scale_radius - self.core_radius)**2, so if scale_radius equals core_radius this will raise a division-by-zero error; consider either constraining these parameters so they cannot coincide (e.g. via priors / validation) or handling the degenerate scale_radius == core_radius limit explicitly.

Copilot uses AI. Check for mistakes.
@Jammy2211
Copy link
Copy Markdown
Collaborator

Other than deleting all the commented out code flagged by copilot above, I'm happy for you to go ahead and merge this.

Its worth reading through copilots suggestions, but I dont think any need doing in order to make this mergeable.

@NiekWielders NiekWielders merged commit fce8e58 into main Jan 28, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants