class HPGaussSmooth(HParray): """ adapt an HParray object, and access it via a smoothing Gaussian """ def __init__(self, hparray, sigma_deg): """ hparray : HParray object sigma_deg : float sigma for convolution, in degrees. zero for no change """ self.name = hparray.name self.vec = hparray.vec # note just reference self.nside = hparray.nside band = Band(self.nside) self.dirfun = band.dir self._indexfun = band.index self.sigma = np.radians(sigma_deg) # this guy to give access to basic query_disk (should make the Healpix object accessible in Band) self.hp = Healpix(self.nside, Healpix.RING, SkyDir.GALACTIC) def __call__(self, skydir): if self.sigma == 0: return self.vec[self._indexfun(skydir)] iv = IntVector() self.hp.query_disc(skydir, 3 * self.sigma, iv) sds = map(self.dirfun, iv) deltas = np.array(map(skydir.difference, sds)) values = np.array(self.vec[list(iv)]) notnan = ~np.isnan(values) weights = np.array( map(lambda x: np.exp(-0.5 * (x / self.sigma)**2), deltas[notnan])) ret = np.dot(values[notnan], weights) / sum(weights) if np.isnan(ret) or np.isinf(ret): raise Exception('Bad value at %s' % skydir) return ret
def average(self, radius=1.0): """ average over all pixels within radius""" iv = IntVector() hp = Healpix(self.nside, Healpix.RING, SkyDir.GALACTIC) band = Band(self.nside) newvec = [0] * len(self.vec) for i in range(len(self.vec)): hp.query_disc(band.dir(i), np.radians(radius), iv) newvec[i] = np.array([self.vec[j] for j in iv]).mean() self.vec = newvec
def finish(self): hp = Healpix(self.nside,Healpix.RING,SkyDir.EQUATORIAL) ras,decs = N.asarray( [hp.py_pix2ang(i) for i in xrange(12*self.nside**2)]).transpose() self.COS_HP_DEC = N.cos(decs) self.SIN_HP_DEC = N.sin(decs) self.HP_RA = ras ra_s,dec_s = self.RA_SCZ,self.DEC_SCZ ra_z,dec_z = self.RA_ZENITH,self.DEC_ZENITH self.S_PIX = N.fromiter((hp.py_ang2pix(ra_s[i],dec_s[i]) for i in xrange(len(ra_s))),dtype=int) self.Z_PIX = N.fromiter((hp.py_ang2pix(ra_z[i],dec_z[i]) for i in xrange(len(ra_z))),dtype=int)
def __init__(self, hparray, sigma_deg): """ hparray : HParray object sigma_deg : float sigma for convolution, in degrees. zero for no change """ self.name = hparray.name self.vec = hparray.vec # note just reference self.nside = hparray.nside band = Band(self.nside) self.dirfun = band.dir self._indexfun = band.index self.sigma = np.radians(sigma_deg) # this guy to give access to basic query_disk (should make the Healpix object accessible in Band) self.hp = Healpix(self.nside, Healpix.RING, SkyDir.GALACTIC)