Example #1
0
    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)
Example #2
0
 def get_sDLA_fit(self):
     """Fit an broken power law profile based function to sigma_DLA as binned."""
     ind = np.where(self.real_sub_mass > 0)
     minM = np.min(self.real_sub_mass[ind])
     maxM = np.max(self.real_sub_mass)
     bins=30
     mass=np.logspace(np.log10(minM),np.log10(maxM),num=bins)
     bin_mass = np.array([(mass[i]+mass[i+1])/2. for i in xrange(0,np.size(mass)-1)])
     (sDLA,loq,upq)=self.get_sigma_DLA_binned(mass,sigma=68)
     ind = np.where((sDLA > 0)*(loq+upq > 0)*(bin_mass > 10**8.5))
     err = (upq[ind]+loq[ind])/2.
     #Arbitrary large values if err is zero
     return powerfit(np.log10(bin_mass[ind]), np.log10(sDLA[ind]), np.log10(err), breakpoint=10)
Example #3
0
 def get_sDLA_fit(self):
     """Fit an broken power law profile based function to sigma_DLA as binned."""
     ind = np.where(self.real_sub_mass > 0)
     minM = np.min(self.real_sub_mass[ind])
     maxM = np.max(self.real_sub_mass)
     bins=30
     mass=np.logspace(np.log10(minM),np.log10(maxM),num=bins)
     bin_mass = np.array([(mass[i]+mass[i+1])/2. for i in xrange(0,np.size(mass)-1)])
     (sDLA,loq,upq)=self.get_sigma_DLA_binned(mass,sigma=68)
     ind = np.where((sDLA > 0)*(loq+upq > 0)*(bin_mass > 10**8.5))
     err = (upq[ind]+loq[ind])/2.
     #Arbitrary large values if err is zero
     return powerfit(np.log10(bin_mass[ind]), np.log10(sDLA[ind]), np.log10(err), breakpoint=10)