You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
io.fits add ability to efficiently load single extension header #4589
Currently io.fits/pyfits always loads all extension headers regardless whether one wants them all or not.
At least the obvious api function getheader has this behaviour.
This slows down simple tasks like just checking the primary extension headers keys considerably when the number of extensions is large as it needs to seek through the full file.
Obviously seeking the file is required to load the later extensions but it should only try to read as much as it must to satisfy the users request.
What version of Astropy/PyFITS are you using? When I use getheader() (Astropy 1.1.1), I don't see the behavior you reported. It loads only the extension header that I asked for. See below.
>>>hdr0=fits.getheader('zfoo.fits') # Should be only PRIMARY header>>>hdr0SIMPLE=T/conformstoFITSstandardBITPIX=8/arraydatatypeNAXIS=0/numberofarraydimensionsEXTEND=TFOO_0='foo_0 '>>>hdr1=fits.getheader('zfoo.fits', ext=1) # Only EXT=1 header>>>hdr1XTENSION='IMAGE '/ImageextensionBITPIX=64/arraydatatypeNAXIS=2/numberofarraydimensionsNAXIS1=3NAXIS2=3PCOUNT=0/numberofparametersGCOUNT=1/numberofgroupsFOO_1='foo_1 '
Activity
pllim commentedon Feb 9, 2016
What version of Astropy/PyFITS are you using? When I use
getheader()(Astropy 1.1.1), I don't see the behavior you reported. It loads only the extension header that I asked for. See below.First, I create a simple FITS file for testing:
Now, I try to read each extension header back in:
juliantaylor commentedon Feb 9, 2016
I'm using git head, check the seeks astropy actually performs, it reads every header in the file, regardless of what is asked.
pllim commentedon Feb 9, 2016
Maybe @embray can clarify when he gets the chance...
juliantaylor commentedon Feb 9, 2016
see https://github.com/astropy/astropy/blob/master/astropy/io/fits/convenience.py#L102
the
getheaderfunction it simply loads the full hdulist via the same code asopenuses and throws everything else away.Maybe I'm using the wrong function, but getheader is probably the first thing you will find when only interested in the header.
io.fits: allow limiting the number of read extensions
io.fits: allow limiting the number of read extensions
io.fits: allow limiting the number of read extensions
io.fits: allow limiting the number of read extensions
eteq commentedon Dec 9, 2016
@juliantaylor - I'm going to close this because I think #5065 has acheived the same affect. But feel free to re-open if you don't agree!