question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Question: Why is io.fits convenience 'getdata' much faster than fits.open()?

See original GitHub issue
>>> import sys
>>> print(sys.version)
2.7.13 |Continuum Analytics, Inc.| (default, Dec 20 2016, 23:05:08) 
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)]
>>> import astropy 
>>> astropy.__version__
u'2.0.dev17848'
>>> import timeit
>>> timeit.timeit("h=fits.open('jcdua3f4q_flc.fits'); d=h[3].data; h.close()",
... setup="from astropy.io import fits", number=1000) 
22.351375102996826
>>> timeit.timeit("d=fits.getdata('jcdua3f4q_flc.fits', ext=3)",
... setup="from astropy.io import fits", number=1000)
8.482270956039429

How is this possible and what can be done to make “regular” fits.io operations as fast as “convenience” functions?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:22 (22 by maintainers)

github_iconTop GitHub Comments

3reactions
saimncommented, Mar 28, 2017

The explanation is in a comment in getheader: https://github.com/astropy/astropy/blob/master/astropy/io/fits/convenience.py#L115

    # Use _close instead of close to close without loading any
    # remaining HDUs for pre-lazy-loading backwards compatibility
    # In other words, when the full HDUList is opened by a user they
    # previously expected to be able to look at arbitrary HDUs even
    # after the file was closed, but for getheader and other convenience
    # functions this is irrelevant
1reaction
embraycommented, Mar 30, 2017

Due to this weird implementation of “lazy”, now regular functions are slower than “convenience” functions.

In fairness, they’re just as slow as they always were 😉

Read more comments on GitHub >

github_iconTop Results From Across the Web

astropy.io.fits FAQ
Why is fitsio so much faster than astropy at reading tables? ... astropy.io.fits.open has an option to access the data portion of an...
Read more >
FITS File handling (astropy.io.fits)
The open() function supports a memmap=True argument that allows the array data of each HDU to be accessed with mmap, rather than being...
Read more >
astropy.io.fits read row from large fits file with mutliple HDUs
This code works well and fast for fits files up to ~20 GB, but runs out of memory for bigger ones (larger files...
Read more >
pyfits 3.4 - PyPI
This brings PyFITS mostly to parity with the version of astropy.io.fits that ... allowing more than 4 GB of variable-length array data in...
Read more >
lecture-3---numerical-manipulation-ii.pdf - Mubdi Rahman
At some point, you need to do more than ... Convenience functions make reading FITS images easy: ... img1 = fits.getdata(filename) # Getting...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found