本文介绍了Astropy Fits:如何写出一个表,其中的行被切掉?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用一些fits表,但是在Astropy.io.fits中输出时遇到了麻烦.本质上,我要切出一排包含我不感兴趣的对象的数据的行,但是当我保存新表时,所有这些行都神奇地重新出现了.

I'm currently working with some fits tables and I'm having trouble with outputting in Astropy.io.fits. Essentially, I am slicing out a bunch of rows that have data for objects I'm not interested in, but when I save the new table all of those rows have magically reappeared.

例如:

import astropy.io.fits as fits
import numpy as np

hdu = fits.open('some_fits_file.fits')[1].data

sample_slice = [True True True False False True]

hdu_sliced = hdu[sample_slice]

现在,我天真的想法期望"hdu"有6行,hdu_sliced有4行,这就是使用np.size()会得到的结果.因此,如果我保存hdu_sliced,则新的fits文件也将包含4行:

Now my naive mind expects that "hdu" has 6 rows and hdu_sliced has 4 rows, which is what you would get if you used np.size(). So if I save hdu_sliced, the new fits file will also have 4 rows:

new_hdu = fits.BinTableHDU.from_columns(fits.ColDefs(hdu_sliced.columns))

new_hdu.writeto('new_fits_file.fits')

np.size(hdu3)
6

因此,由于某种原因,我从切片中删除的那两行实际上并未从表中删除,并且输出的文件与原始文件相同.

So those two rows that I got rid of with the slice are for some reason not actually being removed from the table and the outputted file is just the same as the original file.

如何从表中删除不需要的行,然后将新数据输出到新文件?

How do I delete the rows I don't want from the table and then output that new data to a new file?

干杯,阿什利

推荐答案

如果您想坚持使用FITS_rec,可以尝试以下方法,这似乎是一种解决方法:

If you want to stick to using FITS_rec, you can try the following, which seems to be a workaround:

new_hdu = fits.BinTableHDU.from_columns(hdu_sliced._get_raw_data())

这篇关于Astropy Fits:如何写出一个表,其中的行被切掉?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-15 12:26