def test__unit_luminosity__extracted_from_profile(self): profile = MockDimensionsProfile( luminosity=al.Luminosity(value=3.0, unit_luminosity="eps"), mass_over_luminosity=al.MassOverLuminosity( value=3.0, unit_luminosity="eps" ), ) assert profile.unit_luminosity == "eps" profile = MockDimensionsProfile( luminosity=1.0, mass_over_luminosity=al.MassOverLuminosity( value=3.0, unit_luminosity="eps" ), ) assert profile.unit_luminosity == "eps" profile = MockDimensionsProfile( luminosity=al.Luminosity(value=3.0, unit_luminosity="eps"), mass_over_luminosity=1.0, ) assert profile.unit_luminosity == "eps" profile = MockDimensionsProfile( luminosity=al.Luminosity(value=3.0, unit_luminosity="counts"), mass_over_luminosity=al.MassOverLuminosity( value=3.0, unit_luminosity="counts" ), ) assert profile.unit_luminosity == "counts" profile = MockDimensionsProfile( luminosity=1.0, mass_over_luminosity=al.MassOverLuminosity( value=3.0, unit_luminosity="counts" ), ) assert profile.unit_luminosity == "counts" profile = MockDimensionsProfile( luminosity=al.Luminosity(value=3.0, unit_luminosity="counts"), mass_over_luminosity=1.0, ) assert profile.unit_luminosity == "counts" profile = MockDimensionsProfile(luminosity=1.0, mass_over_luminosity=1.0) assert profile.unit_luminosity == None
def test__luminosity_units_conversions__uses_exposure_time(self): sersic_eps = al.light_profiles.SphericalSersic(intensity=al.Luminosity( 3.0, "eps"), effective_radius=2.0, sersic_index=1.0) radius = al.Length(0.5, "arcsec") luminosity_analytic = luminosity_from_radius_and_profile( radius=radius, profile=sersic_eps) luminosity_integral = sersic_eps.luminosity_within_circle_in_units( radius=radius, unit_luminosity="eps", exposure_time=3.0) # eps -> eps assert luminosity_analytic == pytest.approx(luminosity_integral, 1e-3) # eps -> counts luminosity_integral = sersic_eps.luminosity_within_circle_in_units( radius=radius, unit_luminosity="counts", exposure_time=3.0) assert 3.0 * luminosity_analytic == pytest.approx( luminosity_integral, 1e-3) sersic_counts = al.light_profiles.SphericalSersic( intensity=al.Luminosity(3.0, "counts"), effective_radius=2.0, sersic_index=1.0, ) radius = al.Length(0.5, "arcsec") luminosity_analytic = luminosity_from_radius_and_profile( radius=radius, profile=sersic_counts) luminosity_integral = sersic_counts.luminosity_within_circle_in_units( radius=radius, unit_luminosity="eps", exposure_time=3.0) # counts -> eps assert luminosity_analytic / 3.0 == pytest.approx( luminosity_integral, 1e-3) luminosity_integral = sersic_counts.luminosity_within_circle_in_units( radius=radius, unit_luminosity="counts", exposure_time=3.0) # counts -> counts assert luminosity_analytic == pytest.approx(luminosity_integral, 1e-3)
def test__conversions_from_eps_and_counts_and_back__errors_raised_if_no_exposure_time( self ): unit_eps = al.Luminosity(value=2.0) assert unit_eps == 2.0 assert unit_eps.unit_luminosity == "eps" unit_eps = unit_eps.convert(unit_luminosity="eps") assert unit_eps == 2.0 assert unit_eps.unit == "eps" unit_counts = unit_eps.convert(unit_luminosity="counts", exposure_time=2.0) assert unit_counts == 4.0 assert unit_counts.unit == "counts" unit_counts = unit_counts.convert(unit_luminosity="counts") assert unit_counts == 4.0 assert unit_counts.unit == "counts" unit_eps = unit_counts.convert(unit_luminosity="eps", exposure_time=2.0) assert unit_eps == 2.0 assert unit_eps.unit == "eps" with pytest.raises(exc.UnitsException): unit_eps.convert(unit_luminosity="counts") unit_counts.convert(unit_luminosity="eps") unit_eps.convert(unit_luminosity="lol")
def unit_luminosity_calc( self, luminosity_input: al.Luminosity = None, redshift_profile=None, cosmology=MockCosmology(), unit_luminosity="eps", exposure_time: float = None, **kwargs ): return al.Luminosity(self.luminosity + luminosity_input, self.unit_luminosity)
def test__mass_conversion_requires_critical_surface_density_but_does_not_supply_it_raises_error( self ): profile_angular = MockDimensionsProfile( position=(al.Length(1.0, "arcsec"), al.Length(2.0, "arcsec")), param_float=2.0, length=al.Length(value=3.0, unit_length="arcsec"), luminosity=al.Luminosity(value=4.0, unit_luminosity="eps"), mass=al.Mass(value=5.0, unit_mass="angular"), mass_over_luminosity=al.MassOverLuminosity( value=6.0, unit_luminosity="eps", unit_mass="angular" ), ) with pytest.raises(exc.UnitsException): profile_angular.new_profile_with_units_converted(unit_mass="solMass") profile_solMass = profile_angular.new_profile_with_units_converted( unit_mass="solMass", critical_surface_density=10.0 ) with pytest.raises(exc.UnitsException): profile_solMass.new_profile_with_units_converted(unit_mass="angular")
def test__profile_luminosity_units_calculations__profile_is_converted_for_calculation_if_different_to_input_units( self ): profile = MockDimensionsProfile(luminosity=al.Luminosity(3.0, "eps")) cosmo = MockCosmology() # luminosity: eps -> eps, stays 3.0, luminosity_input: eps -> eps, stays 1.0 luminosity_input = al.Luminosity(1.0, "eps") luminosity = profile.unit_luminosity_calc( luminosity_input=luminosity_input, unit_luminosity="eps" ) assert luminosity.unit_luminosity == "eps" assert luminosity == 4.0 # luminosity: eps -> eps, stays 3.0, luminosity_input counts -> eps, converts to 1.0 / 2.0 = 0.5 luminosity_input = al.Luminosity(1.0, "counts") luminosity = profile.unit_luminosity_calc( luminosity_input=luminosity_input, unit_luminosity="eps", redshift_profile=0.5, cosmology=cosmo, exposure_time=2.0, ) assert luminosity.unit_luminosity == "eps" assert luminosity == 3.5 # luminosity: eps -> counts, converts to 3.0 * 2.0 = 6.0, luminosity_input counts -> counts, stays 1.0 luminosity_input = al.Luminosity(1.0, "counts") luminosity = profile.unit_luminosity_calc( luminosity_input=luminosity_input, unit_luminosity="counts", redshift_profile=0.5, cosmology=cosmo, exposure_time=2.0, ) assert luminosity.unit_luminosity == "counts" assert luminosity == 7.0 profile = MockDimensionsProfile(luminosity=al.Luminosity(3.0, "counts")) # luminosity: counts -> counts, stays 3.0, luminosity_input: counts -> counts, stays 1.0 luminosity_input = al.Luminosity(1.0, "counts") luminosity = profile.unit_luminosity_calc( luminosity_input=luminosity_input, unit_luminosity="counts", redshift_profile=0.5, cosmology=cosmo, exposure_time=2.0, ) assert luminosity.unit_luminosity == "counts" assert luminosity == 4.0 # luminosity: counts -> counts, stays 3.0, luminosity_input: eps -> counts, convert to 1.0 * 2.0 = 2.0 luminosity_input = al.Luminosity(1.0, "eps") luminosity = profile.unit_luminosity_calc( luminosity_input=luminosity_input, unit_luminosity="counts", redshift_profile=0.5, cosmology=cosmo, exposure_time=2.0, ) assert luminosity.unit_luminosity == "counts" assert luminosity == 5.0 # luminosity: counts -> eps, converts to 3.0 / 2.0 = 1.5, luminosity_input: counts -> counts, stays 1.0 luminosity_input = al.Luminosity(1.0, "eps") luminosity = profile.unit_luminosity_calc( luminosity_input=luminosity_input, unit_luminosity="eps", redshift_profile=0.5, cosmology=cosmo, exposure_time=2.0, ) assert luminosity.unit_luminosity == "eps" assert luminosity == 2.5
def test__angular_to_solMass_conversions_of_mass__conversions_convert_values( self ): profile_angular = MockDimensionsProfile( position=(al.Length(1.0, "arcsec"), al.Length(2.0, "arcsec")), param_float=2.0, length=al.Length(value=3.0, unit_length="arcsec"), luminosity=al.Luminosity(value=4.0, unit_luminosity="eps"), mass=al.Mass(value=5.0, unit_mass="angular"), mass_over_luminosity=al.MassOverLuminosity( value=6.0, unit_luminosity="eps", unit_mass="angular" ), ) assert profile_angular.position == (1.0, 2.0) assert profile_angular.position[0].unit_length == "arcsec" assert profile_angular.position[1].unit_length == "arcsec" assert profile_angular.param_float == 2.0 assert profile_angular.length == 3.0 assert profile_angular.length.unit_length == "arcsec" assert profile_angular.luminosity == 4.0 assert profile_angular.luminosity.unit_luminosity == "eps" assert profile_angular.mass == 5.0 assert profile_angular.mass.unit_mass == "angular" assert profile_angular.mass_over_luminosity == 6.0 assert profile_angular.mass_over_luminosity.unit == "angular / eps" profile_angular = profile_angular.new_profile_with_units_converted( unit_mass="angular" ) assert profile_angular.position == (1.0, 2.0) assert profile_angular.position[0].unit_length == "arcsec" assert profile_angular.position[1].unit_length == "arcsec" assert profile_angular.param_float == 2.0 assert profile_angular.length == 3.0 assert profile_angular.length.unit_length == "arcsec" assert profile_angular.luminosity == 4.0 assert profile_angular.luminosity.unit_luminosity == "eps" assert profile_angular.mass == 5.0 assert profile_angular.mass.unit_mass == "angular" assert profile_angular.mass_over_luminosity == 6.0 assert profile_angular.mass_over_luminosity.unit == "angular / eps" profile_solMass = profile_angular.new_profile_with_units_converted( unit_mass="solMass", critical_surface_density=10.0 ) assert profile_solMass.position == (1.0, 2.0) assert profile_solMass.position[0].unit_length == "arcsec" assert profile_solMass.position[1].unit_length == "arcsec" assert profile_solMass.param_float == 2.0 assert profile_solMass.length == 3.0 assert profile_solMass.length.unit_length == "arcsec" assert profile_solMass.luminosity == 4.0 assert profile_solMass.luminosity.unit_luminosity == "eps" assert profile_solMass.mass == 50.0 assert profile_solMass.mass.unit_mass == "solMass" assert profile_solMass.mass_over_luminosity == pytest.approx(60.0, 1.0e-4) assert profile_solMass.mass_over_luminosity.unit == "solMass / eps" profile_solMass = profile_solMass.new_profile_with_units_converted( unit_mass="solMass" ) assert profile_solMass.position == (1.0, 2.0) assert profile_solMass.position[0].unit_length == "arcsec" assert profile_solMass.position[1].unit_length == "arcsec" assert profile_solMass.param_float == 2.0 assert profile_solMass.length == 3.0 assert profile_solMass.length.unit_length == "arcsec" assert profile_solMass.luminosity == 4.0 assert profile_solMass.luminosity.unit_luminosity == "eps" assert profile_solMass.mass == 50.0 assert profile_solMass.mass.unit_mass == "solMass" assert profile_solMass.mass_over_luminosity == pytest.approx(60.0, 1.0e-4) assert profile_solMass.mass_over_luminosity.unit == "solMass / eps" profile_angular = profile_solMass.new_profile_with_units_converted( unit_mass="angular", critical_surface_density=10.0 ) assert profile_angular.position == (1.0, 2.0) assert profile_angular.position[0].unit_length == "arcsec" assert profile_angular.position[1].unit_length == "arcsec" assert profile_angular.param_float == 2.0 assert profile_angular.length == 3.0 assert profile_angular.length.unit_length == "arcsec" assert profile_angular.luminosity == 4.0 assert profile_angular.luminosity.unit_luminosity == "eps" assert profile_angular.mass == 5.0 assert profile_angular.mass.unit_mass == "angular" assert profile_angular.mass_over_luminosity == pytest.approx(6.0, 1.0e-4) assert profile_angular.mass_over_luminosity.unit == "angular / eps"
def test__eps_to_counts_conversions_of_luminosity__conversions_convert_values( self ): profile_eps = MockDimensionsProfile( position=(al.Length(1.0, "arcsec"), al.Length(2.0, "arcsec")), param_float=2.0, length=al.Length(value=3.0, unit_length="arcsec"), luminosity=al.Luminosity(value=4.0, unit_luminosity="eps"), mass=al.Mass(value=5.0, unit_mass="angular"), mass_over_luminosity=al.MassOverLuminosity( value=6.0, unit_luminosity="eps", unit_mass="angular" ), ) assert profile_eps.position == (1.0, 2.0) assert profile_eps.position[0].unit_length == "arcsec" assert profile_eps.position[1].unit_length == "arcsec" assert profile_eps.param_float == 2.0 assert profile_eps.length == 3.0 assert profile_eps.length.unit_length == "arcsec" assert profile_eps.luminosity == 4.0 assert profile_eps.luminosity.unit_luminosity == "eps" assert profile_eps.mass == 5.0 assert profile_eps.mass.unit_mass == "angular" assert profile_eps.mass_over_luminosity == 6.0 assert profile_eps.mass_over_luminosity.unit == "angular / eps" profile_eps = profile_eps.new_profile_with_units_converted( unit_luminosity="eps" ) assert profile_eps.position == (1.0, 2.0) assert profile_eps.position[0].unit_length == "arcsec" assert profile_eps.position[1].unit_length == "arcsec" assert profile_eps.param_float == 2.0 assert profile_eps.length == 3.0 assert profile_eps.length.unit_length == "arcsec" assert profile_eps.luminosity == 4.0 assert profile_eps.luminosity.unit_luminosity == "eps" assert profile_eps.mass == 5.0 assert profile_eps.mass.unit_mass == "angular" assert profile_eps.mass_over_luminosity == 6.0 assert profile_eps.mass_over_luminosity.unit == "angular / eps" profile_counts = profile_eps.new_profile_with_units_converted( unit_luminosity="counts", exposure_time=10.0 ) assert profile_counts.position == (1.0, 2.0) assert profile_counts.position[0].unit_length == "arcsec" assert profile_counts.position[1].unit_length == "arcsec" assert profile_counts.param_float == 2.0 assert profile_counts.length == 3.0 assert profile_counts.length.unit_length == "arcsec" assert profile_counts.luminosity == 40.0 assert profile_counts.luminosity.unit_luminosity == "counts" assert profile_counts.mass == 5.0 assert profile_counts.mass.unit_mass == "angular" assert profile_counts.mass_over_luminosity == pytest.approx(0.6, 1.0e-4) assert profile_counts.mass_over_luminosity.unit == "angular / counts" profile_counts = profile_counts.new_profile_with_units_converted( unit_luminosity="counts" ) assert profile_counts.position == (1.0, 2.0) assert profile_counts.position[0].unit_length == "arcsec" assert profile_counts.position[1].unit_length == "arcsec" assert profile_counts.param_float == 2.0 assert profile_counts.length == 3.0 assert profile_counts.length.unit_length == "arcsec" assert profile_counts.luminosity == 40.0 assert profile_counts.luminosity.unit_luminosity == "counts" assert profile_counts.mass == 5.0 assert profile_counts.mass.unit_mass == "angular" assert profile_counts.mass_over_luminosity == pytest.approx(0.6, 1.0e-4) assert profile_counts.mass_over_luminosity.unit == "angular / counts" profile_eps = profile_counts.new_profile_with_units_converted( unit_luminosity="eps", exposure_time=10.0 ) assert profile_eps.position == (1.0, 2.0) assert profile_eps.position[0].unit_length == "arcsec" assert profile_eps.position[1].unit_length == "arcsec" assert profile_eps.param_float == 2.0 assert profile_eps.length == 3.0 assert profile_eps.length.unit_length == "arcsec" assert profile_eps.luminosity == 4.0 assert profile_eps.luminosity.unit_luminosity == "eps" assert profile_eps.mass == 5.0 assert profile_eps.mass.unit_mass == "angular" assert profile_eps.mass_over_luminosity == pytest.approx(6.0, 1.0e-4) assert profile_eps.mass_over_luminosity.unit == "angular / eps"
def test__arcsec_to_kpc_conversions_of_length__float_and_tuple_length__conversion_converts_values( self ): profile_arcsec = MockDimensionsProfile( position=(al.Length(1.0, "arcsec"), al.Length(2.0, "arcsec")), param_float=2.0, length=al.Length(value=3.0, unit_length="arcsec"), luminosity=al.Luminosity(value=4.0, unit_luminosity="eps"), mass=al.Mass(value=5.0, unit_mass="angular"), mass_over_luminosity=al.MassOverLuminosity( value=6.0, unit_luminosity="eps", unit_mass="angular" ), ) assert profile_arcsec.position == (1.0, 2.0) assert profile_arcsec.position[0].unit_length == "arcsec" assert profile_arcsec.position[1].unit_length == "arcsec" assert profile_arcsec.param_float == 2.0 assert profile_arcsec.length == 3.0 assert profile_arcsec.length.unit_length == "arcsec" assert profile_arcsec.luminosity == 4.0 assert profile_arcsec.luminosity.unit_luminosity == "eps" assert profile_arcsec.mass == 5.0 assert profile_arcsec.mass.unit_mass == "angular" assert profile_arcsec.mass_over_luminosity == 6.0 assert profile_arcsec.mass_over_luminosity.unit == "angular / eps" profile_arcsec = profile_arcsec.new_profile_with_units_converted( unit_length="arcsec" ) assert profile_arcsec.position == (1.0, 2.0) assert profile_arcsec.position[0].unit == "arcsec" assert profile_arcsec.position[1].unit == "arcsec" assert profile_arcsec.param_float == 2.0 assert profile_arcsec.length == 3.0 assert profile_arcsec.length.unit == "arcsec" assert profile_arcsec.luminosity == 4.0 assert profile_arcsec.luminosity.unit == "eps" assert profile_arcsec.mass == 5.0 assert profile_arcsec.mass.unit_mass == "angular" assert profile_arcsec.mass_over_luminosity == 6.0 assert profile_arcsec.mass_over_luminosity.unit == "angular / eps" profile_kpc = profile_arcsec.new_profile_with_units_converted( unit_length="kpc", kpc_per_arcsec=2.0 ) assert profile_kpc.position == (2.0, 4.0) assert profile_kpc.position[0].unit == "kpc" assert profile_kpc.position[1].unit == "kpc" assert profile_kpc.param_float == 2.0 assert profile_kpc.length == 6.0 assert profile_kpc.length.unit == "kpc" assert profile_kpc.luminosity == 4.0 assert profile_kpc.luminosity.unit == "eps" assert profile_arcsec.mass == 5.0 assert profile_arcsec.mass.unit_mass == "angular" assert profile_kpc.mass_over_luminosity == 6.0 assert profile_kpc.mass_over_luminosity.unit == "angular / eps" profile_kpc = profile_kpc.new_profile_with_units_converted( unit_length="kpc" ) assert profile_kpc.position == (2.0, 4.0) assert profile_kpc.position[0].unit == "kpc" assert profile_kpc.position[1].unit == "kpc" assert profile_kpc.param_float == 2.0 assert profile_kpc.length == 6.0 assert profile_kpc.length.unit == "kpc" assert profile_kpc.luminosity == 4.0 assert profile_kpc.luminosity.unit == "eps" assert profile_arcsec.mass == 5.0 assert profile_arcsec.mass.unit_mass == "angular" assert profile_kpc.mass_over_luminosity == 6.0 assert profile_kpc.mass_over_luminosity.unit == "angular / eps" profile_arcsec = profile_kpc.new_profile_with_units_converted( unit_length="arcsec", kpc_per_arcsec=2.0 ) assert profile_arcsec.position == (1.0, 2.0) assert profile_arcsec.position[0].unit == "arcsec" assert profile_arcsec.position[1].unit == "arcsec" assert profile_arcsec.param_float == 2.0 assert profile_arcsec.length == 3.0 assert profile_arcsec.length.unit == "arcsec" assert profile_arcsec.luminosity == 4.0 assert profile_arcsec.luminosity.unit == "eps" assert profile_arcsec.mass == 5.0 assert profile_arcsec.mass.unit_mass == "angular" assert profile_arcsec.mass_over_luminosity == 6.0 assert profile_arcsec.mass_over_luminosity.unit == "angular / eps"
def test__radius_units_conversions__light_profile_updates_units_and_computes_correct_luminosity( self): cosmology = mock_cosmology.MockCosmology(arcsec_per_kpc=0.5, kpc_per_arcsec=2.0) sersic_arcsec = al.light_profiles.SphericalSersic( centre=(al.Length(0.0, "arcsec"), al.Length(0.0, "arcsec")), intensity=al.Luminosity(3.0, "eps"), effective_radius=al.Length(2.0, "arcsec"), sersic_index=1.0, ) sersic_kpc = al.light_profiles.SphericalSersic( centre=(al.Length(0.0, "kpc"), al.Length(0.0, "kpc")), intensity=al.Luminosity(3.0, "eps"), effective_radius=al.Length(4.0, "kpc"), sersic_index=1.0, ) radius = al.Length(0.5, "arcsec") luminosity_analytic = luminosity_from_radius_and_profile( radius=radius, profile=sersic_arcsec) # arcsec -> arcsec luminosity = sersic_arcsec.luminosity_within_circle_in_units( radius=radius) assert luminosity_analytic == pytest.approx(luminosity, 1e-3) # kpc -> arcsec luminosity_analytic = luminosity_from_radius_and_profile( radius=1.0, profile=sersic_kpc) luminosity = sersic_kpc.luminosity_within_circle_in_units( radius=radius, redshift_profile=0.5, cosmology=cosmology) assert luminosity_analytic == pytest.approx(luminosity, 1e-3) radius = al.Length(0.5, "kpc") luminosity_analytic = luminosity_from_radius_and_profile( radius=radius, profile=sersic_kpc) # kpc -> kpc luminosity = sersic_kpc.luminosity_within_circle_in_units( radius=radius) assert luminosity_analytic == pytest.approx(luminosity, 1e-3) # kpc -> arcsec luminosity_analytic = luminosity_from_radius_and_profile( radius=0.25, profile=sersic_arcsec) luminosity = sersic_arcsec.luminosity_within_circle_in_units( radius=radius, redshift_profile=0.5, cosmology=cosmology) assert luminosity_analytic == pytest.approx(luminosity, 1e-3) radius = al.Length(2.0, "arcsec") luminosity_arcsec = sersic_arcsec.luminosity_within_circle_in_units( radius=radius, redshift_profile=0.5, unit_mass="angular", cosmology=cosmology, ) radius = al.Length(4.0, "kpc") luminosity_kpc = sersic_arcsec.luminosity_within_circle_in_units( radius=radius, redshift_profile=0.5, unit_mass="angular", cosmology=cosmology, ) assert luminosity_arcsec == luminosity_kpc