From 05abbd54765857562a4a9c0c0e6a60f110cb79a6 Mon Sep 17 00:00:00 2001 From: Jammy2211 Date: Fri, 13 Mar 2026 17:36:49 +0000 Subject: [PATCH] Refactor mass profile unit tests to be more granular Split multi-scenario test functions into individual focused tests, each testing one specific configuration. Renamed test functions to be more descriptive. No test logic or values were changed. Co-Authored-By: Claude Sonnet 4.6 --- test_autogalaxy/operate/test_deflections.py | 49 ++++++++-- .../profiles/mass/abstract/test_abstract.py | 29 ++++-- .../profiles/mass/abstract/test_mge.py | 85 +++++++++++++++-- .../profiles/mass/dark/test_abstract.py | 93 +++++++++++++++---- .../profiles/mass/dark/test_gnfw.py | 26 +++++- .../profiles/mass/dark/test_nfw.py | 66 +++++++++++-- .../profiles/mass/dark/test_nfw_mcr.py | 11 ++- .../profiles/mass/dark/test_nfw_scatter.py | 34 ++++--- .../profiles/mass/dark/test_nfw_truncated.py | 67 ++++++------- .../dark/test_nfw_truncated_mcr_scatter.py | 8 +- .../profiles/mass/point/test_point.py | 12 ++- .../profiles/mass/point/test_smbh_binary.py | 20 +++- .../mass/sheets/test_external_shear.py | 22 +++-- .../profiles/mass/sheets/test_mass_sheet.py | 18 +++- .../profiles/mass/stellar/test_chameleon.py | 10 +- .../mass/stellar/test_dev_vaucouleurs.py | 20 +++- .../profiles/mass/stellar/test_exponential.py | 24 ++++- .../profiles/mass/stellar/test_gaussian.py | 60 +++++++++++- .../mass/stellar/test_gaussian_gradient.py | 4 +- .../profiles/mass/stellar/test_sersic.py | 34 ++++++- .../profiles/mass/stellar/test_sersic_core.py | 6 +- .../mass/stellar/test_sersic_gradient.py | 32 ++++++- .../profiles/mass/test_scaling_relations.py | 8 +- .../total/test_dual_pseudo_isothermal_mass.py | 8 +- .../test_dual_pseudo_isothermal_potential.py | 18 +++- .../profiles/mass/total/test_isothermal.py | 45 +++++++-- .../mass/total/test_isothermal_cored.py | 42 ++++++++- .../profiles/mass/total/test_power_law.py | 38 +++++++- .../mass/total/test_power_law_broken.py | 34 ++++++- .../mass/total/test_power_law_cored.py | 28 +++++- .../mass/total/test_power_law_multipole.py | 8 +- 31 files changed, 779 insertions(+), 180 deletions(-) diff --git a/test_autogalaxy/operate/test_deflections.py b/test_autogalaxy/operate/test_deflections.py index ee4617979..cfa933b43 100644 --- a/test_autogalaxy/operate/test_deflections.py +++ b/test_autogalaxy/operate/test_deflections.py @@ -92,7 +92,7 @@ def test__fermat_potential_from(): ) -def test__hessian_from(): +def test__hessian_from__diagonal_grid__correct_values(): grid = ag.Grid2DIrregular(values=[(0.5, 0.5), (1.0, 1.0)]) mp = ag.mp.Isothermal( @@ -107,8 +107,15 @@ def test__hessian_from(): assert hessian_yx == pytest.approx(np.array([-1.388165, -0.694099]), 1.0e-4) assert hessian_xx == pytest.approx(np.array([1.3883824, 0.694127]), 1.0e-4) + +def test__hessian_from__axis_aligned_grid__correct_values(): grid = ag.Grid2DIrregular(values=[(1.0, 0.0), (0.0, 1.0)]) + mp = ag.mp.Isothermal( + centre=(0.0, 0.0), ell_comps=(0.0, -0.111111), einstein_radius=2.0 + ) + + od = LensCalc.from_mass_obj(mp) hessian_yy, hessian_xy, hessian_yx, hessian_xx = od.hessian_from(grid=grid) assert hessian_yy == pytest.approx(np.array([0.0, 1.777699]), 1.0e-4) @@ -149,7 +156,7 @@ def test__magnification_2d_via_hessian_from(): assert magnification.in_list[1] == pytest.approx(-2.57591, 1.0e-4) -def test__tangential_critical_curve_list_from(): +def test__tangential_critical_curve_list_from__radius_matches_einstein_radius(): grid = ag.Grid2D.uniform(shape_native=(15, 15), pixel_scales=0.3) mp = ag.mp.IsothermalSph(centre=(0.0, 0.0), einstein_radius=2.0) @@ -166,6 +173,8 @@ def test__tangential_critical_curve_list_from(): x_critical_tangential**2 + y_critical_tangential**2 ) == pytest.approx(mp.einstein_radius**2, 5e-1) + +def test__tangential_critical_curve_list_from__centre_at_origin__curve_centred_on_origin(): grid = ag.Grid2D.uniform(shape_native=(50, 50), pixel_scales=0.2) mp = ag.mp.IsothermalSph(centre=(0.0, 0.0), einstein_radius=2.0) @@ -179,6 +188,10 @@ def test__tangential_critical_curve_list_from(): assert -0.03 < y_centre < 0.03 assert -0.03 < x_centre < 0.03 + +def test__tangential_critical_curve_list_from__offset_centre__curve_centred_on_offset(): + grid = ag.Grid2D.uniform(shape_native=(50, 50), pixel_scales=0.2) + mp = ag.mp.IsothermalSph(centre=(0.5, 1.0), einstein_radius=2.0) od = LensCalc.from_mass_obj(mp) @@ -225,7 +238,7 @@ def test__tangential_critical_curve_list_from(): # ) -def test__radial_critical_curve_list_from(): +def test__radial_critical_curve_list_from__centre_at_origin__curve_centred_on_origin(): grid = ag.Grid2D.uniform(shape_native=(50, 50), pixel_scales=0.2) mp = ag.mp.PowerLawSph(centre=(0.0, 0.0), einstein_radius=2.0, slope=1.5) @@ -239,6 +252,10 @@ def test__radial_critical_curve_list_from(): assert -0.05 < y_centre < 0.05 assert -0.05 < x_centre < 0.05 + +def test__radial_critical_curve_list_from__offset_centre__curve_centred_on_offset(): + grid = ag.Grid2D.uniform(shape_native=(50, 50), pixel_scales=0.2) + mp = ag.mp.PowerLawSph(centre=(0.5, 1.0), einstein_radius=2.0, slope=1.5) od = LensCalc.from_mass_obj(mp) @@ -271,7 +288,7 @@ def test__radial_critical_curve_list_from__compare_via_magnification(): ) -def test__tangential_caustic_list_from(): +def test__tangential_caustic_list_from__centre_at_origin__caustic_centred_on_origin(): grid = ag.Grid2D.uniform(shape_native=(50, 50), pixel_scales=0.2) mp = ag.mp.IsothermalSph(centre=(0.0, 0.0), einstein_radius=2.0) @@ -285,6 +302,10 @@ def test__tangential_caustic_list_from(): assert -0.03 < y_centre < 0.03 assert -0.03 < x_centre < 0.03 + +def test__tangential_caustic_list_from__offset_centre__caustic_centred_on_offset(): + grid = ag.Grid2D.uniform(shape_native=(50, 50), pixel_scales=0.2) + mp = ag.mp.IsothermalSph(centre=(0.5, 1.0), einstein_radius=2.0) od = LensCalc.from_mass_obj(mp) @@ -319,7 +340,7 @@ def test__tangential_caustic_list_from(): # ) -def test__radial_caustic_list_from(): +def test__radial_caustic_list_from__radius_check__correct_mean_radius(): grid = ag.Grid2D.uniform(shape_native=(20, 20), pixel_scales=0.2) mp = ag.mp.PowerLawSph(centre=(0.0, 0.0), einstein_radius=2.0, slope=1.5) @@ -336,6 +357,8 @@ def test__radial_caustic_list_from(): 0.25, 5e-1 ) + +def test__radial_caustic_list_from__centre_at_origin__caustic_centred_on_origin(): grid = ag.Grid2D.uniform(shape_native=(50, 50), pixel_scales=0.2) mp = ag.mp.PowerLawSph(centre=(0.0, 0.0), einstein_radius=2.0, slope=1.5) @@ -349,6 +372,10 @@ def test__radial_caustic_list_from(): assert -0.2 < y_centre < 0.2 assert -0.35 < x_centre < 0.35 + +def test__radial_caustic_list_from__offset_centre__caustic_centred_near_offset(): + grid = ag.Grid2D.uniform(shape_native=(50, 50), pixel_scales=0.2) + mp = ag.mp.PowerLawSph(centre=(0.5, 1.0), einstein_radius=2.0, slope=1.5) od = LensCalc.from_mass_obj(mp) @@ -410,7 +437,7 @@ def test__tangential_critical_curve_area_list_from(): ) -def test__einstein_radius_list_from(): +def test__einstein_radius_list_from__isothermal_sph__correct_einstein_radius(): grid = ag.Grid2D.uniform(shape_native=(50, 50), pixel_scales=0.2) mp = ag.mp.IsothermalSph(centre=(0.0, 0.0), einstein_radius=2.0) @@ -420,6 +447,10 @@ def test__einstein_radius_list_from(): assert einstein_radius_list[0] == pytest.approx(2.0, 1e-1) + +def test__einstein_radius_list_from__isothermal_elliptical__correct_einstein_radius(): + grid = ag.Grid2D.uniform(shape_native=(50, 50), pixel_scales=0.2) + mp = ag.mp.Isothermal( centre=(0.0, 0.0), einstein_radius=2.0, ell_comps=(0.0, -0.25) ) @@ -430,7 +461,7 @@ def test__einstein_radius_list_from(): assert einstein_radius_list[0] == pytest.approx(1.9360, 1e-1) -def test__einstein_radius_from(): +def test__einstein_radius_from__isothermal_sph__correct_einstein_radius(): grid = ag.Grid2D.uniform(shape_native=(50, 50), pixel_scales=0.2) mp = ag.mp.IsothermalSph(centre=(0.0, 0.0), einstein_radius=2.0) @@ -440,6 +471,10 @@ def test__einstein_radius_from(): assert einstein_radius == pytest.approx(2.0, 1e-1) + +def test__einstein_radius_from__isothermal_elliptical__correct_einstein_radius(): + grid = ag.Grid2D.uniform(shape_native=(50, 50), pixel_scales=0.2) + mp = ag.mp.Isothermal( centre=(0.0, 0.0), einstein_radius=2.0, ell_comps=(0.0, -0.25) ) diff --git a/test_autogalaxy/profiles/mass/abstract/test_abstract.py b/test_autogalaxy/profiles/mass/abstract/test_abstract.py index 7532e48ea..51bd775dd 100644 --- a/test_autogalaxy/profiles/mass/abstract/test_abstract.py +++ b/test_autogalaxy/profiles/mass/abstract/test_abstract.py @@ -26,13 +26,12 @@ def mass_within_radius_of_profile_from_grid_calculation(radius, profile): return mass_total -def test__deflections_2d_via_potential_2d_from(): +def test__deflections_2d_via_potential_2d_from__isothermal_sph(): mp = ag.mp.IsothermalSph(centre=(0.0, 0.0), einstein_radius=2.0) grid = ag.Grid2D.uniform(shape_native=(10, 10), pixel_scales=0.05) deflections_via_calculation = mp.deflections_yx_2d_from(grid=grid) - deflections_via_potential = mp.deflections_2d_via_potential_2d_from(grid=grid) mean_error = np.mean( @@ -41,6 +40,8 @@ def test__deflections_2d_via_potential_2d_from(): assert mean_error < 1e-4 + +def test__deflections_2d_via_potential_2d_from__isothermal_ell_comps_1(): sie = ag.mp.Isothermal( centre=(0.0, 0.0), ell_comps=(0.111111, 0.0), einstein_radius=2.0 ) @@ -48,7 +49,6 @@ def test__deflections_2d_via_potential_2d_from(): grid = ag.Grid2D.uniform(shape_native=(10, 10), pixel_scales=0.05) deflections_via_calculation = sie.deflections_yx_2d_from(grid=grid) - deflections_via_potential = sie.deflections_2d_via_potential_2d_from(grid=grid) mean_error = np.mean( @@ -57,6 +57,8 @@ def test__deflections_2d_via_potential_2d_from(): assert mean_error < 1e-4 + +def test__deflections_2d_via_potential_2d_from__isothermal_ell_comps_2(): sie = ag.mp.Isothermal( centre=(0.0, 0.0), ell_comps=(0.0, -0.111111), einstein_radius=2.0 ) @@ -64,7 +66,6 @@ def test__deflections_2d_via_potential_2d_from(): grid = ag.Grid2D.uniform(shape_native=(10, 10), pixel_scales=0.05) deflections_via_calculation = sie.deflections_yx_2d_from(grid=grid) - deflections_via_potential = sie.deflections_2d_via_potential_2d_from(grid=grid) mean_error = np.mean( @@ -74,17 +75,21 @@ def test__deflections_2d_via_potential_2d_from(): assert mean_error < 1e-4 -def test__mass_angular_within_circle_from(): +def test__mass_angular_within_circle_from__sph_einstein_radius_2(): mp = ag.mp.IsothermalSph(einstein_radius=2.0) mass = mp.mass_angular_within_circle_from(radius=2.0) assert math.pi * mp.einstein_radius * 2.0 == pytest.approx(mass, 1e-3) + +def test__mass_angular_within_circle_from__sph_einstein_radius_4(): mp = ag.mp.IsothermalSph(einstein_radius=4.0) mass = mp.mass_angular_within_circle_from(radius=4.0) assert math.pi * mp.einstein_radius * 4.0 == pytest.approx(mass, 1e-3) + +def test__mass_angular_within_circle_from__sph_grid_integration(): mp = ag.mp.IsothermalSph(einstein_radius=2.0) mass_grid = mass_within_radius_of_profile_from_grid_calculation( @@ -96,23 +101,29 @@ def test__mass_angular_within_circle_from(): assert mass_grid == pytest.approx(mass, 0.02) -def test__average_convergence_of_1_radius(): +def test__average_convergence_of_1_radius__isothermal_sph(): mp = ag.mp.IsothermalSph(centre=(0.0, 0.0), einstein_radius=2.0) assert mp.average_convergence_of_1_radius == pytest.approx(2.0, 1e-4) + +def test__average_convergence_of_1_radius__isothermal_low_ellipticity(): sie = ag.mp.Isothermal( centre=(0.0, 0.0), einstein_radius=1.0, ell_comps=(0.0, 0.111111) ) assert sie.average_convergence_of_1_radius == pytest.approx(1.0, 1e-4) + +def test__average_convergence_of_1_radius__isothermal_medium_ellipticity(): sie = ag.mp.Isothermal( centre=(0.0, 0.0), einstein_radius=3.0, ell_comps=(0.0, 0.333333) ) assert sie.average_convergence_of_1_radius == pytest.approx(3.0, 1e-4) + +def test__average_convergence_of_1_radius__isothermal_high_ellipticity(): sie = ag.mp.Isothermal( centre=(0.0, 0.0), einstein_radius=8.0, ell_comps=(0.0, 0.666666) ) @@ -163,7 +174,7 @@ def test__extract_attribute(): mp.extract_attribute(cls=ag.LightProfile, attr_name="einstein_radius") -def test__regression__centre_of_profile_in_right_place(): +def test__regression__centre_of_profile_in_right_place__isothermal(): grid = ag.Grid2D.uniform(shape_native=(7, 7), pixel_scales=1.0) mass_profile = ag.mp.Isothermal(centre=(1.999999, 0.9999999), einstein_radius=1.0) @@ -184,6 +195,10 @@ def test__regression__centre_of_profile_in_right_place(): assert deflections.native[1, 4, 1] > 0 assert deflections.native[1, 3, 1] < 0 + +def test__regression__centre_of_profile_in_right_place__isothermal_sph(): + grid = ag.Grid2D.uniform(shape_native=(7, 7), pixel_scales=1.0) + mass_profile = ag.mp.IsothermalSph(centre=(2.0, 1.0), einstein_radius=1.0) convergence = mass_profile.convergence_2d_from(grid=grid) max_indexes = np.unravel_index( diff --git a/test_autogalaxy/profiles/mass/abstract/test_mge.py b/test_autogalaxy/profiles/mass/abstract/test_mge.py index 4babc8137..e40aad764 100644 --- a/test_autogalaxy/profiles/mass/abstract/test_mge.py +++ b/test_autogalaxy/profiles/mass/abstract/test_mge.py @@ -6,7 +6,7 @@ import autogalaxy as ag -def test__gnfw_deflections_yx_2d_via_mge(): +def test__gnfw_deflections_yx_2d_via_mge__config_1__inner_slope_05(): nfw = ag.mp.gNFW( centre=(0.0, 0.0), kappa_s=1.0, @@ -36,6 +36,8 @@ def test__gnfw_deflections_yx_2d_via_mge(): assert deflections_via_integral == pytest.approx(deflections_via_mge, 1.0e-3) + +def test__gnfw_deflections_yx_2d_via_mge__config_2__inner_slope_15(): nfw = ag.mp.gNFW( centre=(0.3, 0.2), kappa_s=2.5, @@ -65,7 +67,7 @@ def test__gnfw_deflections_yx_2d_via_mge(): assert deflections_via_integral == pytest.approx(deflections_via_mge, 1.0e-3) -def test__sersic_deflections_yx_2d_via_mge(): +def test__sersic_deflections_yx_2d_via_mge__sersic_index_2(): mp = ag.mp.Sersic( centre=(-0.4, -0.2), ell_comps=(-0.07142, -0.085116), @@ -95,6 +97,8 @@ def test__sersic_deflections_yx_2d_via_mge(): assert deflections_via_integral == pytest.approx(deflections_via_mge, 1.0e-3) + +def test__sersic_deflections_yx_2d_via_mge__sersic_index_3(): mp = ag.mp.Sersic( centre=(-0.4, -0.2), ell_comps=(-0.07142, -0.085116), @@ -104,6 +108,11 @@ def test__sersic_deflections_yx_2d_via_mge(): mass_to_light_ratio=1.0, ) + radii_min = mp.effective_radius / 100.0 + radii_max = mp.effective_radius * 20.0 + log_sigmas = np.linspace(np.log(radii_min), np.log(radii_max), 20) + sigmas = np.exp(log_sigmas) + deflections_via_integral = mp.deflections_2d_via_integral_from( grid=ag.Grid2DIrregular([[0.1625, 0.1625]]) ) @@ -205,7 +214,7 @@ def test__chameleon_deflections_yx_2d_via_mge(): assert deflections_analytic == pytest.approx(deflections_via_mge, 1.0e-3) -def test__DevVaucouleurs_convergence_2d_via_mge_from(): +def test__DevVaucouleurs_convergence_2d_via_mge_from__config_1(): mp = ag.mp.DevVaucouleurs( ell_comps=(0.0, 0.333333), intensity=3.0, @@ -229,6 +238,8 @@ def test__DevVaucouleurs_convergence_2d_via_mge_from(): assert convergence == pytest.approx(5.6697, 1e-3) + +def test__DevVaucouleurs_convergence_2d_via_mge_from__config_2(): mp = ag.mp.DevVaucouleurs( ell_comps=(0.0, -0.333333), intensity=2.0, @@ -252,6 +263,8 @@ def test__DevVaucouleurs_convergence_2d_via_mge_from(): assert convergence == pytest.approx(7.4455, 1e-3) + +def test__DevVaucouleurs_convergence_2d_via_mge_from__intensity_4(): mp = ag.mp.DevVaucouleurs( ell_comps=(0.0, -0.333333), intensity=4.0, @@ -275,6 +288,8 @@ def test__DevVaucouleurs_convergence_2d_via_mge_from(): assert convergence == pytest.approx(2.0 * 7.4455, 1e-3) + +def test__DevVaucouleurs_convergence_2d_via_mge_from__mass_to_light_2(): mp = ag.mp.DevVaucouleurs( ell_comps=(0.0, -0.333333), intensity=2.0, @@ -298,6 +313,8 @@ def test__DevVaucouleurs_convergence_2d_via_mge_from(): assert convergence == pytest.approx(2.0 * 7.4455, 1e-3) + +def test__DevVaucouleurs_convergence_2d_via_mge_from__small_effective_radius(): mp = ag.mp.DevVaucouleurs( centre=(0.0, 0.0), intensity=1.0, @@ -322,7 +339,7 @@ def test__DevVaucouleurs_convergence_2d_via_mge_from(): assert convergence == pytest.approx(0.351797, 1e-3) -def test__convergence_2d_via_mge_from(): +def test__exponential_convergence_2d_via_mge_from__config_1(): mp = ag.mp.Exponential( ell_comps=(0.0, 0.333333), intensity=3.0, @@ -346,6 +363,8 @@ def test__convergence_2d_via_mge_from(): assert convergence == pytest.approx(4.9047, 1e-3) + +def test__exponential_convergence_2d_via_mge_from__config_2(): mp = ag.mp.Exponential( ell_comps=(0.0, -0.333333), intensity=2.0, @@ -369,12 +388,15 @@ def test__convergence_2d_via_mge_from(): assert convergence == pytest.approx(4.8566, 1e-3) + +def test__exponential_convergence_2d_via_mge_from__intensity_4(): mp = ag.mp.Exponential( ell_comps=(0.0, -0.333333), intensity=4.0, effective_radius=3.0, mass_to_light_ratio=1.0, ) + radii_min = mp.effective_radius / 100.0 radii_max = mp.effective_radius * 20.0 log_sigmas = np.linspace(np.log(radii_min), np.log(radii_max), 20) @@ -391,6 +413,8 @@ def test__convergence_2d_via_mge_from(): assert convergence == pytest.approx(2.0 * 4.8566, 1e-3) + +def test__exponential_convergence_2d_via_mge_from__mass_to_light_2(): mp = ag.mp.Exponential( ell_comps=(0.0, -0.333333), intensity=2.0, @@ -414,6 +438,8 @@ def test__convergence_2d_via_mge_from(): assert convergence == pytest.approx(2.0 * 4.8566, 1e-3) + +def test__exponential_convergence_2d_via_mge_from__mass_to_light_1(): mp = ag.mp.Exponential( ell_comps=(0.0, -0.333333), intensity=2.0, @@ -438,11 +464,7 @@ def test__convergence_2d_via_mge_from(): assert convergence == pytest.approx(4.8566, 1e-3) -def test__nfw_convergence_2d_via_mge_from(): - # r = 2.0 (> 1.0) - # F(r) = (1/(sqrt(3))*atan(sqrt(3)) = 0.60459978807 - # kappa(r) = 2 * kappa_s * (1 - 0.60459978807) / (4-1) = 0.263600141 - +def test__nfw_convergence_2d_via_mge_from__grid_2(): nfw = ag.mp.NFWSph(centre=(0.0, 0.0), kappa_s=1.0, scale_radius=1.0) radii_min = nfw.scale_radius / 2000.0 @@ -461,6 +483,17 @@ def test__nfw_convergence_2d_via_mge_from(): assert convergence == pytest.approx(0.263600141, 1e-2) + +def test__nfw_convergence_2d_via_mge_from__grid_05(): + nfw = ag.mp.NFWSph(centre=(0.0, 0.0), kappa_s=1.0, scale_radius=1.0) + + radii_min = nfw.scale_radius / 2000.0 + radii_max = nfw.scale_radius * 30.0 + log_sigmas = np.linspace(np.log(radii_min), np.log(radii_max), 20) + sigmas = np.exp(log_sigmas) + + mge_decomp = MGEDecomposer(mass_profile=nfw) + convergence = mge_decomp.convergence_2d_via_mge_from( grid=ag.Grid2DIrregular([[0.5, 0.0]]), sigma_log_list=sigmas, @@ -470,8 +503,15 @@ def test__nfw_convergence_2d_via_mge_from(): assert convergence == pytest.approx(1.388511, 1e-2) + +def test__nfw_convergence_2d_via_mge_from__kappa_s_2(): nfw = ag.mp.NFWSph(centre=(0.0, 0.0), kappa_s=2.0, scale_radius=1.0) + radii_min = nfw.scale_radius / 2000.0 + radii_max = nfw.scale_radius * 30.0 + log_sigmas = np.linspace(np.log(radii_min), np.log(radii_max), 20) + sigmas = np.exp(log_sigmas) + mge_decomp = MGEDecomposer(mass_profile=nfw) convergence = mge_decomp.convergence_2d_via_mge_from( @@ -483,6 +523,8 @@ def test__nfw_convergence_2d_via_mge_from(): assert convergence == pytest.approx(2.0 * 1.388511, 1e-2) + +def test__nfw_convergence_2d_via_mge_from__scale_radius_2(): nfw = ag.mp.NFWSph(centre=(0.0, 0.0), kappa_s=1.0, scale_radius=2.0) radii_min = nfw.scale_radius / 2000.0 @@ -501,6 +543,8 @@ def test__nfw_convergence_2d_via_mge_from(): assert convergence == pytest.approx(1.388511, 1e-2) + +def test__nfw_convergence_2d_via_mge_from__elliptical(): nfw = ag.mp.NFW( centre=(0.0, 0.0), ell_comps=(0.0, 0.333333), @@ -525,7 +569,7 @@ def test__nfw_convergence_2d_via_mge_from(): assert convergence == pytest.approx(1.388511, 1e-3) -def test__sersic_convergence_2d_via_mge_from(): +def test__sersic_convergence_2d_via_mge_from__intensity_3(): mp = ag.mp.Sersic( centre=(0.0, 0.0), intensity=3.0, @@ -550,6 +594,8 @@ def test__sersic_convergence_2d_via_mge_from(): assert convergence == pytest.approx(4.90657319276, 1e-3) + +def test__sersic_convergence_2d_via_mge_from__intensity_6(): mp = ag.mp.Sersic( centre=(0.0, 0.0), intensity=6.0, @@ -558,6 +604,11 @@ def test__sersic_convergence_2d_via_mge_from(): mass_to_light_ratio=1.0, ) + radii_min = mp.effective_radius / 100.0 + radii_max = mp.effective_radius * 20.0 + log_sigmas = np.linspace(np.log(radii_min), np.log(radii_max), 20) + sigmas = np.exp(log_sigmas) + mge_decomp = MGEDecomposer(mass_profile=mp) convergence = mge_decomp.convergence_2d_via_mge_from( @@ -569,6 +620,8 @@ def test__sersic_convergence_2d_via_mge_from(): assert convergence == pytest.approx(2.0 * 4.90657319276, 1e-3) + +def test__sersic_convergence_2d_via_mge_from__mass_to_light_2(): mp = ag.mp.Sersic( centre=(0.0, 0.0), intensity=3.0, @@ -577,6 +630,11 @@ def test__sersic_convergence_2d_via_mge_from(): mass_to_light_ratio=2.0, ) + radii_min = mp.effective_radius / 100.0 + radii_max = mp.effective_radius * 20.0 + log_sigmas = np.linspace(np.log(radii_min), np.log(radii_max), 20) + sigmas = np.exp(log_sigmas) + mge_decomp = MGEDecomposer(mass_profile=mp) convergence = mge_decomp.convergence_2d_via_mge_from( @@ -588,6 +646,8 @@ def test__sersic_convergence_2d_via_mge_from(): assert convergence == pytest.approx(2.0 * 4.90657319276, 1e-3) + +def test__sersic_convergence_2d_via_mge_from__elliptical(): mp = ag.mp.Sersic( centre=(0.0, 0.0), ell_comps=(0.0, 0.333333), @@ -597,6 +657,11 @@ def test__sersic_convergence_2d_via_mge_from(): mass_to_light_ratio=1.0, ) + radii_min = mp.effective_radius / 100.0 + radii_max = mp.effective_radius * 20.0 + log_sigmas = np.linspace(np.log(radii_min), np.log(radii_max), 20) + sigmas = np.exp(log_sigmas) + mge_decomp = MGEDecomposer(mass_profile=mp) convergence = mge_decomp.convergence_2d_via_mge_from( diff --git a/test_autogalaxy/profiles/mass/dark/test_abstract.py b/test_autogalaxy/profiles/mass/dark/test_abstract.py index a058381bc..567934673 100644 --- a/test_autogalaxy/profiles/mass/dark/test_abstract.py +++ b/test_autogalaxy/profiles/mass/dark/test_abstract.py @@ -4,48 +4,60 @@ import autogalaxy as ag -def test__coord_function_f__from(): +def test__coord_function_f__from__r_greater_than_1(): mp = ag.mp.NFWTruncatedSph( centre=(0.0, 0.0), kappa_s=2.0, scale_radius=10.0, truncation_radius=3.0 ) - # r > 1 - coord_f = mp.coord_func_f(grid_radius=np.array([2.0, 3.0])) assert coord_f == pytest.approx(np.array([0.604599, 0.435209]), 1.0e-4) - # r < 1 + +def test__coord_function_f__from__r_less_than_1(): + mp = ag.mp.NFWTruncatedSph( + centre=(0.0, 0.0), kappa_s=2.0, scale_radius=10.0, truncation_radius=3.0 + ) coord_f = mp.coord_func_f(grid_radius=np.array([0.5, 1.0 / 3.0])) assert coord_f == pytest.approx(1.52069, 1.86967, 1.0e-4) - # - # r == 1 + + +def test__coord_function_f__from__r_equals_1(): + mp = ag.mp.NFWTruncatedSph( + centre=(0.0, 0.0), kappa_s=2.0, scale_radius=10.0, truncation_radius=3.0 + ) coord_f = mp.coord_func_f(grid_radius=np.array([1.0, 1.0])) assert (coord_f == np.array([1.0, 1.0])).all() -def test__coord_function_g__from(): +def test__coord_function_g__from__r_greater_than_1(): mp = ag.mp.NFWTruncatedSph( centre=(0.0, 0.0), kappa_s=2.0, scale_radius=10.0, truncation_radius=3.0 ) - # r > 1 - coord_g = mp.coord_func_g(grid_radius=np.array([2.0, 3.0])) assert coord_g == pytest.approx(np.array([0.13180, 0.070598]), 1.0e-4) - # r < 1 + +def test__coord_function_g__from__r_less_than_1(): + mp = ag.mp.NFWTruncatedSph( + centre=(0.0, 0.0), kappa_s=2.0, scale_radius=10.0, truncation_radius=3.0 + ) coord_g = mp.coord_func_g(grid_radius=np.array([0.5, 1.0 / 3.0])) assert coord_g == pytest.approx(np.array([0.69425, 0.97838]), 1.0e-4) - # r == 1 + +def test__coord_function_g__from__r_equals_1(): + mp = ag.mp.NFWTruncatedSph( + centre=(0.0, 0.0), kappa_s=2.0, scale_radius=10.0, truncation_radius=3.0 + ) coord_g = mp.coord_func_g(grid_radius=np.array([1.0, 1.0])) @@ -62,7 +74,7 @@ def test__coord_function_h__from(): assert coord_h == pytest.approx(np.array([0.134395, 0.840674]), 1.0e-4) -def test__coord_function_k__from(): +def test__coord_function_k__from__truncation_radius_2(): mp = ag.mp.NFWTruncatedSph( centre=(0.0, 0.0), kappa_s=2.0, scale_radius=10.0, truncation_radius=2.0 ) @@ -71,6 +83,8 @@ def test__coord_function_k__from(): assert coord_k == pytest.approx(np.array([-0.09983408, -0.06661738]), 1.0e-4) + +def test__coord_function_k__from__truncation_radius_4(): mp = ag.mp.NFWTruncatedSph( centre=(0.0, 0.0), kappa_s=2.0, scale_radius=10.0, truncation_radius=4.0 ) @@ -80,7 +94,7 @@ def test__coord_function_k__from(): assert coord_k == pytest.approx(np.array([-0.19869011, -0.1329414]), 1.0e-4) -def test__coord_function_l__from(): +def test__coord_function_l__from__grid_radius_2_truncation_2(): mp = ag.mp.NFWTruncatedSph( centre=(0.0, 0.0), kappa_s=2.0, scale_radius=10.0, truncation_radius=2.0 ) @@ -89,6 +103,8 @@ def test__coord_function_l__from(): assert coord_l == pytest.approx(np.array([0.00080191, 0.00080191]), 1.0e-4) + +def test__coord_function_l__from__grid_radius_2_truncation_3(): mp = ag.mp.NFWTruncatedSph( centre=(0.0, 0.0), kappa_s=2.0, scale_radius=10.0, truncation_radius=3.0 ) @@ -97,6 +113,8 @@ def test__coord_function_l__from(): assert coord_l == pytest.approx(np.array([0.00178711, 0.00178711]), 1.0e-4) + +def test__coord_function_l__from__grid_radius_3_truncation_3(): mp = ag.mp.NFWTruncatedSph( centre=(0.0, 0.0), kappa_s=2.0, scale_radius=10.0, truncation_radius=3.0 ) @@ -106,7 +124,7 @@ def test__coord_function_l__from(): assert coord_l == pytest.approx(np.array([0.00044044, 0.00044044]), 1.0e-4) -def test__coord_function_m__from(): +def test__coord_function_m__from__grid_radius_2_truncation_2(): mp = ag.mp.NFWTruncatedSph( centre=(0.0, 0.0), kappa_s=2.0, scale_radius=10.0, truncation_radius=2.0 ) @@ -115,6 +133,8 @@ def test__coord_function_m__from(): assert coord_m == pytest.approx(np.array([0.0398826, 0.0398826]), 1.0e-4) + +def test__coord_function_m__from__grid_radius_2_truncation_3(): mp = ag.mp.NFWTruncatedSph( centre=(0.0, 0.0), kappa_s=2.0, scale_radius=10.0, truncation_radius=3.0 ) @@ -123,6 +143,8 @@ def test__coord_function_m__from(): assert coord_m == pytest.approx(np.array([0.06726646, 0.06726646]), 1.0e-4) + +def test__coord_function_m__from__grid_radius_3_truncation_3(): mp = ag.mp.NFWTruncatedSph( centre=(0.0, 0.0), kappa_s=2.0, scale_radius=10.0, truncation_radius=3.0 ) @@ -132,7 +154,7 @@ def test__coord_function_m__from(): assert coord_m == pytest.approx(np.array([0.06946888, 0.06946888]), 1.0e-4) -def test__rho_at_scale_radius__unit_conversions(): +def test__rho_at_scale_radius__arcsec_per_kpc_05(): cosmology = ag.m.MockCosmology( arcsec_per_kpc=0.5, kpc_per_arcsec=2.0, critical_surface_density=2.0 ) @@ -147,26 +169,34 @@ def test__rho_at_scale_radius__unit_conversions(): ) assert rho == pytest.approx(0.5 / 2.0, 1e-3) + +def test__rho_at_scale_radius__arcsec_per_kpc_025(): cosmology = ag.m.MockCosmology( arcsec_per_kpc=0.25, kpc_per_arcsec=4.0, critical_surface_density=2.0 ) + mp = ag.mp.NFWSph(centre=(0.0, 0.0), kappa_s=1.0, scale_radius=1.0) + rho = mp.rho_at_scale_radius_solar_mass_per_kpc3( redshift_object=0.5, redshift_source=1.0, cosmology=cosmology ) assert rho == pytest.approx(0.5 / 4.0, 1e-3) + +def test__rho_at_scale_radius__critical_surface_density_4(): cosmology = ag.m.MockCosmology( arcsec_per_kpc=0.25, kpc_per_arcsec=4.0, critical_surface_density=4.0 ) + mp = ag.mp.NFWSph(centre=(0.0, 0.0), kappa_s=1.0, scale_radius=1.0) + rho = mp.rho_at_scale_radius_solar_mass_per_kpc3( redshift_object=0.5, redshift_source=1.0, cosmology=cosmology ) assert rho == pytest.approx(0.25 / 4.0, 1e-3) -def test__delta_concentration_value_in_default_units(): +def test__delta_concentration__kappa_s_1(): mp = ag.mp.NFWSph(centre=(0.0, 0.0), kappa_s=1.0, scale_radius=1.0) cosmology = ag.m.MockCosmology( @@ -181,13 +211,33 @@ def test__delta_concentration_value_in_default_units(): ) assert delta_concentration == pytest.approx(1.0, 1e-3) + +def test__delta_concentration__kappa_s_3(): mp = ag.mp.NFWSph(centre=(0.0, 0.0), kappa_s=3.0, scale_radius=1.0) + + cosmology = ag.m.MockCosmology( + arcsec_per_kpc=1.0, + kpc_per_arcsec=1.0, + critical_surface_density=1.0, + cosmic_average_density=1.0, + ) + delta_concentration = mp.delta_concentration( redshift_object=0.5, redshift_source=1.0, cosmology=cosmology ) assert delta_concentration == pytest.approx(3.0, 1e-3) + +def test__delta_concentration__scale_radius_4(): mp = ag.mp.NFWSph(centre=(0.0, 0.0), kappa_s=1.0, scale_radius=4.0) + + cosmology = ag.m.MockCosmology( + arcsec_per_kpc=1.0, + kpc_per_arcsec=1.0, + critical_surface_density=1.0, + cosmic_average_density=1.0, + ) + delta_concentration = mp.delta_concentration( redshift_object=0.5, redshift_source=1.0, cosmology=cosmology ) @@ -254,7 +304,7 @@ def test__mass_at_200__unit_conversions_work(): assert mass_at_200 == pytest.approx(mass_calc, 1.0e-5) -def test__values_of_quantities_for_real_cosmology(): +def test__values_of_quantities_for_real_cosmology__local_density(): from autogalaxy.cosmology.model import FlatLambdaCDM @@ -308,6 +358,15 @@ def test__values_of_quantities_for_real_cosmology(): assert mass_at_200 == pytest.approx(27664107754813.824, 1.0e-4) assert mass_at_truncation_radius == pytest.approx(14883851437772.34, 1.0e-4) + +def test__values_of_quantities_for_real_cosmology__profile_density(): + + from autogalaxy.cosmology.model import FlatLambdaCDM + + cosmology = FlatLambdaCDM(H0=70.0, Om0=0.3, m_nu=0.06) + + mp = ag.mp.NFWTruncatedSph(kappa_s=0.5, scale_radius=5.0, truncation_radius=10.0) + rho = mp.rho_at_scale_radius_solar_mass_per_kpc3( redshift_object=0.6, redshift_source=2.5, cosmology=cosmology ) diff --git a/test_autogalaxy/profiles/mass/dark/test_gnfw.py b/test_autogalaxy/profiles/mass/dark/test_gnfw.py index 99b70c0cb..df4743075 100644 --- a/test_autogalaxy/profiles/mass/dark/test_gnfw.py +++ b/test_autogalaxy/profiles/mass/dark/test_gnfw.py @@ -6,7 +6,7 @@ grid = ag.Grid2DIrregular([[1.0, 1.0], [2.0, 2.0], [3.0, 3.0], [2.0, 4.0]]) -def test__deflections_2d_via_integral_from(): +def test__deflections_2d_via_integral_from__gnfw_sph_config_1(): mp = ag.mp.gNFWSph( centre=(0.0, 0.0), kappa_s=1.0, inner_slope=0.5, scale_radius=8.0 ) @@ -18,6 +18,8 @@ def test__deflections_2d_via_integral_from(): assert deflections[0, 0] == pytest.approx(0.43501, 1e-3) assert deflections[0, 1] == pytest.approx(0.37701, 1e-3) + +def test__deflections_2d_via_integral_from__gnfw_sph_config_2(): mp = ag.mp.gNFWSph( centre=(0.3, 0.2), kappa_s=2.5, inner_slope=1.5, scale_radius=4.0 ) @@ -29,6 +31,8 @@ def test__deflections_2d_via_integral_from(): assert deflections[0, 0] == pytest.approx(-9.31254, 1e-3) assert deflections[0, 1] == pytest.approx(-3.10418, 1e-3) + +def test__deflections_2d_via_integral_from__gnfw_ell_config_1(): mp = ag.mp.gNFW( centre=(0.0, 0.0), kappa_s=1.0, @@ -42,6 +46,8 @@ def test__deflections_2d_via_integral_from(): assert deflections[0, 0] == pytest.approx(0.26604, 1e-3) assert deflections[0, 1] == pytest.approx(0.58988, 1e-3) + +def test__deflections_2d_via_integral_from__gnfw_ell_config_2(): mp = ag.mp.gNFW( centre=(0.3, 0.2), kappa_s=2.5, @@ -56,7 +62,7 @@ def test__deflections_2d_via_integral_from(): assert deflections[0, 1] == pytest.approx(-4.02541, 1e-3) -def test__deflections_yx_2d_from(): +def test__deflections_yx_2d_from__gnfw(): mp = ag.mp.gNFW() deflections = mp.deflections_yx_2d_from(grid=ag.Grid2DIrregular([[1.0, 0.0]])) @@ -66,6 +72,8 @@ def test__deflections_yx_2d_from(): assert deflections == pytest.approx(deflections_via_integral.array, 1.0e-4) + +def test__deflections_yx_2d_from__gnfw_sph(): mp = ag.mp.gNFWSph() deflections = mp.deflections_yx_2d_from(grid=ag.Grid2DIrregular([[1.0, 0.0]])) @@ -75,6 +83,8 @@ def test__deflections_yx_2d_from(): assert deflections == pytest.approx(deflections_via_integral.array, 1.0e-4) + +def test__deflections_yx_2d_from__elliptical_vs_spherical(): elliptical = ag.mp.gNFW( centre=(0.1, 0.2), ell_comps=(0.0, 0.0), @@ -91,7 +101,7 @@ def test__deflections_yx_2d_from(): ) -def test__convergence_2d_from(): +def test__convergence_2d_from__gnfw_sph(): mp = ag.mp.gNFWSph( centre=(0.0, 0.0), kappa_s=1.0, inner_slope=1.5, scale_radius=1.0 ) @@ -100,6 +110,8 @@ def test__convergence_2d_from(): assert convergence == pytest.approx(0.30840, 1e-2) + +def test__convergence_2d_from__elliptical_vs_spherical(): elliptical = ag.mp.gNFW( centre=(0.1, 0.2), ell_comps=(0.0, 0.0), @@ -116,7 +128,7 @@ def test__convergence_2d_from(): ) -def test__potential_2d_from(): +def test__potential_2d_from__gnfw_sph_inner_slope_05(): mp = ag.mp.gNFWSph( centre=(0.0, 0.0), kappa_s=1.0, inner_slope=0.5, scale_radius=8.0 ) @@ -125,6 +137,8 @@ def test__potential_2d_from(): assert potential == pytest.approx(0.00920, 1e-3) + +def test__potential_2d_from__gnfw_sph_inner_slope_15(): mp = ag.mp.gNFWSph( centre=(0.0, 0.0), kappa_s=1.0, inner_slope=1.5, scale_radius=8.0 ) @@ -133,6 +147,8 @@ def test__potential_2d_from(): assert potential == pytest.approx(0.17448, 1e-3) + +def test__potential_2d_from__gnfw_ell(): mp = ag.mp.gNFW( centre=(1.0, 1.0), kappa_s=5.0, @@ -144,6 +160,8 @@ def test__potential_2d_from(): 2.4718, 1e-4 ) + +def test__potential_2d_from__elliptical_vs_spherical(): elliptical = ag.mp.gNFW( centre=(0.1, 0.2), ell_comps=(0.0, 0.0), diff --git a/test_autogalaxy/profiles/mass/dark/test_nfw.py b/test_autogalaxy/profiles/mass/dark/test_nfw.py index fbdf4d6b3..f9c894d64 100644 --- a/test_autogalaxy/profiles/mass/dark/test_nfw.py +++ b/test_autogalaxy/profiles/mass/dark/test_nfw.py @@ -6,8 +6,7 @@ grid = ag.Grid2DIrregular([[1.0, 1.0], [2.0, 2.0], [3.0, 3.0], [2.0, 4.0]]) -def test__deflections_via_analytical_from(): - +def test__deflections_via_analytical_from__nfw_config_1(): nfw = ag.mp.NFW( centre=(0.0, 0.0), ell_comps=(0.0, 0.0), @@ -22,6 +21,8 @@ def test__deflections_via_analytical_from(): assert deflections[0, 0] == pytest.approx(0.56194, 1e-3) assert deflections[0, 1] == pytest.approx(0.56194, 1e-3) + +def test__deflections_via_analytical_from__nfw_config_2(): nfw = ag.mp.NFW( centre=(0.3, 0.2), ell_comps=(0.03669, 0.172614), @@ -36,6 +37,8 @@ def test__deflections_via_analytical_from(): assert deflections[0, 0] == pytest.approx(-2.59480, 1e-3) assert deflections[0, 1] == pytest.approx(-0.44204, 1e-3) + +def test__deflections_via_analytical_from__analytic_vs_cse_config_1(): nfw = ag.mp.NFW( centre=(0.0, 0.0), ell_comps=(0.0, 0.0), @@ -52,6 +55,8 @@ def test__deflections_via_analytical_from(): assert deflections_via_analytic == pytest.approx(deflections_via_cse.array, 1.0e-4) + +def test__deflections_via_analytical_from__analytic_vs_cse_config_2(): nfw = ag.mp.NFW( centre=(0.3, -0.2), ell_comps=(0.09, 0.172614), @@ -69,7 +74,7 @@ def test__deflections_via_analytical_from(): assert deflections_via_analytic == pytest.approx(deflections_via_cse.array, 1.0e-4) -def test__deflections_via_integral_from(): +def test__deflections_via_integral_from__nfw_sph_config_1(): nfw = ag.mp.NFWSph(centre=(0.0, 0.0), kappa_s=1.0, scale_radius=1.0) deflections = nfw.deflections_2d_via_integral_from( @@ -79,6 +84,8 @@ def test__deflections_via_integral_from(): assert deflections[0, 0] == pytest.approx(0.56194, 1e-3) assert deflections[0, 1] == pytest.approx(0.56194, 1e-3) + +def test__deflections_via_integral_from__nfw_sph_config_2(): nfw = ag.mp.NFWSph(centre=(0.3, 0.2), kappa_s=2.5, scale_radius=4.0) deflections = nfw.deflections_2d_via_integral_from( @@ -88,6 +95,8 @@ def test__deflections_via_integral_from(): assert deflections[0, 0] == pytest.approx(-2.08909, 1e-3) assert deflections[0, 1] == pytest.approx(-0.69636, 1e-3) + +def test__deflections_via_integral_from__nfw_ell_config_1(): nfw = ag.mp.NFW( centre=(0.0, 0.0), ell_comps=(0.0, 0.0), @@ -102,6 +111,8 @@ def test__deflections_via_integral_from(): assert deflections[0, 0] == pytest.approx(0.56194, 1e-3) assert deflections[0, 1] == pytest.approx(0.56194, 1e-3) + +def test__deflections_via_integral_from__nfw_ell_config_2(): nfw = ag.mp.NFW( centre=(0.3, 0.2), ell_comps=(0.03669, 0.172614), @@ -117,7 +128,7 @@ def test__deflections_via_integral_from(): assert deflections[0, 1] == pytest.approx(-0.44204, 1e-3) -def test__deflections_2d_via_cse_from(): +def test__deflections_2d_via_cse_from__nfw_sph_config_1(): nfw = ag.mp.NFWSph(centre=(0.0, 0.0), kappa_s=1.0, scale_radius=1.0) deflections_via_integral = nfw.deflections_2d_via_integral_from( @@ -129,6 +140,8 @@ def test__deflections_2d_via_cse_from(): assert deflections_via_integral == pytest.approx(deflections_via_cse.array, 1.0e-4) + +def test__deflections_2d_via_cse_from__nfw_sph_config_2(): nfw = ag.mp.NFWSph(centre=(0.3, 0.2), kappa_s=2.5, scale_radius=4.0) deflections_via_integral = nfw.deflections_2d_via_integral_from( @@ -140,6 +153,8 @@ def test__deflections_2d_via_cse_from(): assert deflections_via_integral == pytest.approx(deflections_via_cse.array, 1.0e-4) + +def test__deflections_2d_via_cse_from__nfw_ell_config_1(): nfw = ag.mp.NFW( centre=(0.0, 0.0), ell_comps=(0.0, 0.0), @@ -156,6 +171,8 @@ def test__deflections_2d_via_cse_from(): assert deflections_via_integral == pytest.approx(deflections_via_cse.array, 1.0e-4) + +def test__deflections_2d_via_cse_from__nfw_ell_config_2(): nfw = ag.mp.NFW( centre=(0.3, 0.2), ell_comps=(0.03669, 0.172614), @@ -173,7 +190,7 @@ def test__deflections_2d_via_cse_from(): assert deflections_via_integral == pytest.approx(deflections_via_cse.array, 1.0e-4) -def test__deflections_2d__numerical_precision_of_csv_compared_to_integral(): +def test__deflections_2d_numerical_precision__config_1(): nfw = ag.mp.NFW( centre=(0.3, 0.2), ell_comps=(0.03669, 0.172614), @@ -190,6 +207,8 @@ def test__deflections_2d__numerical_precision_of_csv_compared_to_integral(): assert deflections_via_integral == pytest.approx(deflections_via_cse.array, 1.0e-4) + +def test__deflections_2d_numerical_precision__config_2(): nfw = ag.mp.NFW( centre=(0.3, 0.2), ell_comps=(0.2, 0.3), @@ -206,6 +225,15 @@ def test__deflections_2d__numerical_precision_of_csv_compared_to_integral(): assert deflections_via_integral == pytest.approx(deflections_via_cse.array, 1.0e-4) + +def test__deflections_2d_numerical_precision__config_3(): + nfw = ag.mp.NFW( + centre=(0.3, 0.2), + ell_comps=(0.2, 0.3), + kappa_s=3.5, + scale_radius=40.0, + ) + deflections_via_integral = nfw.deflections_2d_via_integral_from( grid=ag.Grid2DIrregular([[-1000.0, -2000.0]]) ) @@ -227,7 +255,7 @@ def test__deflections_yx_2d_from(): assert deflections == pytest.approx(deflections_via_integral.array, 1.0e-4) -def test__convergence_2d_via_cse_from(): +def test__convergence_2d_via_cse_from__nfw_grid_2(): # r = 2.0 (> 1.0) # F(r) = (1/(sqrt(3))*atan(sqrt(3)) = 0.60459978807 # kappa(r) = 2 * kappa_s * (1 - 0.60459978807) / (4-1) = 0.263600141 @@ -238,24 +266,32 @@ def test__convergence_2d_via_cse_from(): assert convergence == pytest.approx(0.263600141, 1e-2) + +def test__convergence_2d_via_cse_from__nfw_grid_05(): nfw = ag.mp.NFWSph(centre=(0.0, 0.0), kappa_s=1.0, scale_radius=1.0) convergence = nfw.convergence_2d_via_cse_from(grid=ag.Grid2DIrregular([[0.5, 0.0]])) assert convergence == pytest.approx(1.388511, 1e-2) + +def test__convergence_2d_via_cse_from__nfw_kappa_s_2(): nfw = ag.mp.NFWSph(centre=(0.0, 0.0), kappa_s=2.0, scale_radius=1.0) convergence = nfw.convergence_2d_via_cse_from(grid=ag.Grid2DIrregular([[0.5, 0.0]])) assert convergence == pytest.approx(2.0 * 1.388511, 1e-2) + +def test__convergence_2d_via_cse_from__nfw_scale_radius_2(): nfw = ag.mp.NFWSph(centre=(0.0, 0.0), kappa_s=1.0, scale_radius=2.0) convergence = nfw.convergence_2d_via_cse_from(grid=ag.Grid2DIrregular([[1.0, 0.0]])) assert convergence == pytest.approx(1.388511, 1e-2) + +def test__convergence_2d_via_cse_from__nfw_ell(): nfw = ag.mp.NFW( centre=(0.0, 0.0), ell_comps=(0.0, 0.333333), @@ -270,7 +306,7 @@ def test__convergence_2d_via_cse_from(): assert convergence == pytest.approx(1.388511, 1e-3) -def test__convergence_2d_from(): +def test__convergence_2d_from__nfw_sph_grid_2(): # r = 2.0 (> 1.0) # F(r) = (1/(sqrt(3))*atan(sqrt(3)) = 0.60459978807 # kappa(r) = 2 * kappa_s * (1 - 0.60459978807) / (4-1) = 0.263600141 @@ -281,24 +317,32 @@ def test__convergence_2d_from(): assert convergence == pytest.approx(0.263600141, 1e-3) + +def test__convergence_2d_from__nfw_sph_grid_05(): nfw = ag.mp.NFWSph(centre=(0.0, 0.0), kappa_s=1.0, scale_radius=1.0) convergence = nfw.convergence_2d_from(grid=ag.Grid2DIrregular([[0.5, 0.0]])) assert convergence == pytest.approx(1.388511, 1e-3) + +def test__convergence_2d_from__nfw_sph_kappa_s_2(): nfw = ag.mp.NFWSph(centre=(0.0, 0.0), kappa_s=2.0, scale_radius=1.0) convergence = nfw.convergence_2d_from(grid=ag.Grid2DIrregular([[0.5, 0.0]])) assert convergence == pytest.approx(2.0 * 1.388511, 1e-3) + +def test__convergence_2d_from__nfw_sph_scale_radius_2(): nfw = ag.mp.NFWSph(centre=(0.0, 0.0), kappa_s=1.0, scale_radius=2.0) convergence = nfw.convergence_2d_from(grid=ag.Grid2DIrregular([[1.0, 0.0]])) assert convergence == pytest.approx(1.388511, 1e-3) + +def test__convergence_2d_from__nfw_ell(): nfw = ag.mp.NFW( centre=(0.0, 0.0), ell_comps=(0.0, 0.333333), @@ -353,7 +397,7 @@ def test__convergence_2d_from(): # assert potential_spherical == pytest.approx(potential_elliptical, 1e-3) -def test__shear_yx_2d_from(): +def test__shear_yx_2d_from__nfw_sph_config_1(): mp = ag.mp.NFWSph(centre=(0.0, 0.0), kappa_s=1.0, scale_radius=1.0) shear = mp.shear_yx_2d_from(grid=ag.Grid2DIrregular([[2.0, 1.0]])) @@ -361,11 +405,17 @@ def test__shear_yx_2d_from(): assert shear[0, 0] == pytest.approx(-0.24712463, abs=1e-3) assert shear[0, 1] == pytest.approx(0.185340150, abs=1e-3) + +def test__shear_yx_2d_from__nfw_sph_config_2(): + mp = ag.mp.NFWSph(centre=(0.0, 0.0), kappa_s=1.0, scale_radius=1.0) + shear = mp.shear_yx_2d_from(grid=ag.Grid2DIrregular([[3.0, 5.0]])) assert shear[0, 0] == pytest.approx(-0.09588857, abs=1e-3) assert shear[0, 1] == pytest.approx(-0.05114060, abs=1e-3) + +def test__shear_yx_2d_from__nfw_ell(): mp = ag.mp.NFW( centre=(0.0, 0.0), ell_comps=(0.3, 0.4), kappa_s=1.0, scale_radius=1.0 ) diff --git a/test_autogalaxy/profiles/mass/dark/test_nfw_mcr.py b/test_autogalaxy/profiles/mass/dark/test_nfw_mcr.py index 477f65319..0b18a4bb0 100644 --- a/test_autogalaxy/profiles/mass/dark/test_nfw_mcr.py +++ b/test_autogalaxy/profiles/mass/dark/test_nfw_mcr.py @@ -218,7 +218,7 @@ def test__same_as_above_but_generalized_elliptical(): assert (deflections_ludlow == deflections).all() -def test__same_as_above_but_cored_nfw(): +def test__same_as_above_but_cored_nfw__spherical(): from autogalaxy.cosmology.model import FlatLambdaCDM @@ -273,6 +273,13 @@ def test__same_as_above_but_cored_nfw(): assert (deflections_ludlow == deflections).all() + +def test__same_as_above_but_cored_nfw__elliptical(): + + from autogalaxy.cosmology.model import FlatLambdaCDM + + cosmology = FlatLambdaCDM(H0=70.0, Om0=0.3) + mp = ag.mp.cNFWMCRLudlow( centre=(1.0, 2.0), ell_comps=(0.1, 0.2), @@ -324,4 +331,4 @@ def test__same_as_above_but_cored_nfw(): deflections_ludlow = mp.deflections_yx_2d_from(grid=grid) deflections = cnfw_kappa_s.deflections_yx_2d_from(grid=grid) - assert (deflections_ludlow == deflections).all() \ No newline at end of file + assert (deflections_ludlow == deflections).all() diff --git a/test_autogalaxy/profiles/mass/dark/test_nfw_scatter.py b/test_autogalaxy/profiles/mass/dark/test_nfw_scatter.py index 7cd95e008..650b025b3 100644 --- a/test_autogalaxy/profiles/mass/dark/test_nfw_scatter.py +++ b/test_autogalaxy/profiles/mass/dark/test_nfw_scatter.py @@ -6,7 +6,7 @@ grid = ag.Grid2DIrregular([[1.0, 1.0], [2.0, 2.0], [3.0, 3.0], [2.0, 4.0]]) -def test__scatter_is_nonzero(): +def test__scatter_is_nonzero__sph_scatter_positive(): mp = ag.mp.NFWMCRScatterLudlowSph( mass_at_200=1.0e9, scatter_sigma=1.0, @@ -14,10 +14,10 @@ def test__scatter_is_nonzero(): redshift_source=2.5, ) - # We uare using the NFWTruncatedSph to check the mass gives a conosistnt kappa_s, given certain radii. - assert mp.scale_radius == pytest.approx(0.14978, 1.0e-4) + +def test__scatter_is_nonzero__sph_scatter_negative(): mp = ag.mp.NFWMCRScatterLudlowSph( mass_at_200=1.0e9, scatter_sigma=-1.0, @@ -25,10 +25,10 @@ def test__scatter_is_nonzero(): redshift_source=2.5, ) - # We uare using the NFWTruncatedSph to check the mass gives a conosistnt kappa_s, given certain radii. - assert mp.scale_radius == pytest.approx(0.29886, 1.0e-4) + +def test__scatter_is_nonzero__ell_scatter_positive(): nfw_ell = ag.mp.NFWMCRScatterLudlow( ell_comps=(0.5, 0.5), mass_at_200=1.0e9, @@ -37,11 +37,18 @@ def test__scatter_is_nonzero(): redshift_source=2.5, ) - # We uare using the NFWTruncated to check the mass gives a conosistnt kappa_s, given certain radii. - assert nfw_ell.ell_comps == (0.5, 0.5) assert nfw_ell.scale_radius == pytest.approx(0.14978, 1.0e-4) + +def test__scatter_is_nonzero__ell_scatter_negative__deflections_differ_from_sph(): + mp_sph = ag.mp.NFWMCRScatterLudlowSph( + mass_at_200=1.0e9, + scatter_sigma=-1.0, + redshift_object=0.6, + redshift_source=2.5, + ) + nfw_ell = ag.mp.NFWMCRScatterLudlow( ell_comps=(0.5, 0.5), mass_at_200=1.0e9, @@ -50,18 +57,16 @@ def test__scatter_is_nonzero(): redshift_source=2.5, ) - # We uare using the NFWTruncated to check the mass gives a conosistnt kappa_s, given certain radii. - assert nfw_ell.ell_comps == (0.5, 0.5) assert nfw_ell.scale_radius == pytest.approx(0.29886, 1.0e-4) - deflections_sph = mp.deflections_yx_2d_from(grid=grid) + deflections_sph = mp_sph.deflections_yx_2d_from(grid=grid) deflections_ell = nfw_ell.deflections_yx_2d_from(grid=grid) assert deflections_sph[0] != pytest.approx(deflections_ell[0], 1.0e-4) -def test__scatter_is_nonzero_cored(): +def test__scatter_is_nonzero_cored__sph_scatter_positive(): cnfw_sph = ag.mp.cNFWMCRScatterLudlowSph( mass_at_200=1.0e9, scatter_sigma=1.0, @@ -72,6 +77,8 @@ def test__scatter_is_nonzero_cored(): assert cnfw_sph.scale_radius == pytest.approx(0.14978, 1.0e-4) + +def test__scatter_is_nonzero_cored__sph_scatter_negative(): cnfw_sph = ag.mp.cNFWMCRScatterLudlowSph( mass_at_200=1.0e9, scatter_sigma=-1.0, @@ -82,6 +89,8 @@ def test__scatter_is_nonzero_cored(): assert cnfw_sph.scale_radius == pytest.approx(0.29886, 1.0e-4) + +def test__scatter_is_nonzero_cored__ell_scatter_positive(): cnfw = ag.mp.cNFWMCRScatterLudlow( ell_comps=(-0.1, 0.2), mass_at_200=1.0e9, @@ -93,6 +102,8 @@ def test__scatter_is_nonzero_cored(): assert cnfw.scale_radius == pytest.approx(0.14978, 1.0e-4) + +def test__scatter_is_nonzero_cored__ell_scatter_negative(): cnfw_sph = ag.mp.cNFWMCRScatterLudlow( mass_at_200=1.0e9, scatter_sigma=-1.0, @@ -102,4 +113,3 @@ def test__scatter_is_nonzero_cored(): ) assert cnfw_sph.scale_radius == pytest.approx(0.29886, 1.0e-4) - diff --git a/test_autogalaxy/profiles/mass/dark/test_nfw_truncated.py b/test_autogalaxy/profiles/mass/dark/test_nfw_truncated.py index 7f5082674..ead493029 100644 --- a/test_autogalaxy/profiles/mass/dark/test_nfw_truncated.py +++ b/test_autogalaxy/profiles/mass/dark/test_nfw_truncated.py @@ -6,7 +6,7 @@ grid = ag.Grid2DIrregular([[1.0, 1.0], [2.0, 2.0], [3.0, 3.0], [2.0, 4.0]]) -def test__deflections_yx_2d_from(): +def test__deflections_yx_2d_from__config_1__y_axis(): mp = ag.mp.NFWTruncatedSph( centre=(0.0, 0.0), kappa_s=1.0, scale_radius=1.0, truncation_radius=2.0 ) @@ -19,11 +19,25 @@ def test__deflections_yx_2d_from(): assert deflections[0, 0] == pytest.approx(factor * 0.38209715, abs=1.0e-4) assert deflections[0, 1] == pytest.approx(0.0, abs=1.0e-4) + +def test__deflections_yx_2d_from__config_1__x_axis(): + mp = ag.mp.NFWTruncatedSph( + centre=(0.0, 0.0), kappa_s=1.0, scale_radius=1.0, truncation_radius=2.0 + ) + + factor = (4.0 * 1.0 * 1.0) / (2.0 / 1.0) + deflections = mp.deflections_yx_2d_from(grid=ag.Grid2DIrregular([[0.0, 2.0]])) assert deflections[0, 0] == pytest.approx(0.0, abs=1.0e-4) assert deflections[0, 1] == pytest.approx(factor * 0.38209715, abs=1.0e-4) + +def test__deflections_yx_2d_from__config_1__diagonal(): + mp = ag.mp.NFWTruncatedSph( + centre=(0.0, 0.0), kappa_s=1.0, scale_radius=1.0, truncation_radius=2.0 + ) + deflections = mp.deflections_yx_2d_from(grid=ag.Grid2DIrregular([[1.0, 1.0]])) factor = (4.0 * 1.0 * 1.0) / (np.sqrt(2) / 1.0) @@ -34,6 +48,8 @@ def test__deflections_yx_2d_from(): (1.0 / np.sqrt(2)) * factor * 0.3125838, abs=1.0e-4 ) + +def test__deflections_yx_2d_from__kappa_s_2(): mp = ag.mp.NFWTruncatedSph( centre=(0.0, 0.0), kappa_s=2.0, scale_radius=1.0, truncation_radius=2.0 ) @@ -44,6 +60,8 @@ def test__deflections_yx_2d_from(): assert deflections[0, 0] == pytest.approx(factor * 0.38209715, abs=1.0e-4) assert deflections[0, 1] == pytest.approx(0.0, abs=1.0e-4) + +def test__deflections_yx_2d_from__scale_radius_4(): mp = ag.mp.NFWTruncatedSph( centre=(0.0, 0.0), kappa_s=1.0, scale_radius=4.0, truncation_radius=2.0 ) @@ -54,7 +72,7 @@ def test__deflections_yx_2d_from(): assert deflections[0, 1] == pytest.approx(0.0, abs=1.0e-4) -def test__convergence_2d_from(): +def test__convergence_2d_from__grid_2(): mp = ag.mp.NFWTruncatedSph( centre=(0.0, 0.0), kappa_s=1.0, scale_radius=1.0, truncation_radius=2.0 ) @@ -63,10 +81,18 @@ def test__convergence_2d_from(): assert convergence == pytest.approx(2.0 * 0.046409642, abs=1.0e-4) + +def test__convergence_2d_from__grid_diagonal(): + mp = ag.mp.NFWTruncatedSph( + centre=(0.0, 0.0), kappa_s=1.0, scale_radius=1.0, truncation_radius=2.0 + ) + convergence = mp.convergence_2d_from(grid=ag.Grid2DIrregular([[1.0, 1.0]])) assert convergence == pytest.approx(2.0 * 0.10549515, abs=1.0e-4) + +def test__convergence_2d_from__kappa_s_3(): mp = ag.mp.NFWTruncatedSph( centre=(0.0, 0.0), kappa_s=3.0, scale_radius=1.0, truncation_radius=2.0 ) @@ -75,6 +101,8 @@ def test__convergence_2d_from(): assert convergence == pytest.approx(6.0 * 0.046409642, abs=1.0e-4) + +def test__convergence_2d_from__scale_radius_5(): mp = ag.mp.NFWTruncatedSph( centre=(0.0, 0.0), kappa_s=3.0, scale_radius=5.0, truncation_radius=2.0 ) @@ -102,41 +130,6 @@ def test__mass_at_truncation_radius(): assert mass_at_truncation_radius == pytest.approx(0.00009792581, 1.0e-5) - # mp = ag.mp.NFWTruncatedSph(centre=(0.0, 0.0), kappa_s=1.0, scale_radius=1.0, - # truncation_radius=1.0) - # - # cosmology = ag.m.MockCosmology(arcsec_per_kpc=1.0, kpc_per_arcsec=1.0, critical_surface_density=2.0, - # cosmic_average_density=3.0) - # - # mass_at_truncation_radius = mp.mass_at_truncation_radius(redshift_galaxy=0.5, redshift_source=1.0, - # unit_length='arcsec', unit_mass='solMass', cosmology=cosmology) - # - # assert mass_at_truncation_radius == pytest.approx(0.00008789978, 1.0e-5) - # - # mp = ag.mp.NFWTruncatedSph(centre=(0.0, 0.0), kappa_s=1.0, scale_radius=2.0, - # truncation_radius=1.0) - # - # mass_at_truncation_radius = mp.mass_at_truncation_radius(redshift_galaxy=0.5, redshift_source=1.0, - # unit_length='arcsec', unit_mass='solMass', cosmology=cosmology) - # - # assert mass_at_truncation_radius == pytest.approx(0.0000418378, 1.0e-5) - # - # mp = ag.mp.NFWTruncatedSph(centre=(0.0, 0.0), kappa_s=1.0, scale_radius=8.0, - # truncation_radius=4.0) - # - # mass_at_truncation_radius = mp.mass_at_truncation_radius(redshift_galaxy=0.5, redshift_source=1.0, - # unit_length='arcsec', unit_mass='solMass', cosmology=cosmology) - # - # assert mass_at_truncation_radius == pytest.approx(0.0000421512, abs=1.0e-4) - # - # mp = ag.mp.NFWTruncatedSph(centre=(0.0, 0.0), kappa_s=2.0, scale_radius=8.0, - # truncation_radius=4.0) - # - # mass_at_truncation_radius = mp.mass_at_truncation_radius(redshift_galaxy=0.5, redshift_source=1.0, - # unit_length='arcsec', unit_mass='solMass', cosmology=cosmology) - # - # assert mass_at_truncation_radius == pytest.approx(0.00033636625, abs=1.0e-4) - def test__compare_nfw_and_truncated_nfw_with_large_truncation_radius(): truncated_nfw = ag.mp.NFWTruncatedSph( diff --git a/test_autogalaxy/profiles/mass/dark/test_nfw_truncated_mcr_scatter.py b/test_autogalaxy/profiles/mass/dark/test_nfw_truncated_mcr_scatter.py index bce1951b3..20c3c31f7 100644 --- a/test_autogalaxy/profiles/mass/dark/test_nfw_truncated_mcr_scatter.py +++ b/test_autogalaxy/profiles/mass/dark/test_nfw_truncated_mcr_scatter.py @@ -6,7 +6,7 @@ grid = ag.Grid2DIrregular([[1.0, 1.0], [2.0, 2.0], [3.0, 3.0], [2.0, 4.0]]) -def test__scatter_is_nonzero(): +def test__scatter_is_nonzero__scatter_positive(): mp = ag.mp.NFWTruncatedMCRScatterLudlowSph( centre=(1.0, 2.0), mass_at_200=1.0e9, @@ -15,11 +15,11 @@ def test__scatter_is_nonzero(): redshift_source=2.5, ) - # We uare using the NFWTruncatedSph to check the mass gives a conosistnt kappa_s, given certain radii. - assert mp.scale_radius == pytest.approx(0.14978, 1.0e-4) assert mp.truncation_radius == pytest.approx(33.7134116, 1.0e-4) + +def test__scatter_is_nonzero__scatter_negative(): mp = ag.mp.NFWTruncatedMCRScatterLudlowSph( centre=(1.0, 2.0), mass_at_200=1.0e9, @@ -28,7 +28,5 @@ def test__scatter_is_nonzero(): redshift_source=2.5, ) - # We uare using the NFWTruncatedSph to check the mass gives a conosistnt kappa_s, given certain radii. - assert mp.scale_radius == pytest.approx(0.29886, 1.0e-4) assert mp.truncation_radius == pytest.approx(33.7134116, 1.0e-4) diff --git a/test_autogalaxy/profiles/mass/point/test_point.py b/test_autogalaxy/profiles/mass/point/test_point.py index 22b30b448..ab407fb80 100644 --- a/test_autogalaxy/profiles/mass/point/test_point.py +++ b/test_autogalaxy/profiles/mass/point/test_point.py @@ -6,7 +6,7 @@ grid = ag.Grid2DIrregular([[1.0, 1.0], [2.0, 2.0], [3.0, 3.0], [2.0, 4.0]]) -def test__deflections_yx_2d_from(): +def test__deflections_yx_2d_from__einstein_radius_1_grid_11(): # The radial coordinate at (1.0, 1.0) is sqrt(2) # This is decomposed into (y,x) angles of sin(45) = cos(45) = sqrt(2) / 2.0 # Thus, for an EinR of 1.0, the deflection angle is (1.0 / sqrt(2)) * (sqrt(2) / 2.0) @@ -18,30 +18,40 @@ def test__deflections_yx_2d_from(): assert deflections[0, 0] == pytest.approx(0.5, 1e-3) assert deflections[0, 1] == pytest.approx(0.5, 1e-3) + +def test__deflections_yx_2d_from__einstein_radius_2_grid_11(): mp = ag.mp.PointMass(centre=(0.0, 0.0), einstein_radius=2.0) deflections = mp.deflections_yx_2d_from(grid=ag.Grid2DIrregular([[1.0, 1.0]])) assert deflections[0, 0] == pytest.approx(2.0, 1e-3) assert deflections[0, 1] == pytest.approx(2.0, 1e-3) + +def test__deflections_yx_2d_from__einstein_radius_1_grid_22(): mp = ag.mp.PointMass(centre=(0.0, 0.0), einstein_radius=1.0) deflections = mp.deflections_yx_2d_from(grid=ag.Grid2DIrregular([[2.0, 2.0]])) assert deflections[0, 0] == pytest.approx(0.25, 1e-3) assert deflections[0, 1] == pytest.approx(0.25, 1e-3) + +def test__deflections_yx_2d_from__einstein_radius_1_grid_21(): mp = ag.mp.PointMass(centre=(0.0, 0.0), einstein_radius=1.0) deflections = mp.deflections_yx_2d_from(grid=ag.Grid2DIrregular([[2.0, 1.0]])) assert deflections[0, 0] == pytest.approx(0.4, 1e-3) assert deflections[0, 1] == pytest.approx(0.2, 1e-3) + +def test__deflections_yx_2d_from__einstein_radius_2_grid_49(): mp = ag.mp.PointMass(centre=(0.0, 0.0), einstein_radius=2.0) deflections = mp.deflections_yx_2d_from(grid=ag.Grid2DIrregular([[4.0, 9.0]])) assert deflections[0, 0] == pytest.approx(16.0 / 97.0, 1e-3) assert deflections[0, 1] == pytest.approx(36.0 / 97.0, 1e-3) + +def test__deflections_yx_2d_from__offset_centre(): mp = ag.mp.PointMass(centre=(1.0, 2.0), einstein_radius=1.0) deflections = mp.deflections_yx_2d_from(grid=ag.Grid2DIrregular([[2.0, 3.0]])) diff --git a/test_autogalaxy/profiles/mass/point/test_smbh_binary.py b/test_autogalaxy/profiles/mass/point/test_smbh_binary.py index fcca199a0..4bcc31fc0 100644 --- a/test_autogalaxy/profiles/mass/point/test_smbh_binary.py +++ b/test_autogalaxy/profiles/mass/point/test_smbh_binary.py @@ -4,7 +4,7 @@ import autogalaxy as ag -def test__x2_smbhs__centres_correct_based_on_angle__init(): +def test__x2_smbhs__centres_correct_based_on_angle__angle_0001(): mp = ag.mp.SMBHBinary( centre=(0.0, 0.0), separation=1.0, @@ -14,6 +14,8 @@ def test__x2_smbhs__centres_correct_based_on_angle__init(): assert mp.smbh_0.centre == pytest.approx((8.726646259967217e-07, 0.5), 1e-2) assert mp.smbh_1.centre == pytest.approx((-8.726646259967217e-07, -0.5), 1e-2) + +def test__x2_smbhs__centres_correct_based_on_angle__angle_90(): mp = ag.mp.SMBHBinary( centre=(0.0, 0.0), separation=1.0, @@ -27,6 +29,8 @@ def test__x2_smbhs__centres_correct_based_on_angle__init(): assert mp.smbh_0.centre == pytest.approx((0.5, 0.0), 1e-2) assert mp.smbh_1.centre == pytest.approx((-0.5, 0.0), 1e-2) + +def test__x2_smbhs__centres_correct_based_on_angle__angle_180(): mp = ag.mp.SMBHBinary( centre=(0.0, 0.0), separation=1.0, @@ -36,6 +40,8 @@ def test__x2_smbhs__centres_correct_based_on_angle__init(): assert mp.smbh_0.centre == pytest.approx((0.0, -0.5), 1e-2) assert mp.smbh_1.centre == pytest.approx((0.0, 0.5), 1e-2) + +def test__x2_smbhs__centres_correct_based_on_angle__angle_270(): mp = ag.mp.SMBHBinary( centre=(0.0, 0.0), separation=1.0, @@ -45,6 +51,8 @@ def test__x2_smbhs__centres_correct_based_on_angle__init(): assert mp.smbh_0.centre == pytest.approx((-0.5, 0.0), 1e-2) assert mp.smbh_1.centre == pytest.approx((0.5, 0.0), 1e-2) + +def test__x2_smbhs__centres_correct_based_on_angle__angle_360(): mp = ag.mp.SMBHBinary( centre=(0.0, 0.0), separation=1.0, @@ -55,7 +63,7 @@ def test__x2_smbhs__centres_correct_based_on_angle__init(): assert mp.smbh_1.centre == pytest.approx((8.726646259456063e-06, -0.5), 1e-2) -def test__x2_smbhs__separation__init(): +def test__x2_smbhs__separation__separation_2(): mp = ag.mp.SMBHBinary( centre=(0.0, 0.0), separation=2.0, @@ -66,7 +74,7 @@ def test__x2_smbhs__separation__init(): assert mp.smbh_1.centre == pytest.approx((0.0, -1.0), 1e-2) -def test__x2_smbhs__centres_shifted_based_on_centre__init(): +def test__x2_smbhs__centres_shifted_based_on_centre__positive_centre(): mp = ag.mp.SMBHBinary( centre=(3.0, 1.0), separation=1.0, @@ -76,6 +84,8 @@ def test__x2_smbhs__centres_shifted_based_on_centre__init(): assert mp.smbh_0.centre == pytest.approx((3.0, 1.5), 1e-2) assert mp.smbh_1.centre == pytest.approx((3.0, 0.5), 1e-2) + +def test__x2_smbhs__centres_shifted_based_on_centre__negative_centre(): mp = ag.mp.SMBHBinary( centre=(-3.0, -1.0), separation=1.0, @@ -86,7 +96,7 @@ def test__x2_smbhs__centres_shifted_based_on_centre__init(): assert mp.smbh_1.centre == pytest.approx((-3.0, -1.5), 1e-2) -def test__x2_smbhs__masses_corrected_based_on_mass_and_ratio__init(): +def test__x2_smbhs__masses_corrected_based_on_mass_and_ratio__ratio_2(): mp = ag.mp.SMBHBinary( mass=3.0, mass_ratio=2.0, @@ -95,6 +105,8 @@ def test__x2_smbhs__masses_corrected_based_on_mass_and_ratio__init(): assert mp.smbh_0.mass == pytest.approx(2.0, 1e-2) assert mp.smbh_1.mass == pytest.approx(1.0, 1e-2) + +def test__x2_smbhs__masses_corrected_based_on_mass_and_ratio__ratio_05(): mp = ag.mp.SMBHBinary( mass=3.0, mass_ratio=0.5, diff --git a/test_autogalaxy/profiles/mass/sheets/test_external_shear.py b/test_autogalaxy/profiles/mass/sheets/test_external_shear.py index b24f88973..89125cd4a 100644 --- a/test_autogalaxy/profiles/mass/sheets/test_external_shear.py +++ b/test_autogalaxy/profiles/mass/sheets/test_external_shear.py @@ -5,52 +5,58 @@ grid = ag.Grid2DIrregular([[1.0, 1.0], [2.0, 2.0], [3.0, 3.0], [2.0, 4.0]]) -def test__potential_2d_from(): +def test__potential_2d_from__gamma_2_only(): mp = ag.mp.ExternalShear(gamma_1=0.0, gamma_2=0.1) potential = mp.potential_2d_from(grid=ag.Grid2DIrregular([[0.1, 0.1]])) assert potential == pytest.approx(np.array([0.001]), 1.0e-4) + +def test__potential_2d_from__multiple_grid_points(): mp = ag.mp.ExternalShear(gamma_1=0.0, gamma_2=0.1) potential = mp.potential_2d_from( grid=ag.Grid2DIrregular([[0.1, 0.1], [0.2, 0.2], [0.3, 0.3]]) ) assert potential == pytest.approx(np.array([0.001, 0.004, 0.009]), 1.0e-4) + +def test__potential_2d_from__gamma_1_and_gamma_2(): mp = ag.mp.ExternalShear(gamma_1=0.1, gamma_2=-0.05) potential = mp.potential_2d_from(grid=ag.Grid2DIrregular([[0.1, 0.1]])) assert potential == pytest.approx(np.array([-0.0005]), 1.0e-4) -def test__deflections_yx_2d_from(): +def test__deflections_yx_2d_from__gamma_2_only(): mp = ag.mp.ExternalShear(gamma_1=0.0, gamma_2=0.1) deflections = mp.deflections_yx_2d_from(grid=ag.Grid2DIrregular([[0.1625, 0.1625]])) assert deflections[0, 0] == pytest.approx(0.01625, 1e-3) assert deflections[0, 1] == pytest.approx(0.01625, 1e-3) - mp = ag.mp.ExternalShear(gamma_1=-0.17320, gamma_2=0.1) - deflections = mp.deflections_yx_2d_from(grid=ag.Grid2DIrregular([[0.1625, 0.1625]])) - assert deflections[0, 0] == pytest.approx(0.04439, 1e-3) - assert deflections[0, 1] == pytest.approx(-0.011895, 1e-3) +def test__deflections_yx_2d_from__gamma_1_and_gamma_2(): + mp = ag.mp.ExternalShear(gamma_1=-0.17320, gamma_2=0.1) deflections = mp.deflections_yx_2d_from(grid=ag.Grid2DIrregular([[0.1625, 0.1625]])) - assert deflections[0, 0] == pytest.approx(0.04439, 1e-3) assert deflections[0, 1] == pytest.approx(-0.011895, 1e-3) -def test__convergence_returns_zeros(): +def test__convergence_returns_zeros__single_point(): mp = ag.mp.ExternalShear(gamma_1=0.0, gamma_2=0.1) convergence = mp.convergence_2d_from(grid=ag.Grid2DIrregular([[0.1, 0.1]])) assert (convergence == np.array([0.0])).all() + +def test__convergence_returns_zeros__multiple_grid_points(): mp = ag.mp.ExternalShear(gamma_1=0.0, gamma_2=0.1) convergence = mp.convergence_2d_from( grid=ag.Grid2DIrregular([[0.1, 0.1], [0.2, 0.2], [0.3, 0.3]]) ) assert (convergence == np.array([0.0, 0.0, 0.0])).all() + +def test__convergence_returns_zeros__y_axis(): + mp = ag.mp.ExternalShear(gamma_1=0.0, gamma_2=0.1) convergence = mp.convergence_2d_from(grid=ag.Grid2DIrregular([[1.0, 0.0]])) assert convergence[0] == pytest.approx(0.0, 1e-3) diff --git a/test_autogalaxy/profiles/mass/sheets/test_mass_sheet.py b/test_autogalaxy/profiles/mass/sheets/test_mass_sheet.py index 2d0b1b9f0..f66c02ce8 100644 --- a/test_autogalaxy/profiles/mass/sheets/test_mass_sheet.py +++ b/test_autogalaxy/profiles/mass/sheets/test_mass_sheet.py @@ -7,7 +7,7 @@ grid = ag.Grid2DIrregular([[1.0, 1.0], [2.0, 2.0], [3.0, 3.0], [2.0, 4.0]]) -def test__deflections_yx_2d_from(): +def test__deflections_yx_2d_from__kappa_1_y_axis(): mp = ag.mp.MassSheet(centre=(0.0, 0.0), kappa=1.0) deflections = mp.deflections_yx_2d_from(grid=ag.Grid2DIrregular([[2.0, 0.0]])) @@ -15,6 +15,8 @@ def test__deflections_yx_2d_from(): assert deflections[0, 0] == pytest.approx(2.0, 1e-3) assert deflections[0, 1] == pytest.approx(0.0, abs=1e-3) + +def test__deflections_yx_2d_from__kappa_neg1_y_axis(): mp = ag.mp.MassSheet(centre=(0.0, 0.0), kappa=-1.0) deflections = mp.deflections_yx_2d_from(grid=ag.Grid2DIrregular([[2.0, 0.0]])) @@ -22,6 +24,8 @@ def test__deflections_yx_2d_from(): assert deflections[0, 0] == pytest.approx(-2.0, 1e-3) assert deflections[0, 1] == pytest.approx(0.0, abs=1e-3) + +def test__deflections_yx_2d_from__kappa_2_diagonal(): # The radial coordinate at (1.0, 1.0) is sqrt(2) # This is decomposed into (y,x) angles of sin(45) = cos(45) = sqrt(2) / 2.0 # Thus, for a mass sheet, the deflection angle is (sqrt(2) * sqrt(2) / 2.0) = 1.0 @@ -32,6 +36,8 @@ def test__deflections_yx_2d_from(): assert deflections[0, 0] == pytest.approx(4.0, 1e-3) assert deflections[0, 1] == pytest.approx(4.0, 1e-3) + +def test__deflections_yx_2d_from__kappa_1_off_axis(): mp = ag.mp.MassSheet(centre=(0.0, 0.0), kappa=1.0) # The radial coordinate at (2.0, 1.0) is sqrt(5) @@ -43,6 +49,8 @@ def test__deflections_yx_2d_from(): assert deflections[0, 0] == pytest.approx(0.8944271 * np.sqrt(5), 1e-3) assert deflections[0, 1] == pytest.approx(0.4472135 * np.sqrt(5), 1e-3) + +def test__deflections_yx_2d_from__offset_centre(): mp = ag.mp.MassSheet(centre=(1.0, 2.0), kappa=-1.0) deflections = mp.deflections_yx_2d_from(grid=ag.Grid2DIrregular([[2.0, 3.0]])) @@ -50,13 +58,17 @@ def test__deflections_yx_2d_from(): assert deflections[0, 1] == pytest.approx(-1.0, 1e-3) -def test__convergence_2d_from(): +def test__convergence_2d_from__kappa_1(): mp = ag.mp.MassSheet(centre=(0.0, 0.0), kappa=1.0) convergence = mp.convergence_2d_from(grid=ag.Grid2DIrregular([[1.0, 0.0]])) assert convergence[0] == pytest.approx(1.0, 1e-3) + +def test__convergence_2d_from__kappa_1_multiple_grid_points(): + mp = ag.mp.MassSheet(centre=(0.0, 0.0), kappa=1.0) + convergence = mp.convergence_2d_from( grid=ag.Grid2DIrregular([[1.0, 0.0], [3.0, 3.0], [5.0, -9.0]]) ) @@ -65,6 +77,8 @@ def test__convergence_2d_from(): assert convergence[1] == pytest.approx(1.0, 1e-3) assert convergence[2] == pytest.approx(1.0, 1e-3) + +def test__convergence_2d_from__kappa_neg3(): mp = ag.mp.MassSheet(centre=(0.0, 0.0), kappa=-3.0) convergence = mp.convergence_2d_from( diff --git a/test_autogalaxy/profiles/mass/stellar/test_chameleon.py b/test_autogalaxy/profiles/mass/stellar/test_chameleon.py index 2312839d1..a3fe3b13f 100644 --- a/test_autogalaxy/profiles/mass/stellar/test_chameleon.py +++ b/test_autogalaxy/profiles/mass/stellar/test_chameleon.py @@ -24,7 +24,7 @@ def test__deflections_2d_via_analytic_from(): assert deflections[0, 1] == pytest.approx(1.55252, 1e-3) -def test__deflections_yx_2d_from(): +def test__deflections_yx_2d_from__chameleon(): mp = ag.mp.Chameleon() deflections = mp.deflections_yx_2d_from(grid=ag.Grid2DIrregular([[1.0, 0.0]])) @@ -34,6 +34,8 @@ def test__deflections_yx_2d_from(): assert deflections == pytest.approx(deflections_via_integral.array, 1.0e-4) + +def test__deflections_yx_2d_from__chameleon_sph(): mp = ag.mp.ChameleonSph() deflections = mp.deflections_yx_2d_from(grid=ag.Grid2DIrregular([[1.0, 0.0]])) @@ -62,7 +64,7 @@ def test__spherical_and_elliptical_identical(): assert elliptical_deflections == pytest.approx(spherical_deflections.array, 1.0e-4) -def test__convergence_2d_from(): +def test__convergence_2d_from__chameleon_config_1(): mp = ag.mp.Chameleon( ell_comps=(0.0, 0.0), intensity=1.0, @@ -75,6 +77,8 @@ def test__convergence_2d_from(): assert convergence == pytest.approx(2.0 * 0.018605, 1e-3) + +def test__convergence_2d_from__chameleon_config_2(): mp = ag.mp.Chameleon( ell_comps=(0.5, 0.0), intensity=3.0, @@ -87,6 +91,8 @@ def test__convergence_2d_from(): assert convergence == pytest.approx(0.007814, 1e-3) + +def test__convergence_2d_from__elliptical_vs_spherical(): elliptical = ag.mp.Chameleon( centre=(0.0, 0.0), ell_comps=(0.0, 0.0), diff --git a/test_autogalaxy/profiles/mass/stellar/test_dev_vaucouleurs.py b/test_autogalaxy/profiles/mass/stellar/test_dev_vaucouleurs.py index 55d84ae8d..d49ee19ac 100644 --- a/test_autogalaxy/profiles/mass/stellar/test_dev_vaucouleurs.py +++ b/test_autogalaxy/profiles/mass/stellar/test_dev_vaucouleurs.py @@ -6,7 +6,7 @@ grid = ag.Grid2DIrregular([[1.0, 1.0], [2.0, 2.0], [3.0, 3.0], [2.0, 4.0]]) -def test__deflections_yx_2d_from(): +def test__deflections_yx_2d_from__dev_vaucouleurs(): mp = ag.mp.DevVaucouleurs() deflections = mp.deflections_yx_2d_from(grid=ag.Grid2DIrregular([[1.0, 0.0]])) @@ -16,6 +16,8 @@ def test__deflections_yx_2d_from(): assert deflections == pytest.approx(deflections_via_cse.array, 1.0e-4) + +def test__deflections_yx_2d_from__dev_vaucouleurs_sph(): mp = ag.mp.DevVaucouleursSph() deflections = mp.deflections_yx_2d_from(grid=ag.Grid2DIrregular([[1.0, 0.0]])) @@ -43,7 +45,7 @@ def test__deflections_via_integral_from(): assert deflections[0, 1] == pytest.approx(-3.37605, 1e-3) -def test__deflections_2d_via_cse_from(): +def test__deflections_2d_via_cse_from__config_1(): mp = ag.mp.DevVaucouleurs( centre=(0.4, 0.2), ell_comps=(0.0180010, 0.0494575), @@ -61,6 +63,8 @@ def test__deflections_2d_via_cse_from(): assert deflections_via_integral == pytest.approx(deflections_via_cse.array, 1.0e-4) + +def test__deflections_2d_via_cse_from__config_2(): mp = ag.mp.DevVaucouleurs( centre=(0.4, 0.2), ell_comps=(0.4180010, 0.694575), @@ -79,7 +83,7 @@ def test__deflections_2d_via_cse_from(): assert deflections_via_integral == pytest.approx(deflections_via_cse.array, 1.0e-4) -def test__convergence_2d_from(): +def test__convergence_2d_from__dev_vaucouleurs_config_1(): mp = ag.mp.DevVaucouleurs( ell_comps=(0.0, 0.333333), intensity=3.0, @@ -91,6 +95,8 @@ def test__convergence_2d_from(): assert convergence == pytest.approx(5.6697, 1e-3) + +def test__convergence_2d_from__dev_vaucouleurs_config_2(): mp = ag.mp.DevVaucouleurs( ell_comps=(0.0, -0.333333), intensity=2.0, @@ -102,6 +108,8 @@ def test__convergence_2d_from(): assert convergence == pytest.approx(7.4455, 1e-3) + +def test__convergence_2d_from__dev_vaucouleurs_intensity_4(): mp = ag.mp.DevVaucouleurs( ell_comps=(0.0, -0.333333), intensity=4.0, @@ -113,6 +121,8 @@ def test__convergence_2d_from(): assert convergence == pytest.approx(2.0 * 7.4455, 1e-3) + +def test__convergence_2d_from__dev_vaucouleurs_mass_to_light_2(): mp = ag.mp.DevVaucouleurs( ell_comps=(0.0, -0.333333), intensity=2.0, @@ -124,6 +134,8 @@ def test__convergence_2d_from(): assert convergence == pytest.approx(2.0 * 7.4455, 1e-3) + +def test__convergence_2d_from__dev_vaucouleurs_small_effective_radius(): mp = ag.mp.DevVaucouleurs( centre=(0.0, 0.0), intensity=1.0, @@ -135,6 +147,8 @@ def test__convergence_2d_from(): assert convergence == pytest.approx(0.351797, 1e-3) + +def test__convergence_2d_from__elliptical_vs_spherical(): elliptical = ag.mp.DevVaucouleurs( centre=(0.0, 0.0), ell_comps=(0.0, 0.0), diff --git a/test_autogalaxy/profiles/mass/stellar/test_exponential.py b/test_autogalaxy/profiles/mass/stellar/test_exponential.py index 45349bf5f..e1b9f4dc3 100644 --- a/test_autogalaxy/profiles/mass/stellar/test_exponential.py +++ b/test_autogalaxy/profiles/mass/stellar/test_exponential.py @@ -6,7 +6,7 @@ grid = ag.Grid2DIrregular([[1.0, 1.0], [2.0, 2.0], [3.0, 3.0], [2.0, 4.0]]) -def test__deflections_yx_2d_from(): +def test__deflections_yx_2d_from__exponential(): mp = ag.mp.Exponential() deflections = mp.deflections_yx_2d_from(grid=ag.Grid2DIrregular([[1.0, 0.0]])) @@ -16,6 +16,8 @@ def test__deflections_yx_2d_from(): assert deflections == pytest.approx(deflections_via_cse.array, 1.0e-4) + +def test__deflections_yx_2d_from__exponential_sph(): mp = ag.mp.ExponentialSph() deflections = mp.deflections_yx_2d_from(grid=ag.Grid2DIrregular([[1.0, 0.0]])) @@ -26,7 +28,7 @@ def test__deflections_yx_2d_from(): assert deflections == pytest.approx(deflections_via_cse.array, 1.0e-4) -def test__deflections_2d_via_integral_from(): +def test__deflections_2d_via_integral_from__config_1(): mp = ag.mp.Exponential( centre=(-0.4, -0.2), ell_comps=(-0.07142, -0.085116), @@ -42,6 +44,8 @@ def test__deflections_2d_via_integral_from(): assert deflections[0, 0] == pytest.approx(0.90493, 1e-3) assert deflections[0, 1] == pytest.approx(0.62569, 1e-3) + +def test__deflections_2d_via_integral_from__config_2(): mp = ag.mp.Exponential( centre=(-0.4, -0.2), ell_comps=(-0.07142, -0.085116), @@ -58,7 +62,7 @@ def test__deflections_2d_via_integral_from(): assert deflections[0, 1] == pytest.approx(0.62569, 1e-3) -def test__deflections_2d_via_cse_from(): +def test__deflections_2d_via_cse_from__config_1(): mp = ag.mp.Exponential( centre=(-0.4, -0.2), ell_comps=(-0.07142, -0.085116), @@ -76,6 +80,8 @@ def test__deflections_2d_via_cse_from(): assert deflections_via_integral == pytest.approx(deflections_via_cse.array, 1.0e-4) + +def test__deflections_2d_via_cse_from__config_2(): mp = ag.mp.Exponential( centre=(-0.4, -0.2), ell_comps=(-0.07142, -0.085116), @@ -94,7 +100,7 @@ def test__deflections_2d_via_cse_from(): assert deflections_via_integral == pytest.approx(deflections_via_cse.array, 1.0e-4) -def test__convergence_2d_from(): +def test__convergence_2d_from__exponential_config_1(): mp = ag.mp.Exponential( ell_comps=(0.0, 0.333333), intensity=3.0, @@ -106,6 +112,8 @@ def test__convergence_2d_from(): assert convergence == pytest.approx(4.9047, 1e-3) + +def test__convergence_2d_from__exponential_config_2(): mp = ag.mp.Exponential( ell_comps=(0.0, -0.333333), intensity=2.0, @@ -117,6 +125,8 @@ def test__convergence_2d_from(): assert convergence == pytest.approx(4.8566, 1e-3) + +def test__convergence_2d_from__exponential_intensity_4(): mp = ag.mp.Exponential( ell_comps=(0.0, -0.333333), intensity=4.0, @@ -127,6 +137,8 @@ def test__convergence_2d_from(): assert convergence == pytest.approx(2.0 * 4.8566, 1e-3) + +def test__convergence_2d_from__exponential_mass_to_light_2(): mp = ag.mp.Exponential( ell_comps=(0.0, -0.333333), intensity=2.0, @@ -138,6 +150,8 @@ def test__convergence_2d_from(): assert convergence == pytest.approx(2.0 * 4.8566, 1e-3) + +def test__convergence_2d_from__exponential_config_5(): mp = ag.mp.Exponential( ell_comps=(0.0, -0.333333), intensity=2.0, @@ -149,6 +163,8 @@ def test__convergence_2d_from(): assert convergence == pytest.approx(4.8566, 1e-3) + +def test__convergence_2d_from__elliptical_vs_spherical(): elliptical = ag.mp.Exponential( centre=(0.0, 0.0), ell_comps=(0.0, 0.0), diff --git a/test_autogalaxy/profiles/mass/stellar/test_gaussian.py b/test_autogalaxy/profiles/mass/stellar/test_gaussian.py index d706a663b..e820ffee4 100644 --- a/test_autogalaxy/profiles/mass/stellar/test_gaussian.py +++ b/test_autogalaxy/profiles/mass/stellar/test_gaussian.py @@ -6,7 +6,7 @@ grid = ag.Grid2DIrregular([[1.0, 1.0], [2.0, 2.0], [3.0, 3.0], [2.0, 4.0]]) -def test__deflections_2d_via_analytic_from(): +def test__deflections_2d_via_analytic_from__config_1_positive_y(): mp = ag.mp.Gaussian( centre=(0.0, 0.0), ell_comps=(0.0, 0.05263), @@ -22,6 +22,16 @@ def test__deflections_2d_via_analytic_from(): assert deflections[0, 0] == pytest.approx(1.024423, 1.0e-4) assert deflections[0, 1] == pytest.approx(0.0, abs=1.0e-4) + +def test__deflections_2d_via_analytic_from__config_1_negative_y(): + mp = ag.mp.Gaussian( + centre=(0.0, 0.0), + ell_comps=(0.0, 0.05263), + intensity=1.0, + sigma=3.0, + mass_to_light_ratio=1.0, + ) + deflections = mp.deflections_2d_via_analytic_from( grid=ag.Grid2DIrregular([[-1.0, 0.0]]) ) @@ -29,6 +39,8 @@ def test__deflections_2d_via_analytic_from(): assert deflections[0, 0] == pytest.approx(-1.024423, 1.0e-4) assert deflections[0, 1] == pytest.approx(0.0, abs=1.0e-4) + +def test__deflections_2d_via_analytic_from__config_2_positive(): mp = ag.mp.Gaussian( centre=(0.0, 0.0), ell_comps=(0.0, 0.111111), @@ -44,6 +56,16 @@ def test__deflections_2d_via_analytic_from(): assert deflections[0, 0] == pytest.approx(0.554062, 1.0e-4) assert deflections[0, 1] == pytest.approx(0.177336, 1.0e-4) + +def test__deflections_2d_via_analytic_from__config_2_negative(): + mp = ag.mp.Gaussian( + centre=(0.0, 0.0), + ell_comps=(0.0, 0.111111), + intensity=1.0, + sigma=5.0, + mass_to_light_ratio=1.0, + ) + deflections = mp.deflections_2d_via_analytic_from( grid=ag.Grid2DIrregular([[-0.5, -0.2]]) ) @@ -51,6 +73,8 @@ def test__deflections_2d_via_analytic_from(): assert deflections[0, 0] == pytest.approx(-0.554062, 1.0e-4) assert deflections[0, 1] == pytest.approx(-0.177336, 1.0e-4) + +def test__deflections_2d_via_analytic_from__mass_to_light_2(): mp = ag.mp.Gaussian( centre=(0.0, 0.0), ell_comps=(0.0, 0.111111), @@ -66,6 +90,8 @@ def test__deflections_2d_via_analytic_from(): assert deflections[0, 0] == pytest.approx(1.108125, 1.0e-4) assert deflections[0, 1] == pytest.approx(0.35467, 1.0e-4) + +def test__deflections_2d_via_analytic_from__intensity_2(): mp = ag.mp.Gaussian( centre=(0.0, 0.0), ell_comps=(0.0, 0.111111), @@ -82,7 +108,7 @@ def test__deflections_2d_via_analytic_from(): assert deflections[0, 1] == pytest.approx(0.35467, 1.0e-4) -def test__deflections_2d_via_integral_from(): +def test__deflections_2d_via_integral_from__config_1(): mp = ag.mp.Gaussian( centre=(0.0, 0.0), ell_comps=(0.0, 0.05263), @@ -100,6 +126,8 @@ def test__deflections_2d_via_integral_from(): assert deflections == pytest.approx(deflections_via_analytic.array, 1.0e-3) + +def test__deflections_2d_via_integral_from__config_2(): mp = ag.mp.Gaussian( centre=(0.0, 0.0), ell_comps=(0.0, 0.111111), @@ -117,6 +145,8 @@ def test__deflections_2d_via_integral_from(): assert deflections == pytest.approx(deflections_via_analytic.array, 1.0e-3) + +def test__deflections_2d_via_integral_from__mass_to_light_2(): mp = ag.mp.Gaussian( centre=(0.0, 0.0), ell_comps=(0.0, 0.111111), @@ -134,6 +164,8 @@ def test__deflections_2d_via_integral_from(): assert deflections == pytest.approx(deflections_via_analytic.array, 1.0e-3) + +def test__deflections_2d_via_integral_from__intensity_2(): mp = ag.mp.Gaussian( centre=(0.0, 0.0), ell_comps=(0.0, 0.111111), @@ -163,7 +195,7 @@ def test__deflections_yx_2d_from(): assert deflections == pytest.approx(deflections_via_integral.array, 1.0e-4) -def test__convergence_2d_from(): +def test__convergence_2d_from__gaussian_config_1(): mp = ag.mp.Gaussian( centre=(0.0, 0.0), ell_comps=(0.0, 0.0), @@ -176,6 +208,8 @@ def test__convergence_2d_from(): assert convergence == pytest.approx(0.60653, 1e-2) + +def test__convergence_2d_from__gaussian_mass_to_light_2(): mp = ag.mp.Gaussian( centre=(0.0, 0.0), ell_comps=(0.0, 0.0), @@ -188,6 +222,8 @@ def test__convergence_2d_from(): assert convergence == pytest.approx(2.0 * 0.60653, 1e-2) + +def test__convergence_2d_from__gaussian_elliptical(): mp = ag.mp.Gaussian( centre=(0.0, 0.0), ell_comps=(0.0, 0.333333), @@ -223,7 +259,7 @@ def test__intensity_and_convergence_match_for_mass_light_ratio_1(): assert (intensity == convergence).all() -def test__image_2d_via_radii_from__correct_value(): +def test__image_2d_via_radii_from__config_1(): mp = ag.mp.Gaussian( centre=(0.0, 0.0), ell_comps=(0.0, 0.0), intensity=1.0, sigma=1.0 ) @@ -232,6 +268,8 @@ def test__image_2d_via_radii_from__correct_value(): assert intensity == pytest.approx(0.60653, 1e-2) + +def test__image_2d_via_radii_from__intensity_2(): mp = ag.mp.Gaussian( centre=(0.0, 0.0), ell_comps=(0.0, 0.0), intensity=2.0, sigma=1.0 ) @@ -240,6 +278,8 @@ def test__image_2d_via_radii_from__correct_value(): assert intensity == pytest.approx(2.0 * 0.60653, 1e-2) + +def test__image_2d_via_radii_from__sigma_2(): mp = ag.mp.Gaussian( centre=(0.0, 0.0), ell_comps=(0.0, 0.0), intensity=1.0, sigma=2.0 ) @@ -247,6 +287,8 @@ def test__image_2d_via_radii_from__correct_value(): assert intensity == pytest.approx(0.882496, 1e-2) + +def test__image_2d_via_radii_from__sigma_2_radii_3(): mp = ag.mp.Gaussian( centre=(0.0, 0.0), ell_comps=(0.0, 0.0), intensity=1.0, sigma=2.0 ) @@ -256,7 +298,7 @@ def test__image_2d_via_radii_from__correct_value(): assert intensity == pytest.approx(0.32465, 1e-2) -def test__wofz(): +def test__wofz__regions_1_2_3(): from scipy.special import wofz mp = ag.mp.Gaussian( @@ -271,6 +313,14 @@ def test__wofz(): assert wofz_approx_reg_2 == pytest.approx(wofz(2.0 + 1j * 0.001), 1e-4) assert wofz_approx_reg_3 == pytest.approx(wofz(1.0 + 1j * 0.001), 1e-4) + +def test__wofz__regions_4_5_6(): + from scipy.special import wofz + + mp = ag.mp.Gaussian( + centre=(0.0, 0.0), ell_comps=(0.0, 0.0), intensity=1.0, sigma=2.0 + ) + wofz_approx_reg_1 = mp.wofz(7.0 + 1j * 0.1) wofz_approx_reg_2 = mp.wofz(7.0 + 1j * 1e-11) wofz_approx_reg_3 = mp.wofz(2.0 + 1j * 1.0) diff --git a/test_autogalaxy/profiles/mass/stellar/test_gaussian_gradient.py b/test_autogalaxy/profiles/mass/stellar/test_gaussian_gradient.py index 53d07f2ba..954953628 100644 --- a/test_autogalaxy/profiles/mass/stellar/test_gaussian_gradient.py +++ b/test_autogalaxy/profiles/mass/stellar/test_gaussian_gradient.py @@ -6,7 +6,7 @@ grid = ag.Grid2DIrregular([[1.0, 1.0], [2.0, 2.0], [3.0, 3.0], [2.0, 4.0]]) -def test__init_constructor__scales_values_correct(): +def test__init_constructor__gradient_0_scales_values_correctly(): mp = ag.mp.GaussianGradient( centre=(0.0, 0.0), ell_comps=(0.0, 0.05), @@ -26,6 +26,8 @@ def test__init_constructor__scales_values_correct(): assert mp.mass_to_light_radius == 1.0 assert mp.mass_to_light_ratio == 1.0 + +def test__init_constructor__gradient_1_scales_values_correctly(): mp = ag.mp.GaussianGradient( centre=(0.0, 0.0), ell_comps=(0.0, 0.05), diff --git a/test_autogalaxy/profiles/mass/stellar/test_sersic.py b/test_autogalaxy/profiles/mass/stellar/test_sersic.py index b010aafbe..46f22bc35 100644 --- a/test_autogalaxy/profiles/mass/stellar/test_sersic.py +++ b/test_autogalaxy/profiles/mass/stellar/test_sersic.py @@ -6,7 +6,7 @@ grid = ag.Grid2DIrregular([[1.0, 1.0], [2.0, 2.0], [3.0, 3.0], [2.0, 4.0]]) -def test__deflections_via_integral_from(): +def test__deflections_via_integral_from__config_1(): mp = ag.mp.Sersic( centre=(-0.4, -0.2), ell_comps=(-0.07142, -0.085116), @@ -23,6 +23,8 @@ def test__deflections_via_integral_from(): assert deflections[0, 0] == pytest.approx(1.1446, 1e-3) assert deflections[0, 1] == pytest.approx(0.79374, 1e-3) + +def test__deflections_via_integral_from__config_2(): mp = ag.mp.Sersic( centre=(-0.4, -0.2), ell_comps=(-0.07142, -0.085116), @@ -40,7 +42,7 @@ def test__deflections_via_integral_from(): assert deflections[0, 1] == pytest.approx(1.80719, 1e-3) -def test__deflections_2d_via_cse_from(): +def test__deflections_2d_via_cse_from__config_1(): mp = ag.mp.Sersic( centre=(-0.4, -0.2), ell_comps=(-0.07142, -0.085116), @@ -59,6 +61,8 @@ def test__deflections_2d_via_cse_from(): assert deflections_via_integral == pytest.approx(deflections_via_cse.array, 1.0e-4) + +def test__deflections_2d_via_cse_from__config_2(): mp = ag.mp.Sersic( centre=(-0.4, -0.2), ell_comps=(-0.07142, -0.085116), @@ -77,6 +81,8 @@ def test__deflections_2d_via_cse_from(): assert deflections_via_integral == pytest.approx(deflections_via_cse.array, 1.0e-3) + +def test__deflections_2d_via_cse_from__config_3(): mp = ag.mp.Sersic( centre=(-0.4, -0.2), ell_comps=(-0.07142, -0.085116), @@ -96,7 +102,7 @@ def test__deflections_2d_via_cse_from(): assert deflections_via_integral == pytest.approx(deflections_via_cse.array, 1.0e-3) -def test__deflections_yx_2d_from(): +def test__deflections_yx_2d_from__sersic(): mp = ag.mp.Sersic() deflections = mp.deflections_yx_2d_from(grid=ag.Grid2DIrregular([[1.0, 0.0]])) @@ -106,6 +112,8 @@ def test__deflections_yx_2d_from(): assert deflections == pytest.approx(deflections_via_integral.array, 1.0e-4) + +def test__deflections_yx_2d_from__sersic_sph(): mp = ag.mp.SersicSph() deflections = mp.deflections_yx_2d_from(grid=ag.Grid2DIrregular([[1.0, 0.0]])) @@ -115,6 +123,8 @@ def test__deflections_yx_2d_from(): assert deflections == pytest.approx(deflections_via_integral.array, 1.0e-4) + +def test__deflections_yx_2d_from__elliptical_vs_spherical(): elliptical = ag.mp.Sersic( centre=(0.0, 0.0), ell_comps=(0.0, 0.0), @@ -138,7 +148,7 @@ def test__deflections_yx_2d_from(): assert elliptical_deflections == pytest.approx(spherical_deflections.array, 1.0e-4) -def test__convergence_2d_via_cse_from(): +def test__convergence_2d_via_cse_from__sersic_intensity_3(): mp = ag.mp.Sersic( centre=(0.0, 0.0), intensity=3.0, @@ -151,6 +161,8 @@ def test__convergence_2d_via_cse_from(): assert convergence == pytest.approx(4.90657319276, 1e-3) + +def test__convergence_2d_via_cse_from__sersic_intensity_6(): mp = ag.mp.Sersic( centre=(0.0, 0.0), intensity=6.0, @@ -163,6 +175,8 @@ def test__convergence_2d_via_cse_from(): assert convergence == pytest.approx(2.0 * 4.90657319276, 1e-3) + +def test__convergence_2d_via_cse_from__sersic_mass_to_light_2(): mp = ag.mp.Sersic( centre=(0.0, 0.0), intensity=3.0, @@ -175,6 +189,8 @@ def test__convergence_2d_via_cse_from(): assert convergence == pytest.approx(2.0 * 4.90657319276, 1e-3) + +def test__convergence_2d_via_cse_from__sersic_elliptical(): mp = ag.mp.Sersic( centre=(0.0, 0.0), ell_comps=(0.0, 0.333333), @@ -189,7 +205,7 @@ def test__convergence_2d_via_cse_from(): assert convergence == pytest.approx(5.38066670129, 1e-3) -def test__convergence_2d_from(): +def test__convergence_2d_from__sersic_intensity_3(): mp = ag.mp.Sersic( centre=(0.0, 0.0), intensity=3.0, @@ -202,6 +218,8 @@ def test__convergence_2d_from(): assert convergence == pytest.approx(4.90657319276, 1e-3) + +def test__convergence_2d_from__sersic_intensity_6(): mp = ag.mp.Sersic( centre=(0.0, 0.0), intensity=6.0, @@ -214,6 +232,8 @@ def test__convergence_2d_from(): assert convergence == pytest.approx(2.0 * 4.90657319276, 1e-3) + +def test__convergence_2d_from__sersic_mass_to_light_2(): mp = ag.mp.Sersic( centre=(0.0, 0.0), intensity=3.0, @@ -226,6 +246,8 @@ def test__convergence_2d_from(): assert convergence == pytest.approx(2.0 * 4.90657319276, 1e-3) + +def test__convergence_2d_from__sersic_elliptical(): mp = ag.mp.Sersic( centre=(0.0, 0.0), ell_comps=(0.0, 0.333333), @@ -239,6 +261,8 @@ def test__convergence_2d_from(): assert convergence == pytest.approx(5.38066670129, 1e-3) + +def test__convergence_2d_from__elliptical_vs_spherical(): elliptical = ag.mp.Sersic( centre=(0.0, 0.0), ell_comps=(0.0, 0.0), diff --git a/test_autogalaxy/profiles/mass/stellar/test_sersic_core.py b/test_autogalaxy/profiles/mass/stellar/test_sersic_core.py index 488c1e107..72c182561 100644 --- a/test_autogalaxy/profiles/mass/stellar/test_sersic_core.py +++ b/test_autogalaxy/profiles/mass/stellar/test_sersic_core.py @@ -98,7 +98,7 @@ # -def test__convergence_2d_from(): +def test__convergence_2d_from__sersic_core_mass_to_light_1(): mp = ag.mp.SersicCore( ell_comps=(0.0, 0.0), effective_radius=5.0, @@ -114,6 +114,8 @@ def test__convergence_2d_from(): assert convergence == pytest.approx(0.1, 1e-3) + +def test__convergence_2d_from__sersic_core_mass_to_light_2(): mp = ag.mp.SersicCore( ell_comps=(0.0, 0.0), effective_radius=5.0, @@ -129,6 +131,8 @@ def test__convergence_2d_from(): assert convergence == pytest.approx(0.2, 1e-3) + +def test__convergence_2d_from__elliptical_vs_spherical(): elliptical = ag.mp.SersicCore( centre=(0.0, 0.0), ell_comps=(0.0, 0.0), diff --git a/test_autogalaxy/profiles/mass/stellar/test_sersic_gradient.py b/test_autogalaxy/profiles/mass/stellar/test_sersic_gradient.py index f85156c26..4d09ed218 100644 --- a/test_autogalaxy/profiles/mass/stellar/test_sersic_gradient.py +++ b/test_autogalaxy/profiles/mass/stellar/test_sersic_gradient.py @@ -5,7 +5,7 @@ grid = ag.Grid2DIrregular([[1.0, 1.0], [2.0, 2.0], [3.0, 3.0], [2.0, 4.0]]) -def test__deflections_via_integral_from(): +def test__deflections_via_integral_from__gradient_1(): mp = ag.mp.SersicGradient( centre=(-0.4, -0.2), ell_comps=(-0.07142, -0.085116), @@ -23,6 +23,8 @@ def test__deflections_via_integral_from(): assert deflections[0, 0] == pytest.approx(3.60324873535244, 1e-3) assert deflections[0, 1] == pytest.approx(2.3638898009652, 1e-3) + +def test__deflections_via_integral_from__gradient_neg_1(): mp = ag.mp.SersicGradient( centre=(-0.4, -0.2), ell_comps=(-0.07142, -0.085116), @@ -62,7 +64,7 @@ def test__deflections_via_integral_from(): # assert deflections_via_integral == pytest.approx(deflections_via_mge.array, 1.0e-3) -def test__deflections_2d_via_cse_from(): +def test__deflections_2d_via_cse_from__gradient_1(): mp = ag.mp.SersicGradient( centre=(-0.4, -0.2), ell_comps=(-0.07142, -0.085116), @@ -82,6 +84,8 @@ def test__deflections_2d_via_cse_from(): assert deflections_via_integral == pytest.approx(deflections_via_cse.array, 1.0e-4) + +def test__deflections_2d_via_cse_from__gradient_neg_1(): mp = ag.mp.SersicGradient( centre=(-0.4, -0.2), ell_comps=(-0.07142, -0.085116), @@ -102,7 +106,7 @@ def test__deflections_2d_via_cse_from(): assert deflections_via_integral == pytest.approx(deflections_via_cse.array, 1.0e-4) -def test__deflections_yx_2d_from(): +def test__deflections_yx_2d_from__sersic_gradient(): mp = ag.mp.SersicGradient() deflections = mp.deflections_yx_2d_from(grid=ag.Grid2DIrregular([[1.0, 0.0]])) @@ -112,6 +116,8 @@ def test__deflections_yx_2d_from(): assert deflections == pytest.approx(deflections_via_integral.array, 1.0e-4) + +def test__deflections_yx_2d_from__sersic_gradient_sph(): mp = ag.mp.SersicGradientSph() deflections = mp.deflections_yx_2d_from(grid=ag.Grid2DIrregular([[1.0, 0.0]])) @@ -121,6 +127,8 @@ def test__deflections_yx_2d_from(): assert deflections == pytest.approx(deflections_via_integral.array, 1.0e-4) + +def test__deflections_yx_2d_from__elliptical_vs_spherical(): elliptical = ag.mp.SersicGradient( centre=(0.0, 0.0), ell_comps=(0.0, 0.0), @@ -146,7 +154,7 @@ def test__deflections_yx_2d_from(): ell_deflections_yx_2d == pytest.approx(sph_deflections_yx_2d.array, 1.0e-4) -def test__convergence_2d_from(): +def test__convergence_2d_from__sersic_gradient_config_1(): # ((axis_ratio*radius/effective_radius)**-mass_to_light_gradient) = (1/0.6)**-1.0 = 0.6 mp = ag.mp.SersicGradient( centre=(0.0, 0.0), @@ -162,6 +170,8 @@ def test__convergence_2d_from(): assert convergence == pytest.approx(0.6 * 0.351797, 1e-3) + +def test__convergence_2d_from__sersic_gradient_config_2(): # ((axis_ratio*radius/effective_radius)**-mass_to_light_gradient) = (1.5/2.0)**1.0 = 0.75 mp = ag.mp.SersicGradient( @@ -177,6 +187,8 @@ def test__convergence_2d_from(): assert convergence == pytest.approx(0.75 * 4.90657319276, 1e-3) + +def test__convergence_2d_from__sersic_gradient_intensity_6(): mp = ag.mp.SersicGradient( ell_comps=(0.0, 0.0), intensity=6.0, @@ -190,6 +202,8 @@ def test__convergence_2d_from(): assert convergence == pytest.approx(2.0 * 0.75 * 4.90657319276, 1e-3) + +def test__convergence_2d_from__sersic_gradient_mass_to_light_2(): mp = ag.mp.SersicGradient( ell_comps=(0.0, 0.0), intensity=3.0, @@ -203,6 +217,8 @@ def test__convergence_2d_from(): assert convergence == pytest.approx(2.0 * 0.75 * 4.90657319276, 1e-3) + +def test__convergence_2d_from__sersic_gradient_elliptical(): # ((axis_ratio*radius/effective_radius)**-mass_to_light_gradient) = ((0.5*1.41)/2.0)**-1.0 = 2.836 mp = ag.mp.SersicGradient( ell_comps=(0.0, 0.333333), @@ -217,6 +233,8 @@ def test__convergence_2d_from(): assert convergence == pytest.approx(2.836879 * 5.38066670129, abs=2e-01) + +def test__convergence_2d_from__elliptical_vs_spherical(): elliptical = ag.mp.SersicGradient( centre=(0.0, 0.0), ell_comps=(0.0, 0.0), @@ -242,7 +260,7 @@ def test__convergence_2d_from(): assert ell_convergence_2d == pytest.approx(sph_convergence_2d.array, 1.0e-4) -def test__compare_to_sersic(): +def test__compare_to_sersic__gradient_0_vs_exponential(): mp = ag.mp.SersicGradient( centre=(-0.4, -0.2), ell_comps=(-0.07142, -0.085116), @@ -277,6 +295,8 @@ def test__compare_to_sersic(): ) assert sersic_deflections[0, 1] == pytest.approx(0.62569, 1e-3) + +def test__compare_to_sersic__gradient_0_vs_dev_vaucouleurs(): mp = ag.mp.SersicGradient( centre=(0.4, 0.2), ell_comps=(0.0180010, 0.0494575), @@ -307,6 +327,8 @@ def test__compare_to_sersic(): # assert sersic_deflections[0, 1] == pytest.approx(dev_deflections[0, 1], 1e-3) # assert sersic_deflections[0, 1] == pytest.approx(-3.37605, 1e-3) + +def test__compare_to_sersic__gradient_0_vs_sersic(): sersic_grad = ag.mp.SersicGradient( centre=(-0.4, -0.2), ell_comps=(-0.07142, -0.085116), diff --git a/test_autogalaxy/profiles/mass/test_scaling_relations.py b/test_autogalaxy/profiles/mass/test_scaling_relations.py index e201272c9..0c4432605 100644 --- a/test_autogalaxy/profiles/mass/test_scaling_relations.py +++ b/test_autogalaxy/profiles/mass/test_scaling_relations.py @@ -2,7 +2,7 @@ class TestMassLightRelation: - def test__einstein_radius_from(self): + def test__einstein_radius_from__gradient_1_denominator_1(self): mass_light_relation = ag.sr.MassLightRelation( gradient=1.0, denominator=1.0, power=1.0 ) @@ -15,6 +15,7 @@ def test__einstein_radius_from(self): assert einstein_radius == 2.0 + def test__einstein_radius_from__gradient_2_denominator_1(self): mass_light_relation = ag.sr.MassLightRelation( gradient=2.0, denominator=1.0, power=1.0 ) @@ -23,6 +24,7 @@ def test__einstein_radius_from(self): assert einstein_radius == 4.0 + def test__einstein_radius_from__gradient_2_denominator_05(self): mass_light_relation = ag.sr.MassLightRelation( gradient=2.0, denominator=0.5, power=1.0 ) @@ -31,6 +33,7 @@ def test__einstein_radius_from(self): assert einstein_radius == 16.0 + def test__einstein_radius_from__gradient_2_denominator_05_power_2(self): mass_light_relation = ag.sr.MassLightRelation( gradient=2.0, denominator=0.5, power=2.0 ) @@ -41,7 +44,7 @@ def test__einstein_radius_from(self): class TestIsothermalMLR: - def test__setup_correctly_from_luminosity(self): + def test__setup_correctly_from_luminosity__isothermal_sph(self): relation = ag.sr.MassLightRelation(gradient=2.0, denominator=0.5, power=2.0) sis = ag.sr.IsothermalSphMLR( @@ -53,6 +56,7 @@ def test__setup_correctly_from_luminosity(self): assert sis.centre == (1.0, 1.0) assert sis.einstein_radius == 128.0 + def test__setup_correctly_from_luminosity__isothermal_elliptical(self): relation = ag.sr.MassLightRelation(gradient=2.0, denominator=0.5, power=2.0) sie = ag.sr.IsothermalMLR( diff --git a/test_autogalaxy/profiles/mass/total/test_dual_pseudo_isothermal_mass.py b/test_autogalaxy/profiles/mass/total/test_dual_pseudo_isothermal_mass.py index ef5b441c0..5d0e30afd 100644 --- a/test_autogalaxy/profiles/mass/total/test_dual_pseudo_isothermal_mass.py +++ b/test_autogalaxy/profiles/mass/total/test_dual_pseudo_isothermal_mass.py @@ -5,7 +5,7 @@ grid = ag.Grid2DIrregular([[1.0, 1.0], [2.0, 2.0], [3.0, 3.0], [2.0, 4.0]]) -def test__deflections_yx_2d_from(): +def test__deflections_yx_2d_from__sph_config_1(): mp = ag.mp.dPIEMassSph(centre=(-0.7, 0.5), b0=5.2, ra=2.0, rs=3.0) deflections = mp.deflections_yx_2d_from(grid=ag.Grid2DIrregular([[0.1875, 0.1625]])) @@ -13,6 +13,8 @@ def test__deflections_yx_2d_from(): assert deflections[0, 0] == pytest.approx(1.033080741, 1e-4) assert deflections[0, 1] == pytest.approx(-0.39286169026, 1e-4) + +def test__deflections_yx_2d_from__sph_config_2(): mp = ag.mp.dPIEMassSph(centre=(-0.1, 0.1), b0=20.0, ra=2.0, rs=3.0) deflections = mp.deflections_yx_2d_from(grid=ag.Grid2DIrregular([[0.1875, 0.1625]])) @@ -20,6 +22,8 @@ def test__deflections_yx_2d_from(): assert deflections[0, 0] == pytest.approx(1.4212977207, 1e-4) assert deflections[0, 1] == pytest.approx(0.308977765378, 1e-4) + +def test__deflections_yx_2d_from__elliptical(): # First deviation from potential case due to ellipticity mp = ag.mp.dPIEMass( @@ -31,6 +35,8 @@ def test__deflections_yx_2d_from(): assert deflections[0, 0] == pytest.approx(0.21461366, 1e-3) assert deflections[0, 1] == pytest.approx(0.10753914, 1e-3) + +def test__deflections_yx_2d_from__elliptical_vs_spherical(): elliptical = ag.mp.dPIEMass( centre=(1.1, 1.1), ell_comps=(0.000001, 0.0000001), b0=12.0, ra=2.0, rs=3.0 ) diff --git a/test_autogalaxy/profiles/mass/total/test_dual_pseudo_isothermal_potential.py b/test_autogalaxy/profiles/mass/total/test_dual_pseudo_isothermal_potential.py index ea43e7c06..2ea341b4c 100644 --- a/test_autogalaxy/profiles/mass/total/test_dual_pseudo_isothermal_potential.py +++ b/test_autogalaxy/profiles/mass/total/test_dual_pseudo_isothermal_potential.py @@ -5,7 +5,7 @@ grid = ag.Grid2DIrregular([[1.0, 1.0], [2.0, 2.0], [3.0, 3.0], [2.0, 4.0]]) -def test__deflections_yx_2d_from(): +def test__deflections_yx_2d_from__sph_config_1(): mp = ag.mp.dPIEPotentialSph(centre=(-0.7, 0.5), b0=5.2, ra=2.0, rs=3.0) deflections = mp.deflections_yx_2d_from(grid=ag.Grid2DIrregular([[0.1875, 0.1625]])) @@ -13,6 +13,8 @@ def test__deflections_yx_2d_from(): assert deflections[0, 0] == pytest.approx(1.033080741, 1e-4) assert deflections[0, 1] == pytest.approx(-0.39286169026, 1e-4) + +def test__deflections_yx_2d_from__sph_config_2(): mp = ag.mp.dPIEPotentialSph(centre=(-0.1, 0.1), b0=20.0, ra=2.0, rs=3.0) deflections = mp.deflections_yx_2d_from(grid=ag.Grid2DIrregular([[0.1875, 0.1625]])) @@ -20,6 +22,8 @@ def test__deflections_yx_2d_from(): assert deflections[0, 0] == pytest.approx(1.4212977207, 1e-4) assert deflections[0, 1] == pytest.approx(0.308977765378, 1e-4) + +def test__deflections_yx_2d_from__elliptical(): mp = ag.mp.dPIEPotential( centre=(0, 0), ell_comps=(0.0, 0.333333), b0=4.0, ra=2.0, rs=3.0 ) @@ -29,6 +33,8 @@ def test__deflections_yx_2d_from(): assert deflections[0, 0] == pytest.approx(0.186341843, 1e-3) assert deflections[0, 1] == pytest.approx(0.13176363087, 1e-3) + +def test__deflections_yx_2d_from__elliptical_vs_spherical(): elliptical = ag.mp.dPIEPotential( centre=(1.1, 1.1), ell_comps=(0.0, 0.0), b0=12.0, ra=2.0, rs=3.0 ) @@ -39,7 +45,7 @@ def test__deflections_yx_2d_from(): ) -def test__convergence_2d_from(): +def test__convergence_2d_from__sph(): # eta = 1.0 # kappa = 0.5 * 1.0 ** 1.0 @@ -49,6 +55,8 @@ def test__convergence_2d_from(): assert convergence == pytest.approx(1.57182995, 1e-3) + +def test__convergence_2d_from__elliptical_no_ell_comps_b0_4(): mp = ag.mp.dPIEPotential( centre=(0.0, 0.0), ell_comps=(0.0, 0.0), b0=4.0, ra=2.0, rs=3.0 ) @@ -57,6 +65,8 @@ def test__convergence_2d_from(): assert convergence == pytest.approx(0.78591498, 1e-3) + +def test__convergence_2d_from__elliptical_no_ell_comps_b0_8(): mp = ag.mp.dPIEPotential( centre=(0.0, 0.0), ell_comps=(0.0, 0.0), b0=8.0, ra=2.0, rs=3.0 ) @@ -65,6 +75,8 @@ def test__convergence_2d_from(): assert convergence == pytest.approx(1.57182995, 1e-3) + +def test__convergence_2d_from__elliptical_with_ell_comps(): mp = ag.mp.dPIEPotential( centre=(0.0, 0.0), ell_comps=(0.0, 0.333333), b0=4.0, ra=2.0, rs=3.0 ) @@ -73,6 +85,8 @@ def test__convergence_2d_from(): assert convergence == pytest.approx(0.87182837, 1e-3) + +def test__convergence_2d_from__elliptical_vs_spherical(): elliptical = ag.mp.dPIEPotential( centre=(1.1, 1.1), ell_comps=(0.0, 0.0), b0=12.0, ra=2.0, rs=3.0 ) diff --git a/test_autogalaxy/profiles/mass/total/test_isothermal.py b/test_autogalaxy/profiles/mass/total/test_isothermal.py index 22605bb1b..2f961b45b 100644 --- a/test_autogalaxy/profiles/mass/total/test_isothermal.py +++ b/test_autogalaxy/profiles/mass/total/test_isothermal.py @@ -5,7 +5,7 @@ grid = ag.Grid2DIrregular([[1.0, 1.0], [2.0, 2.0], [3.0, 3.0], [2.0, 4.0]]) -def test__deflections_yx_2d_from(): +def test__deflections_yx_2d_from__isothermal_sph_config_1(): mp = ag.mp.IsothermalSph(centre=(-0.7, 0.5), einstein_radius=1.3) deflections = mp.deflections_yx_2d_from(grid=ag.Grid2DIrregular([[0.1875, 0.1625]])) @@ -13,6 +13,8 @@ def test__deflections_yx_2d_from(): assert deflections[0, 0] == pytest.approx(1.21510, 1e-4) assert deflections[0, 1] == pytest.approx(-0.46208, 1e-4) + +def test__deflections_yx_2d_from__isothermal_sph_config_2(): mp = ag.mp.IsothermalSph(centre=(-0.1, 0.1), einstein_radius=5.0) deflections = mp.deflections_yx_2d_from(grid=ag.Grid2DIrregular([[0.1875, 0.1625]])) @@ -20,6 +22,8 @@ def test__deflections_yx_2d_from(): assert deflections[0, 0] == pytest.approx(4.88588, 1e-4) assert deflections[0, 1] == pytest.approx(1.06214, 1e-4) + +def test__deflections_yx_2d_from__isothermal_ell_config_1(): mp = ag.mp.Isothermal(centre=(0, 0), ell_comps=(0.0, 0.333333), einstein_radius=1.0) deflections = mp.deflections_yx_2d_from(grid=ag.Grid2DIrregular([[0.1625, 0.1625]])) @@ -27,6 +31,8 @@ def test__deflections_yx_2d_from(): assert deflections[0, 0] == pytest.approx(0.79421, 1e-3) assert deflections[0, 1] == pytest.approx(0.50734, 1e-3) + +def test__deflections_yx_2d_from__isothermal_ell_config_2(): mp = ag.mp.Isothermal(centre=(0, 0), ell_comps=(0.0, 0.333333), einstein_radius=1.0) deflections = mp.deflections_yx_2d_from(grid=ag.Grid2DIrregular([[0.1625, 0.1625]])) @@ -34,6 +40,8 @@ def test__deflections_yx_2d_from(): assert deflections[0, 0] == pytest.approx(0.79421, 1e-3) assert deflections[0, 1] == pytest.approx(0.50734, 1e-3) + +def test__deflections_yx_2d_from__elliptical_vs_spherical(): elliptical = ag.mp.Isothermal( centre=(1.1, 1.1), ell_comps=(0.0, 0.0), einstein_radius=3.0 ) @@ -44,28 +52,31 @@ def test__deflections_yx_2d_from(): ) -def test__convergence_2d_from(): - # eta = 1.0 - # kappa = 0.5 * 1.0 ** 1.0 - +def test__convergence_2d_from__isothermal_sph(): mp = ag.mp.IsothermalSph(centre=(0.0, 0.0), einstein_radius=2.0) convergence = mp.convergence_2d_from(grid=ag.Grid2DIrregular([[0.0, 1.0]])) assert convergence == pytest.approx(0.5 * 2.0, 1e-3) + +def test__convergence_2d_from__isothermal_no_ell(): mp = ag.mp.Isothermal(centre=(0.0, 0.0), ell_comps=(0.0, 0.0), einstein_radius=1.0) convergence = mp.convergence_2d_from(grid=ag.Grid2DIrregular([[0.0, 1.0]])) assert convergence == pytest.approx(0.5, 1e-3) + +def test__convergence_2d_from__isothermal_einstein_radius_2(): mp = ag.mp.Isothermal(centre=(0.0, 0.0), ell_comps=(0.0, 0.0), einstein_radius=2.0) convergence = mp.convergence_2d_from(grid=ag.Grid2DIrregular([[0.0, 1.0]])) assert convergence == pytest.approx(0.5 * 2.0, 1e-3) + +def test__convergence_2d_from__isothermal_with_ell_comps(): mp = ag.mp.Isothermal( centre=(0.0, 0.0), ell_comps=(0.0, 0.333333), einstein_radius=1.0 ) @@ -74,6 +85,8 @@ def test__convergence_2d_from(): assert convergence == pytest.approx(0.66666, 1e-3) + +def test__convergence_2d_from__elliptical_vs_spherical(): elliptical = ag.mp.Isothermal( centre=(1.1, 1.1), ell_comps=(0.0, 0.0), einstein_radius=3.0 ) @@ -84,13 +97,15 @@ def test__convergence_2d_from(): ) -def test__potential_2d_from(): +def test__potential_2d_from__isothermal_sph(): mp = ag.mp.IsothermalSph(centre=(-0.7, 0.5), einstein_radius=1.3) potential = mp.potential_2d_from(grid=ag.Grid2DIrregular([[0.1875, 0.1625]])) assert potential == pytest.approx(1.23435, 1e-3) + +def test__potential_2d_from__isothermal_elliptical(): mp = ag.mp.Isothermal( centre=(-0.7, 0.5), ell_comps=(0.152828, -0.088235), @@ -101,6 +116,8 @@ def test__potential_2d_from(): assert potential == pytest.approx(1.19268, 1e-3) + +def test__potential_2d_from__elliptical_vs_spherical(): elliptical = ag.mp.Isothermal( centre=(1.1, 1.1), ell_comps=(0.0, 0.0), einstein_radius=3.0 ) @@ -111,37 +128,47 @@ def test__potential_2d_from(): ) -def test__shear_yx_2d_from(): +def test__shear_yx_2d_from__isothermal_sph_grid_1(): mp = ag.mp.IsothermalSph(centre=(0.0, 0.0), einstein_radius=2.0) convergence = mp.convergence_2d_from(grid=ag.Grid2DIrregular([[0.0, 1.0]])) - shear = mp.shear_yx_2d_from(grid=ag.Grid2DIrregular([[0.0, 1.0]])) assert shear[0, 0] == pytest.approx(0.0, 1e-4) assert shear[0, 1] == pytest.approx(-convergence.array[0], 1e-4) + +def test__shear_yx_2d_from__isothermal_sph_grid_2(): + mp = ag.mp.IsothermalSph(centre=(0.0, 0.0), einstein_radius=2.0) + convergence = mp.convergence_2d_from(grid=ag.Grid2DIrregular([[2.0, 1.0]])) shear = mp.shear_yx_2d_from(grid=ag.Grid2DIrregular([[2.0, 1.0]])) assert shear[0, 0] == pytest.approx(-(4.0 / 5.0) * convergence.array[0], 1e-4) assert shear[0, 1] == pytest.approx((3.0 / 5.0) * convergence.array[0], 1e-4) + +def test__shear_yx_2d_from__isothermal_sph_grid_3(): + mp = ag.mp.IsothermalSph(centre=(0.0, 0.0), einstein_radius=2.0) + convergence = mp.convergence_2d_from(grid=ag.Grid2DIrregular([[3.0, 5.0]])) shear = mp.shear_yx_2d_from(grid=ag.Grid2DIrregular([[3.0, 5.0]])) assert shear[0, 0] == pytest.approx(-(30.0 / 34.0) * convergence.array[0], 1e-4) assert shear[0, 1] == pytest.approx(-(16.0 / 34.0) * convergence.array[0], 1e-4) + +def test__shear_yx_2d_from__isothermal_no_ell(): mp = ag.mp.Isothermal(centre=(0.0, 0.0), ell_comps=(0.0, 0.0), einstein_radius=2.0) convergence = mp.convergence_2d_from(grid=ag.Grid2DIrregular([[0.0, 1.0]])) - shear = mp.shear_yx_2d_from(grid=ag.Grid2DIrregular([[0.0, 1.0]])) assert shear[0, 0] == pytest.approx(0.0, 1e-4) assert shear[0, 1] == pytest.approx(-convergence.array[0], 1e-4) + +def test__shear_yx_2d_from__isothermal_with_ell_comps(): mp = ag.mp.Isothermal(centre=(0.0, 0.0), ell_comps=(0.3, 0.4), einstein_radius=2.0) shear = mp.shear_yx_2d_from(grid=ag.Grid2DIrregular([[0.0, 1.0]])) diff --git a/test_autogalaxy/profiles/mass/total/test_isothermal_cored.py b/test_autogalaxy/profiles/mass/total/test_isothermal_cored.py index 143a1d294..ed5cedf9c 100644 --- a/test_autogalaxy/profiles/mass/total/test_isothermal_cored.py +++ b/test_autogalaxy/profiles/mass/total/test_isothermal_cored.py @@ -6,7 +6,7 @@ grid = ag.Grid2DIrregular([[1.0, 1.0], [2.0, 2.0], [3.0, 3.0], [2.0, 4.0]]) -def test__deflections_yx_2d_from(): +def test__deflections_yx_2d_from__isothermal_core_sph_config_1(): mp = ag.mp.IsothermalCoreSph( centre=(-0.7, 0.5), einstein_radius=1.3, core_radius=0.2 ) @@ -16,6 +16,8 @@ def test__deflections_yx_2d_from(): assert deflections[0, 0] == pytest.approx(0.98582, 1e-3) assert deflections[0, 1] == pytest.approx(-0.37489, 1e-3) + +def test__deflections_yx_2d_from__isothermal_core_sph_config_2(): mp = ag.mp.IsothermalCoreSph( centre=(0.2, -0.2), einstein_radius=0.5, core_radius=0.5 ) @@ -25,6 +27,8 @@ def test__deflections_yx_2d_from(): assert deflections[0, 0] == pytest.approx(-0.00559, 1e-3) assert deflections[0, 1] == pytest.approx(0.16216, 1e-3) + +def test__deflections_yx_2d_from__isothermal_core_ell_config_1(): mp = ag.mp.IsothermalCore( centre=(-0.7, 0.5), ell_comps=(0.152828, -0.088235), @@ -37,6 +41,8 @@ def test__deflections_yx_2d_from(): assert deflections[0, 0] == pytest.approx(0.95429, 1e-3) assert deflections[0, 1] == pytest.approx(-0.52047, 1e-3) + +def test__deflections_yx_2d_from__isothermal_core_ell_config_2(): mp = ag.mp.IsothermalCore( centre=(0.2, -0.2), ell_comps=(-0.216506, -0.125), @@ -49,6 +55,8 @@ def test__deflections_yx_2d_from(): assert deflections[0, 0] == pytest.approx(0.02097, 1e-3) assert deflections[0, 1] == pytest.approx(0.20500, 1e-3) + +def test__deflections_yx_2d_from__elliptical_vs_spherical(): elliptical = ag.mp.IsothermalCore( centre=(1.1, 1.1), ell_comps=(0.0, 0.0), @@ -64,19 +72,23 @@ def test__deflections_yx_2d_from(): ) -def test__convergence_2d_from(): +def test__convergence_2d_from__isothermal_core_sph_convergence_func(): mp = ag.mp.IsothermalCoreSph(centre=(1, 1), einstein_radius=1.0, core_radius=0.1) convergence = mp.convergence_func(grid_radius=1.0) assert convergence == pytest.approx(0.49752, 1e-4) + +def test__convergence_2d_from__isothermal_core_sph_config_2(): mp = ag.mp.IsothermalCoreSph(centre=(1, 1), einstein_radius=1.0, core_radius=0.1) convergence = mp.convergence_func(grid_radius=1.0) assert convergence == pytest.approx(0.49752, 1e-4) + +def test__convergence_2d_from__isothermal_core_sph_core_radius_02(): mp = ag.mp.IsothermalCoreSph( centre=(0.0, 0.0), einstein_radius=1.0, core_radius=0.2 ) @@ -85,6 +97,8 @@ def test__convergence_2d_from(): assert convergence == pytest.approx(0.49029, 1e-3) + +def test__convergence_2d_from__isothermal_core_sph_einstein_radius_2(): mp = ag.mp.IsothermalCoreSph( centre=(0.0, 0.0), einstein_radius=2.0, core_radius=0.2 ) @@ -93,6 +107,8 @@ def test__convergence_2d_from(): assert convergence == pytest.approx(2.0 * 0.49029, 1e-3) + +def test__convergence_2d_from__isothermal_core_sph_y_axis(): mp = ag.mp.IsothermalCoreSph( centre=(0.0, 0.0), einstein_radius=1.0, core_radius=0.2 ) @@ -101,7 +117,9 @@ def test__convergence_2d_from(): assert convergence == pytest.approx(0.49029, 1e-3) - # axis ratio changes only einstein_rescaled, so wwe can use the above value and times by 1.0/1.5. + +def test__convergence_2d_from__isothermal_core_ell_config_1(): + # axis ratio changes only einstein_rescaled, so we can use the above value and times by 1.0/1.5. mp = ag.mp.IsothermalCore( centre=(0.0, 0.0), ell_comps=(0.0, 0.333333), @@ -113,6 +131,8 @@ def test__convergence_2d_from(): assert convergence == pytest.approx(0.49029 * 1.33333, 1e-3) + +def test__convergence_2d_from__isothermal_core_ell_config_2(): mp = ag.mp.IsothermalCore( centre=(0.0, 0.0), ell_comps=(0.0, 0.0), @@ -124,10 +144,12 @@ def test__convergence_2d_from(): assert convergence == pytest.approx(2.0 * 0.49029, 1e-3) + +def test__convergence_2d_from__isothermal_core_ell_config_3(): # for axis_ratio = 1.0, the factor is 1/2 # for axis_ratio = 0.5, the factor is 1/(1.5) # So the change in the value is 0.5 / (1/1.5) = 1.0 / 0.75 - # axis ratio changes only einstein_rescaled, so wwe can use the above value and times by 1.0/1.5. + # axis ratio changes only einstein_rescaled, so we can use the above value and times by 1.0/1.5. mp = ag.mp.IsothermalCore( centre=(0.0, 0.0), @@ -140,6 +162,8 @@ def test__convergence_2d_from(): assert convergence == pytest.approx((1.0 / 0.75) * 0.49029, 1e-3) + +def test__convergence_2d_from__elliptical_vs_spherical(): elliptical = ag.mp.IsothermalCore( centre=(1.1, 1.1), ell_comps=(0.0, 0.0), @@ -155,7 +179,7 @@ def test__convergence_2d_from(): ) -def test__potential_2d_from(): +def test__potential_2d_from__isothermal_core_sph_config_1(): mp = ag.mp.IsothermalCoreSph( centre=(-0.7, 0.5), einstein_radius=1.3, core_radius=0.2 ) @@ -164,6 +188,8 @@ def test__potential_2d_from(): assert potential == pytest.approx(0.72231, 1e-3) + +def test__potential_2d_from__isothermal_core_sph_config_2(): mp = ag.mp.IsothermalCoreSph( centre=(0.2, -0.2), einstein_radius=0.5, core_radius=0.5 ) @@ -172,6 +198,8 @@ def test__potential_2d_from(): assert potential == pytest.approx(0.03103, 1e-3) + +def test__potential_2d_from__isothermal_core_ell_config_1(): mp = ag.mp.IsothermalCore( centre=(-0.7, 0.5), ell_comps=(0.152828, -0.088235), @@ -183,6 +211,8 @@ def test__potential_2d_from(): assert potential == pytest.approx(0.74354, 1e-3) + +def test__potential_2d_from__isothermal_core_ell_config_2(): mp = ag.mp.IsothermalCore( centre=(0.2, -0.2), ell_comps=(-0.216506, -0.125), @@ -194,6 +224,8 @@ def test__potential_2d_from(): assert potential == pytest.approx(0.04024, 1e-3) + +def test__potential_2d_from__elliptical_vs_spherical(): elliptical = ag.mp.IsothermalCore( centre=(1.1, 1.1), ell_comps=(0.0, 0.0), diff --git a/test_autogalaxy/profiles/mass/total/test_power_law.py b/test_autogalaxy/profiles/mass/total/test_power_law.py index 856340d1e..9f9886634 100644 --- a/test_autogalaxy/profiles/mass/total/test_power_law.py +++ b/test_autogalaxy/profiles/mass/total/test_power_law.py @@ -6,7 +6,7 @@ grid = ag.Grid2DIrregular([[1.0, 1.0], [2.0, 2.0], [3.0, 3.0], [2.0, 4.0]]) -def test__deflections_yx_2d_from(): +def test__deflections_yx_2d_from__power_law_sph_slope_2(): mp = ag.mp.PowerLawSph(centre=(0.2, 0.2), einstein_radius=1.0, slope=2.0) deflections = mp.deflections_yx_2d_from(grid=ag.Grid2DIrregular([[0.1875, 0.1625]])) @@ -14,6 +14,8 @@ def test__deflections_yx_2d_from(): assert deflections[0, 0] == pytest.approx(-0.31622, 1e-3) assert deflections[0, 1] == pytest.approx(-0.94868, 1e-3) + +def test__deflections_yx_2d_from__power_law_sph_slope_25(): mp = ag.mp.PowerLawSph(centre=(0.2, 0.2), einstein_radius=1.0, slope=2.5) deflections = mp.deflections_yx_2d_from(grid=ag.Grid2DIrregular([[0.1875, 0.1625]])) @@ -21,6 +23,8 @@ def test__deflections_yx_2d_from(): assert deflections[0, 0] == pytest.approx(-1.59054, 1e-3) assert deflections[0, 1] == pytest.approx(-4.77162, 1e-3) + +def test__deflections_yx_2d_from__power_law_sph_slope_15(): mp = ag.mp.PowerLawSph(centre=(0.2, 0.2), einstein_radius=1.0, slope=1.5) deflections = mp.deflections_yx_2d_from(grid=ag.Grid2DIrregular([[0.1875, 0.1625]])) @@ -28,6 +32,8 @@ def test__deflections_yx_2d_from(): assert deflections[0, 0] == pytest.approx(-0.06287, 1e-3) assert deflections[0, 1] == pytest.approx(-0.18861, 1e-3) + +def test__deflections_yx_2d_from__power_law_ell_slope_2(): mp = ag.mp.PowerLaw( centre=(0, 0), ell_comps=(0.0, 0.333333), @@ -40,6 +46,8 @@ def test__deflections_yx_2d_from(): assert deflections[0, 0] == pytest.approx(0.79421, 1e-3) assert deflections[0, 1] == pytest.approx(0.50734, 1e-3) + +def test__deflections_yx_2d_from__power_law_ell_slope_25(): mp = ag.mp.PowerLaw( centre=(0, 0), ell_comps=(0.0, 0.333333), @@ -52,6 +60,8 @@ def test__deflections_yx_2d_from(): assert deflections[0, 0] == pytest.approx(1.29641, 1e-3) assert deflections[0, 1] == pytest.approx(0.99629, 1e-3) + +def test__deflections_yx_2d_from__power_law_ell_slope_15(): mp = ag.mp.PowerLaw( centre=(0, 0), ell_comps=(0.0, 0.333333), @@ -64,6 +74,8 @@ def test__deflections_yx_2d_from(): assert deflections[0, 0] == pytest.approx(0.48036, 1e-3) assert deflections[0, 1] == pytest.approx(0.26729, 1e-3) + +def test__deflections_yx_2d_from__power_law_ell_slope_19(): mp = ag.mp.PowerLaw( centre=(-0.7, 0.5), ell_comps=(0.152828, -0.088235), @@ -76,6 +88,8 @@ def test__deflections_yx_2d_from(): # assert deflections[0, 0] == pytest.approx(1.12841, 1e-3) # assert deflections[0, 1] == pytest.approx(-0.60205, 1e-3) + +def test__deflections_yx_2d_from__elliptical_vs_spherical(): elliptical = ag.mp.PowerLaw( centre=(1.1, 1.1), ell_comps=(0.0, 0.0), @@ -90,25 +104,31 @@ def test__deflections_yx_2d_from(): ) -def test__convergence_2d_from(): +def test__convergence_2d_from__power_law_sph_config_1(): mp = ag.mp.PowerLawSph(centre=(0.0, 0.0), einstein_radius=1.0, slope=2.0) convergence = mp.convergence_2d_from(grid=ag.Grid2DIrregular([[1.0, 0.0]])) assert convergence == pytest.approx(0.5, 1e-3) + +def test__convergence_2d_from__power_law_sph_config_2(): mp = ag.mp.PowerLawSph(centre=(0.0, 0.0), einstein_radius=2.0, slope=2.2) convergence = mp.convergence_2d_from(grid=ag.Grid2DIrregular([[2.0, 0.0]])) assert convergence == pytest.approx(0.4, 1e-3) + +def test__convergence_2d_from__power_law_sph_config_3(): mp = ag.mp.PowerLawSph(centre=(0.0, 0.0), einstein_radius=2.0, slope=2.2) convergence = mp.convergence_2d_from(grid=ag.Grid2DIrregular([[2.0, 0.0]])) assert convergence == pytest.approx(0.4, 1e-3) + +def test__convergence_2d_from__power_law_ell_config_1(): mp = ag.mp.PowerLaw( centre=(0.0, 0.0), ell_comps=(0.0, 0.333333), @@ -120,6 +140,8 @@ def test__convergence_2d_from(): assert convergence == pytest.approx(0.466666, 1e-3) + +def test__convergence_2d_from__power_law_ell_config_2(): mp = ag.mp.PowerLaw( centre=(0.0, 0.0), ell_comps=(0.0, 0.333333), @@ -131,6 +153,8 @@ def test__convergence_2d_from(): assert convergence == pytest.approx(1.4079, 1e-3) + +def test__convergence_2d_from__elliptical_vs_spherical(): elliptical = ag.mp.PowerLaw( centre=(1.1, 1.1), ell_comps=(0.0, 0.0), @@ -145,19 +169,23 @@ def test__convergence_2d_from(): ) -def test__potential_2d_from(): +def test__potential_2d_from__power_law_sph_config_1(): mp = ag.mp.PowerLawSph(centre=(-0.7, 0.5), einstein_radius=1.3, slope=2.3) potential = mp.potential_2d_from(grid=ag.Grid2DIrregular([[0.1625, 0.1625]])) assert potential == pytest.approx(1.90421, 1e-3) + +def test__potential_2d_from__power_law_sph_config_2(): mp = ag.mp.PowerLawSph(centre=(-0.7, 0.5), einstein_radius=1.3, slope=1.8) potential = mp.potential_2d_from(grid=ag.Grid2DIrregular([[0.1625, 0.1625]])) assert potential == pytest.approx(0.93758, 1e-3) + +def test__potential_2d_from__power_law_ell_config_1(): mp = ag.mp.PowerLaw( centre=(-0.7, 0.5), ell_comps=(0.152828, -0.088235), @@ -169,6 +197,8 @@ def test__potential_2d_from(): assert potential == pytest.approx(1.53341, 1e-3) + +def test__potential_2d_from__power_law_ell_config_2(): mp = ag.mp.PowerLaw( centre=(-0.7, 0.5), ell_comps=(0.152828, -0.088235), @@ -180,6 +210,8 @@ def test__potential_2d_from(): assert potential == pytest.approx(0.96723, 1e-3) + +def test__potential_2d_from__elliptical_vs_spherical(): elliptical = ag.mp.PowerLaw( centre=(1.1, 1.1), ell_comps=(0.0, 0.0), diff --git a/test_autogalaxy/profiles/mass/total/test_power_law_broken.py b/test_autogalaxy/profiles/mass/total/test_power_law_broken.py index d9859a0e3..8139ea065 100644 --- a/test_autogalaxy/profiles/mass/total/test_power_law_broken.py +++ b/test_autogalaxy/profiles/mass/total/test_power_law_broken.py @@ -6,7 +6,7 @@ grid = ag.Grid2DIrregular([[1.0, 1.0], [2.0, 2.0], [3.0, 3.0], [2.0, 4.0]]) -def test__deflections_yx_2d_from(): +def test__deflections_yx_2d_from__power_law_broken_sph__single_and_multi_grid(): mp = ag.mp.PowerLawBrokenSph( centre=(0, 0), einstein_radius=1.0, @@ -29,6 +29,8 @@ def test__deflections_yx_2d_from(): assert deflections[1, 0] == pytest.approx(0.404076, 1e-3) assert deflections[1, 1] == pytest.approx(0.808152, 1e-3) + +def test__deflections_yx_2d_from__power_law_broken_ell_config_1(): mp = ag.mp.PowerLawBroken( centre=(0, 0), ell_comps=(0.096225, 0.055555), @@ -43,6 +45,8 @@ def test__deflections_yx_2d_from(): assert deflections[0, 0] == pytest.approx(0.40392, 1e-3) assert deflections[0, 1] == pytest.approx(0.811619, 1e-3) + +def test__deflections_yx_2d_from__power_law_broken_ell_config_2(): mp = ag.mp.PowerLawBroken( centre=(0, 0), ell_comps=(-0.07142, -0.085116), @@ -57,6 +61,8 @@ def test__deflections_yx_2d_from(): assert deflections[0, 0] == pytest.approx(0.4005338, 1e-3) assert deflections[0, 1] == pytest.approx(0.8067221, 1e-3) + +def test__deflections_yx_2d_from__power_law_broken_ell_config_3(): mp = ag.mp.PowerLawBroken( centre=(0, 0), ell_comps=(0.109423, 0.019294), @@ -71,6 +77,8 @@ def test__deflections_yx_2d_from(): assert deflections[0, 0] == pytest.approx(0.399651, 1e-3) assert deflections[0, 1] == pytest.approx(0.813372, 1e-3) + +def test__deflections_yx_2d_from__power_law_broken_ell_config_4(): mp = ag.mp.PowerLawBroken( centre=(0, 0), ell_comps=(-0.216506, -0.125), @@ -86,7 +94,7 @@ def test__deflections_yx_2d_from(): assert deflections[0, 1] == pytest.approx(0.798795, 1e-3) -def test__convergence_2d_from(): +def test__convergence_2d_from__power_law_broken_sph_single_grid(): mp = ag.mp.PowerLawBrokenSph( centre=(0, 0), einstein_radius=1.0, @@ -99,12 +107,24 @@ def test__convergence_2d_from(): assert convergence == pytest.approx(0.0355237, 1e-4) + +def test__convergence_2d_from__power_law_broken_sph_two_grids(): + mp = ag.mp.PowerLawBrokenSph( + centre=(0, 0), + einstein_radius=1.0, + inner_slope=1.5, + outer_slope=2.5, + break_radius=0.1, + ) + convergence = mp.convergence_2d_from( grid=ag.Grid2DIrregular([[0.5, 1.0], [0.5, 1.0]]) ) assert convergence == pytest.approx([0.0355237, 0.0355237], 1e-4) + +def test__convergence_2d_from__power_law_broken_ell_config_1(): mp = ag.mp.PowerLawBroken( centre=(0, 0), ell_comps=(0.096225, 0.055555), @@ -118,6 +138,8 @@ def test__convergence_2d_from(): assert convergence == pytest.approx(0.05006035, 1e-4) + +def test__convergence_2d_from__power_law_broken_ell_config_2(): mp = ag.mp.PowerLawBroken( centre=(0, 0), ell_comps=(-0.113433, 0.135184), @@ -131,6 +153,8 @@ def test__convergence_2d_from(): assert convergence == pytest.approx(0.034768, 1e-4) + +def test__convergence_2d_from__power_law_broken_ell_config_3(): mp = ag.mp.PowerLawBroken( centre=(0, 0), ell_comps=(0.113433, -0.135184), @@ -144,6 +168,8 @@ def test__convergence_2d_from(): assert convergence == pytest.approx(0.03622852, 1e-4) + +def test__convergence_2d_from__power_law_broken_ell_config_4(): mp = ag.mp.PowerLawBroken( centre=(0, 0), ell_comps=(-0.173789, -0.030643), @@ -158,7 +184,7 @@ def test__convergence_2d_from(): assert convergence == pytest.approx(0.026469, 1e-4) -def test__deflections_yx_2d_from__compare_to_power_law(): +def test__deflections_yx_2d_from__compare_to_power_law__slope_2(): mp = ag.mp.PowerLawBrokenSph( centre=(0, 0), einstein_radius=2.0, @@ -181,6 +207,8 @@ def test__deflections_yx_2d_from__compare_to_power_law(): assert broken_yx_ratio == pytest.approx(power_law_yx_ratio, 1.0e-4) + +def test__deflections_yx_2d_from__compare_to_power_law__slope_24(): mp = ag.mp.PowerLawBrokenSph( centre=(0, 0), einstein_radius=2.0, diff --git a/test_autogalaxy/profiles/mass/total/test_power_law_cored.py b/test_autogalaxy/profiles/mass/total/test_power_law_cored.py index 5c4efa896..5ef3ba51f 100644 --- a/test_autogalaxy/profiles/mass/total/test_power_law_cored.py +++ b/test_autogalaxy/profiles/mass/total/test_power_law_cored.py @@ -6,7 +6,7 @@ grid = ag.Grid2DIrregular([[1.0, 1.0], [2.0, 2.0], [3.0, 3.0], [2.0, 4.0]]) -def test__deflections_yx_2d_from(): +def test__deflections_yx_2d_from__power_law_core_sph_config_1(): mp = ag.mp.PowerLawCoreSph( centre=(-0.7, 0.5), einstein_radius=1.0, slope=1.8, core_radius=0.2 ) @@ -16,6 +16,8 @@ def test__deflections_yx_2d_from(): assert deflections[0, 0] == pytest.approx(0.80677, 1e-3) assert deflections[0, 1] == pytest.approx(-0.30680, 1e-3) + +def test__deflections_yx_2d_from__power_law_core_sph_config_2(): mp = ag.mp.PowerLawCoreSph( centre=(0.2, -0.2), einstein_radius=0.5, slope=2.4, core_radius=0.5 ) @@ -25,6 +27,8 @@ def test__deflections_yx_2d_from(): assert deflections[0, 0] == pytest.approx(-0.00321, 1e-3) assert deflections[0, 1] == pytest.approx(0.09316, 1e-3) + +def test__deflections_yx_2d_from__power_law_core_ell_config_1(): cored_power_law = ag.mp.PowerLawCore( centre=(-0.7, 0.5), ell_comps=(0.152828, -0.088235), @@ -40,6 +44,8 @@ def test__deflections_yx_2d_from(): assert deflections[0, 0] == pytest.approx(0.9869, 1e-3) assert deflections[0, 1] == pytest.approx(-0.54882, 1e-3) + +def test__deflections_yx_2d_from__power_law_core_ell_config_2(): cored_power_law = ag.mp.PowerLawCore( centre=(0.2, -0.2), ell_comps=(-0.216506, -0.125), @@ -54,6 +60,8 @@ def test__deflections_yx_2d_from(): assert deflections[0, 0] == pytest.approx(0.01111, 1e-3) assert deflections[0, 1] == pytest.approx(0.11403, 1e-3) + +def test__deflections_yx_2d_from__elliptical_vs_spherical(): elliptical = ag.mp.PowerLawCore( centre=(1.1, 1.1), ell_comps=(0.0, 0.0), @@ -70,7 +78,7 @@ def test__deflections_yx_2d_from(): ) -def test__convergence_2d_from(): +def test__convergence_2d_from__power_law_core_sph_convergence_func(): mp = ag.mp.PowerLawCoreSph( centre=(1, 1), einstein_radius=1.0, slope=2.2, core_radius=0.1 ) @@ -79,6 +87,8 @@ def test__convergence_2d_from(): assert convergence == pytest.approx(0.39762, 1e-4) + +def test__convergence_2d_from__power_law_core_ell_config_1(): mp = ag.mp.PowerLawCore( centre=(0.0, 0.0), ell_comps=(0.0, 0.333333), @@ -91,6 +101,8 @@ def test__convergence_2d_from(): assert convergence == pytest.approx(0.45492, 1e-3) + +def test__convergence_2d_from__power_law_core_ell_config_2(): mp = ag.mp.PowerLawCore( centre=(0.0, 0.0), ell_comps=(0.0, 0.333333), @@ -103,6 +115,8 @@ def test__convergence_2d_from(): assert convergence == pytest.approx(1.3887, 1e-3) + +def test__convergence_2d_from__elliptical_vs_spherical(): elliptical = ag.mp.PowerLawCore( centre=(1.1, 1.1), ell_comps=(0.0, 0.0), @@ -119,7 +133,7 @@ def test__convergence_2d_from(): ) -def test__potential_2d_from(): +def test__potential_2d_from__power_law_core_sph_config_1(): mp = ag.mp.PowerLawCoreSph( centre=(-0.7, 0.5), einstein_radius=1.0, slope=1.8, core_radius=0.2 ) @@ -128,6 +142,8 @@ def test__potential_2d_from(): assert potential == pytest.approx(0.54913, 1e-3) + +def test__potential_2d_from__power_law_core_sph_config_2(): mp = ag.mp.PowerLawCoreSph( centre=(0.2, -0.2), einstein_radius=0.5, slope=2.4, core_radius=0.5 ) @@ -136,6 +152,8 @@ def test__potential_2d_from(): assert potential == pytest.approx(0.01820, 1e-3) + +def test__potential_2d_from__power_law_core_ell_config_1(): cored_power_law = ag.mp.PowerLawCore( centre=(0.2, -0.2), ell_comps=(-0.216506, -0.125), @@ -150,6 +168,8 @@ def test__potential_2d_from(): assert potential == pytest.approx(0.02319, 1e-3) + +def test__potential_2d_from__power_law_core_ell_config_2(): cored_power_law = ag.mp.PowerLawCore( centre=(-0.7, 0.5), ell_comps=(0.152828, -0.088235), @@ -164,6 +184,8 @@ def test__potential_2d_from(): assert potential == pytest.approx(0.71185, 1e-3) + +def test__potential_2d_from__elliptical_vs_spherical(): elliptical = ag.mp.PowerLawCore( centre=(1.1, 1.1), ell_comps=(0.0, 0.0), diff --git a/test_autogalaxy/profiles/mass/total/test_power_law_multipole.py b/test_autogalaxy/profiles/mass/total/test_power_law_multipole.py index 29271d67a..284d43721 100644 --- a/test_autogalaxy/profiles/mass/total/test_power_law_multipole.py +++ b/test_autogalaxy/profiles/mass/total/test_power_law_multipole.py @@ -5,7 +5,7 @@ grid = ag.Grid2DIrregular([[1.0, 1.0], [2.0, 2.0], [3.0, 3.0], [2.0, 4.0]]) -def test__deflections_yx_2d_from(): +def test__deflections_yx_2d_from__config_1(): mp = ag.mp.PowerLawMultipole( m=4, centre=(0.1, 0.2), @@ -19,6 +19,8 @@ def test__deflections_yx_2d_from(): assert deflections[0, 0] == pytest.approx(-0.036120991, 1e-3) assert deflections[0, 1] == pytest.approx(-0.0476260676, 1e-3) + +def test__deflections_yx_2d_from__config_2(): mp = ag.mp.PowerLawMultipole( m=4, centre=(0.2, 0.3), @@ -33,7 +35,7 @@ def test__deflections_yx_2d_from(): assert deflections[0, 1] == pytest.approx(-0.1298677210, 1e-3) -def test__convergence_2d_from(): +def test__convergence_2d_from__config_1(): mp = ag.mp.PowerLawMultipole( m=4, centre=(0.1, 0.2), @@ -46,6 +48,8 @@ def test__convergence_2d_from(): assert convergence[0] == pytest.approx(0.25958037, 1e-3) + +def test__convergence_2d_from__config_2(): mp = ag.mp.PowerLawMultipole( m=4, centre=(0.2, 0.3),