简体   繁体   English

如何将 a.fits 二进制表转换为图像?

[英]How to convert a .fits binary table into an image?

I am working on a Data Analysis project for the Emirates Mars Mission(EMM).我正在为阿联酋火星任务 (EMM) 进行数据分析项目。

I am having difficulty viewing images from the UV Emission Data (from the EMUS instrument).我在查看来自 UV 发射数据(来自 EMUS 仪器)的图像时遇到困难。 The.fits data is only present in BinaryTables and not Images when I use Astropy or FitsViewer to read them.当我使用 Astropy 或 FitsViewer 读取它们时,.fits 数据仅存在于 BinaryTables 而不是图像中。

UI of fits viewer showing rows of Binary Table Data显示二进制表数据行的拟合查看器 UI

Also, I am aware that Images can be produced since the same data was used to produce an image of the Martian Corona like the one I have attached below.另外,我知道可以生成图像,因为使用相同的数据来生成火星日冕的图像,就像我在下面附上的那样。

False-color images from the EMUS instrument来自 EMUS 仪器的假彩色图像

I would appreciate any type of help - either Astropy code or software that might help me.我将不胜感激任何类型的帮助 - Astropy 代码或可能对我有帮助的软件。

PS: I'm using l2a data from the science data center if anyone would like to download it. PS:如果有人想下载,我正在使用来自科学数据中心的 l2a 数据。

PS2: SAO DS9 is unable to even open the.fits file PS2:SAO DS9 甚至无法打开.fits 文件

SA0 DS9 has trouble with the Binary HDU data types. SA0 DS9 在二进制 HDU 数据类型方面存在问题。 If you want to view using this viewer you would want to convert to ImageHDU first.如果要使用此查看器查看,则需要先转换为 ImageHDU。

Let's say that the SC_GEOM HDU is all of the same type and you would like to view this data as an image.假设 SC_GEOM HDU 都是同一类型,并且您希望将此数据视为图像。 In heasarc fits viewer you can explore the data types and confirm whether or not the table data is all of the same desired type.在 heasarc 拟合查看器中,您可以探索数据类型并确认表数据是否都是相同的所需类型。 Then grabbing the data and viewing it in Matpotlib can be done in a few simple lines of code.然后抓取数据并在 Matpotlib 中查看,只需几行简单的代码即可完成。

from astropy.io import fits
from astropy import table
import matplotlib.pyplot as plt

# grab the data with 8 being the SC_GEOM HDU index in the FITS file
table_data = table.Table(fits.getdata('data.fits', 8))

# this is the most elegant way I can think of to grab a 27x153 data
# as a numpy array
array_data = table_data.to_pandas().values

# use Matplotlib to show the image
plt.imshow(array_data)

If you want to convert the data to an ImageHDU so that DS9 can open it.如果要将数据转换为 ImageHDU 以便 DS9 可以打开它。 The following can be done.可以做到以下几点。

from astropy.io import fits
from astropy import table
new_hdulist = fits.HDUList()
# convert to ImageHDU
with fits.open('data.fits') as ff:
    # transferring the primary HDU from the original file
    # all FITS files should start with a PrimaryHDU
    new_hdulist.append(ff[0])
    
    for hdu in ff[1:]:
        # grab each table HDU
        t = table.Table(hdu.data)
        # grab the header
        header = hdu.header
        # transfer header and data to an ImageHDU
        img_hdu = fits.ImageHDU(data=t.to_pandas().values, header=header)
        # append new ImageHDU to the list of HDU to write out
        new_hdulist.append(img_hdu)
    # write the HDUList to a new file with all ImageHDU instead of Tables
    new_hdulist.writeto('newfile.fits')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM