代码之家  ›  专栏  ›  技术社区  ›  Federer

破解图像标题

  •  2
  • Federer  · 技术社区  · 16 年前

    我需要在两个FITs图像头中更改一些值,以适应我拥有的一些测试数据。因此,我试图在应用程序运行时立即破解一个FITs图像头。

    但是在那一刻-我甚至看不到头球,更不用说砍了。我运行Ubuntu。

    6 回复  |  直到 11 年前
        1
  •  5
  •   Jvinniec    10 年前

    有点旧,但我认为答案可能需要一些更新和附加信息。

    我个人最喜欢的用于查看“.fits”文件的GUI是 DS9 ds9 /path/to/file.fits . 或者,您可以使用GUI中的菜单加载图像。在查看器中加载图像后,您可以使用最上方的菜单栏并转到“文件->显示标题'。不幸的是,我不相信你能修改DS9中的头。

    修改配合头

    对于修改fits标题,我发现最简单的方法是使用 astropy (一个python包)。既然你使用的是Ubuntu,你应该可以通过 apt-get ,所以希望很容易。要实际编辑fits头,可以在python脚本中或从解释器中执行以下操作( here's some additional help

    # Import the astropy fits tools
    from astropy.io import fits
    
    # Open the file header for viewing and load the header
    hdulist = fits.open('yourfile.fits')
    header = hdulist[0].header
    
    # Print the header keys from the file to the terminal
    header.keys
    
    # Modify the key called 'NAXIS1' to have a value of 100
    header['NAXIS1'] = '100'
    
    # Modify the key called 'NAXIS1' and give it a comment
    header['NAXIS1'] = ('100','This value has been modified!')
    
    # Add a new key to the header
    header.set('NEWKEY','50.5')
    
    # Save the new file
    hdulist.writeto('MyNewFile.fits')
    
    # Make sure to close the file
    hdulist.close()
    

    您还可以将其放入多个文件操作的循环中。

        2
  •  4
  •   VinceP    10 年前

    python 你可以使用编程语言 astropy

    from astropy.io.fits import getheader
    
    header = getheader('image.fits') # Load the data
    print header                     # Print the header to screen
    

    如果要修改标头的特定键,请执行以下操作:

    header['key'] = 'new_key' 
    
        3
  •  2
  •   Federer    16 年前

    edhead 看来这项工作做得很好。我发现的唯一一个软件允许您在命令行编辑标题。

        4
  •  1
  •   pavium    16 年前

    这是天文学家使用的灵活图像传输系统格式吗?

    This site

    不过,您可以将其用于自己的目的。

        5
  •  1
  •   Joe    16 年前

    由于只有1/2的问题得到了回答(编辑FITS标题),为了查看图像,我通常使用 DS9 (又名SAOImage)。

    CFITSIO 或 Astro::FITS::Header

    ... 而且,只要遵循一些简单的规则,就可以使用任何文本编辑器编辑FITS标题——卡片(键/值/注释集)的长度始终为80个字符,FITS标题的长度始终为2880字节的倍数。根据文件的不同,可能有多个头,因为第一个头可以声明文件包含多个图像或表。

        6
  •  0
  •   Tim Long    16 年前

    Sloan Digital Sky Survey developer web site 有 some libraries that should meet your needs .

    FITS代表灵活的图像传输系统。FitsLib旨在为网络平台上的FITS文件提供接口。它是作为围绕 菲西奥 FITS文件的库接口。

    推荐文章