def make_galaxy(): return aast.Galaxy( redshift=3, sersic=aast.lp.EllipticalSersic(), exponential=aast.lp.EllipticalExponential(), spherical=aast.mp.SphericalIsothermal(), )
def test__convergence(self, gal_data_7x7, sub_mask_7x7): galaxy_fit_data = aast.masked.galaxy_data(galaxy_data=gal_data_7x7, mask=sub_mask_7x7, use_convergence=True) galaxy = aast.Galaxy( redshift=0.5, mass=aast.mp.SphericalIsothermal(centre=(1.0, 2.0), einstein_radius=1.0), ) fit = aast.fit_galaxy(galaxy_data=galaxy_fit_data, model_galaxies=[galaxy]) assert fit.model_galaxies == [galaxy] model_data = galaxy.convergence_from_grid(grid=galaxy_fit_data.grid) residual_map = aa.util.fit.residual_map_from_data_and_model_data( data=galaxy_fit_data.image, model_data=model_data.in_1d_binned) assert residual_map == pytest.approx(fit.residual_map, 1e-4) chi_squared_map = aa.util.fit.chi_squared_map_from_residual_map_and_noise_map( residual_map=residual_map, noise_map=galaxy_fit_data.noise_map) assert chi_squared_map == pytest.approx(fit.chi_squared_map, 1e-4) chi_squared = aa.util.fit.chi_squared_from_chi_squared_map( chi_squared_map=chi_squared_map) noise_normalization = aa.util.fit.noise_normalization_from_noise_map( noise_map=galaxy_fit_data.noise_map) likelihood = aa.util.fit.likelihood_from_chi_squared_and_noise_normalization( chi_squared=chi_squared, noise_normalization=noise_normalization) assert likelihood == pytest.approx(fit.likelihood, 1e-4)
def test__image(self, gal_data_7x7, sub_mask_7x7): galaxy_fit_data = aast.masked_galaxy_data(galaxy_data=gal_data_7x7, mask=sub_mask_7x7, use_image=True) galaxy = aast.Galaxy( redshift=0.5, light=aast.lp.SphericalSersic(centre=(1.0, 2.0), intensity=1.0), ) fit = aast.fit_galaxy(galaxy_data=galaxy_fit_data, model_galaxies=[galaxy]) assert fit.model_galaxies == [galaxy] model_data = galaxy.profile_image_from_grid(grid=galaxy_fit_data.grid) residual_map = aa.util.fit.residual_map_from_data_and_model_data( data=galaxy_fit_data.image, model_data=model_data.in_1d_binned) assert residual_map == pytest.approx(fit.residual_map, 1e-4) chi_squared_map = aa.util.fit.chi_squared_map_from_residual_map_and_noise_map( residual_map=residual_map, noise_map=galaxy_fit_data.noise_map) assert chi_squared_map == pytest.approx(fit.chi_squared_map, 1e-4) chi_squared = aa.util.fit.chi_squared_from_chi_squared_map( chi_squared_map=chi_squared_map) noise_normalization = aa.util.fit.noise_normalization_from_noise_map( noise_map=galaxy_fit_data.noise_map) likelihood = aa.util.fit.likelihood_from_chi_squared_and_noise_normalization( chi_squared=chi_squared, noise_normalization=noise_normalization) assert likelihood == pytest.approx(fit.likelihood, 1e-4)
def test__convergence_bounding_box__mass_profiles_are_only_point_masses__uses_their_einstein_radii( self): point_mass_0 = aast.mp.PointMass(einstein_radius=0.1) convergence_bounding_box = point_mass_0.convergence_bounding_box() assert convergence_bounding_box == pytest.approx( [-0.3, 0.3, -0.3, 0.3], 1.0e-4) galaxy = MockGalaxy(mass_profiles=[point_mass_0]) convergence_bounding_box = galaxy.convergence_bounding_box() assert convergence_bounding_box == pytest.approx( [-0.3, 0.3, -0.3, 0.3], 1.0e-4) point_mass_1 = aast.mp.PointMass(einstein_radius=0.3) galaxy = MockGalaxy(mass_profiles=[point_mass_0, point_mass_1]) convergence_bounding_box = galaxy.convergence_bounding_box() assert convergence_bounding_box == pytest.approx( [-1.2, 1.2, -1.2, 1.2], 1.0e-4) sis_0 = aast.mp.SphericalIsothermal(einstein_radius=2.0) galaxy = aast.Galaxy(redshift=0.5, point0=point_mass_0, point1=point_mass_1, sis0=sis_0) convergence_bounding_box = galaxy.convergence_bounding_box() assert convergence_bounding_box != pytest.approx( [-1.2, 1.2, -1.2, 1.2], 1.0e-4)
def make_gal_x2_mp(mp_0, mp_1): return aast.Galaxy(redshift=0.5, mass_profile_0=mp_0, mass_profile_1=mp_1)
def make_gal_x1_mp(mp_0): return aast.Galaxy(redshift=0.5, mass_profile_0=mp_0)
def make_gal_x2_lp(lp_0, lp_1): return aast.Galaxy(redshift=0.5, light_profile_0=lp_0, light_profile_1=lp_1)
def make_gal_x1_lp(lp_0): return aast.Galaxy(redshift=0.5, light_profile_0=lp_0)
def test__gal_data_7x7_deflections_x(self, gal_data_7x7, sub_mask_7x7): galaxy_fit_data = aast.masked_galaxy_data( galaxy_data=gal_data_7x7, mask=sub_mask_7x7, use_deflections_x=True ) assert galaxy_fit_data.pixel_scales == (1.0, 1.0) assert (galaxy_fit_data.galaxy_data.image.in_2d == np.ones((7, 7))).all() assert ( galaxy_fit_data.galaxy_data.noise_map.in_2d == 2.0 * np.ones((7, 7)) ).all() assert (galaxy_fit_data.image.in_1d == np.ones(9)).all() assert (galaxy_fit_data.noise_map.in_1d == 2.0 * np.ones(9)).all() assert ( galaxy_fit_data.mask == np.array( [ [True, True, True, True, True, True, True], [True, True, True, True, True, True, True], [True, True, False, False, False, True, True], [True, True, False, False, False, True, True], [True, True, False, False, False, True, True], [True, True, True, True, True, True, True], [True, True, True, True, True, True, True], ] ) ).all() assert ( galaxy_fit_data.image.in_2d == np.array( [ [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 0.0], [0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 0.0], [0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], ] ) ).all() assert ( galaxy_fit_data.noise_map.in_2d == np.array( [ [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 2.0, 2.0, 2.0, 0.0, 0.0], [0.0, 0.0, 2.0, 2.0, 2.0, 0.0, 0.0], [0.0, 0.0, 2.0, 2.0, 2.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], ] ) ).all() galaxy = mock_galaxy.MockGalaxy(value=1, shape=36) deflections_x = galaxy_fit_data.profile_quantity_from_galaxies( galaxies=[galaxy] ) assert (deflections_x.in_1d_binned == np.ones(9)).all() galaxy = aast.Galaxy( redshift=0.5, mass=aast.mp.SphericalIsothermal(einstein_radius=1.0) ) deflections_gal = galaxy.deflections_from_grid(grid=galaxy_fit_data.grid) deflections_gal = np.asarray( [ galaxy_fit_data.grid.mapping.array_stored_1d_binned_from_sub_array_1d( deflections_gal[:, 0] ), galaxy_fit_data.grid.mapping.array_stored_1d_binned_from_sub_array_1d( deflections_gal[:, 1] ), ] ).T deflections_gd = galaxy_fit_data.profile_quantity_from_galaxies( galaxies=[galaxy] ) assert (deflections_gal[:, 1] == deflections_gd.in_1d_binned).all()
def test__gal_data_7x7_potential(self, gal_data_7x7, sub_mask_7x7): galaxy_fit_data = aast.masked_galaxy_data( galaxy_data=gal_data_7x7, mask=sub_mask_7x7, use_potential=True ) assert galaxy_fit_data.pixel_scales == (1.0, 1.0) assert (galaxy_fit_data.galaxy_data.image.in_2d == np.ones((7, 7))).all() assert ( galaxy_fit_data.galaxy_data.noise_map.in_2d == 2.0 * np.ones((7, 7)) ).all() assert (galaxy_fit_data.image.in_1d == np.ones(9)).all() assert (galaxy_fit_data.noise_map.in_1d == 2.0 * np.ones(9)).all() assert ( galaxy_fit_data.mask == np.array( [ [True, True, True, True, True, True, True], [True, True, True, True, True, True, True], [True, True, False, False, False, True, True], [True, True, False, False, False, True, True], [True, True, False, False, False, True, True], [True, True, True, True, True, True, True], [True, True, True, True, True, True, True], ] ) ).all() assert ( galaxy_fit_data.image.in_2d == np.array( [ [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 0.0], [0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 0.0], [0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], ] ) ).all() assert ( galaxy_fit_data.noise_map.in_2d == np.array( [ [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 2.0, 2.0, 2.0, 0.0, 0.0], [0.0, 0.0, 2.0, 2.0, 2.0, 0.0, 0.0], [0.0, 0.0, 2.0, 2.0, 2.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], ] ) ).all() galaxy = mock_galaxy.MockGalaxy(value=1, shape=36) potential = galaxy_fit_data.profile_quantity_from_galaxies(galaxies=[galaxy]) assert (potential.in_1d_binned == np.ones(9)).all() galaxy = aast.Galaxy( redshift=0.5, mass=aast.mp.SphericalIsothermal(einstein_radius=1.0) ) potential_gal = galaxy.potential_from_grid(grid=galaxy_fit_data.grid) potential_gd = galaxy_fit_data.profile_quantity_from_galaxies(galaxies=[galaxy]) assert (potential_gal == potential_gd).all()
def test__gal_data_7x7_image(self, gal_data_7x7, sub_mask_7x7): galaxy_fit_data = aast.masked_galaxy_data( galaxy_data=gal_data_7x7, mask=sub_mask_7x7, use_image=True ) assert galaxy_fit_data.pixel_scales == (1.0, 1.0) assert (galaxy_fit_data.galaxy_data.image.in_2d == np.ones((7, 7))).all() assert ( galaxy_fit_data.galaxy_data.noise_map.in_2d == 2.0 * np.ones((7, 7)) ).all() assert (galaxy_fit_data.image.in_1d == np.ones(9)).all() assert (galaxy_fit_data.noise_map.in_1d == 2.0 * np.ones(9)).all() assert ( galaxy_fit_data.mask == np.array( [ [True, True, True, True, True, True, True], [True, True, True, True, True, True, True], [True, True, False, False, False, True, True], [True, True, False, False, False, True, True], [True, True, False, False, False, True, True], [True, True, True, True, True, True, True], [True, True, True, True, True, True, True], ] ) ).all() assert ( galaxy_fit_data.image.in_2d == np.array( [ [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 0.0], [0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 0.0], [0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], ] ) ).all() assert ( galaxy_fit_data.noise_map.in_2d == np.array( [ [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 2.0, 2.0, 2.0, 0.0, 0.0], [0.0, 0.0, 2.0, 2.0, 2.0, 0.0, 0.0], [0.0, 0.0, 2.0, 2.0, 2.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], ] ) ).all() galaxy = mock_galaxy.MockGalaxy(value=1, shape=36) image = galaxy_fit_data.profile_quantity_from_galaxies(galaxies=[galaxy]) assert (image.in_1d_binned == np.ones(9)).all() galaxy = aast.Galaxy(redshift=0.5, light=aast.lp.SphericalSersic(intensity=1.0)) image_gal = galaxy.profile_image_from_grid(grid=galaxy_fit_data.grid) image_gd = galaxy_fit_data.profile_quantity_from_galaxies(galaxies=[galaxy]) assert (image_gal == image_gd).all()