【发布时间】:2021-11-25 19:39:29
【问题描述】:
我终于想出了如何使用 astropy.io 中的“表格”模块来编辑适合表格,但我仍然遇到超出范围的错误。 给定一个 fit 文件中包含 75.000 行星系的表,我想将所有 ID = 13 的星系导出到一个新文件中。这是我的代码:
import numpy as np
from astropy.io import fits
from astropy.table import Table
import matplotlib.pyplot as plt
# Opening the file and printing it as a table
hdul = fits.open("data_SDSS_Info.fit")
t = Table.read(hdul)
print("Printing data_SDSS_Info in Table format...","\n")
print(t)
# Removing rows from the table and outputting the subsample into a new FITS file
for i in range(len(hdul[1].data)):
if hdul[1].data[i][36] != 13:
t.remove_rows(i)
t.write("subsample.fit",overwrite=True)
print("Printing subsample table...")
print(t)
我认为这可以正常工作并且我无法发现任何错误(尽管我确信有更有效的方法可以做到这一点) - 但是当我运行此代码时它仍然超级慢 ,最后返回:“索引 37781 超出轴 0 的范围,大小为 37780”
第 37781 行是否特别有问题,或者这是由什么奇怪的东西引起的?
如果我尝试通过将子样本放入普通数组中来提取子样本,则该行不会出现任何错误...
有什么想法吗?
【问题讨论】: