如何从卷积healpix地图中删除戒指?

时间:2015-08-04 20:12:30

标签: python numpy scipy scientific-computing healpy

我正在应用卷积技术卷积2个数据集,一个nside = 256的healpix地图和一个主要的形状波束(256,256),以便测量卷积的healpix地图的总强度。我的问题是,在用主光束卷积我的地图后,我在我的卷积地图中得到了响铃。我已经尝试使用lanczos或高斯内核对其进行规范化以处理环,但所有这些方法都失败了。

在下面的代码中,我使用scipy中的查询函数在给定半径内搜索healpix地图中最近的像素,并使用地图坐标获取主光束中相应像素的乘积之和。我得到的最终图像中有环。请任何人帮我解决这个问题?提前致谢。

def query_npix(nside, npix, radius):
    print 'searching for nearest pixels:......'
    t1, t2 = hp.pix2ang(nside, np.arange(npix)) 
    tree = spatial.cKDTree(zip(t1, t2))

    dist, ipix_indx = tree.query(zip(t1, t2), k = 150, distance_upper_bound = radius)
    r1, r2 = hp.pix2ang(nside, ipix_indx)
    ra = r1.T - t1
    dec = r2.T - t2
    print 'Done searching'
    return np.array(dist), np.array(ipix_indx), np.array(ra.T), np.array(dec.T)

def fullSky_convolve(healpix_map, primary_beam_fits, ipix_indx, dist, radius, r1, r2):

    measured_map = []

    hdulist = openFitsFile(primary_beam_fits)
    beam_data = hdulist[0].data
    header = hdulist[0].header  
    nside = hp.get_nside(healpix_map[0, ...])
    npix = hp.get_map_size(healpix_map[0, ...])         # total number of pixels in the map must be  12 * nside^2 

    crpix1, crval1, cdelt1 = [ header.get(x) for x in "CRPIX1", "CRVAL1", "CDELT1" ]
    crpix2, crval2, cdelt2 = [ header.get(x) for x in "CRPIX2", "CRVAL2", "CDELT2" ]

    # beam centres in pixel coordinates
    xc = crpix1-1 + (np.rad2deg(r1.ravel()) - crval1)/(256*cdelt1)
    yc = crpix2-1 + (np.rad2deg(r2.ravel()) - crval2)/(256*cdelt2)
    #xc =  (np.rad2deg(r1.ravel()) )/cdelt1

    for j in xrange(4):
        print 'started Stokes: %d' %j

        for iter in xrange(0 + j, 16, 4):
            outpt = np.zeros(shape = npix, dtype=np.float64)
            #by = outpt.copy()
            # mask beam
            bm_data = beam_data[iter]
            #masked_beam= beam_data[iter]
            shape = bm_data.shape
            rad = np.linspace(-shape[0]/2,shape[-1]/2,shape[0])
            rad2d =  np.sqrt(rad[np.newaxis,:]**2+rad[:,np.newaxis]**2)
            mask = rad2d <= radius/abs(cdelt2)
            masked_beam = bm_data*mask

            s1 = ndimage.map_coordinates(masked_beam, [xc, yc], mode = 'constant')
            bm_map = s1.reshape(dist.shape[0], dist.shape[-1])

        for itr in xrange(npix):
            g_xy = (1.0/(np.sqrt(2*np.pi)*np.std(dist[itr])))*np.exp(-(dist[itr])**2/(2*np.var(dist[itr])))
            #weighted_healpix_map = np.convolve(healpix_map[j, ...][ipix_indx[itr]],  g_xy/g_xy.sum(), mode='same')
            weighted_healpix_map = ndimage.filters.convolve(healpix_map[j, ...][ipix_indx[itr]],  g_xy/g_xy.sum(), mode='reflect')
            #outpt[itr] = np.sum(weighted_healpix_map*(bm_map[itr]/bm_map[itr].sum()))
            outpt[itr] = np.sum(weighted_healpix_map*(bm_map[itr]))
            #print 'itr', itr           
            alpha = file('pap%d.save'%iter, 'wb')
            #h_map = ndimage.filters.gaussian_filter(outpt, sigma = 3.)
            cPickle.dump(outpt, alpha, protocol = cPickle.HIGHEST_PROTOCOL)
            alpha.close()
            print 'Just dumped stripp%d.save:-------'%iter
    print 'Loading dumped files:-------'
    loaded_objects = []
    for itr4 in xrange(16):
        alpha = file('stripp%d.save'%itr4, 'rb')
        loaded_objects.append(cPickle.load(alpha))
        alpha.close()
        measured_map.append(copy.deepcopy(loaded_objects))
    return measured_map

1 个答案:

答案 0 :(得分:0)

请记住,HEALPix地图可以在&#34; Ring&#34;或者&#34;嵌套&#34;格式。听起来您可能需要将关键字nest=True添加到hp.pix2ang等healpy函数中。如果输入映射采用嵌套格式,则需要此关键字。

例如:     我最近尝试使用healpy.smoothing()函数,并在使用healpix.mollview()查看输出映射时发现我生成的图像有环(可能与您描述的一样)。在使用mollview关键字运行nested=True之后,环消失了,图像按照我的预期显示。检查输入文件使用的排序方案

  

参考:       http://healpy.readthedocs.org/en/latest/tutorial.html#creating-and-manipulating-maps

     

Healpix支持两种不同的订购方案,即RING或NESTED。通过   默认情况下,healpy地图采用RING排序。为了合作   NESTED排序,所有与地图相关的函数都支持nest关键字,   例如:hp.mollview(m,nest = True,title =&#34; Mollview image NESTED&#34;)