def runtest_BrokenPowerlawSED(sed, plot=False): nu_912 = sed.lambdanu(912.) ratio_1500_L_num = (sed(sed.lambdanu(1500.))/ sed(sed.lambdanu(912. - 1e-10)))[0] # Test the magnitude of the break. assert numpy.abs(ratio_1500_L_num - sed.break_factor) < 1e-9 # Test the normalization of the integral. numintegral = utils.logquad(sed, sed.lambdanu(3000.), sed.lambdanu(1e-6))[0] assert numpy.abs(numintegral - 1.) < 1e-6 if plot: import pylab wav = numpy.arange(100.,2000.,1.0) nu = sed.lambdanu(wav) pylab.subplot(121) #norm = sed(nu_912 + 1e10) norm = 1.0 pylab.plot(wav, sed(nu)/norm) #pylab.axhline(y=6, ls=':') #pylab.axvline(x=1500, ls=':') pylab.subplot(122) pylab.plot(nu, sed(nu)/norm)
def test_plot_schechter(): phiStar = 1.8e-3 MStar = -20.04 alpha = -1.71 LStar = magnitudes.L_nu_from_magAB(MStar) mags = numpy.arange(-22, -11.0, 0.5) lums = magnitudes.L_nu_from_magAB(mags) phi_L = schechterL(lums, phiStar, alpha, LStar) phi_M = schechterM(mags, phiStar, alpha, MStar) L_L = schechterCumuLL(lums, phiStar, alpha, LStar) L_M = schechterCumuLM(mags, phiStar, alpha, MStar) phi_L_func = lambda l: l * schechterL(l, phiStar, alpha, LStar) L_L_num = utils.logquad(phi_L_func, lums, 1e35)[0] L_L_num2 = utils.vecquad(phi_L_func, lums, 1e29)[0] phi_M_func = lambda m: (magnitudes.L_nu_from_magAB(m) * schechterM( m, phiStar, alpha, MStar)) L_M_num2 = utils.vecquad(phi_M_func, -25, mags)[0] Ltot_L = schechterTotLL(phiStar, alpha, LStar) Ltot_M = schechterTotLM(phiStar, alpha, MStar) pylab.figure() pylab.subplot(221) pylab.plot(lums, lums * lums * phi_L) pylab.xscale('log') pylab.yscale('log') pylab.ylabel(r'$ L^2 \Phi_L$') pylab.subplot(222) pylab.plot(mags, -mags * lums * phi_M) pylab.yscale('log') pylab.ylabel(r'$ -M L \Phi_M$') pylab.subplot(223) pylab.plot(lums, Ltot_L - L_L) pylab.plot(lums, L_M) pylab.plot(lums, L_L_num, '--') pylab.plot(lums, L_L_num2, ':') pylab.plot(lums, L_M_num2, 'x') pylab.axhline(y=Ltot_L) pylab.axhline(y=Ltot_M) pylab.xscale('log') pylab.yscale('log') pylab.subplot(224) pylab.plot(mags, Ltot_M - L_M) pylab.plot(mags, L_L) pylab.plot(mags, L_L_num, '--') pylab.plot(mags, L_L_num2, ':') pylab.plot(mags, L_M_num2, 'x') pylab.axhline(y=Ltot_L) pylab.axhline(y=Ltot_M) pylab.yscale('log')
def test_plot_schechter(): phiStar = 1.8e-3 MStar = -20.04 alpha = -1.71 LStar = magnitudes.L_nu_from_magAB(MStar) mags = numpy.arange(-22, -11.0, 0.5) lums = magnitudes.L_nu_from_magAB(mags) phi_L = schechterL(lums, phiStar, alpha, LStar) phi_M = schechterM(mags, phiStar, alpha, MStar) L_L = schechterCumuLL(lums, phiStar, alpha, LStar) L_M = schechterCumuLM(mags, phiStar, alpha, MStar) phi_L_func = lambda l: l * schechterL(l, phiStar, alpha, LStar) L_L_num = utils.logquad(phi_L_func, lums, 1e35)[0] L_L_num2 = utils.vecquad(phi_L_func, lums, 1e29)[0] phi_M_func = lambda m: (magnitudes.L_nu_from_magAB(m) * schechterM(m, phiStar, alpha, MStar)) L_M_num2 = utils.vecquad(phi_M_func, -25, mags)[0] Ltot_L = schechterTotLL(phiStar, alpha, LStar) Ltot_M = schechterTotLM(phiStar, alpha, MStar) pylab.figure() pylab.subplot(221) pylab.plot(lums, lums * lums * phi_L) pylab.xscale('log') pylab.yscale('log') pylab.ylabel(r'$ L^2 \Phi_L$') pylab.subplot(222) pylab.plot(mags, -mags * lums * phi_M) pylab.yscale('log') pylab.ylabel(r'$ -M L \Phi_M$') pylab.subplot(223) pylab.plot(lums, Ltot_L - L_L) pylab.plot(lums, L_M) pylab.plot(lums, L_L_num, '--') pylab.plot(lums, L_L_num2, ':') pylab.plot(lums, L_M_num2, 'x') pylab.axhline(y=Ltot_L) pylab.axhline(y=Ltot_M) pylab.xscale('log') pylab.yscale('log') pylab.subplot(224) pylab.plot(mags, Ltot_M - L_M) pylab.plot(mags, L_L) pylab.plot(mags, L_L_num, '--') pylab.plot(mags, L_L_num2, ':') pylab.plot(mags, L_M_num2, 'x') pylab.axhline(y=Ltot_L) pylab.axhline(y=Ltot_M) pylab.yscale('log')
def runtest_BrokenPowerlawSED(sed, plot=False): nu_912 = sed.lambdanu(912.) ratio_1500_L_num = (sed(sed.lambdanu(1500.)) / sed(sed.lambdanu(912. - 1e-10)))[0] # Test the magnitude of the break. assert numpy.abs(ratio_1500_L_num - sed.break_factor) < 1e-9 # Test the normalization of the integral. numintegral = utils.logquad(sed, sed.lambdanu(3000.), sed.lambdanu(1e-6))[0] assert numpy.abs(numintegral - 1.) < 1e-6 if plot: import pylab wav = numpy.arange(100., 2000., 1.0) nu = sed.lambdanu(wav) pylab.subplot(121) #norm = sed(nu_912 + 1e10) norm = 1.0 pylab.plot(wav, sed(nu) / norm) #pylab.axhline(y=6, ls=':') #pylab.axvline(x=1500, ls=':') pylab.subplot(122) pylab.plot(nu, sed(nu) / norm)
def test_plot_norm_imf(imf_function): """Plot and test the normalization of imf_function.""" label = imf_function.__name__.replace('imf_', '') label = label.replace('_', ' ') print label dm = 0.005 mmin = 0.1 mmax = 100. mass = numpy.arange(mmin, mmax + 1.1 * dm, dm) imf = imf_function(mass) # Test that the normalization is correct. liimf = utils.logquad(imf_function, mmin, mmax) print liimf[0], ", ", print 1.-liimf[0] assert abs(liimf[0] - 1) < 1e-10 # Test normalization using a different integration method. cimf = scipy.integrate.cumtrapz(imf * dm) print cimf[-1], ", ", print 1.-cimf[-1] assert abs(cimf[-1] - 1) < 1e-3 pylab.subplot(121) l = pylab.plot(mass, imf, label=label) pylab.plot(mass[1:], cimf, l[0].get_c()) pylab.gca().set_yscale('log') pylab.legend(loc='best') pylab.subplot(122) pylab.plot(mass, imf, l[0].get_c(), label=label) pylab.plot(mass[1:], cimf, l[0].get_c()) pylab.gca().set_yscale('log') pylab.gca().set_xscale('log')