我需要用python3中的astropy.fits
替换FITS
文件中的一些数据。为了与原始FITS文件保持一致,我想写一个numpy.chararray
的dtype='<U100'
我试过使用numpy.chararray(x)
,其中x
是一个字符串列表,我得到了*** TypeError: 'str' object cannot be interpreted as an integer
我非常困惑,因为我认为在python 3
中所有的字符串都是unicode,而在我的理解中'<U100'
是unicode。我想知道我做错了什么
FITS标准不处理unicode。在astropy.fits中,当您编写时,它将尝试编码为ASCII。当你阅读一个FITS文件时,有一种神奇的方法可以让ASCII
bytes
看起来像str
简而言之,如果您试图直接处理存储在FITS中的数据,则需要使用
bytes
。例如:如果没有更多关于您试图更改的内容的详细信息,很难说,但是假设您使用的是FITS表,最简单的方法可能是使用表API
下面是一个示例表:
您可以使用
Table.read
加载它,然后像修改任何字符串数组一样修改它。它将正确地处理重新编码如果您想直接使用较低级别的FITS界面,也可以。在大多数情况下,不必手动构造
chararray
(这是一个内部实现细节):相关问题 更多 >
编程相关推荐