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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 42 additions & 7 deletions test_autogalaxy/operate/test_deflections.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
)
Expand All @@ -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)
Expand All @@ -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)
)
Expand Down
29 changes: 22 additions & 7 deletions test_autogalaxy/profiles/mass/abstract/test_abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -41,14 +40,15 @@ 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
)

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(
Expand All @@ -57,14 +57,15 @@ 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
)

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(
Expand All @@ -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(
Expand All @@ -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)
)
Expand Down Expand Up @@ -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)
Expand All @@ -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(
Expand Down
Loading
Loading