Пример #1
0
def _lambda(lambda_value, z, R, mag, mlim, Cfilter, Lfilter, bx, mag_err=0,
            sigma_R=0.05, Ro=0.9, Rs=0.15, Rcore=0.1, beta=0.2, maxiter=1000):
    """
    bx is background per sq. deg.
    """
    Rc = Ro * (lambda_value/100.)**beta
    j = (R < Rc)
    # the radius in radians
    d = numpy.pi/180 * cosmology.dProj(z, Rc, input_unit='Mpc', unit='deg')
    # the prefactor (180/pi)**2 is to convert to sq. deg.
    area = (180/numpy.pi)**2 * 2*numpy.pi * (1 - numpy.cos(d/2.))
    Rfilter = filter_radius(R, Rc=Rc, Rs=Rs, Rcore=Rcore)
    ux = 2*numpy.pi*R*Rfilter * Cfilter * Lfilter
    ux[ux == 0] = 1e-100
    bg = 2 * numpy.pi * R * bx * area
    px = numpy.zeros(ux.shape)
    # smooth edges (Rozo et al. 2015, Appendix B)
    thetaL = 0.5 * (1 + erf((mlim - mag[j])/mag_err[j]))
    thetaR = 0.5 * (1 + erf((Rc - R[j])/sigma_R))
    #thetaL = thetaR = 1
    eq = lambda n: n - (n*ux[j] * thetaL * thetaR / (n*ux[j] + bg[j])).sum()
    try:
        richness = optimize.newton(eq, lambda_value, maxiter=maxiter)
    except RuntimeError:
        # doing this means that the loop
        print 'Hit RuntimeError with maxiter=%d' %maxiter
        return lambda_value, px, Rfilter, Rc
    #print 'z=%.2f Rc=%.2f area=%.4f No=%.1f N=%.1f' \
          #%(z, Rc, area, lambda_value, richness)
    px[j] = richness * ux[j] / (richness * ux[j] + bg[j])
    return richness, px, Rfilter, Rc
Пример #2
0
def one_group(out,
              hostid,
              x,
              y,
              v,
              zobs=0.5,
              fov=10,
              slit_size=None,
              ngals=40,
              width=1.,
              rnd=False,
              fill=False,
              mbm=True,
              iterate=True):
    # relative positions -- is the BCG actually the first object in the list?
    x -= x[0]
    y -= y[0]
    r = scipy.hypot(x, y)
    if fov is None:
        obs = scipy.arange(len(x), dtype=int)
    else:
        # coordinates in arcmin
        X = scipy.array([cosmology.dProj(zobs, xi, input_unit='Mpc',
                                         unit='arcmin') \
                         for xi in x])
        Y = scipy.array([cosmology.dProj(zobs, yi, input_unit='Mpc',
                                         unit='arcmin') \
                         for yi in y])
        if rnd:
            size = min(ngals, len(x))
            j = scipy.arange(len(x))
            obs = random.permutation(j[(X < fov) & (Y < fov)])[:size]
        else:
            obs = make_mask(X,
                            Y,
                            v,
                            fov=fov,
                            slit_size=slit_size,
                            ngals=ngals,
                            width=width,
                            fill=fill)
    dynamics(hostid, r, v, obs, out, mbm=mbm, iterate=iterate)
    return
