简体   繁体   English

如何在不调整大小和不修改颜色的情况下查看此适合图像?

[英]How to view this .fits image without resizing and without modifying colors?

I am trying to open a full-color image from a '.fits' file. 我正在尝试从'.fits'文件中打开全彩色图像。 But, when comparing it to the corresponding '.gif' image, there appears to be an error regarding its color and size. 但是,将其与相应的'.gif'图像进行比较时,似乎在颜色和大小方面存在错误。

How can I view the real-color image in its proper dimensions? 如何查看正确尺寸的彩色图像?

As an example, one can select the '.fits' file and corresponding '.gif' file located at the top of this webpage . 例如,可以选择位于此页面顶部'.fits'文件和相应的'.gif'文件。 My example code, which uses the APLPY module, is below. 我的示例代码使用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()

So long as one provides the proper rloc (the location of the downloaded '.fits' file) and color_scheme , the above code will run. 只要提供正确的rloc (下载的'.fits'文件的位置)和color_scheme ,上述代码就会运行。

Calling the function below will show an empty plot of the proper dimensions. 调用下面的函数将显示正确尺寸的空白图表。 To make it non-empty, I must supply another existing filename, though I am unclear on what exactly that should be. 要使其为非空,我必须提供另一个现有的文件名,尽管我不清楚确切的名称是什么。

from_fits_to_image(color_scheme='rgb', rloc=rloc) 

在此处输入图片说明

Each of the function calls below reveal a plot that has been resized to small. 下面的每个函数调用都显示了已调整为较小尺寸的图。 While color_scheme='grayscale' seems to colorize the plot properly, the other methods do not properly colorize the image. 虽然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')

在此处输入图片说明

For comparison, the '.gif' image is below. 为了进行比较,下面是'.gif'图像。 Ideally, the output will look exactly like the image below. 理想情况下,输出将与下图完全一样。

EDIT: 编辑:

I have tried using astropy , PIL , and pyfits unsuccessfully. 我尝试使用astropyPILpyfits失败。 Any help would be appreciated. 任何帮助,将不胜感激。

在此处输入图片说明

EDIT 2: 编辑2:

Below is the result using fits from astropy.io . 以下是使用astropy.io fits结果。

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)

I've played with the vmin and vmax kwargs, but to no success. 我玩过vminvmax kwargs,但没有成功。 Also, using pyfits to open the file results in the following error, even when using pyfits.open(rpath, uint=True, do_not_scale_image_data=True) : 另外,即使使用pyfits.open(rpath, uint=True, do_not_scale_image_data=True) ,使用pyfits打开文件pyfits导致以下错误:

TypeError: Image data can not convert to float

在此处输入图片说明

Judging from the gif, it seems that the image is a false-color one, and it's a matter of choosing a right color map. 从gif来看,图像似乎是假色的,这是选择正确的颜色图的问题。 I can't say if there's an equivalent color map in python to the one you've linked to, but we can find something that is pretty close, recreating all the features in the image: 我不能说在python中是否有与您链接到的颜色映射相同的颜色映射,但是我们可以找到非常接近的颜色映射,重新创建图像中的所有功能:

fig = aplpy.FITSFigure('synop_Ml_0.2104.fits')
fig.show_colorscale(vmin=-60, vmax=60, cmap='hot')

which shows the following (note that aplpy does not understand this coordinate system so it plots the figure in pixel coordinates): 其中显示以下内容(请注意, aplpy无法理解此坐标系,因此它以像素坐标绘制图形): 在此处输入图片说明

The second part of the question is more tricky, and I can't fully answer it. 问题的第二部分比较棘手,我无法完全回答。 Firstly, you need to convert the Carrington time into longitude, and sine latitude into degrees, and then plot the new values for the axis labels either instead of the old ones or as a parasite axes alongside the old ones (you can refer to an parasite axes example here ). 首先,您需要将卡灵顿时间转换为经度,将正弦纬度转换为度数,然后绘制轴标签的新值,而不是旧标签,或将寄生标签与旧标签并列(您可以将其称为寄生虫) 此处的轴示例)。

