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__unit_mass__extracted_from_profile(self): profile = MockDimensionsProfile( mass=al.Mass(value=3.0, unit_mass="angular"), mass_over_luminosity=al.MassOverLuminosity( value=3.0, unit_mass="angular" ), ) assert profile.unit_mass == "angular" profile = MockDimensionsProfile( mass=1.0, mass_over_luminosity=al.MassOverLuminosity( value=3.0, unit_mass="angular" ), ) assert profile.unit_mass == "angular" profile = MockDimensionsProfile( mass=al.Mass(value=3.0, unit_mass="angular"), mass_over_luminosity=1.0 ) assert profile.unit_mass == "angular" profile = MockDimensionsProfile( mass=al.Mass(value=3.0, unit_mass="solMass"), mass_over_luminosity=al.MassOverLuminosity( value=3.0, unit_mass="solMass" ), ) assert profile.unit_mass == "solMass" profile = MockDimensionsProfile( mass=1.0, mass_over_luminosity=al.MassOverLuminosity( value=3.0, unit_mass="solMass" ), ) assert profile.unit_mass == "solMass" profile = MockDimensionsProfile( mass=al.Mass(value=3.0, unit_mass="solMass"), mass_over_luminosity=1.0 ) assert profile.unit_mass == "solMass" profile = MockDimensionsProfile(mass=1.0, mass_over_luminosity=1.0) assert profile.unit_mass == None
def test__conversions_from_angular_and_sol_mass_and_back__errors_raised_if_critical_mass_density( self ): unit_angular = al.MassOverLuminosity(value=2.0) assert unit_angular == 2.0 assert unit_angular.unit == "angular / eps" unit_angular = unit_angular.convert(unit_mass="angular", unit_luminosity="eps") assert unit_angular == 2.0 assert unit_angular.unit == "angular / eps" unit_sol_mass = unit_angular.convert( unit_mass="solMass", critical_surface_density=2.0, unit_luminosity="eps" ) assert unit_sol_mass == 4.0 assert unit_sol_mass.unit == "solMass / eps" unit_sol_mass = unit_sol_mass.convert( unit_mass="solMass", unit_luminosity="eps" ) assert unit_sol_mass == 4.0 assert unit_sol_mass.unit == "solMass / eps" unit_angular = unit_sol_mass.convert( unit_mass="angular", critical_surface_density=2.0, unit_luminosity="eps" ) assert unit_angular == 2.0 assert unit_angular.unit == "angular / eps" with pytest.raises(exc.UnitsException): unit_angular.convert(unit_mass="solMass", unit_luminosity="eps") unit_sol_mass.convert(unit_mass="angular", unit_luminosity="eps") unit_angular.convert(unit_mass="lol", unit_luminosity="eps")
def test__conversions_from_eps_and_counts_and_back__errors_raised_if_no_exposure_time( self ): unit_eps = al.MassOverLuminosity(value=2.0) assert unit_eps == 2.0 assert unit_eps.unit == "angular / eps" unit_eps = unit_eps.convert(unit_mass="angular", unit_luminosity="eps") assert unit_eps == 2.0 assert unit_eps.unit == "angular / eps" unit_counts = unit_eps.convert( unit_mass="angular", exposure_time=2.0, unit_luminosity="counts" ) assert unit_counts == 1.0 assert unit_counts.unit == "angular / counts" unit_counts = unit_counts.convert(unit_mass="angular", unit_luminosity="counts") assert unit_counts == 1.0 assert unit_counts.unit == "angular / counts" unit_eps = unit_counts.convert( unit_mass="angular", exposure_time=2.0, unit_luminosity="eps" ) assert unit_eps == 2.0 assert unit_eps.unit == "angular / eps" with pytest.raises(exc.UnitsException): unit_eps.convert(unit_mass="angular", unit_luminosity="eps") unit_counts.convert(unit_mass="angular", unit_luminosity="eps") unit_eps.convert(unit_mass="lol", unit_luminosity="eps")
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__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"