【发布时间】:2021-06-30 17:53:51
【问题描述】:
我是新来的,这几天我一直在为此苦苦挣扎。所以我有一个带有 cds 数据表的 txt 文件,我需要将其转换为 fit 文件,以便在特定程序中打开它。根据我阅读的 many 帮助网站以及完成此操作的代码示例,我需要的代码基本上类似于我在下面粘贴的内容,无需使用 open() 或 close () 函数(尽管我也尝试过)。我正在使用 jupyter notebooks 来运行它,到目前为止它还没有停止运行;我总是不得不打断它,我认为它卡在了 read() 行上。我还将发布我在下面遇到的错误。事件虽然它从来没有真正起作用,但它以某种方式创建并保存了一个新的 fit 文件,就像我想要的那样,但表中只有 22 行数据,但格式有点不对劲,即使文件提供了正确的 cd 信息表文件。如果您有任何建议,请告诉我。
代码:
from astropy.table import Table
from astropy.io import fits
from astropy.io import ascii
data = ascii.read(r"C:\...", format='cds')
# (comment: At this line I also tried Table.read() instead of ascii.read() as suggested and "ascii.cds" for format)
data.write("new_table.fits", format='fits')
错误:
OverflowError Traceback (most recent call last)
~\anaconda\lib\site-packages\astropy\io\ascii\core.py in _convert_vals(self, cols)
971 raise TypeError('converter type does not match column type')
--> 972 col.data = converter_func(col.str_vals)
973 col.type = converter_type
~\anaconda\lib\site-packages\astropy\io\ascii\core.py in generic_converter(vals)
915 def generic_converter(vals):
--> 916 return numpy.array(vals, numpy_type)
917
OverflowError: Python int too large to convert to C long
During handling of the above exception, another exception occurred:
KeyboardInterrupt Traceback (most recent call last)
<ipython-input-54-f59c9c65394f> in <module>
3 from astropy.io import ascii
4
----> 5 data = ascii.read(r"C:\....", format='cds')
6 # Table.read() instead of ascii.read(), the url instead of the file path, and "cds" for format
7
~\anaconda\lib\site-packages\astropy\io\ascii\ui.py in read(table, guess, **kwargs)
321 else:
322 reader = get_reader(**new_kwargs)
--> 323 dat = reader.read(table)
324 _read_trace.append({'kwargs': copy.deepcopy(new_kwargs),
325 'Reader': reader.__class__,
~\anaconda\lib\site-packages\astropy\io\ascii\cds.py in read(self, table)
325 return table
326 else:
--> 327 return super().read(table)
~\anaconda\lib\site-packages\astropy\io\ascii\core.py in read(self, table)
1228 self.meta['table'].update(self.header.table_meta)
1229
-> 1230 table = self.outputter(cols, self.meta)
1231 self.cols = self.header.cols
1232
~\anaconda\lib\site-packages\astropy\io\ascii\core.py in __call__(self, cols, meta)
1000 # Sets col.data to numpy array and col.type to io.ascii Type class (e.g.
1001 # FloatType) for each col.
-> 1002 self._convert_vals(cols)
1003
1004 t_cols = [numpy.ma.MaskedArray(x.data, mask=x.mask)
~\anaconda\lib\site-packages\astropy\io\ascii\core.py in _convert_vals(self, cols)
972 col.data = converter_func(col.str_vals)
973 col.type = converter_type
--> 974 except (TypeError, ValueError) as err:
975 col.converters.pop(0)
976 last_err = err
KeyboardInterrupt:
【问题讨论】:
-
文件有多大?
标签: python jupyter-notebook file-conversion astropy fits