Now it looks like the Carrington time is just degrees rotated since November 9, 1853, and the x-axis spans exactly 360, so I assume the conversion is simply an offset by 757079.95, the the x-axis value at the left edge. 现在看来,自1853年11月9日以来,卡林顿时间只是度数旋转,并且x轴正好跨度360,所以我假设转换只是偏移了757079.95,即左边的x轴值。 We can double-check it on the world coordinates, by looking at how the pixel span of the map corresponds to the coordinate span: 通过查看地图的像素跨度与坐标跨度的对应关系,我们可以在世界坐标上对其进行重新检查:

In [88]: fig._wcs.wcs_pix2world(fig._ax1.get_xlim(), fig._ax1.get_ylim(), origin=1)
Out[88]: [array([757439.95, 757079.95]), array([-1.,  1.])]

and the difference in values for the xaxis edges, 757079.95 and 757439.95, is exactly 360 degrees. 而xaxis边缘的值之差757079.95和757439.95恰好是360度。

So then we can use some matplotlib tricks to manually offset the coordinate values to force them to go from zero to 360 and get the xaxis to match your gif image: 因此,我们可以使用一些matplotlib技巧来手动偏移坐标值,以迫使它们从零变为360,并让xaxis匹配您的gif图像:

# using hidden attributes is non-pythonic but aplpy does not leave us other options
ax = fig._ax1
x_range = ax.get_xlim()
new_ticklabels = np.arange(60, 361, 60)
new_tick_positions = new_ticklabels / 360. * x_range[1] + x_range[0]
ax.set_xticks(new_tick_positions)
ax.set_xticklabels(new_ticklabels)
fig.axis_labels.set_xtext('Carrington Longitude')

在此处输入图片说明

Keep in mind that aplpy is a library designed for plotting celestial, not solar, coordinates, so getting the axes transform to work properly could be a rather painful process. 请记住, aplpy是一个用于绘制天体坐标(而不是太阳坐标)的库,因此使轴进行变换以使其正常工作可能是一个相当痛苦的过程。 An alternative way, and perhaps a better one, would be to plot the fits file with sunpy , a python library for solar physics. 另一种方法,也许是一种更好的方法,是使用sunpy (一个用于太阳物理学的python 库)绘制拟合文件。 However, I have never used it, and it seems to throw an error for this particular fits file. 但是,我从未使用过它,它似乎为此特定的拟合文件引发错误。 Looks like you need to modify the header of the fits file to get the coordinates properly read. 看来您需要修改fits文件的标题才能正确读取坐标。 Perhaps you can get in touch with sunpy community if you want to use the library? 如果您想使用图书馆,也许可以与sunpy社区取得联系?

暂无
暂无

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

相关问题 如何在不调整大小的情况下使SVG图像的视口方形化? - How to make the viewport of an SVG image square, without resizing its contents? 如何检查 RGB colors 列表中的所有项目是否在没有循环的图像中? - How to check if all items in list of RGB colors is in an image without a loop? 如何在编辑后保存 .fits 文件而不会丢失标题? - How to save a .fits file after editing it without losing the header? 如何在没有Django修改时间的情况下获取日期时间? - How to get datetime without Django modifying time? 在 Python, Python Image Library 1.1.6 中,如何在不调整大小的情况下扩展画布? - In Python, Python Image Library 1.1.6, how can I expand the canvas without resizing? 由设计人员定制的django前端(无需修改视图或表单) - django front end customization by designer (without modifying view or form) 不使用CV2,如何显示仅显示孤立绿色的图像 - Without using CV2, how do I display an image showing only the isolated green colors 估计大小的图像将仅使用URL调整大小而无需下载 - Estimate size image will be after resizing with only url without downloading it python裁剪并保存不规则图像或裁剪并将其放在中心而不调整大小 - python to crop and save irregular image or crop and place it in the centre without resizing 在不失真的情况下调整图像大小会创建方形背景,但为黑色 - Resizing image without distortion creates a square background but in black
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM