我试图从'.fits'
文件打开一个全彩图像。但是,当它与相应的'.gif'
图像比较时,它的颜色和大小似乎有错误。在
如何才能以适当的尺寸查看真实的彩色图像?
例如,可以选择'.fits'
文件和相应的'.gif'
文件located at the top of this webpage。下面是使用APLPY模块的示例代码。在
def from_fits_to_image(color_scheme, rloc, rname='synop_Ml_0.2104', rext='.fits', cmap=None):
"""
color_scheme : 'rgb', 'grayscale', or 'false color'; color scheme of image to be shown
rloc : type <str>; location of file to be read
rname : type <str>; name of file to be read
rext : type <str>; extension of file to be read
cmap : None or type <str>; colormap
"""
rpath = rloc + rname + rext
if color_scheme == 'rgb':
pic = aplpy.FITSFigure(rpath)
# pic.show_rgb(alt_filename) # what filename is supposed to go here?
else:
pic = aplpy.FITSFigure(rpath)
if color_scheme == 'grayscale':
pic.show_grayscale()
elif color_scheme == 'false color':
if cmap is None:
pic.show_colorscale()
else:
pic.show_colorscale(cmap=cmap)
# plt.savefig(...)
plt.show()
只要提供正确的rloc
(下载的'.fits'
文件的位置)和color_scheme
,上面的代码就会运行。在
下面一个调用适当维度的函数会显示空的。为了使其非空,我必须提供另一个现有的文件名,尽管我不清楚它到底应该是什么。在
^{pr2}$下面的每个函数调用都会显示一个已调整为小的绘图。虽然color_scheme='grayscale'
似乎正确地给绘图着色,但其他方法不能正确地为图像着色。在
from_fits_to_image('grayscale', rloc=rloc)
from_fits_to_image('false color', rloc=rloc)
from_fits_to_image('false color', rloc=rloc, cmap='plasma')
为了比较,'.gif'
图像如下。理想情况下,输出与下图完全相同。在
编辑:
我尝试过使用astropy
、PIL
、和{
编辑2:
下面是使用fits
来自astropy.io
的结果。在
from astropy.io import fits
def reada(rloc, rname='synop_Ml_0.1998', rext='.fits'):
""" """
rpath = rloc + rname + rext
# hdu_list = fits.open(rpath)
# hdu_list.info()
pic = fits.getdata(rpath)
plt.imshow(pic)
plt.show()
reada(rloc=rloc)
我玩过vmin
和{pyfits
打开文件会导致以下错误,即使使用pyfits.open(rpath, uint=True, do_not_scale_image_data=True)
:
TypeError: Image data can not convert to float
从gif的角度来看,这幅图像似乎是一幅假彩色图像,关键在于选择一张正确的彩色地图。我不能说在python中是否有一个与您链接的颜色映射等效的颜色映射,但是我们可以找到一些非常接近的东西,重新创建图像中的所有功能:
其中显示了以下内容(请注意,
aplpy
不理解此坐标系,因此它以像素坐标绘制图形):问题的第二部分比较棘手,我不能完全回答。首先,您需要将卡林顿时间转换为经度,将正弦纬度转换为度,然后为轴标签绘制新值,要么代替旧标签,要么将其作为与旧标签并列的寄生轴(可以参考一个寄生轴示例here)。在
现在看来卡林顿时间是1853年11月9日以来旋转的度数,x轴的跨度正好是360度,所以我假设转换只是偏移757079.95,即左边的x轴值。我们可以通过查看地图的像素范围与坐标范围的对应关系,在世界坐标上进行双重检查:
^{pr2}$X轴边的值,757079.95和757439.95,正好是360度。在
{xaxis>然后我们可以使用一些技巧来匹配你的图像
^{3}$请记住,
aplpy
是一个为绘制天体坐标而不是太阳坐标而设计的库,因此使轴变换正常工作可能是一个相当痛苦的过程。另一种可能更好的方法是用sunpy
绘制fits文件,这是一种用于太阳物理学的pythonlibrary。但是,我从未使用过它,而且它似乎对这个特定的fits文件抛出了一个错误。看来你需要修改fits文件的头来正确读取坐标。如果你想使用这个库,也许你可以联系sunpy
社区?在相关问题 更多 >
编程相关推荐