Пример #3
0
def run(center, min_Nperbin=15, min_binsize=250,
        maingap=500, maxgap=1000, sigma=False, version='1'):
  #center = centers[i]
  id = center[0]
  xo = center[1]
  yo = center[2]
  zo = center[3]

  j = close(xo, yo, zo, ra, dec, z)
  r = astCoords.calcAngSepDeg(xo, yo, ra[j], dec[j])
  r = scipy.array([cosmology.dProj(zo, ri, input_unit='deg', unit='Mpc') \
                   for ri in r])
  if '2' in version:
      r *= (1 + zo)
  r *= 1e3
  outplot = get_plotname(version, id)
  #output = 'phase%s/plots/v%s/rv/halo-%d.png' %(phase, version, id)
  m = members.sgapper(r, z[j], zo=zo, min_Nperbin=min_Nperbin,
                      maingap=maingap, maxgap=maxgap, sigma=sigma,
                      verbose=False, debug=False, plot_output=outplot,
                      full_output=True)
  m, binsize, nit, incut = m
  Nm = len(m)

  zo = stattools.Cbi(z[j[m]])
  s, m200, r200 = mass(z[j[m]], zo)
  mo = m[r[m] <= r200]
  n200 = -1
  it = []
  while n200 != len(mo):
    try:
      n200 = len(mo)
      s, m200, r200 = mass(z[j[mo]], zo)
      #zo = stattools.Cbi(z[j[mo]])
      mo = m[r[m] <= r200]
      # should maybe find a more sophisticated solution by, say, averaging
      # all items from one of these "cycles"
      if r200 in it:
        break
      it.append(r200)
    except ZeroDivisionError:
      print 'broke'
      break

  if n200 > 15:
    stats = (stattools.Cbi, stattools.Sbi)
    z_err, s_err = stattools.bootstrap(stats, z[j[incut]],
                                       n_obj=Nm, n_samples=1000)
    s_err = c * s_err / (1+zo)
  else:
    z_err = scipy.std(z) / scipy.sqrt(Nm)
    s_err = c/(1+zo) * z_err / scipy.sqrt(2)
  m200, m200_err = scalings.sigma(s, zo, s_err, z_err,
                                  separate_errors=True)
  r200 = conversions.rsph(m200, zo)

  # to make it their format
  m200_err = [scipy.log10(1+me/m200) for me in m200_err]

  try:
    #if n200 > 
    line = '%4d  %.3f  %.3f  %6d  %.1e  %4d  %.1f  %4d  %.2f  %.2f  %4d' \
           %(id, xo*deg2rad, yo*deg2rad, round(c*zo, 0), m200,
             round(s, 0), r200/1e3, n200, m200_err[0], m200_err[1], Nm)
  except TypeError:
    line = '%4d  %.3f  %.3f  %6d     -1      -1   -1    -1    -1    -1  %4d' \
           %(id, xo*deg2rad, yo*deg2rad, round(c*zo, 0), Nm)
  print line, '%4.1f' %max(r[m]/1e3)
  out = open(output, 'a')
  print >>out, line
  out.close()

  write_members(id, galid[j[m]], galid[j[mo]])
  return m200
Пример #4
0
def dProj(z, r):
  return cosmology.dProj(z, r, input_unit='deg', unit='kpc')
def distances(ra, dec, center, z):
    d = astCoords.calcAngSepDeg(ra, dec, center[0], center[1])
    r = scipy.array([cosmology.dProj(z, di) for di in d])
    return 60 * d, r
Пример #6
0
    be with respect to a center (i.e., cannot be coordinates on the sky).

    """
    if zo == 0:
        zo = scipy.median(z)
    if zunit = 'velocity':
        v = z
        zo /= c
    else:
        v = c * (z-zo)/(1+zo)
    # then x corresponds to cluster-centric distance:
    if len(y) == 0:
        if xyunit == 'kpc':
            r = x / 1e3
        elif xyunit in ('deg', 'arcmin', 'arcsec'):
            r = cosmology.dProj(zo, x, input_unit=xyunit, unit='Mpc')
    # otherwise use the given center to calculate distances
    elif xyunit in ('kpc', 'Mpc'):
        r = scipy.hypot(x, y)
        if xyunit == 'kpc':
            r /= 1e3
    else:
        if xyunit == 'arcsec':
            x /= 3600.
            y /= 3600.
        if xyunit == 'arcmin':
            x /= 60.
            y /= 60.
        dist = astCoords.calcAngSepDeg(x, y, xycenter[0], xycenter[1])
        r = cosmology.dProj(zo, dist, input_unit='deg', unit='Mpc')