Beispiel #1
0
 def calc_age_pdf(self,fehdist='casagrande'):
     """
     NAME:
        calc_age_pdf
     PURPOSE:
        calculate the age PDF for a uniform SFH for a given metallicity 
        distribution
     INPUT:
        fehdist= either:
           1) a single metallicity 
           2) 'casagrande': local metallicity distribution following Casagrande et al. (2011)
           3) a function giving
     OUTPUT:
         a function between 800 Myr and 10 Gyr giving the age distribution
     HISTORY:
        2014-02-27 - Written in this form - Bovy (IAS)
     """
     if isinstance(fehdist,(int,float,numpy.float32,numpy.float64)):
         pz= numpy.zeros(len(self._zs))
         pz[numpy.argmin(numpy.fabs(self._zs-isodist.FEH2Z(fehdist,zsolar=zsolar())))]= 1.
     elif isinstance(fehdist,str) and fehdist.lower() == 'casagrande':
         pz= numpy.array([localfehdist(isodist.Z2FEH(z,zsolar=zsolar()))/z for z in self._zs])
     else:
         pz= numpy.array([fehdist(isodist.Z2FEH(z,zsolar=zsolar()))/z for z in self._zs])
     pz/= numpy.sum(pz)
     agezdist= self._omega/self._coarsemass
     pz= numpy.tile(pz,(len(self._coarselages),1)).T
     postage= numpy.nansum(pz*agezdist,axis=0)/numpy.nansum(pz,axis=0)/10.**self._coarselages
     postage= postage[self._coarselages > numpy.log10(0.8)]
     postage/= numpy.nanmax(postage)
     lages= self._coarselages[self._coarselages > numpy.log10(0.8)]
     postage_spline= interpolate.InterpolatedUnivariateSpline(lages,
                                                              numpy.log(postage),
                                                              k=3)
     return lambda x: dummy_page(x,copy.copy(postage_spline))
Beispiel #2
0
 def calc_age_pdf(self,fehdist='casagrande'):
     """
     NAME:
        calc_age_pdf
     PURPOSE:
        calculate the age PDF for a uniform SFH for a given metallicity 
        distribution
     INPUT:
        fehdist= either:
           1) a single metallicity 
           2) 'casagrande': local metallicity distribution following Casagrande et al. (2011)
           3) a function giving
     OUTPUT:
         a function between 800 Myr and 10 Gyr giving the age distribution
     HISTORY:
        2014-02-27 - Written in this form - Bovy (IAS)
     """
     if isinstance(fehdist,(int,float,numpy.float32,numpy.float64)):
         pz= numpy.zeros(len(self._zs))
         pz[numpy.argmin(numpy.fabs(self._zs-isodist.FEH2Z(fehdist,zsolar=zsolar())))]= 1.
     elif isinstance(fehdist,str) and fehdist.lower() == 'casagrande':
         pz= numpy.array([localfehdist(isodist.Z2FEH(z,zsolar=zsolar()))/z for z in self._zs])
     else:
         pz= numpy.array([fehdist(isodist.Z2FEH(z,zsolar=zsolar()))/z for z in self._zs])
     pz/= numpy.sum(pz)
     agezdist= self._omega/self._coarsemass
     pz= numpy.tile(pz,(len(self._coarselages),1)).T
     postage= numpy.nansum(pz*agezdist,axis=0)/numpy.nansum(pz,axis=0)/10.**self._coarselages
     postage= postage[self._coarselages > numpy.log10(0.8)]
     postage/= numpy.nanmax(postage)
     lages= self._coarselages[self._coarselages > numpy.log10(0.8)]
     postage_spline= interpolate.InterpolatedUnivariateSpline(lages,
                                                              numpy.log(postage),
                                                              k=3)
     return lambda x: dummy_page(x,copy.copy(postage_spline))
Beispiel #3
0
def loggteffcut(teff, z, upper=True):
    if not upper:
        return 1.8
    else:
        feh = isodist.Z2FEH(z, zsolar=zsolar())
        this_teff = (4760. - 4607.) / (-0.4) * feh + 4607.
        return 0.0018 * (teff - this_teff) + 2.5
Beispiel #4
0
def loggteffcut(teff,z,upper=True):
    if not upper:
        return 1.8
    else:
        feh= isodist.Z2FEH(z,zsolar=zsolar())
        this_teff=(4760.-4607.)/(-0.4)*feh+4607.
        return 0.0018*(teff-this_teff)+2.5
Beispiel #5
0
 def popmass(self, feh, lage):
     """
     NAME:
        calc_popmass
     PURPOSE:
        calculate the mass represented by each RC star
     INPUT:
        feh - metallicity
        lage - log10 age
     OUTPUT:
        stellar-pop mass for each RC star
     HISTORY:
        2014-02-28 - Written in this form - Bovy (IAS)
     """
     if lage < numpy.log10(0.8):
         return numpy.nan
     z = isodist.FEH2Z(feh, zsolar=zsolar())
     zindx = numpy.argmin(numpy.fabs(z - self._zs))
     aindx = numpy.argmin((numpy.fabs(lage - self._coarselages)))
     return self._coarsemass[zindx, aindx] / self._omega[zindx, aindx]
