【问题标题】:Turn a fits file into healpix map将 fit 文件转换为 healpix 地图
【发布时间】:2019-12-26 18:40:04
【问题描述】:

我创建了一个 fit 文件。它只是一个二维数组,我可以使用plt.imshow(fits.getdata(my_file)) 对其进行可视化。有没有办法把它变成一个 healpix 地图?如果是,请提供详细答案。如果不是,请解释原因。任何帮助表示赞赏!

我知道healpy.fitsfunc.write_map(filename, m),但我很难使用它(无法设置 m 参数)并且不知道这个函数是否对我的任务有帮助

【问题讨论】:

    标签: python healpy


    【解决方案1】:

    hp.write_map 函数只是将内存中预先存在的 healpix 映射写入 fit 文件。

    根据您的问题,尚不清楚您拥有什么样的数据。但是假设你有一个二维数据网格,因为你使用了imshow。在使用 hp.write_map 之前,您需要将其转换为 healpix 地图。

    根据您的坐标系,您需要知道每个网格点的坐标,才能将网格转换为 healpix 地图。

    要将一些数据(标量)转换为 healpix 地图,在找到坐标后,您可以编写这样的函数,它获取坐标并为您制作 healpix 地图。

    def make_map_vec(theta, phi, data):
        assert len(theta) == len(phi) == len(data)
        e1map = np.full(hp.nside2npix(NSIDE), hp.UNSEEN, dtype=np.float)
        index = hp.ang2pix(NSIDE, theta, phi)
        values = np.fromiter((np.sum(data[index==i]) for i in np.unique(index)), float, count=len(np.unique(index)))
        e1map[np.unique(index)] = values
        return e1map
    

    This 链接为您提供了 healpix 使用的坐标系。

    【讨论】:

      【解决方案2】:

      我有同样的问题,我想在 mollweide 投影中绘制一个二维数组。 我的二维数组是 180*360 数组,使用 matplotlib.pyplot。 imshow 轴不跟随投影:

      所以为了解决这个问题,我想使用 healpy 的 mollview,但我不知道将我的二维数组 Data(180*360) 转换为 mollview 可以绘制的对象。

      在上一个答案中,您假设数据是一维数组,其长度与 theta 和 phi 相同。我试着这样做测试它:

      test = np.ones((180,360))
      data = test.reshape(180*360)
      theta = []
      phi = []
      for i in range (360):
          for j in range (180):
              theta.append((j)*np.pi/180)
              phi.append((i)*np.pi/180)
      
      theta = np.asarray(theta)
      phphi = np.asarray(y)
      
      def make_map_vec(theta, phi, data):
          assert len(theta) == len(phi) == len(data)
          e1map = np.full(hp.nside2npix(NSIDE), hp.UNSEEN, dtype=np.float)
          index = hp.ang2pix(NSIDE, theta, phi)
          values = np.fromiter((np.sum(data[index==i]) for i in np.unique(index)), float, count=len(np.unique(index)))
          e1map[np.unique(index)] = values
          return e1map
      
      map_test = make_map_vec(theta,phi,data)
      hp.mollview(map_test,title="Mollview image RING")
      

      我明白了:

      这是不正确的。

      您知道是否有其他方法可以从二维数组中获取地图?

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2015-06-23
        • 2013-05-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-23
        相关资源
        最近更新 更多