def test_realistic(self): """ realistic test example :return: """ light_profile_list = ['HERNQUIST_ELLIPSE', 'PJAFFE_ELLIPSE'] kwargs_light = [{ 'Rs': 0.10535462602138289, 'q': 0.46728323131925864, 'center_x': -0.02678473951679429, 'center_y': 0.88691126347462712, 'phi_G': 0.74260706384506325, 'sigma0': 3.7114695634960109 }, { 'Rs': 0.44955054610388684, 'q': 0.66582356813012267, 'center_x': 0.019536801118136753, 'center_y': 0.0218888643537157, 'Ra': 0.0010000053334891974, 'phi_G': -0.33379268413794494, 'sigma0': 967.00280526319796 }] lightProfile = LightProfile(light_profile_list) R = 0.01 light2d = lightProfile.light_2d(R=R, kwargs_list=kwargs_light) out = integrate.quad( lambda x: lightProfile.light_3d(np.sqrt(R**2 + x**2), kwargs_light ), 0, 100) print out, 'out' npt.assert_almost_equal(light2d / (out[0] * 2), 1., decimal=3)
def test_light_3d(self): lightProfile = LightProfile(profile_list=['HERNQUIST']) r = np.logspace(-2, 2, 100) kwargs_profile = [{'sigma0': 1., 'Rs': 0.5}] light_3d = lightProfile.light_3d_interp(r, kwargs_profile) light_3d_exact = lightProfile.light_3d(r, kwargs_profile) for i in range(len(r)): npt.assert_almost_equal(light_3d[i] / light_3d_exact[i], 1, decimal=3)
def test_draw_light_PJaffe(self): lightProfile = LightProfile(profile_list=['PJAFFE']) kwargs_profile = [{'sigma0': 1., 'Rs': 0.5, 'Ra': 0.2}] r_list = lightProfile.draw_light_2d(kwargs_profile, n=50000) bins = np.linspace(0, 1, 10) hist, bins_hist = np.histogram(r_list, bins=bins, normed=True) light2d = lightProfile.light_2d(R=(bins_hist[1:] + bins_hist[:-1]) / 2., kwargs_list=kwargs_profile) light2d *= (bins_hist[1:] + bins_hist[:-1]) / 2. light2d /= np.sum(light2d) hist /= np.sum(hist) #print light2d / hist npt.assert_almost_equal(light2d[4] / hist[4], 1, decimal=2) lightProfile = LightProfile(profile_list=['PJAFFE'], kwargs_numerics={ 'min_interpolate': 0.0001, 'max_interpolate': 20. }) kwargs_profile = [{'sigma0': 1., 'Rs': 0.04, 'Ra': 0.02}] r_list = lightProfile.draw_light_2d(kwargs_profile, n=50000) bins = np.linspace(0., 0.1, 10) hist, bins_hist = np.histogram(r_list, bins=bins, normed=True) light2d = lightProfile.light_2d(R=(bins_hist[1:] + bins_hist[:-1]) / 2., kwargs_list=kwargs_profile) light2d *= (bins_hist[1:] + bins_hist[:-1]) / 2. light2d /= np.sum(light2d) hist /= np.sum(hist) print light2d / hist npt.assert_almost_equal(light2d[4] / hist[4], 1, decimal=2)
def test_draw_light(self): lightProfile = LightProfile(profile_list=['HERNQUIST']) kwargs_profile = [{'sigma0': 1., 'Rs': 0.8}] r_list = lightProfile.draw_light_2d(kwargs_profile, n=100000) bins = np.linspace(0., 1, 20) hist, bins_hist = np.histogram(r_list, bins=bins, normed=True) light2d = lightProfile.light_2d(R=(bins_hist[1:] + bins_hist[:-1]) / 2., kwargs_list=kwargs_profile) light2d *= (bins_hist[1:] + bins_hist[:-1]) / 2. light2d /= np.sum(light2d) hist /= np.sum(hist) print light2d / hist for i in range(len(hist)): print bins_hist[i], i, light2d[i] / hist[i] npt.assert_almost_equal(light2d[i] / hist[i], 1, decimal=1)
def test_projected_light_integral_hernquist(self): """ :return: """ light_profile_list = ['HERNQUIST'] r_eff = 1. kwargs_light = [{ 'Rs': r_eff, 'sigma0': 1. }] # effective half light radius (2d projected) in arcsec lightProfile = LightProfile(light_profile_list) R = 2 light2d = lightProfile.light_2d(R=R, kwargs_list=kwargs_light) out = integrate.quad( lambda x: lightProfile.light_3d(np.sqrt(R**2 + x**2), kwargs_light ), 0, 100) npt.assert_almost_equal(light2d, out[0] * 2, decimal=3)
def test_projected_light_integral_pjaffe(self): """ :return: """ light_profile_list = ['PJAFFE'] kwargs_light = [{ 'Rs': .5, 'Ra': 0.01, 'sigma0': 1. }] # effective half light radius (2d projected) in arcsec lightProfile = LightProfile(light_profile_list) R = 0.01 light2d = lightProfile.light_2d(R=R, kwargs_list=kwargs_light) out = integrate.quad( lambda x: lightProfile.light_3d(np.sqrt(R**2 + x**2), kwargs_light ), 0, 100) print out, 'out' npt.assert_almost_equal(light2d / (out[0] * 2), 1., decimal=3)
def test_realistic_0(self): """ realistic test example :return: """ light_profile_list = ['HERNQUIST'] kwargs_light = [{ 'Rs': 0.10535462602138289, 'center_x': -0.02678473951679429, 'center_y': 0.88691126347462712, 'sigma0': 3.7114695634960109 }] lightProfile = LightProfile(light_profile_list) R = 0.01 light2d = lightProfile.light_2d(R=R, kwargs_list=kwargs_light) out = integrate.quad( lambda x: lightProfile.light_3d(np.sqrt(R**2 + x**2), kwargs_light ), 0, 100) print out, 'out' npt.assert_almost_equal(light2d / (out[0] * 2), 1., decimal=3)