def plot_dla_mass_metallicity(self, color="blue"): """Plot host halo mass vs metallicity for DLAs""" (halo_mass, _, _) = self._load_halo(0) self._get_sigma_DLA(0,2) ind = np.where(self.dla_halo >= 0) masses = halo_mass[self.dla_halo[ind]] met = self.get_dla_metallicity()[ind] ind2 = np.where((met > -2.7)*(met < 0.5)*(masses > 10**9)) met = met[ind2] masses = np.log10(masses[ind2]) (H, xedges, yedges) = np.histogram2d(masses, met,bins=10,normed=True) xbins=np.array([(xedges[i+1]+xedges[i])/2 for i in xrange(0,np.size(xedges)-1)]) ybins=np.array([(yedges[i+1]+yedges[i])/2 for i in xrange(0,np.size(yedges)-1)]) plt.contourf(10**xbins,ybins,H.T,[0.1,1],colors=(color,"black"),alpha=0.5) #Get fit amed=halohi.calc_binned_median(xedges, masses, met) aupq=halohi.calc_binned_percentile(xedges, masses, met,75)-amed #Addition to avoid zeros aloq=amed - halohi.calc_binned_percentile(xedges, masses, met,100-75) err = (aupq+aloq)/2. #Arbitrary large values if err is zero ap = powerfit(xbins, amed, np.log10(err), breakpoint=10) mdiff=xbins-ap[0] fit=(ap[2]*mdiff+ap[1]) # asfit=broken_fit(ap, np.log10(mass)) print "Fit: ",ap #Plot median sigma DLA plt.errorbar(10**xbins, amed,yerr=[aloq,aupq],fmt='^',color=color,ms=15,elinewidth=4) plt.semilogx(10**xbins, fit,color=color,ls="-",lw=3) plt.ylabel(r"log $(Z / Z_\odot)$") plt.xlabel(r"Halo mass ($M_\odot$)") return (masses,met)
def get_sigma_DLA_binned(self,mass,DLA_cut=20.3,DLA_upper_cut=42.,sigma=95): """Get the median and scatter of sigma_DLA against mass.""" aind = np.where(self.sigDLA > 0) #plt.loglog(self.real_sub_mass[aind], self.sigDLA[aind],'x') amed=halohi.calc_binned_median(mass, self.real_sub_mass[aind], self.sigDLA[aind]) aupq=halohi.calc_binned_percentile(mass, self.real_sub_mass[aind], self.sigDLA[aind],sigma)-amed #Addition to avoid zeros aloq=amed - halohi.calc_binned_percentile(mass, self.real_sub_mass[aind], self.sigDLA[aind],100-sigma) return (amed, aloq, aupq)
def get_sigma_DLA_binned(self,mass,DLA_cut=20.3,DLA_upper_cut=42.,sigma=95): """Get the median and scatter of sigma_DLA against mass.""" if DLA_cut < 17.5: sigs = self.sigLLS else: sigs = self.sigDLA aind = np.where(sigs > 0) #plt.loglog(self.real_sub_mass[aind], self.sigDLA[aind],'x') amed=calc_binned_median(mass, self.real_sub_mass[aind], sigs[aind]) aupq=calc_binned_percentile(mass, self.real_sub_mass[aind], sigs[aind],sigma)-amed #Addition to avoid zeros aloq=amed - calc_binned_percentile(mass, self.real_sub_mass[aind], sigs[aind],100-sigma) return (amed, aloq, aupq)