|
| 1 | +import numpy as np |
| 2 | +import pytest |
| 3 | + |
| 4 | +import autolens as al |
| 5 | +from autolens.lens import substructure_util |
| 6 | + |
| 7 | + |
| 8 | +requires_kaplinghat = pytest.mark.skipif( |
| 9 | + not hasattr(al.mp, "KaplinghatCoredNFWSph"), |
| 10 | + reason="Kaplinghat SIDM profiles are provided by the pending PyAutoGalaxy release.", |
| 11 | +) |
| 12 | + |
| 13 | + |
| 14 | +@requires_kaplinghat |
| 15 | +def test__autolens_exposes_kaplinghat_profiles_from_autogalaxy(): |
| 16 | + assert hasattr(al.mp, "KaplinghatCoredNFWSph") |
| 17 | + assert hasattr(al.mp, "KaplinghatCoredNFWMCRLudlowSph") |
| 18 | + |
| 19 | + |
| 20 | +@requires_kaplinghat |
| 21 | +def test__galaxies_to_halo_arrays__packs_kaplinghat_profile_parameters(): |
| 22 | + profile = al.mp.KaplinghatCoredNFWSph( |
| 23 | + centre=(0.1, -0.2), |
| 24 | + kappa_s=0.03, |
| 25 | + scale_radius=1.7, |
| 26 | + sigma_over_m=2.0, |
| 27 | + t_age=8.0, |
| 28 | + interaction_radius=0.25, |
| 29 | + ) |
| 30 | + galaxies = [ |
| 31 | + al.Galaxy(redshift=0.5, mass=profile), |
| 32 | + al.Galaxy(redshift=1.0, mass_sheet=al.mp.MassSheet(kappa=-0.01)), |
| 33 | + ] |
| 34 | + |
| 35 | + params, mask, sheet_kappas = substructure_util.galaxies_to_halo_arrays( |
| 36 | + galaxies=galaxies, |
| 37 | + plane_redshifts=[0.5, 1.0], |
| 38 | + max_n=2, |
| 39 | + profile_cls=al.mp.KaplinghatCoredNFWSph, |
| 40 | + ) |
| 41 | + |
| 42 | + assert params.shape == (2, 2, 7) |
| 43 | + assert mask.tolist() == [[True, False], [False, False]] |
| 44 | + assert sheet_kappas.tolist() == [0.0, -0.01] |
| 45 | + |
| 46 | + np.testing.assert_allclose( |
| 47 | + np.asarray(params[0, 0]), |
| 48 | + np.array( |
| 49 | + [ |
| 50 | + 0.1, |
| 51 | + -0.2, |
| 52 | + profile.kappa_s, |
| 53 | + profile.scale_radius, |
| 54 | + profile.interaction_radius, |
| 55 | + profile.central_density, |
| 56 | + profile.isothermal_radius, |
| 57 | + ] |
| 58 | + ), |
| 59 | + ) |
| 60 | + |
| 61 | + |
| 62 | +def test__galaxies_to_halo_arrays__raises_for_unsupported_profile_class(): |
| 63 | + with pytest.raises(ValueError): |
| 64 | + substructure_util.galaxies_to_halo_arrays( |
| 65 | + galaxies=[], |
| 66 | + plane_redshifts=[0.5], |
| 67 | + max_n=1, |
| 68 | + profile_cls=al.mp.IsothermalSph, |
| 69 | + ) |
0 commit comments