def test_NFW_circular_velocity(): """Test circular velocity and radial validation of NFW model.""" # Test parameters mass = 2.0000000000000E15 * u.M_sun concentration = 8.5 redshift = 0.63 cosmo = cosmology.Planck15 r_r = np.array([0.01, 0.1, 0.2, 0.25, 0.3, 0.4, 0.5, 0.75, 1.0, 1.5, 2.5, 6.5, 11.5]) * u.Mpc # 200c Overdensity tests massfactor = ("critical", 200) n200c = NFW(mass=mass, concentration=concentration, redshift=redshift, cosmo=cosmo, massfactor=massfactor) circ_v_200c = np.array([702.45487454, 1812.4138346, 2150.50929296, 2231.5802568, 2283.96950242, 2338.45989696, 2355.78876772, 2332.41766543, 2276.89433811, 2154.53909153, 1950.07947819, 1512.37442943, 1260.94034541]) * (u.km / u.s) assert_quantity_allclose(n200c.circular_velocity(r_r), circ_v_200c) assert_quantity_allclose(n200c.r_max, (0.5338248204429641 * u.Mpc)) assert_quantity_allclose(n200c.v_max, (2356.7204380904027 * (u.km / u.s))) # 200m Overdensity tests massfactor = ("mean", 200) mass = 1.0e14 * u.M_sun concentration = 12.3 redshift = 1.5 n200m = NFW(mass=mass, concentration=concentration, redshift=redshift, cosmo=cosmo, massfactor=massfactor) circ_v_200m = np.array([670.18236647, 1088.9843324, 1046.82334367, 1016.88890732, 987.97273478, 936.00207134, 891.80115232, 806.63307977, 744.91002191, 659.33401039, 557.82823549, 395.9735786, 318.29863006]) * (u.km / u.s) assert_quantity_allclose(n200m.circular_velocity(r_r), circ_v_200m) assert_quantity_allclose(n200m.r_max, (0.10196917920081808 * u.Mpc)) assert_quantity_allclose(n200m.v_max, (1089.0224395818727 * (u.km / u.s))) # Virial Overdensity tests massfactor = ("virial") mass = 1.2e+45 * u.kg concentration = 2.4 redshift = 0.34 r_r = np.array([3.08567758e+20, 3.08567758e+21, 6.17135516e+21, 7.71419395e+21, 9.25703274e+21, 1.23427103e+22, 1.54283879e+22, 2.31425819e+22, 3.08567758e+22, 4.62851637e+22, 7.71419395e+22, 2.00569043e+23, 3.54852922e+23]) * u.m nvir = NFW(mass=mass, concentration=concentration, redshift=redshift, cosmo=cosmo, massfactor=massfactor) circ_v_vir = np.array([205.87461783, 604.65091823, 793.9190629, 857.52516521, 908.90280843, 986.53582718, 1041.69089845, 1124.19719446, 1164.58270747, 1191.33193561, 1174.02934755, 1023.69360527, 895.52206321]) * (u.km / u.s) assert_quantity_allclose(nvir.circular_velocity(r_r), circ_v_vir) assert_quantity_allclose(nvir.r_max, (1.6484542328623448 * u.Mpc)) assert_quantity_allclose(nvir.v_max, (1192.3130989914962 * (u.km / u.s)))
def test_NFW_exceptions_and_warnings_and_misc(): """Test NFW exceptions.""" # Arbitrary Test parameters mass = 2.0000000000000E15 * u.M_sun concentration = 8.5 redshift = 0.63 cosmo = cosmology.Planck15 massfactor = ("critical", 200) r_r = np.array([1.00e+01, 1.00e+02, 2.00e+02, 2.50e+02, 3.00e+02, 4.00e+02, 5.00e+02, 7.50e+02, 1.00e+03, 1.50e+03, 2.50e+03, 6.50e+03, 1.15e+04]) * u.kpc # Massfactor exception tests with pytest.raises(ValueError) as exc: NFW(mass=mass, concentration=concentration, redshift=redshift, cosmo=cosmo, massfactor=("not", "virial")) assert exc.value.args[0] == "Massfactor 'not' not one of 'critical', 'mean', or 'virial'" with pytest.raises(ValueError) as exc: NFW(mass=mass, concentration=concentration, redshift=redshift, cosmo=cosmo, massfactor="not virial") assert exc.value.args[0] == ("Massfactor not virial string not of the form " "'#m', '#c', or 'virial'") with pytest.raises(TypeError) as exc: NFW(mass=mass, concentration=concentration, redshift=redshift, cosmo=cosmo, massfactor=200) assert exc.value.args[0] == "Massfactor 200 not a tuple or string" # Verify unitless mass # Density test n200c = NFW(mass=mass.value, concentration=concentration, redshift=redshift, cosmo=cosmo, massfactor=massfactor) assert_quantity_allclose(n200c(3000.0), (3.709693508e+12 * (u.solMass / u.Mpc ** 3), 7.376391187e+42 * (u.kg / u.Mpc ** 3))) # Circular velocity test with unitless mass circ_v_200c = np.array([702.45487454, 1812.4138346, 2150.50929296, 2231.5802568, 2283.96950242, 2338.45989696, 2355.78876772, 2332.41766543, 2276.89433811, 2154.53909153, 1950.07947819, 1512.37442943, 1260.94034541]) * (u.km / u.s) assert_quantity_allclose(n200c.circular_velocity(r_r), circ_v_200c) # test with unitless input velocity assert_quantity_allclose(n200c.circular_velocity(r_r.value), circ_v_200c) # Test Default Cosmology ncos = NFW(mass=mass, concentration=concentration, redshift=redshift) assert_quantity_allclose(ncos.A_NFW(concentration), 1.356554956501232)