示例#1
0
def Rs(nside,
       field,
       component,
       weight,
       levels=[0.1, 0.5, 0.9],
       center=None,
       rmax=None,
       rmin=None,
       direction=1,
       nbins=500,
       return_all=False):
    """ direction = +1 or -1, for increasing or decreasing """
    if center is None:
        center = field.cut.center
    if rmax is None:
        rmax = field.cut.size[0] / 2
    if rmin is None:
        rmin = rmax / 200

    disp = field['locations'] - center[newaxis, :]
    r = (disp[:, 0:3]**2).sum(axis=-1)**0.5
    mask = (r < rmax) & (r > rmin)
    if nside > 0:
        npix = hy.nside2npix(nside)
        pixid = hy.vec2pix_nest(nside, disp[mask, 0] / r[mask],
                                disp[mask, 1] / r[mask],
                                disp[mask, 2] / r[mask])
    else:
        npix = 1
        pixid = 0
    bins = linspace(rmin, rmax, nbins)
    rid = digitize(r[mask], bins)
    Mhist = zeros((npix, bins.shape[0]))
    HIhist = zeros_like(Mhist)

    flatid = pixid * bins.shape[0] + rid
    Mcount = bincount(flatid, field[weight][mask])
    HIcount = bincount(flatid, field[weight][mask] * field[component][mask])
    a = arange(len(Mcount))
    Mhist.reshape(-1)[a] = Mcount
    a = arange(len(HIcount))
    HIhist.reshape(-1)[a] = HIcount
    ahist = HIhist / Mhist

    result = []
    for l in levels:
        if direction > 0:
            ridout = first(ahist > l)
            ridin = last(ahist < l, first=ridout)
        else:
            ridout = first(ahist < l)
            ridin = last(ahist > l, first=ridout)

        rs = 0.5 * (bins[ridin] + bins[ridout + 1])

        result += [rs]
    if return_all:
        return result, ahist, bins
    else:
        return result
示例#2
0
def Rs(nside, field, component, weight, levels=[0.1, 0.5, 0.9], center=None, rmax=None, rmin=None, direction=1, nbins=500, return_all=False):
  """ direction = +1 or -1, for increasing or decreasing """
  if center is None:
    center = field.cut.center
  if rmax is None:
    rmax = field.cut.size[0] / 2
  if rmin is None:
    rmin = rmax / 200

  disp = field['locations'] - center[newaxis, :]
  r = (disp[:,0:3] **2).sum(axis=-1) ** 0.5
  mask = (r < rmax) & (r > rmin)
  if nside > 0:
    npix = hy.nside2npix(nside)
    pixid = hy.vec2pix_nest(nside, disp[mask,0]/r[mask], disp[mask, 1]/r[mask], disp[mask,2]/r[mask])
  else:
    npix = 1
    pixid = 0
  bins = linspace(rmin, rmax, nbins)
  rid = digitize(r[mask], bins)
  Mhist = zeros((npix , bins.shape[0]))
  HIhist = zeros_like(Mhist)

  flatid = pixid * bins.shape[0] + rid
  Mcount = bincount(flatid, field[weight][mask])
  HIcount = bincount(flatid, field[weight][mask] * field[component][mask])
  a = arange(len(Mcount))
  Mhist.reshape(-1)[a] = Mcount
  a = arange(len(HIcount))
  HIhist.reshape(-1)[a] = HIcount
  ahist = HIhist / Mhist

  result = []
  for l in levels:
    if direction > 0:
      ridout = first(ahist>l)
      ridin = last(ahist<l, first=ridout)
    else:
      ridout = first(ahist<l)
      ridin = last(ahist>l, first=ridout)

    rs = 0.5 * (bins[ridin] + bins[ridout + 1])

    result += [rs]
  if return_all:
    return result, ahist, bins
  else:
    return result
示例#3
0
def chop(Nside, pos):
    """ bootstrap the sky, returns about 100 chunks, only 50 of them are big"""
    # we paint quasar uniformly as long as it is covered by sdss:
    Npix = chealpy.nside2npix(Nside)
    chunkid = sharedmem.empty(len(pos), dtype='intp')
    print len(pos)
    with sharedmem.MapReduce() as pool:
        chunksize = 1024 * 1024
        def work(i):
            sl = slice(i, i + chunksize)
            chunkid[sl] = chealpy.vec2pix_nest(Nside, pos[sl])
        pool.map(work, range(0, len(pos), chunksize))
    arg = sharedmem.argsort(chunkid)
    chunksize = sharedmem.array.bincount(chunkid, minlength=Npix)
    assert (chunksize == numpy.bincount(chunkid, minlength=Npix)).all()
    return sharedmem.array.packarray(arg, chunksize)
示例#4
0
def sum(nside, field, component, center=None, rmax=None, rmin=None):
  if center is None:
    center = field.cut.center
  if rmax is None:
    rmax = field.cut.size[0] / 2
  if rmin is None:
    rmin = rmax / 200

  disp = field['locations'] - center[newaxis, :]
  r = (disp[:,0:3] **2).sum(axis=-1) ** 0.5
  mask = (r < rmax) & (r > rmin)
  npix = hy.nside2npix(nside)
  pixid = hy.vec2pix_nest(nside, disp[mask,0]/r[mask], disp[mask, 1]/r[mask], disp[mask,2]/r[mask])

  Mhist = zeros(npix)

  Mcount = bincount(pixid, field[component][mask])
  a = arange(len(Mcount))
  Mhist.reshape(-1)[a] = Mcount
  return Mhist
示例#5
0
def sum(nside, field, component, center=None, rmax=None, rmin=None):
    if center is None:
        center = field.cut.center
    if rmax is None:
        rmax = field.cut.size[0] / 2
    if rmin is None:
        rmin = rmax / 200

    disp = field['locations'] - center[newaxis, :]
    r = (disp[:, 0:3]**2).sum(axis=-1)**0.5
    mask = (r < rmax) & (r > rmin)
    npix = hy.nside2npix(nside)
    pixid = hy.vec2pix_nest(nside, disp[mask, 0] / r[mask],
                            disp[mask, 1] / r[mask], disp[mask, 2] / r[mask])

    Mhist = zeros(npix)

    Mcount = bincount(pixid, field[component][mask])
    a = arange(len(Mcount))
    Mhist.reshape(-1)[a] = Mcount
    return Mhist