首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在伽马射线贴图上使用healpy.anafast

在伽马射线贴图上使用healpy.anafast
EN

Stack Overflow用户
提问于 2013-11-20 03:18:17
回答 1查看 1.2K关注 0票数 1

我有一个伽马射线地图(图像与表面亮度)在fits格式,也.hpx作为输出的阿拉丁转换器。

我想要计算角功率谱。如何创建healpy.anafast可读的文件?我似乎弄错了数据格式(TypeErrors)。

我尝试的伽马射线图像之一是费米银河系漫射。该文件是位于以下位置的名为gll_iem_v02_P6_V11_DIFFUSE.fit的公共LAT银河漫反射贴图:

http://fermi.gsfc.nasa.gov/ssc/data/access/lat/BackgroundModels.html

我在使用时粘贴了下面的代码,但它实际上是astroml上名为plot_wmap_power_spectra的脚本

代码语言:javascript
复制
    """
    WMAP power spectrum analysis with HealPy
    ----------------------------------------

    This demonstrates how to plot and take a power spectrum of the WMAP data
    using healpy, the python wrapper for healpix.  Healpy is available for
    download at the `github site <https://github.com/healpy/healpy>`_
    """
    # Author: Jake VanderPlas <vanderplas@astro.washington.edu>
    # License: BSD
    #   The figure is an example from astroML: see http://astroML.github.com
    import numpy as np
    from matplotlib import pyplot as plt

    # warning: due to a bug in healpy, importing it before pylab can cause
    #  a segmentation fault in some circumstances.
    import pylab
    import healpy as hp
    ###
    from astroML.datasets import fetch_wmap_temperatures
    ###

    #------------------------------------------------------------
    # Fetch the data
    ###
    wmap_unmasked = fetch_wmap_temperatures(masked=False)

    #PredictedSurfaceFluxFromModelMap =           np.arange(hp.read_map('PredictedSurfaceFluxFromModelMap.hpx[1]'))
    PredictedSurfaceFluxFromModelMap =   hp.read_map('gll_iem_v02_p6_V11_DIFFUSE.fit',dtype=np.float,verbose=True)
    #PredictedSurfaceFluxFromModelMap = hp.read_map('all.fits',dtype=np.float,verbose=True)
    #cl_out =  hp.read_cl('PredictedSurfaceFluxFromModelMap.hpx',dtype=np.float)#,verbose=True)
    wmap_masked = fetch_wmap_temperatures(masked=True)
    ###
    white_noise = np.ma.asarray(np.random.normal(0, 0.062, wmap_masked.shape))
    len(cl_out)

    #------------------------------------------------------------
    # plot the unmasked map
    fig = plt.figure(1)
    #hp.mollview(wmap_unmasked, min=-1, max=1, title='Unmasked map',
    #            fig=1, unit=r'$\Delta$T (mK)')
    ########----------------
    ##hp.mollview(PredictedSurfaceFluxFromModelMap, min=-1, max=1, title='Unmasked map',
    ##            fig=1, unit=r'$\Delta$T (mK)')
    ########----------------
    #------------------------------------------------------------
    # plot the masked map
    #  filled() fills the masked regions with a null value.
    ########----------------
    #fig = plt.figure(2)
    #hp.mollview(wmap_masked.filled(), title='Masked map',
    #            fig=2, unit=r'$\Delta$T (mK)')

    ########----------------
    #------------------------------------------------------------
    # compute and plot the power spectrum
    ########----------------
    #cl = hp.anafast(wmap_masked.filled(), lmax=1024)
    cl = hp.anafast(PredictedSurfaceFluxFromModelMap, lmax=1024)
    #cl = cl_out
    ########----------------
    ell = np.arange(len(cl))

    cl_white = hp.anafast(white_noise, lmax=1024)

    fig = plt.figure(3)
    ax = fig.add_subplot(111)
    ax.scatter(ell, ell * (ell + 1) * cl,
       s=4, c='black', lw=0,
       label='data')
     ax.scatter(ell, ell * (ell + 1) * cl_white,
       s=4, c='gray', lw=0,
       label='white noise')

     ax.set_xlabel(r'$\ell$')
     ax.set_ylabel(r'$\ell(\ell+1)C_\ell$')
     ax.set_title('Angular Power (not mask corrected)')
     ax.legend(loc='upper right')
     ax.grid()
     ax.set_xlim(0, 1100)

     plt.show()
EN

回答 1

Stack Overflow用户

发布于 2013-11-20 05:56:01

I have uploaded your map also to Figshare,其中很可能在未来可用。

获得HEALPix格式的地图后,只需使用healpy即可轻松读取

代码语言:javascript
复制
import healpy as hp
m = hp.ma(hp.read_map("gll_iem_v02_p6_V11_DIFFUSE.hpx"))

遮罩NaN像素:

代码语言:javascript
复制
m.mask = np.isnan(m)

绘制它:

代码语言:javascript
复制
hp.mollview(m, min=-1e-5, max=1e-5, xsize=2000)
title("gll_iem_v02_p6_V11_DIFFUSE")

计算并绘制角功率谱:

代码语言:javascript
复制
plt.loglog(hp.anafast(m))

另请参阅IPython笔记本:http://nbviewer.ipython.org/7553252

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20080176

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档