python - 尝试使用 astropy 将 FITS 文件转换为 ndarray 时获取 NaN 值

标签 python astropy

我正在尝试使用 astropy 将 FITS 文件转换为 ndarray。我正在关注这些 instructions 。我正在使用 fv tool 查看 FITS 文件中的图像,但文件的表仅填充空值:enter image description here 我从 here 获得了这个 FITS 文件。当我按照链接中给出的说明进行操作时,我的 jupyter 笔记本中也得到了 NaN 值:

image_file = 'http://jsoc.stanford.edu/SUM93/D1245657400/S00000/hmi.Ic_720s.20191218_231200_TAI.3.continuum.fits'
hdulist = fits.open(image_file)
hdulist.info() 

### output:

Filename: C:\Users\yatin\.astropy\cache\download\py3\dd629fe158baf0b180d1835a3227eac4
No.    Name      Ver    Type      Cards   Dimensions   Format
  0  PRIMARY       1 PrimaryHDU       6   ()      
  1                1 CompImageHDU    106   (4096, 4096)   int16   

hdulist.verify('fix')

 ### output:
WARNING: VerifyWarning: HDU 1: [astropy.io.fits.verify]
WARNING: VerifyWarning:     Card 74: [astropy.io.fits.verify]
WARNING: VerifyWarning:         Card 'CRDER1' is not FITS standard (invalid value string: 'nan').  Fixed 'CRDER1' card to meet the FITS standard. [astropy.io.fits.verify]
WARNING: VerifyWarning:     Card 75: [astropy.io.fits.verify]
WARNING: VerifyWarning:         Card 'CRDER2' is not FITS standard (invalid value string: 'nan').  Fixed 'CRDER2' card to meet the FITS standard. [astropy.io.fits.verify]
WARNING: VerifyWarning:     Card 76: [astropy.io.fits.verify]
WARNING: VerifyWarning:         Card 'CSYSER1' is not FITS standard (invalid value string: 'nan').  Fixed 'CSYSER1' card to meet the FITS standard. [astropy.io.fits.verify]
WARNING: VerifyWarning:     Card 77: [astropy.io.fits.verify]
WARNING: VerifyWarning:         Card 'CSYSER2' is not FITS standard (invalid value string: 'nan').  Fixed 'CSYSER2' card to meet the FITS standard. [astropy.io.fits.verify]

hdulist[1].data

### output:
array([[nan, nan, nan, ..., nan, nan, nan],
       [nan, nan, nan, ..., nan, nan, nan],
       [nan, nan, nan, ..., nan, nan, nan],
       ...,
       [nan, nan, nan, ..., nan, nan, nan],
       [nan, nan, nan, ..., nan, nan, nan],
       [nan, nan, nan, ..., nan, nan, nan]], dtype=float32)

我做错了什么?

最佳答案

这是一种非答案,但看起来您并没有做错任何事情。我下载了同一个文件,虽然其中一部分包含 NaN,但也有一部分不包含。当您打印 4096x4096 图像的数据时,它不会显示所有值,并且边界周围的大多数值似乎都是 NaN(可能是光圈切口?)。例如:

>>>> np.isnan(hdulist[1].data).all()
False

我可以看到一些非 NaN 的点,例如:

>>> np.where(~np.isnan(hdulist[1].data))
(array([  19,   19,   19, ..., 4069, 4069, 4069]),
 array([2025, 2026, 2027, ..., 2092, 2093, 2094]))

事实上,似乎有很多非 NaN 值:

>>> len(np.where(~np.isnan(hdulist[1].data))[0])
12887376

如有疑问,请尝试使用 matplotlib 绘制数据。默认情况下,它将 NaN 视为空白像素:

>>> from matplotlib import pyplot as plt
>>> plt.imshow(hdulist[1].data)

我得到:

enter image description here

事实上,NaN 看起来就像一个孔径切口。

唯一做“错误”的事情是编写此 FITS 文件的软件,因为我认为 FITS 标准在技术上没有提供一种表示 infnan header 关键字中的值,即使它可能应该...

关于python - 尝试使用 astropy 将 FITS 文件转换为 ndarray 时获取 NaN 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59450462/

相关文章:

python - 3D 张量上的 Keras 点/点层行为

python - 如何将参数化的sql查询放入变量然后在Python中执行?

python - 将 matplotlib hexbin 放入 Aitoff 投影

python - 天体 WCS : "IOError: Header missing END card."

python - py 安装程序 numpy. EXE在运行时抛出错误

Python从HTTPS aspx下载图像

python - 如何将 EST/EDT 转换为 GMT?

javascript - 从 postgres 函数运行 python 或 javascript 文件?

python - 从 bz2 打开适合文件