Ejemplo n.º 1
0
 def work(z):
     Lband, M_AB, S_nu, Phi = _qlf.qlf(band, z, Lbolbins)
     Phi /= (U.MPC ** 3)
     Dc = cosmology.Dc(z)
     DL = Dc * (1 + z)
     distance_modulus = 5 * numpy.log10(DL / (0.01 * U.KPC))
     m_AB = M_AB + distance_modulus
     spl = UnivariateSpline(-m_AB, Phi, k=5)
     print z, DL, m_AB[0], m_AB[-1], Phi.sum(), m_AB.max(), m_AB.min()
     integrated = spl.integral(-faint, -bright)
     if integrated < 0: integrated = 0
     return integrated
Ejemplo n.º 2
0
def qlf(cosmology, band, magnitude=False, returnraw=False):
  """ returns an scipy interpolated function for the hopkins 2007 QLF, 
      at a given band.
      band can be a frequency, or 'bol', 'blue', 'ir', 'soft', 'hard'.
      HOPKINS2007 cosmology is implied.
      result shall not depend on the input cosmology but the HOPKINS cosmology
      is implied in the fits.
      if return raw is true, return 
         zrange, Lbol, Lband, M_AB, S_nu, Phi
  """
  zbins = numpy.linspace(0, 6, 200)
  Lbolbins=numpy.linspace(8, 18, 300)

  U = cosmology.units
  banddict = {'bol':0, 'blue':-1, 'ir':-2, 'soft':-3, 'hard': -4}
  from scipy.interpolate import RectBivariateSpline
  if band in banddict: 
      band = banddict[band]

  else: band = _bandconv(U, band, hertz=True)
  key = band

  if key not in _qlf_interp:
    v = numpy.empty(numpy.broadcast(Lbolbins[None, :], zbins[:, None]).shape)
    Lband, M_AB, S_nu, Phi = _qlf.qlf(band, 1.0, Lbolbins)
    with sharedmem.TPool() as pool:
      def work(v, z):
        Lband_, M_AB_, S_nu, Phi = _qlf.qlf(band, z, Lbolbins)
        v[:] = Phi
      pool.starmap(work, zip(v, zbins))
    v /= (U.MPC ** 3)
    # Notice that hopkins used 3.9e33 ergs/s for Lsun, but we use a different number.
    # but the internal fits of his numbers
    # thus we skip the conversion, in order to match the fits with luminosity in terms of Lsun.
    # Lbol = Lbol - numpy.log10(U.SOLARLUMINOSITY/U.ERG*U.SECOND) + numpy.log10(3.9e33)
    data = numpy.empty(shape=len(Lbolbins),
        dtype=[
          ('Lbol', 'f4'),
          ('Lband', 'f4'),
          ('M_AB', 'f4'),
          ('S_nu', 'f4'),
          ('Phi', ('f4', v.shape[0]))])
    data['Lbol'] = Lbolbins
    data['Lband'] = Lband
    data['M_AB'] = M_AB
    data['S_nu'] = S_nu
    data['Phi'] = v.T
    _qlf_interp[key] = data
  data = _qlf_interp[key]
  if returnraw:
    return data.view(numpy.recarray)
  if magnitude:
    func = RectBivariateSpline(zbins, - data['M_AB'], data['Phi'].T)
    func.x = zbins
    func.y = -data['M_AB']
    func.z = data['Phi'].T
    return func
  else:
    func = RectBivariateSpline(zbins, data['Lband'], data['Phi'].T)
    func.x = zbins
    func.y = data['Lband']
    func.z = data['Phi'].T
    return func
Ejemplo n.º 3
0
 def work(v, z):
   Lband_, M_AB_, S_nu, Phi = _qlf.qlf(band, z, Lbolbins)
   v[:] = Phi