[AstroPy] How to remove specific rows from an existing FITS file ?

Aldcroft, Thomas aldcroft at head.cfa.harvard.edu
Mon Nov 20 09:37:56 EST 2017

Hi Vitte,

Do you want to remove the rows from the original FITS file on disk or just
from the table data that you are working with in memory?

For the second option you need to generate a specification of the table
indices for the rows you want to remove.  For instance, to remove row 0, or
rows [2:5], or rows 1 and 3, the following examples (respectively) will

>>> t.remove_row(0)
>>> t.remove_rows(slice(2, 5))
>>> t.remove_rows([1, 3])

So a simple way to do this might be :

data = Table.read('data.fits')
bad_rows = []
for i_row, row in enumerate(data):
    if (some condition of row):

This isn't necessarily the fastest way but gets the job done.  If you can
express the condition as an array comparison then it can be much faster.


On Mon, Nov 20, 2017 at 9:19 AM, Eloïse Aurélie Bénédicte Vitte <
Eloise.Vitte at etu.unige.ch> wrote:

> Hello,
> I'm encountering a problem with a FITS file. I want to delete some rows
> that have certain values with a FOR loop in which I put IF conditions. It
> doesn't work when I use the function remove_row().
> So, do you have any idea of the mistake I'm commiting ?
> Kind regards,
> Vitte Eloïse
> _______________________________________________
> AstroPy mailing list
> AstroPy at python.org
> https://mail.python.org/mailman/listinfo/astropy
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/astropy/attachments/20171120/b2f20d46/attachment.html>

More information about the AstroPy mailing list