Beispiel #6
0
 def avgmass(self, feh, lage):
     """
     NAME:
        calc_avgmass
     PURPOSE:
        calculate the average mass
     INPUT:
        feh - metallicity
        lage - log10 age
     OUTPUT:
        average mass in solar masses
     HISTORY:
        2014-02-28 - Written in this form - Bovy (IAS)
     """
     if lage < numpy.log10(0.8):
         return numpy.nan
     z = isodist.FEH2Z(feh, zsolar=zsolar())
     zindx = numpy.argmin(numpy.fabs(z - self._zs))
     aindx = numpy.argmin((numpy.fabs(lage - self._finelages)))
     return self._finemass[zindx, aindx]
Beispiel #7
0
 def popmass(self,feh,lage):
     """
     NAME:
        calc_popmass
     PURPOSE:
        calculate the mass represented by each RC star
     INPUT:
        feh - metallicity
        lage - log10 age
     OUTPUT:
        stellar-pop mass for each RC star
     HISTORY:
        2014-02-28 - Written in this form - Bovy (IAS)
     """
     if lage < numpy.log10(0.8):
         return numpy.nan
     z= isodist.FEH2Z(feh,zsolar=zsolar())
     zindx= numpy.argmin(numpy.fabs(z-self._zs))
     aindx= numpy.argmin((numpy.fabs(lage-self._coarselages)))
     return self._coarsemass[zindx,aindx]/self._omega[zindx,aindx]
Beispiel #8
0
 def avgmass(self,feh,lage):
     """
     NAME:
        calc_avgmass
     PURPOSE:
        calculate the average mass
     INPUT:
        feh - metallicity
        lage - log10 age
     OUTPUT:
        average mass in solar masses
     HISTORY:
        2014-02-28 - Written in this form - Bovy (IAS)
     """
     if lage < numpy.log10(0.8):
         return numpy.nan
     z= isodist.FEH2Z(feh,zsolar=zsolar())
     zindx= numpy.argmin(numpy.fabs(z-self._zs))
     aindx= numpy.argmin((numpy.fabs(lage-self._finelages)))
     return self._finemass[zindx,aindx]
Beispiel #9
0
 def plot_popmass(self):
     """
     NAME:
        plot_popmass
     PURPOSE:
        plot the stellar-population mass for each RC star
     INPUT:
         bovy_plot.bovy_plot **kwargs
     OUTPUT:
        bovy_plot.bovy_plot output
     HISTORY:
        2014-02-28 - Written in this form - Bovy (IAS)
     """
     if not _BOVY_PLOT_LOADED:
         raise ImportError("galpy.util.bovy_plot could not be imported")
     fehs = numpy.linspace(-1., 0.5, 101)
     lages = self._coarselages
     plotthis = numpy.empty((len(fehs), len(lages)))
     for ii in range(len(fehs)):
         for jj in range(len(lages)):
             plotthis[ii, jj] = self.popmass(fehs[ii], lages[jj])
     fig = pyplot.gcf()
     left, bottom, width, height = 0.1, 0.1, 0.8, 0.6
     axBottom = pyplot.axes([left, bottom, width, height])
     fig.sca(axBottom)
     xlimits = [fehs[0], fehs[-1]]
     dlages = (lages[1] - lages[0])
     ylimits = [lages[0] - dlages, lages[-1] + dlages]
     vmin, vmax = 0., 50000.
     vmin2, vmax2 = 0., 25000.
     zlabel = r'$\mathrm{Stellar\ population\ mass\ per\ RC\ star}\,(M_\odot)$'
     xlabel = r'$[\mathrm{Fe/H}]\,(\mathrm{dex})$'
     out = bovy_plot.bovy_dens2d(plotthis.T,
                                 origin='lower',
                                 cmap='jet',
                                 xrange=xlimits,
                                 yrange=ylimits,
                                 vmin=vmin,
                                 vmax=vmax,
                                 interpolation='nearest',
                                 colorbar=True,
                                 shrink=.9,
                                 zlabel=zlabel,
                                 overplot=True)
     extent = xlimits + ylimits
     pyplot.axis(extent)
     bovy_plot._add_axislabels(
         xlabel, r'$\log_{10}\,\mathrm{Age} / 1\,\mathrm{Gyr}$')
     bovy_plot._add_ticks()
     left, bottom, width, height = 0.1, 0.68, 0.64, 0.2
     axTop = pyplot.axes([left, bottom, width, height])
     fig.sca(axTop)
     #Plot the average over SFH
     lages = numpy.linspace(-1., 1., 16)
     mtrend = numpy.zeros(len(self._zs))
     exppage = 10.**self._coarselages * numpy.exp(
         (10.**(self._coarselages + 2.)) / 800.)  #e.g., Binney (2010)
     exexppage = 10.**self._coarselages * numpy.exp(
         (10.**(self._coarselages + 2.)) / 100.)  #e.g., Binney (2010)
     page = 10.**self._coarselages
     plotthis = self._coarsemass[:-1, :] / self._omega[:-1, :]
     mtrend = 1. / (numpy.sum(page * 1. / plotthis, axis=1) /
                    numpy.sum(page))
     expmtrend = 1. / (numpy.sum(exppage * 1. / plotthis, axis=1) /
                       numpy.sum(exppage))
     exexpmtrend = 1. / (numpy.sum(exexppage * 1. / plotthis, axis=1) /
                         numpy.sum(exexppage))
     fehs = isodist.Z2FEH(self._zs[:-1], zsolar=zsolar())
     pyplot.plot(fehs, mtrend, 'k-')
     pyplot.plot(fehs, expmtrend, 'k--')
     pyplot.plot(fehs, exexpmtrend, 'k-.')
     pyplot.ylim(vmin2, vmax2)
     pyplot.xlim(xlimits[0], xlimits[1])
     nullfmt = NullFormatter()  # no labels
     thisax = pyplot.gca()
     thisax.xaxis.set_major_formatter(nullfmt)
     bovy_plot._add_ticks()
     return out
