def test__intensity_from_grid__correct_values(self): exponential = aast.lp.EllipticalExponential( axis_ratio=0.5, phi=0.0, intensity=3.0, effective_radius=2.0 ) assert exponential.profile_image_from_grid( grid=aa.grid_irregular.manual_1d([[1.0, 0.0]]) ) == pytest.approx(4.9047, 1e-3) exponential = aast.lp.EllipticalExponential( axis_ratio=0.5, phi=90.0, intensity=2.0, effective_radius=3.0 ) assert exponential.profile_image_from_grid( grid=aa.grid_irregular.manual_1d([[0.0, 1.0]]) ) == pytest.approx(4.8566, 1e-3) exponential = aast.lp.EllipticalExponential( axis_ratio=0.5, phi=90.0, intensity=4.0, effective_radius=3.0 ) assert exponential.profile_image_from_grid( grid=aa.grid_irregular.manual_1d([[0.0, 1.0]]) ) == pytest.approx(2.0 * 4.8566, 1e-3) value = exponential.profile_image_from_grid(grid=aa.coordinates([[(0.0, 1.0)]])) assert value[0][0] == pytest.approx(2.0 * 4.8566, 1e-3)
def test__intensity_from_grid__correct_values(self): dev_vaucouleurs = aast.lp.EllipticalDevVaucouleurs( axis_ratio=0.5, phi=0.0, intensity=3.0, effective_radius=2.0 ) assert dev_vaucouleurs.profile_image_from_grid( grid=aa.grid_irregular.manual_1d([[1.0, 0.0]]) ) == pytest.approx(5.6697, 1e-3) dev_vaucouleurs = aast.lp.EllipticalDevVaucouleurs( axis_ratio=0.5, phi=90.0, intensity=2.0, effective_radius=3.0 ) assert dev_vaucouleurs.profile_image_from_grid( grid=aa.grid_irregular.manual_1d([[0.0, 1.0]]) ) == pytest.approx(7.4455, 1e-3) dev_vaucouleurs = aast.lp.EllipticalDevVaucouleurs( axis_ratio=0.5, phi=90.0, intensity=4.0, effective_radius=3.0 ) assert dev_vaucouleurs.profile_image_from_grid( grid=aa.grid_irregular.manual_1d([[0.0, 1.0]]) ) == pytest.approx(2.0 * 7.4455, 1e-3) value = dev_vaucouleurs.profile_image_from_grid( grid=aa.coordinates([[(0.0, 1.0)]]) ) assert value[0][0] == pytest.approx(2.0 * 7.4455, 1e-3)
def test__potential__correct_values(self): mass_sheet = aast.mp.MassSheet(centre=(0.0, 0.0), kappa=1.0) potential = mass_sheet.potential_from_grid( grid=aa.grid_irregular.manual_1d([[1.0, 0.0], [3.0, 3.0], [5.0, -9.0]])) assert potential[0] == pytest.approx(0.0, 1e-3) assert potential[1] == pytest.approx(0.0, 1e-3) assert potential[2] == pytest.approx(0.0, 1e-3) mass_sheet = aast.mp.MassSheet(centre=(0.0, 0.0), kappa=1.0) potential = mass_sheet.potential_from_grid(grid=aa.grid.manual_2d( [[[1.0, 0.0], [1.0, 0.0]], [[1.0, 0.0], [1.0, 0.0]]], sub_size=2, pixel_scales=(1.0, 1.0), )) assert potential[0] == pytest.approx(0.0, 1e-3) assert potential[1] == pytest.approx(0.0, 1e-3) assert potential[2] == pytest.approx(0.0, 1e-3) assert potential[3] == pytest.approx(0.0, 1e-3) potential = mass_sheet.potential_from_grid( grid=aa.coordinates([[(1.0, 0.0)]])) assert potential[0][0] == pytest.approx(0.0, 1e-3)
def test__potential_returns_zeros(self): shear = aast.mp.ExternalShear(magnitude=0.1, phi=45.0) potential = shear.potential_from_grid( grid=aa.grid_irregular.manual_1d([[0.1, 0.1]])) assert (potential == np.array([[0.0, 0.0]])).all() shear = aast.mp.ExternalShear(magnitude=0.1, phi=45.0) potential = shear.potential_from_grid(grid=aa.grid_irregular.manual_1d( [[0.1, 0.1], [0.2, 0.2], [0.3, 0.3]])) assert (potential == np.array([0.0, 0.0, 0.0])).all() potential = shear.potential_from_grid(grid=aa.grid.manual_2d( [[[1.0, 0.0], [1.0, 0.0]], [[1.0, 0.0], [1.0, 0.0]]], sub_size=2, pixel_scales=(1.0, 1.0), )) assert potential[0] == pytest.approx(0.0, 1e-3) assert potential[1] == pytest.approx(0.0, 1e-3) assert potential[2] == pytest.approx(0.0, 1e-3) assert potential[3] == pytest.approx(0.0, 1e-3) potential = shear.potential_from_grid(grid=aa.coordinates([[(1.0, 0.0)]])) assert potential[0][0] == pytest.approx(0.0, 1e-3)
def test__profile_axis_ratio_1__r_is_root_2__therefore_ecccentric_radius_is_elliptical_radius_is_root_2( self): elliptical_profile = geometry_profiles.EllipticalProfile( axis_ratio=1.0, phi=0.0) eccentric_radius = elliptical_profile.grid_to_eccentric_radii( aa.grid_irregular.manual_1d([[1.0, 1.0]])) assert eccentric_radius == pytest.approx(2.0**0.5, 1e-3) eccentric_radius = elliptical_profile.grid_to_eccentric_radii( aa.coordinates([[(1.0, 1.0)]])) assert eccentric_radius[0][0] == pytest.approx(2.0**0.5, 1e-3)
def test__intensity_from_grid__correct_values(self): sersic = aast.lp.EllipticalSersic( axis_ratio=0.5, phi=0.0, intensity=3.0, effective_radius=2.0, sersic_index=2.0, ) assert sersic.profile_image_from_grid( grid=aa.grid_irregular.manual_1d([[1.0, 0.0]]) ) == pytest.approx(5.38066670129, 1e-3) value = sersic.profile_image_from_grid(grid=aa.coordinates([[(1.0, 0.0)]])) assert value[0][0] == pytest.approx(5.38066670129, 1e-3)
def test__intensity_from_grid__same_values_as_above(self): gaussian = aast.lp.EllipticalGaussian( centre=(0.0, 0.0), axis_ratio=1.0, phi=0.0, intensity=1.0, sigma=1.0 ) assert gaussian.profile_image_from_grid( grid=aa.grid_irregular.manual_1d([[0.0, 1.0]]) ) == pytest.approx(0.24197, 1e-2) gaussian = aast.lp.EllipticalGaussian( centre=(0.0, 0.0), axis_ratio=1.0, phi=0.0, intensity=2.0, sigma=1.0 ) assert gaussian.profile_image_from_grid( grid=aa.grid_irregular.manual_1d([[0.0, 1.0]]) ) == pytest.approx(2.0 * 0.24197, 1e-2) gaussian = aast.lp.EllipticalGaussian( centre=(0.0, 0.0), axis_ratio=1.0, phi=0.0, intensity=1.0, sigma=2.0 ) assert gaussian.profile_image_from_grid( grid=aa.grid_irregular.manual_1d([[0.0, 1.0]]) ) == pytest.approx(0.1760, 1e-2) gaussian = aast.lp.EllipticalGaussian( centre=(0.0, 0.0), axis_ratio=1.0, phi=0.0, intensity=1.0, sigma=2.0 ) assert gaussian.profile_image_from_grid( grid=aa.grid_irregular.manual_1d([[0.0, 3.0]]) ) == pytest.approx(0.0647, 1e-2) value = gaussian.profile_image_from_grid( grid=aa.coordinates(coordinates=[[(0.0, 3.0)]]) ) assert value[0][0] == pytest.approx(0.0647, 1e-2)
def test__deflections_correct_values(self): shear = aast.mp.ExternalShear(magnitude=0.1, phi=45.0) deflections = shear.deflections_from_grid( grid=aa.grid_irregular.manual_1d([[0.1625, 0.1625]])) assert deflections[0, 0] == pytest.approx(0.01625, 1e-3) assert deflections[0, 1] == pytest.approx(0.01625, 1e-3) shear = aast.mp.ExternalShear(magnitude=0.2, phi=75.0) deflections = shear.deflections_from_grid( grid=aa.grid_irregular.manual_1d([[0.1625, 0.1625]])) assert deflections[0, 0] == pytest.approx(0.04439, 1e-3) assert deflections[0, 1] == pytest.approx(-0.011895, 1e-3) deflections = shear.deflections_from_grid(grid=aa.grid.manual_2d( [ [[0.1625, 0.1625], [0.1625, 0.1625]], [[0.1625, 0.1625], [0.1625, 0.1625]], ], sub_size=2, pixel_scales=(1.0, 1.0), )) assert deflections[0, 0] == pytest.approx(0.04439, 1e-3) assert deflections[1, 0] == pytest.approx(0.04439, 1e-3) assert deflections[2, 0] == pytest.approx(0.04439, 1e-3) assert deflections[3, 0] == pytest.approx(0.04439, 1e-3) assert deflections[0, 1] == pytest.approx(-0.011895, 1e-3) assert deflections[1, 1] == pytest.approx(-0.011895, 1e-3) assert deflections[2, 1] == pytest.approx(-0.011895, 1e-3) assert deflections[3, 1] == pytest.approx(-0.011895, 1e-3) deflections = shear.deflections_from_grid( grid=aa.coordinates([[(0.1625, 0.1625)]])) assert deflections[0][0][0] == pytest.approx(0.04439, 1e-3) assert deflections[0][0][1] == pytest.approx(-0.011895, 1e-3)
def make_positions_7x7(): return aa.coordinates(coordinates=[[(0.1, 0.1), (0.2, 0.2)], [(0.3, 0.3)]])
def test__deflections__correct_values(self): mass_sheet = aast.mp.MassSheet(centre=(0.0, 0.0), kappa=1.0) deflections = mass_sheet.deflections_from_grid( grid=aa.grid_irregular.manual_1d([[1.0, 0.0]])) assert deflections[0, 0] == pytest.approx(1.0, 1e-3) assert deflections[0, 1] == pytest.approx(0.0, 1e-3) deflections = mass_sheet.deflections_from_grid( grid=aa.grid_irregular.manual_1d([[2.0, 0.0]])) assert deflections[0, 0] == pytest.approx(2.0, 1e-3) assert deflections[0, 1] == pytest.approx(0.0, 1e-3) mass_sheet = aast.mp.MassSheet(centre=(0.0, 0.0), kappa=-1.0) deflections = mass_sheet.deflections_from_grid( grid=aa.grid_irregular.manual_1d([[1.0, 0.0]])) assert deflections[0, 0] == pytest.approx(-1.0, 1e-3) assert deflections[0, 1] == pytest.approx(0.0, 1e-3) deflections = mass_sheet.deflections_from_grid( grid=aa.grid_irregular.manual_1d([[2.0, 0.0]])) assert deflections[0, 0] == pytest.approx(-2.0, 1e-3) assert deflections[0, 1] == pytest.approx(0.0, 1e-3) mass_sheet = aast.mp.MassSheet(centre=(0.0, 0.0), kappa=2.0) deflections = mass_sheet.deflections_from_grid( grid=aa.grid_irregular.manual_1d([[2.0, 0.0]])) assert deflections[0, 0] == pytest.approx(4.0, 1e-3) assert deflections[0, 1] == pytest.approx(0.0, 1e-3) mass_sheet = aast.mp.MassSheet(centre=(0.0, 0.0), kappa=1.0) # 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 deflections = mass_sheet.deflections_from_grid( grid=aa.grid_irregular.manual_1d([[1.0, 1.0]])) assert deflections[0, 0] == pytest.approx(1.0, 1e-3) assert deflections[0, 1] == pytest.approx(1.0, 1e-3) mass_sheet = aast.mp.MassSheet(centre=(0.0, 0.0), kappa=2.0) deflections = mass_sheet.deflections_from_grid( grid=aa.grid_irregular.manual_1d([[1.0, 1.0]])) assert deflections[0, 0] == pytest.approx(2.0, 1e-3) assert deflections[0, 1] == pytest.approx(2.0, 1e-3) mass_sheet = aast.mp.MassSheet(centre=(0.0, 0.0), kappa=2.0) deflections = mass_sheet.deflections_from_grid( grid=aa.grid_irregular.manual_1d([[2.0, 2.0]])) assert deflections[0, 0] == pytest.approx(4.0, 1e-3) assert deflections[0, 1] == pytest.approx(4.0, 1e-3) mass_sheet = aast.mp.MassSheet(centre=(0.0, 0.0), kappa=1.0) # The radial coordinate at (2.0, 1.0) is sqrt(5) # This gives an angle of 26.5650512 degrees between the 1.0 and np.sqrt(5) of the triangle # This is decomposed into y angle of cos(26.5650512 degrees) = 0.8944271 # This is decomposed into x angle of sin(26.5650512 degrees) = 0.4472135 # Thus, for a mass sheet, the deflection angles are: deflections = mass_sheet.deflections_from_grid( grid=aa.grid_irregular.manual_1d([[2.0, 1.0]])) 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) deflections = mass_sheet.deflections_from_grid( grid=aa.grid_irregular.manual_1d([[-1.0, -1.0]])) assert deflections[0, 0] == pytest.approx(-1.0, 1e-3) assert deflections[0, 1] == pytest.approx(-1.0, 1e-3) mass_sheet = aast.mp.MassSheet(centre=(1.0, 2.0), kappa=1.0) deflections = mass_sheet.deflections_from_grid( grid=aa.grid_irregular.manual_1d([[2.0, 3.0]])) assert deflections[0, 0] == pytest.approx(1.0, 1e-3) assert deflections[0, 1] == pytest.approx(1.0, 1e-3) mass_sheet = aast.mp.MassSheet(centre=(1.0, 2.0), kappa=-1.0) deflections = mass_sheet.deflections_from_grid( grid=aa.grid_irregular.manual_1d([[2.0, 3.0]])) assert deflections[0, 0] == pytest.approx(-1.0, 1e-3) assert deflections[0, 1] == pytest.approx(-1.0, 1e-3) mass_sheet = aast.mp.MassSheet(centre=(0.0, 0.0), kappa=1.0) deflections = mass_sheet.deflections_from_grid(grid=aa.grid.manual_2d( [[[1.0, 0.0], [1.0, 0.0]], [[1.0, 0.0], [1.0, 0.0]]], sub_size=2, pixel_scales=(1.0, 1.0), )) assert deflections[0, 0] == pytest.approx(1.0, 1e-3) assert deflections[1, 0] == pytest.approx(1.0, 1e-3) assert deflections[2, 0] == pytest.approx(1.0, 1e-3) assert deflections[3, 0] == pytest.approx(1.0, 1e-3) assert deflections[0, 1] == pytest.approx(0.0, 1e-3) assert deflections[1, 1] == pytest.approx(0.0, 1e-3) assert deflections[2, 1] == pytest.approx(0.0, 1e-3) assert deflections[3, 1] == pytest.approx(0.0, 1e-3) deflections = mass_sheet.deflections_from_grid( grid=aa.coordinates([[(1.0, 0.0)]])) assert deflections[0][0][0] == pytest.approx(1.0, 1e-3) assert deflections[0][0][1] == pytest.approx(0.0, 1e-3)