Ejemplo n.º 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
Ejemplo n.º 2
0
 def __call__(self, xyz):
     """ look up the sky mask from xyz vectors
         xyz is row vectors [..., 3] """
     if chealpy is None:
         # it is guarranted config.SkymaskInput is None
         return numpy.ones(shape=xyz.shape[0])
     else:
         ipix = chealpy.vec2pix_nest(self.Nside, xyz)
         #Nside, 0.5 * numpy.pi - dec, ra)
         return self.mask[ipix]
Ejemplo n.º 3
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
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 6
0
 def work(i):
     sl = slice(i, i + chunksize)
     chunkid[sl] = chealpy.vec2pix_nest(Nside, pos[sl])