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
Question: Why is io.fits convenience 'getdata' much faster than fits.open()? #5918
That's really weird because essentially _getext (what is called by getdata) just does fitsopen and then extracts the relevant data. So these should be equivalent.
That's really weird because essentially _getext (what is called by getdata) just does fitsopen and then extracts the relevant data. So these should be equivalent.
It seems that close() is much slower than _close(). The reason seems to be due to the following code in close():
ifclosed:
# Get the actual current number of HDUs that have been loadedtotal_read=list.__len__(self)
# Now read in any remaining HDUswhileself._read_next_hdu():
pass
It is reading all HDUs regardless of what the user needed! Why??? @embray
# 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
Reacted by P. L. Lim, Michael Seifert and Simon Conseil
It seems that close() was re-designed in 5c66c2d and this has destroyed any advantage that memmap=True might have had (which kind of was supposed to be a sort of "lazy" loading).
Also, as written in this commit, this is only for headers. Reading data after close was already disabled, so I don't think there is an issue with memap, @mcara ?
And instead of using directly _close, an option would be to add a keyword to disable this behavior:
Activity
MSeifert04 commentedon Mar 28, 2017
That's really weird because essentially
_getext(what is called bygetdata) just doesfitsopenand then extracts the relevant data. So these should be equivalent.pllim commentedon Mar 28, 2017
Is caching done and affected the second test? Try do the timing in different Python sessions?
MSeifert04 commentedon Mar 28, 2017
Well, timing IO is tricky at best but I have similar timings.
mcara commentedon Mar 28, 2017
@pllim Order of operations as well as number of sessions does not affect the outcome
mcara commentedon Mar 28, 2017
@MSeifert04 wrote:
A possible hint may come from:
So, it appears that
close()is responsible for most of the differences (but not all).MSeifert04 commentedon Mar 28, 2017
not closing the file halves the timings?
mcara commentedon Mar 28, 2017
Yes. However,
getdata()does close the files so things are still strange. However, maybe this last test could point to a culprit?pllim commentedon Mar 28, 2017
Profiling it would give you some answers.
mcara commentedon Mar 28, 2017
It seems that
close()is much slower than_close(). The reason seems to be due to the following code inclose():It is reading all HDUs regardless of what the user needed! Why??? @embray
mcara commentedon Mar 28, 2017
This reading of all HDUs defeats any sort of "lazy" reading in fits.
saimn commentedon Mar 28, 2017
The explanation is in a comment in
getheader:https://github.com/astropy/astropy/blob/master/astropy/io/fits/convenience.py#L115
mcara commentedon Mar 28, 2017
Are we then supposed to use "private"
_close()instead ofclose()if we no longer needHDUList?mcara commentedon Mar 28, 2017
It seems that
close()was re-designed in 5c66c2d and this has destroyed any advantage thatmemmap=Truemight have had (which kind of was supposed to be a sort of "lazy" loading).The irony of this comment #4634 (comment) can't be avoided.
CC: @jhunkeler
MSeifert04 commentedon Mar 28, 2017
@mcara I think you pinged the wrong one, juliantaylor submitted the PR.
MSeifert04 commentedon Mar 28, 2017
I thought we added a deprecation warning when accessing closed files. However I can do that without any problems (and/or warnings).
mcara commentedon Mar 28, 2017
@MSeifert04 No, I was having a conversation with @jhunkeler a few days ago about related issues.
saimn commentedon Mar 28, 2017
@MSeifert04 - The commit mentioned by @mcara added the warning: 5c66c2d#diff-817bd3a22004516f0dd0080e2cd0d9baR1028
Also, as written in this commit, this is only for headers. Reading data after close was already disabled, so I don't think there is an issue with
memap, @mcara ?And instead of using directly
_close, an option would be to add a keyword to disable this behavior:(This is also suggested in the commit message)
mcara commentedon Mar 28, 2017
Eh, here is the issue mentioned previously:
#5582
However in #5589 @mwcraig decided not to fix
close().Due to this weird implementation of "lazy", now regular functions are slower than "convenience" functions.
saimn commentedon Mar 28, 2017
If it can be removed for v2.0 it's even better indeed.
pllim commentedon Mar 28, 2017
Should we close this as duplicate of #5582 then?
mwcraig commentedon Mar 28, 2017
IIRC, that came down to running out of time before feature freeze. 😀
In addition, the goal was not to change the previous behavior (in which headers remained available even after closing).
I'd rather just remove this old behavior in 2.0.
Sure; could you please also add a note over there referring to this issue? Would do it myself but about to run to a meeting...
embray commentedon Mar 30, 2017
In fairness, they're just as slow as they always were ;)