Beispiel #10
0
 def plot_popmass(self):
     """
     NAME:
        plot_popmass
     PURPOSE:
        plot the stellar-population mass for each RC star
     INPUT:
         bovy_plot.bovy_plot **kwargs
     OUTPUT:
        bovy_plot.bovy_plot output
     HISTORY:
        2014-02-28 - Written in this form - Bovy (IAS)
     """
     if not _BOVY_PLOT_LOADED:
         raise ImportError("galpy.util.bovy_plot could not be imported")
     fehs= numpy.linspace(-1.,0.5,101)
     lages= self._coarselages
     plotthis= numpy.empty((len(fehs),len(lages)))
     for ii in range(len(fehs)):
         for jj in range(len(lages)):
             plotthis[ii,jj]= self.popmass(fehs[ii],lages[jj])
     fig= pyplot.gcf()
     left, bottom, width, height= 0.1, 0.1, 0.8, 0.6
     axBottom= pyplot.axes([left,bottom,width,height])
     fig.sca(axBottom)
     xlimits= [fehs[0],fehs[-1]]
     dlages= (lages[1]-lages[0])
     ylimits= [lages[0]-dlages,lages[-1]+dlages]
     vmin, vmax= 0.,50000.
     vmin2, vmax2= 0.,25000.
     zlabel= r'$\mathrm{Stellar\ population\ mass\ per\ RC\ star}\,(M_\odot)$'
     xlabel= r'$[\mathrm{Fe/H}]\,(\mathrm{dex})$'
     out= bovy_plot.bovy_dens2d(plotthis.T,origin='lower',cmap='jet',
                                xrange=xlimits,
                                yrange=ylimits,
                                vmin=vmin,vmax=vmax,
                                interpolation='nearest',
                                colorbar=True,
                                shrink=.9,
                                zlabel=zlabel,
                                overplot=True)
     extent= xlimits+ylimits
     pyplot.axis(extent)
     bovy_plot._add_axislabels(xlabel,
                               r'$\log_{10}\,\mathrm{Age} / 1\,\mathrm{Gyr}$')
     bovy_plot._add_ticks()
     left, bottom, width, height= 0.1, 0.68, 0.64, 0.2
     axTop= pyplot.axes([left,bottom,width,height])
     fig.sca(axTop)
     #Plot the average over SFH
     lages= numpy.linspace(-1.,1.,16)
     mtrend= numpy.zeros(len(self._zs))
     exppage= 10.**self._coarselages*numpy.exp((10.**(self._coarselages+2.))/800.) #e.g., Binney (2010)
     exexppage= 10.**self._coarselages*numpy.exp((10.**(self._coarselages+2.))/100.) #e.g., Binney (2010)
     page= 10.**self._coarselages
     plotthis= self._coarsemass[:-1,:]/self._omega[:-1,:]
     mtrend= 1./(numpy.sum(page*1./plotthis,axis=1)/numpy.sum(page))
     expmtrend= 1./(numpy.sum(exppage*1./plotthis,axis=1)/numpy.sum(exppage))
     exexpmtrend= 1./(numpy.sum(exexppage*1./plotthis,axis=1)/numpy.sum(exexppage))
     fehs= isodist.Z2FEH(self._zs[:-1],zsolar=zsolar())
     pyplot.plot(fehs,mtrend,'k-')
     pyplot.plot(fehs,expmtrend,'k--')
     pyplot.plot(fehs,exexpmtrend,'k-.')
     pyplot.ylim(vmin2,vmax2)
     pyplot.xlim(xlimits[0],xlimits[1])
     nullfmt   = NullFormatter()         # no labels
     thisax= pyplot.gca()
     thisax.xaxis.set_major_formatter(nullfmt)
     bovy_plot._add_ticks()
     return out