gpt4 book ai didi

python - 使用多个拟合图像制作图像立方体

转载 作者:太空宇宙 更新时间:2023-11-04 00:05:04 25 4
gpt4 key购买 nike

我有一堆适合的文件,可以使用下面的脚本读取

from astropy.io import fits
hdu = fits.open('file.fits')
data = hdu[0].data

我正在尝试使用从多个拟合文件中读取的数据来制作一个图像立方体。 (图像立方体是包含来自多个拟合文件的数据的 3D 图像,其中 x 和 y 轴是 2D 图像维度,第 3 轴是时间或频率)

我相信它可以使用 spectral _cube 模块来完成,但是大多数文档只讨论如何读取图像立方体,而不是如何使用单独的拟合文件制作图像立方体。

到目前为止,我已经尝试了以下脚本。

#In the below script data is a 3D numpy array
from spectral_cube import SpectralCube
cube = SpectralCube(data=data)
cube.write('new_cube.fits', format='fits')

但是,上面的脚本给出了一个错误,指出需要 3 个参数,而只给出了 2 个参数。

最佳答案

执行此操作的最简单方法是将您希望在立方体中拥有的图像简单地放入 numpy 数组中,然后将该数组保存为适合的文件。您也可以将它们直接保存到 numpy 数组中,但是如果您在 for 循环中添加列表会更容易,而不是像我在这里那样为每个图像显式地添加列表。

import numpy as np
from astropy import fits

# Read the images you want to concatenate into a cube
img1 = fits.getdata('img1.fits')
img2 = fits.getdata('img2.fits')

# Make a list that will hold all your images
img_list = []
img_list.append(img1)
img_list.append(img2)

# Cast the list into a numpy array
img_array = np.array(img_list)

# Save the array as fits - it will save it as an image cube
fits.writeto('mycube.fits', img_array)

关于python - 使用多个拟合图像制作图像立方体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54417393/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com