def plot_one(rates, plotname, *p, frac=0.05, age=13.6): brates = u.gimme_rebinned_data(rates, splits=arange(0, 1.167, 0.167).tolist()) scale_k = quad(imf.salpeter, 3, 8)[0] / quad(imf.salpeter1, 0.1, 125)[0] scale = scale_k * 0.7**2. * 1e4 ## factors of h... dt = 0.05 tt = arange(0.0, age, dt) lbt = age - tt zz = [ct.cosmoz(x, ho=70) for x in lbt] par_model = [0.013, 2.6, 3.2, 6.1] sfh = rz.csfh_time(tt, *par_model) dtd = rz.dtdfunc(tt, *p) tmp = convolve( sfh, dtd, 'full') * dt * frac * scale ## now convolved result in forward time rate_fn = tmp[:len(dtd)] clf() ax = subplot(111) ax2 = ax.twinx() ax2.plot(zz, sfh, 'r-') ax.plot(zz, rate_fn, 'k-') ax.errorbar(rates[:, 0], rates[:, 1], yerr=[rates[:, 3], rates[:, 2]], fmt='o', color='0.6') ax.errorbar(brates[:, 0], brates[:, 1], yerr=[brates[:, 3], brates[:, 2]], xerr=[brates[:, 5], brates[:, 4]], fmt='o', color='0.0', zorder=10) pwrl = (-1.0, 1.0) ax.set_xlim(0, 2.5) ax.set_ylim(0, 1.8) ax2.set_ylim(0, 0.16) ax3 = axes([0.65, 0.6, 0.23, 0.2]) ax3.plot(tt, dtd, 'b-', label='Fit') #label='Norm = %1.1f' %(simps(dtd,x=time))) ax3.plot(tt, rz.powerdtd(tt, *pwrl), 'b:', label=r'$t^{%.1f}$' % (pwrl[0])) ax3.set_ylabel('$\Phi$') ax3.set_xlabel('Delay Time (Gyr)') ax3.set_xlim(0, 12) ax3.set_ylim(0, 1.3) ax3.legend(frameon=False) ax.set_xlabel('Redshift') ax.set_ylabel(r'$10^{-4}$ SNe Ia per year per Mpc$^3$') ax2.set_ylabel(r'M$_{\odot}$ per year per Mpc$^3$') ax.set_title(r'$k=%.4f\,M_{\odot}^{-1},\,\,f=%2.1f\%%$' % (scale_k, frac * 100)) savefig(plotname) return ()
def run_model(tt, *p): ddt = average(diff(tt)) sfh = rz.csfh_time(tt, *csfh_model) dtd = rz.dtdfunc(tt, *p[1:]) tmp = convolve(sfh, dtd, 'full') * ddt * np.exp( p[0]) #*frac*scale ## now convolved result in forward time rate_fn = tmp[:len(dtd)] return (rate_fn)
def run_model(tt, *p): ddt = average(diff(tt)) sfh = rz.csfh_time(tt, *csfh_model) dtd = rz.dtdfunc(tt, *p[1:]) tmp = convolve(sfh, dtd, 'full')*ddt*p[0]#*frac*scale ## now convolved result in forward time rate_fn=tmp[:len(dtd)] ## print(p,sum(rate_fn)) ## if sum(rate_fn)==0.: ## pdb.set_trace() return(rate_fn)
def dtdfit(time, *p): ff, aa, bb, cc = p scale = quad(imf.salpeter, 3, 8)[0] / quad(imf.salpeter1, 0.1, 125)[0] scale = scale * 0.7**2. * 1e4 par_model = [0.0134, 2.55, 3.3, 6.1] sfh = rz.csfh_time(time, *par_model) dt = sum(diff(time)) / (len(time) - 1) p1 = (aa, bb, cc) res = rz.dtdfunc(time, *p1, norm=True) tmp = convolve(sfh, res, 'full') return (ff * tmp[:len(time)] * dt * scale)
def dtdfit(time, *p): ff, m, w, k = p scale = quad(imf.salpeter, 3, 8)[0] / quad(imf.salpeter1, 0.1, 125)[0] scale = scale * 0.7**2. * 1e4 par_model = [0.0134, 2.55, 3.3, 6.1] ## Compendium ## par_model = [0.013, 2.6, 3.2, 6.1] ## MD14 ## par_model = [0.009, 2.7, 2.5, 4.1] ## Driver18 sfh = rz.csfh_time(time, *par_model) dt = sum(diff(time)) / (len(time) - 1) p1 = (m, w, k) res = rz.dtdfunc(time, *p1, norm=True) tmp = convolve(sfh, res, 'full') return (np.exp(ff) * tmp[:len(time)] * dt * scale)
color='0.0', zorder=10) ysample = asarray([run_model(tta, *pi[:-1]) for pi in draws]) * scale ax.plot(zz, run_model(tta, *p_val) * scale, 'b-', label='Fit') lower = percentile(ysample, 15.9, axis=0) upper = percentile(ysample, 84.1, axis=0) ax.fill_between(zz, upper, lower, color='green', alpha=0.2) lower = percentile(ysample, 2.5, axis=0) upper = percentile(ysample, 97.5, axis=0) ax.fill_between(zz, upper, lower, color='green', alpha=0.2) pwrl = (-1.0, 1.0) dud = rz.powerdtd(tta, *pwrl) jdud = convolve(rz.csfh_time(tta, *csfh_model), dud, 'full') * average( diff(tta)) * frac * scale jdud = jdud[:len(dud)] ax.plot(zz, jdud, 'b:', label=r'$t^{%.1f}$' % (pwrl[0])) ## pdb.set_trace() ax.set_xlim(0, 2.5) ax.set_ylim(0, 1.8) ax2.set_xlim(0, 12) ax2.set_ylim(-3, 0.5) ax.set_xlabel('Redshift') ax.set_ylabel(r'$10^{-4}$ SNe Ia per year per Mpc$^3$') ax2.set_ylabel('$\log(\Phi)$') ax2.set_xlabel('Delay Time (Gyr)') ax.set_title(r'$k=%.4f\,M_{\odot}^{-1},\,\,\varepsilon=%2.1f\%%$' %
idx = where(ysample[:,2]>0.) ysample = ysample[idx] ax.plot(zz, run_model(tta, *p_val)*scale, 'b-') lower = percentile(ysample, 15.9, axis=0) upper = percentile(ysample, 84.1, axis=0) ax.fill_between(zz, upper, lower, color='green', alpha=0.2) lower = percentile(ysample, 2.5, axis=0) upper = percentile(ysample, 97.5, axis=0) ax.fill_between(zz, upper, lower, color='green', alpha=0.2) pwrl = (-1.0,1.0) dud = rz.powerdtd(tta, *pwrl) jdud = convolve(rz.csfh_time(tta, *csfh_model), dud, 'full')*average(diff(tta))*frac*scale jdud = jdud[:len(dud)] ax.plot(zz, jdud, 'b:') ## pdb.set_trace() ax.set_xlim(0,2.5) ax.set_xlabel('Redshift') ax.set_ylabel(r'$10^{-4}$ SNe Ia per year per Mpc$^3$') ax2.set_ylabel('$\Phi$') ax2.set_xlabel('Delay Time (Gyr)') ax.set_title(r'$k=%.4f\,M_{\odot}^{-1},\,\,\varepsilon=%2.1f\%%$' %(scale_k, p_val[0]*100)) savefig('figure_fit_demo_werr.png', transparent=True)