def fitMAPs(type, savefilename): setup_selection_function() if os.path.exists(savefilename): with open(savefilename, 'rb') as savefile: bf = pickle.load(savefile) samples = pickle.load(savefile) bf_g15 = pickle.load(savefile) samples_g15 = pickle.load(savefile) bf_zero = pickle.load(savefile) samples_zero = pickle.load(savefile) bii = pickle.load(savefile) else: bf = [] samples = [] bf_g15 = [] samples_g15 = [] bf_zero = [] samples_zero = [] bii = 0 maps = define_rcsample.MAPs() for ii, map in enumerate(maps.map()): if ii < bii: continue tbf, ts = fitmap(map, type=type, dmap='marshall06') bf.append(tbf) samples.append(ts) tbf, ts = fitmap(map, type=type, dmap='green15') bf_g15.append(tbf) samples_g15.append(ts) tbf, ts = fitmap(map, type=type, dmap='zero') bf_zero.append(tbf) samples_zero.append(ts) print ii, numpy.median(samples[-1], axis=1) save_pickles(savefilename, bf, samples, bf_g15, samples_g15, bf_zero, samples_zero, ii + 1) return None
def plot_maprmax(savefilename, plotname): with open(savefilename, 'rb') as savefile: bf = numpy.array(pickle.load(savefile)) samples = numpy.array(pickle.load(savefile)) bf_g15 = numpy.array(pickle.load(savefile)) samples_g15 = numpy.array(pickle.load(savefile)) bf_zero = numpy.array(pickle.load(savefile)) samples_zero = numpy.array(pickle.load(savefile)) maps = define_rcsample.MAPs() plotthis = numpy.zeros(len(bf)) + numpy.nan for ii, map in enumerate(maps.map()): tmed = numpy.median( numpy.exp(samples[ii, 3])[True - numpy.isnan(numpy.exp(samples[ii, 3]))]) if tmed < 5.: tmed = 0. plotthis[ii] = tmed bovy_plot.bovy_print() maps.plot(plotthis, vmin=5., vmax=13., minnstar=15, zlabel=r'$R_{\mathrm{peak}}\,(\mathrm{kpc})$', shrink=0.68, cmap='coolwarm_r') # Sequences haloc = define_rcsample.highalphalocus() bovy_plot.bovy_plot(haloc[:, 0], haloc[:, 1], '-', color='0.75', lw=2.5, overplot=True) haloc = define_rcsample.lowalphalocus() haloc = haloc[(haloc[:, 0] > -0.55) * (haloc[:, 0] < 0.225)] bovy_plot.bovy_plot(haloc[:, 0], haloc[:, 1], '-', color='0.75', lw=2.5, overplot=True) # Label #t= pyplot.text(-0.51,0.235,r'$\mathrm{single}$', # size=16.,color='w') #t.set_bbox(dict(alpha=0.5,color=cm.coolwarm(0.), # edgecolor='none')) #t= pyplot.text(-0.475,0.195,r'$\mathrm{exponential}$', # size=16.,color='w') t = pyplot.text(-0.625, 0.195, r'$R_{\mathrm{peak}} < 5\,\mathrm{kpc}$', size=16., color='w') t.set_bbox(dict(alpha=0.5, color=cm.coolwarm_r(0.), edgecolor='none')) pyplot.tight_layout() bovy_plot.bovy_end_print(plotname, dpi=300) return None
def plot_maphz(plotname): # Load the two fit with open('../mapfits/tribrokentwoexp.sav', 'rb') as savefile: bf = numpy.array(pickle.load(savefile)) samples = numpy.array(pickle.load(savefile)) maps = define_rcsample.MAPs() plotthisz1 = numpy.zeros(len(bf)) + numpy.nan plotthisz1e = numpy.zeros(len(bf)) + numpy.nan plotthisz2 = numpy.zeros(len(bf)) + numpy.nan plotthisz2e = numpy.zeros(len(bf)) + numpy.nan for ii, map in enumerate(maps.map()): hzindx= (True-numpy.isnan(samples[ii,4]))\ *(True-numpy.isnan(samples[ii,5]))\ *(densprofiles.ilogit(samples[ii,4]) > 0.15) tmed = numpy.median(1. / samples[ii, 1, hzindx]) terr = numpy.std(1. / samples[ii, 1, hzindx]) plotthisz1[ii] = tmed plotthisz1e[ii] = terr tmed = numpy.median(1. / samples[ii, 5, hzindx]) terr = numpy.std(1. / samples[ii, 5, hzindx]) plotthisz2[ii] = tmed plotthisz2e[ii] = terr plotthisz1[plotthisz1e / plotthisz1 > 0.5] = numpy.nan bovy_plot.bovy_print() bovy_plot.bovy_plot( plotthisz2 * 1000., plotthisz1 * 1000., 'ko', xrange=[0., 1200.], yrange=[0., 1200.], xlabel=r'$2^\mathrm{nd}\ \mathrm{scale\ height\,(pc)}$', ylabel=r'$1^\mathrm{st}\ \mathrm{scale\ height\,(pc)}$', zorder=2) bovy_plot.bovy_plot([0, 1200], [0, 1200], 'k--', overplot=True, lw=2.) pyplot.errorbar(plotthisz2 * 1000., plotthisz1 * 1000., yerr=plotthisz1e * 1000., marker='o', color='k', ls='none', zorder=1) bovy_plot.bovy_end_print(plotname) return None
def triangleMAPs(savefilename, basename): with open(savefilename, 'rb') as savefile: bf = numpy.array(pickle.load(savefile)) samples = numpy.array(pickle.load(savefile)) bf_g15 = numpy.array(pickle.load(savefile)) samples_g15 = numpy.array(pickle.load(savefile)) bf_zero = numpy.array(pickle.load(savefile)) samples_zero = numpy.array(pickle.load(savefile)) labels = [] for jj in range(samples.shape[2]): labels.append(r"$\mathrm{param}\ %i$" % jj) maps = define_rcsample.MAPs() for ii, map in enumerate(maps.map()): if ii >= len(bf): break tfeh = numpy.nanmedian(map['FE_H']) tafe = numpy.nanmedian(map[define_rcsample._AFETAG]) for tbf, tsamples, ext in zip([bf, bf_g15, bf_zero], [samples, samples_g15, samples_zero], ['fid', 'g15', 'zero']): try: triangle.corner(tsamples[ii, ].T, quantiles=[0.16, 0.5, 0.84], labels=labels, show_titles=True, title_args={"fontsize": 12}, bins=21) except ValueError: pass else: bovy_plot.bovy_text(r'$[\mathrm{{Fe/H}}] = {feh:.1f},$'\ .format(feh=tfeh)+'\n' +r'$[\alpha/\mathrm{{Fe}}] = {afe:.2f}$'\ .format(afe=tafe), top_left=True,size=16.) bovy_plot.bovy_end_print(basename + "_%i_%s.png" % (ii, ext)) return None
def plot_mapsurfdens(plotname): with open('../mapfits/tribrokenexpflare.sav','rb') as savefile: bf= numpy.array(pickle.load(savefile)) samples_brexp= numpy.array(pickle.load(savefile)) plotmaps= [19,26,32,39,45] bovy_plot.bovy_print(fig_width=8.,fig_height=3.) maps= define_rcsample.MAPs() cmap= cm.coolwarm overplot= False for ii, map in enumerate(maps.map()): if not ii in plotmaps: continue # Create all density profiles Rs= numpy.linspace(4.,14.,1001) samples= samples_brexp[ii,:,::_SKIP] nsamples= len(samples[0]) tRs= numpy.tile(Rs,(nsamples,1)).T ldp= numpy.empty((len(Rs),nsamples)) Rb= numpy.tile(numpy.exp(samples[3]),(len(Rs),1)) ihRin= numpy.tile(samples[0],(len(Rs),1)) ihRout= numpy.tile(samples[2],(len(Rs),1)) # Rb >= R0 leRb= (tRs <= Rb)*(Rb >= densprofiles._R0) ldp[leRb]= ihRin[leRb]*(tRs[leRb]-densprofiles._R0) gtRb= (tRs > Rb)*(Rb >= densprofiles._R0) ldp[gtRb]= -ihRout[gtRb]*(tRs[gtRb]-densprofiles._R0)\ +ihRout[gtRb]*(Rb[gtRb]-densprofiles._R0)\ +ihRin[gtRb]*(Rb[gtRb]-densprofiles._R0) # Rb < R0, normalize outer at R0 leRb= (tRs <= Rb)*(Rb < densprofiles._R0) ldp[leRb]= ihRin[leRb]*(tRs[leRb]-densprofiles._R0)\ -ihRout[leRb]*(Rb[leRb]-densprofiles._R0)\ -ihRin[leRb]*(Rb[leRb]-densprofiles._R0) gtRb= (tRs > Rb)*(Rb < densprofiles._R0) ldp[gtRb]= -ihRout[gtRb]*(tRs[gtRb]-densprofiles._R0) # Label and relative normalization tfeh= round(numpy.median(map['FE_H'])*20.)/20. if tfeh == 0.25: tfeh= 0.3 if tfeh == -0.1: tfeh= -0.1 print ii, tfeh, len(map) anorm= 10**(-10.*(-tfeh-0.5)) #if (-tfeh-0.4) > 0.3: anorm= 10**(-12.*(-tfeh+0.4)) if (-tfeh-0.5) == -0.2: anorm= 10**(-11.*(-tfeh-0.5)) anorm= 1./anorm # re-order anorm/= 3. norm= numpy.exp(numpy.median(ldp,axis=1))[numpy.argmin(numpy.fabs(Rs-densprofiles._R0))]/anorm bovy_plot.bovy_plot(Rs,numpy.exp(numpy.median(ldp,axis=1))/norm, '-', color=cmap((tfeh+0.5)*0.95/0.5+0.05), lw=2.,overplot=overplot, ylabel=r'$\Sigma(R)\times\mathrm{constant}$', xrange=[0.,16.], yrange=[0.000001,90.], semilogy=True) pyplot.fill_between(Rs, numpy.exp(numpy.sort(ldp,axis=1)[:,int(round(_SIGNIF*nsamples))])/norm, numpy.exp(numpy.sort(ldp,axis=1)[:,int(round((1.-_SIGNIF)*nsamples))])/norm, color=cmap((tfeh+0.5)/0.4), lw=0.) overplot= True if ii == 19: bovy_plot.bovy_text(2., 10.**1., r'$[\mathrm{Fe/H}]$',size=16.,color='k') bovy_plot.bovy_text(2.,(numpy.exp(numpy.median(ldp,axis=1))/norm)[0], r'$%+.1f$' % tfeh,size=16., color=cmap((tfeh+0.5)*0.95/0.5+0.05)) bovy_plot.bovy_text(10.,10.**1., r'$\mathrm{high-}[\alpha/\mathrm{Fe}]\ \mathrm{MAPs}$', size=16.) pyplot.gca().tick_params(axis='y',which='minor',left='off',right='off') bovy_plot.bovy_end_print(plotname)
def plot_mapflare(plotname): with open('../mapfits/tribrokenexpflare.sav', 'rb') as savefile: bf = numpy.array(pickle.load(savefile)) samples_brexp = numpy.array(pickle.load(savefile)) with open('../mapfits/tribrokenexpinvlinflare.sav', 'rb') as savefile: bf = numpy.array(pickle.load(savefile)) samples_brexp_invlin = numpy.array(pickle.load(savefile)) with open('../mapfits/tribrokenexplinflare.sav', 'rb') as savefile: bf = numpy.array(pickle.load(savefile)) samples_brexp_lin = numpy.array(pickle.load(savefile)) plotmaps = [19, 26, 32, 39, 45] bovy_plot.bovy_print(fig_width=8., fig_height=9. * 3.99 / 8.98) maps = define_rcsample.MAPs() cmap = cm.coolwarm overplot = False for ii, map in enumerate(maps.map()): if not ii in plotmaps: continue # Create all flaring profiles #Rmin= numpy.sort(map['RC_GALR_H'])[int(round(0.005*len(map)))] #Rmax= numpy.sort(map['RC_GALR_H'])[numpy.amin([len(map)-1,int(round(0.995*len(map)))])] Rs = numpy.linspace(4., 14., 1001) samples = samples_brexp[ii, :, ::_SKIP] samples_invlin = samples_brexp_invlin[ii, :, ::_SKIP] samples_lin = samples_brexp_lin[ii, :, ::_SKIP] nsamples = len(samples[0]) tRs = numpy.tile(Rs, (nsamples, 1)).T ldp = numpy.empty((len(Rs), nsamples)) ldp = samples[1] * numpy.exp(samples[4] * (tRs - densprofiles._R0)) ldp_invlin= samples_invlin[1]\ *(1.+samples_invlin[4]*(tRs-densprofiles._R0)*(numpy.exp(1.)-1.)) ldp_lin= samples_lin[1]\ /(1.-(tRs-densprofiles._R0)*samples_lin[4]*(numpy.exp(1.)-1.)) ldp = 1000. / ldp # make it hz instead of its inverse ldp_invlin = 1000. / ldp_invlin ldp_lin = 1000. / ldp_lin # Label and relative normalization tfeh = round(numpy.median(map['FE_H']) * 20.) / 20. if tfeh == 0.25: tfeh = 0.3 if tfeh == -0.0: tfeh = 0.0 offset = 10.**(-6. * (tfeh + 0.1)) - 0.4 if tfeh < -0.1: offset /= 1.5 if tfeh < -0.2: offset /= 1.15 print ii, tfeh, len(map), offset bovy_plot.bovy_plot( Rs, numpy.median(ldp, axis=1) * offset, '-', color=cmap((tfeh + 0.5) * 0.95 / 0.5 + 0.05), lw=2., overplot=overplot, ylabel=r'$h_Z\,(\mathrm{pc})\times\mathrm{constant}$', xrange=[0., 16.], yrange=[10.**2., 10**5.99], zorder=10 + ii, semilogy=True) #skipped because the median for the other profiles are indistinguishable for that with exponential flaring """ pyplot.fill_between(Rs, numpy.median(ldp_lin,axis=1)*offset, numpy.median(ldp_invlin,axis=1)*offset, color='0.65', lw=0.,zorder=ii-1) """ pyplot.fill_between( Rs, numpy.sort(ldp, axis=1)[:, int(round(_SIGNIF * nsamples))] * offset, numpy.sort(ldp, axis=1)[:, int(round( (1. - _SIGNIF) * nsamples))] * offset, color=cmap((tfeh + 0.5) / 0.4), lw=0., zorder=ii) line, = pyplot.plot(Rs, Rs * 0. + 300. * offset, color=cmap((tfeh + 0.5) * 0.95 / 0.5 + 0.05), ls='--', lw=2. * 0.8, zorder=ii + 5) line.set_dashes([8, 6]) overplot = True if ii == 19: bovy_plot.bovy_text(2., 10.**5.6, r'$[\mathrm{Fe/H}]$', size=16., color='k') bovy_plot.bovy_text(2., numpy.median(ldp, axis=1)[0] * offset, r'$%+.1f$' % tfeh, size=16., color=cmap((tfeh + 0.5) * 0.95 / 0.5 + 0.05)) bovy_plot.bovy_text(10., 10.**5.6, r'$\mathrm{high-}[\alpha/\mathrm{Fe}]\ \mathrm{MAPs}$', size=16.) bovy_plot.bovy_end_print(plotname)
def plot_mapsurfdens(plotname): with open('../mapfits/tribrokenexpflare.sav', 'rb') as savefile: bf = numpy.array(pickle.load(savefile)) samples_brexp = numpy.array(pickle.load(savefile)) plotmaps = [19, 26, 32, 39, 45] bovy_plot.bovy_print(fig_width=8., fig_height=3.) maps = define_rcsample.MAPs() cmap = cm.coolwarm overplot = False Rs = numpy.linspace(4., 14., 1001) # Setup for saving the profiles csvfile = open(os.path.join('..', 'out', 'mapsurfdens_highalpha.csv'), 'w') writer = csv.writer(csvfile, delimiter=',', quoting=csv.QUOTE_NONE) writer.writerow( ['# Surface density profile for MAPs (Figure 11 in Bovy et al. 2016)']) writer.writerow([ '# The first line lists the radii at which the surface density profiles' ]) writer.writerow(['# are evaluated']) writer.writerow( ['# The rest of the file are the log surface profiles; the 0.025']) writer.writerow(['# lower limit and the 0.0975 upper limit (each 1 line)']) writer.writerow(['# Different MAPs are separated by a comment line']) writer.writerow(['{:.2f}'.format(x) for x in Rs]) for ii, map in enumerate(maps.map()): if not ii in plotmaps: continue # Create all density profiles samples = samples_brexp[ii, :, ::_SKIP] nsamples = len(samples[0]) tRs = numpy.tile(Rs, (nsamples, 1)).T ldp = numpy.empty((len(Rs), nsamples)) Rb = numpy.tile(numpy.exp(samples[3]), (len(Rs), 1)) ihRin = numpy.tile(samples[0], (len(Rs), 1)) ihRout = numpy.tile(samples[2], (len(Rs), 1)) # Rb >= R0 leRb = (tRs <= Rb) * (Rb >= densprofiles._R0) ldp[leRb] = ihRin[leRb] * (tRs[leRb] - densprofiles._R0) gtRb = (tRs > Rb) * (Rb >= densprofiles._R0) ldp[gtRb]= -ihRout[gtRb]*(tRs[gtRb]-densprofiles._R0)\ +ihRout[gtRb]*(Rb[gtRb]-densprofiles._R0)\ +ihRin[gtRb]*(Rb[gtRb]-densprofiles._R0) # Rb < R0, normalize outer at R0 leRb = (tRs <= Rb) * (Rb < densprofiles._R0) ldp[leRb]= ihRin[leRb]*(tRs[leRb]-densprofiles._R0)\ -ihRout[leRb]*(Rb[leRb]-densprofiles._R0)\ -ihRin[leRb]*(Rb[leRb]-densprofiles._R0) gtRb = (tRs > Rb) * (Rb < densprofiles._R0) ldp[gtRb] = -ihRout[gtRb] * (tRs[gtRb] - densprofiles._R0) # Label and relative normalization tfeh = round(numpy.median(map['FE_H']) * 20.) / 20. if tfeh == 0.25: tfeh = 0.3 if tfeh == -0.1: tfeh = -0.1 print ii, tfeh, len(map) anorm = 10**(-10. * (-tfeh - 0.5)) #if (-tfeh-0.4) > 0.3: anorm= 10**(-12.*(-tfeh+0.4)) if (-tfeh - 0.5) == -0.2: anorm = 10**(-11. * (-tfeh - 0.5)) anorm = 1. / anorm # re-order anorm /= 3. norm = numpy.exp(numpy.median(ldp, axis=1))[numpy.argmin( numpy.fabs(Rs - densprofiles._R0))] / anorm bovy_plot.bovy_plot(Rs, numpy.exp(numpy.median(ldp, axis=1)) / norm, '-', color=cmap((tfeh + 0.5) * 0.95 / 0.5 + 0.05), lw=2., overplot=overplot, ylabel=r'$\Sigma(R)\times\mathrm{constant}$', xrange=[0., 16.], yrange=[0.000001, 90.], semilogy=True) pyplot.fill_between( Rs, numpy.exp( numpy.sort(ldp, axis=1)[:, int(round(_SIGNIF * nsamples))]) / norm, numpy.exp( numpy.sort(ldp, axis=1)[:, int(round( (1. - _SIGNIF) * nsamples))]) / norm, color=cmap((tfeh + 0.5) / 0.4), lw=0.) overplot = True if ii == 19: bovy_plot.bovy_text(2., 10.**1., r'$[\mathrm{Fe/H}]$', size=16., color='k') bovy_plot.bovy_text(2., (numpy.exp(numpy.median(ldp, axis=1)) / norm)[0], r'$%+.1f$' % tfeh, size=16., color=cmap((tfeh + 0.5) * 0.95 / 0.5 + 0.05)) writer.writerow(['# High-alpha MAP w/ [Fe/H]=%g' % tfeh]) writer.writerow( ['{:.3f}'.format(x) for x in list(numpy.median(ldp, axis=1))]) writer.writerow([ '{:.3f}'.format(x) for x in list( numpy.sort(ldp, axis=1)[:, int(round(_SIGNIF * nsamples))]) ]) writer.writerow([ '{:.3f}'.format(x) for x in list( numpy.sort(ldp, axis=1)[:, int(round((1. - _SIGNIF) * nsamples))]) ]) csvfile.close() bovy_plot.bovy_text(10., 10.**1., r'$\mathrm{high-}[\alpha/\mathrm{Fe}]\ \mathrm{MAPs}$', size=16.) pyplot.gca().tick_params(axis='y', which='minor', left='off', right='off') bovy_plot.bovy_end_print(plotname)
def plot_mapflarepdf(savename, plotname): # Load the samples with open('../mapfits/tribrokenexpflare.sav', 'rb') as savefile: bf = numpy.array(pickle.load(savefile)) samples = numpy.array(pickle.load(savefile)) maps = define_rcsample.MAPs() # Loop through the low-alpha MAPs and compute the XD decomposition if 'lowalpha' in savename: plotmaps = [9, 16, 23, 29, 36, 43, 50, 57, 64, 71] else: plotmaps = [19, 26, 32, 39, 45] if not os.path.exists(savename): ngauss = 2 allxamp = numpy.empty((len(plotmaps), ngauss)) allxmean = numpy.empty((len(plotmaps), ngauss, 1)) allxcovar = numpy.empty((len(plotmaps), ngauss, 1, 1)) cnt = 0 for ii, map in enumerate(maps.map()): if not ii in plotmaps: continue print ii # Fit PDFs with XD xamp = numpy.array([0.45, 0.5]) xmean = numpy.array([ numpy.mean(samples[ii, 4]) + numpy.random.normal() * numpy.std(samples[ii, 4]), numpy.mean(samples[ii, 4]) + numpy.random.normal() * numpy.std(samples[ii, 4]) ])[:, numpy.newaxis] xcovar = numpy.reshape( numpy.tile(numpy.var(samples[ii, 4]), (2, 1)), (2, 1, 1)) XD.extreme_deconvolution(samples[ii, 4][:, numpy.newaxis], numpy.zeros((len(samples[ii, 4]), 1)), xamp, xmean, xcovar) allxamp[cnt] = xamp allxmean[cnt] = xmean allxcovar[cnt] = xcovar cnt += 1 save_pickles(savename, allxamp, allxmean, allxcovar) else: with open(savename, 'rb') as savefile: allxamp = pickle.load(savefile) allxmean = pickle.load(savefile) allxcovar = pickle.load(savefile) # Now plot cmap = cm.coolwarm xrange = [-0.37, 0.25] if 'lowalpha' in savename: # xrange= [-0.4,0.2] yrange = [0., 30.] combDiv = 2. colorFunc = lambda x: cmap((x + 0.6) * 0.95 / 0.9 + 0.05) else: # xrange= [-0.3,0.3] yrange = [0., 13.5] colorFunc = lambda x: cmap((x + 0.5) * 0.95 / 0.5 + 0.05) combDiv = 1.5 overplot = False plotXDFit = True cnt = 0 bovy_plot.bovy_print(axes_labelsize=18, text_fontsize=18, xtick_labelsize=14, ytick_labelsize=14) for ii, map in enumerate(maps.map()): if not ii in plotmaps: continue tfeh = round(numpy.median(map['FE_H']) * 20.) / 20. if tfeh == 0.25: tfeh = 0.3 if tfeh == -0.1: tfeh = -0.1 bovy_plot.bovy_hist( samples[ii, 4], range=xrange, bins=51, overplot=overplot, yrange=yrange, histtype='step', normed=True, zorder=2, color=colorFunc(tfeh), xlabel=r'$R_{\mathrm{flare}}^{-1}\,(\mathrm{kpc}^{-1})$') if plotXDFit: txs = numpy.linspace(xrange[0], xrange[1], 1001) pyplot.plot( txs, 1. / numpy.sqrt(2. * numpy.pi) * (allxamp[cnt, 0] / numpy.sqrt(allxcovar[cnt, 0, 0, 0]) * numpy.exp(-0.5 * (txs - allxmean[cnt, 0, 0])**2. / allxcovar[cnt, 0, 0, 0]) + allxamp[cnt, 1] / numpy.sqrt(allxcovar[cnt, 1, 0, 0]) * numpy.exp(-0.5 * (txs - allxmean[cnt, 1, 0])**2. / allxcovar[cnt, 1, 0, 0])), color=colorFunc(tfeh), zorder=1) overplot = True cnt += 1 txs = numpy.linspace(xrange[0], xrange[1], 1001) comb = numpy.ones_like(txs) for ii in range(len(plotmaps)): comb *= 1. / numpy.sqrt(2. * numpy.pi) * ( allxamp[ii, 0] / numpy.sqrt(allxcovar[ii, 0, 0, 0]) * numpy.exp(-0.5 * (txs - allxmean[ii, 0, 0])**2. / allxcovar[ii, 0, 0, 0]) + allxamp[ii, 1] / numpy.sqrt(allxcovar[ii, 1, 0, 0]) * numpy.exp(-0.5 * (txs - allxmean[ii, 1, 0])**2. / allxcovar[ii, 1, 0, 0])) comb /= numpy.sum(comb) * (txs[1] - txs[0]) pyplot.plot(txs, comb / combDiv, 'k-', lw=2., zorder=20) pyplot.plot([0., 0.], [0., 50.], 'k--', lw=1.5, zorder=0) t = pyplot.text( xrange[0] + 0.25 * (xrange[1] - xrange[0]) + 0.03 * ('highalpha' in savename), 0.8 * yrange[1], r'$R_{\mathrm{flare}}^{-1} = %.2f \pm %.2f\,\mathrm{kpc}^{-1}$' % (numpy.sum(comb * txs) / numpy.sum(comb), numpy.sqrt( numpy.sum(comb * txs**2.) / numpy.sum(comb) - (numpy.sum(comb * txs) / numpy.sum(comb))**2.)), size=18.) t.set_bbox(dict(color='w', edgecolor='none')) if 'lowalpha' in savename: bovy_plot.bovy_text( r'$\mathrm{low-}[\alpha/\mathrm{Fe}]\ \mathrm{MAPs}$', top_left=True, size=16.) else: bovy_plot.bovy_text( r'$\mathrm{high-}[\alpha/\mathrm{Fe}]\ \mathrm{MAPs}$', top_left=True, size=16.) bovy_plot.bovy_end_print(plotname) return None
def plot_mapflare(plotname): # Open all three alternative models with open('../mapfits/tribrokenexpflare.sav', 'rb') as savefile: bf = numpy.array(pickle.load(savefile)) samples_brexp = numpy.array(pickle.load(savefile)) with open('../mapfits/tribrokenexpinvlinflare.sav', 'rb') as savefile: bf = numpy.array(pickle.load(savefile)) samples_brexp_invlin = numpy.array(pickle.load(savefile)) with open('../mapfits/tribrokenexplinflare.sav', 'rb') as savefile: bf = numpy.array(pickle.load(savefile)) samples_brexp_lin = numpy.array(pickle.load(savefile)) plotmaps = [16, 23, 29, 36, 43, 50, 57, 64, 71] bovy_plot.bovy_print(fig_width=8., fig_height=9. * 4.99 / 8.98) maps = define_rcsample.MAPs() cmap = cm.coolwarm overplot = False Rs = numpy.linspace(4., 14., 1001) # Setup for saving the profiles csvfile = open(os.path.join('..', 'out', 'mapflare.csv'), 'w') writer = csv.writer(csvfile, delimiter=',', quoting=csv.QUOTE_NONE) writer.writerow( ['# Scale height profile for MAPs (Figure 13 in Bovy et al. 2016)']) writer.writerow([ '# The first line lists the radii at which the scale height profiles' ]) writer.writerow(['# are evaluated']) writer.writerow( ['# The rest of the file are the scale heights; the 0.025']) writer.writerow(['# lower limit and the 0.0975 upper limit (each 1 line)']) writer.writerow(['# Different MAPs are separated by a comment line']) writer.writerow(['{:.2f}'.format(x) for x in Rs]) for ii, map in enumerate(maps.map()): if not ii in plotmaps: continue # Create all flaring profiles #Rmin= numpy.sort(map['RC_GALR_H'])[int(round(0.005*len(map)))] #Rmax= numpy.sort(map['RC_GALR_H'])[numpy.amin([len(map)-1,int(round(0.995*len(map)))])] samples = samples_brexp[ii, :, ::_SKIP] samples_invlin = samples_brexp_invlin[ii, :, ::_SKIP] samples_lin = samples_brexp_lin[ii, :, ::_SKIP] nsamples = len(samples[0]) tRs = numpy.tile(Rs, (nsamples, 1)).T ldp = numpy.empty((len(Rs), nsamples)) ldp = samples[1] * numpy.exp(samples[4] * (tRs - densprofiles._R0)) ldp_invlin= samples_invlin[1]\ *(1.+samples_invlin[4]*(tRs-densprofiles._R0)*(numpy.exp(1.)-1.)) ldp_lin= samples_lin[1]\ /(1.-(tRs-densprofiles._R0)*samples_lin[4]*(numpy.exp(1.)-1.)) ldp = 1000. / ldp # make it hz instead of its inverse ldp_invlin = 1000. / ldp_invlin ldp_lin = 1000. / ldp_lin # Label and relative normalization tfeh = round(numpy.median(map['FE_H']) * 20.) / 20. if tfeh == 0.25: tfeh = 0.3 if tfeh == -0.0: tfeh = 0.0 offset = 10.**(4. * (tfeh + 0.5)) if tfeh == 0.3: offset *= 3. print ii, tfeh, len(map), offset bovy_plot.bovy_plot( Rs, numpy.median(ldp, axis=1) * offset, '-', color=cmap((tfeh + 0.6) * 0.95 / 0.9 + 0.05), lw=2., overplot=overplot, xlabel=r'$R\,(\mathrm{kpc})$', ylabel=r'$h_Z\,(\mathrm{pc})\times\mathrm{constant}$', xrange=[0., 16.], yrange=[10.**2., 10.**6.99], zorder=12 + ii, semilogy=True) pyplot.fill_between(Rs, numpy.median(ldp_lin, axis=1) * offset, numpy.median(ldp_invlin, axis=1) * offset, color='0.65', lw=0., zorder=ii - 1) pyplot.fill_between( Rs, numpy.sort(ldp, axis=1)[:, int(round(_SIGNIF * nsamples))] * offset, numpy.sort(ldp, axis=1)[:, int(round( (1. - _SIGNIF) * nsamples))] * offset, color=cmap((tfeh + 0.6)), lw=0., zorder=ii) line, = pyplot.plot(Rs, Rs * 0. + 300. * offset, color=cmap((tfeh + 0.6) * 0.95 / 0.9 + 0.05), ls='-', lw=2. * 0.8, zorder=ii + 5) line.set_dashes([8, 6]) overplot = True if ii == 16: bovy_plot.bovy_text(2., 10.**6.3, r'$[\mathrm{Fe/H}]$', size=16., color='k') bovy_plot.bovy_text(2., numpy.median(ldp, axis=1)[0] * offset, r'$%+.1f$' % tfeh, size=16., color=cmap((tfeh + 0.6) * 0.95 / 0.9 + 0.05)) writer.writerow(['# Low-alpha MAP w/ [Fe/H]=%g' % tfeh]) writer.writerow( ['{:.3f}'.format(x) for x in list(numpy.median(ldp, axis=1))]) writer.writerow([ '{:.3f}'.format(x) for x in list( numpy.sort(ldp, axis=1)[:, int(round(_SIGNIF * nsamples))]) ]) writer.writerow([ '{:.3f}'.format(x) for x in list( numpy.sort(ldp, axis=1)[:, int(round((1. - _SIGNIF) * nsamples))]) ]) csvfile.close() bovy_plot.bovy_text(1., 10.**6.6, r'$\mathrm{low-}[\alpha/\mathrm{Fe}]\ \mathrm{MAPs}$', size=16.) bovy_plot.bovy_end_print(plotname)
def plot_maphz(plotname): # Load the three fits with open('../mapfits/tribrokenexpflare.sav', 'rb') as savefile: bf = numpy.array(pickle.load(savefile)) samples = numpy.array(pickle.load(savefile)) with open('../mapfits/tribrokenexp.sav', 'rb') as savefile: bfnf = numpy.array(pickle.load(savefile)) samplesnf = numpy.array(pickle.load(savefile)) with open('../mapfits/tribrokenexpfixedflare.sav', 'rb') as savefile: bfff = numpy.array(pickle.load(savefile)) samplesff = numpy.array(pickle.load(savefile)) maps = define_rcsample.MAPs() plotthisz = numpy.zeros(len(bf)) + numpy.nan plotthisze = numpy.zeros(len(bf)) + numpy.nan for ii, map in enumerate(maps.map()): if numpy.median( numpy.exp( samples[ii, 3])[True - numpy.isnan(numpy.exp(samples[ii, 3]))]) < 5.: tmed = numpy.median( (1. / samplesnf[ii, 1])[True - numpy.isnan(1. / samplesnf[ii, 1])]) terr = numpy.std( (1. / samplesnf[ii, 1])[True - numpy.isnan(1. / samplesnf[ii, 1])]) else: tmed = numpy.median( (1. / samplesff[ii, 1])[True - numpy.isnan(1. / samplesff[ii, 1])]) terr = numpy.std( (1. / samplesff[ii, 1])[True - numpy.isnan(1. / samplesff[ii, 1])]) plotthisz[ii] = tmed plotthisze[ii] = terr plotthisz[plotthisze / plotthisz > 0.2] = numpy.nan bovy_plot.bovy_print() maps.plot(plotthisz * 1000., vmin=200., vmax=1000., minnstar=15, zlabel=r'$h_Z\,(\mathrm{pc})$', shrink=0.655) # Sequences haloc = define_rcsample.highalphalocus() bovy_plot.bovy_plot(haloc[:, 0], haloc[:, 1], '-', color='0.75', lw=2.5, overplot=True) haloc = define_rcsample.lowalphalocus() haloc = haloc[(haloc[:, 0] > -0.55) * (haloc[:, 0] < 0.225)] bovy_plot.bovy_plot(haloc[:, 0], haloc[:, 1], '-', color='0.75', lw=2.5, overplot=True) # Label #t= pyplot.text(-0.51,0.235,r'$\mathrm{single}$', # size=16.,color='w') #t.set_bbox(dict(alpha=0.5,color=cm.coolwarm(0.), # edgecolor='none')) #t= pyplot.text(-0.475,0.195,r'$\mathrm{exponential}$', # size=16.,color='w') #t.set_bbox(dict(alpha=0.5,color=cm.coolwarm(0.), # edgecolor='none')) pyplot.tight_layout() bovy_plot.bovy_end_print(plotname, dpi=300) return None