Repository navigation
Raise error if fits.open(memmap=True) is impossible. - #2298
Conversation
|
This is a possible solution to #2295, if there is interest |
|
The tests fail because the new ValueError is triggered on test images. I'm not sure what the "correct" behavior should be -- I'm happy to revise the PR to make the behavior conform to what a dev thinks should happen. |
|
What if some HDUs are memmappable and others aren't? It's conceivable that a user would want to open a FITS file to read a memmapped HDU and not care that others aren't memmappable. Is it possible to move this exception to the point at which the data for an HDU is actually read in from the file? |
|
The exception is triggered at the moment when an HDU data property is accessed: I haven't looked at the test failures carefully enough to see if there are situations where |
|
Oh -- my bad. Ignore my comment -- it seems to work as I would expect. |
There was a problem hiding this comment.
I definitely do not want to raise an error here--given that memmap=True is the default behavior, and that for the average file the additional memory usage is not a problem, this would result in too much breakage. I'm not too keen on a warning either because users will find it obnoxious. I used to have a warning like this in fact but took it out after too many complaints.
I'm also not crazy about using do_not_scale_image_data for this. I'd rather add a separate option for controlling whether or not to replace blanks (for that matter I really want to rename do_not_scale_image_data to something a little less cumbersome). This also ties in to my desire to overhaul how data interpretation options are handled entirely, since right now they apply to an entire file, when really it should be possible to control this on a per-HDU basis.
|
Yeah, still not sure how I feel about this. The thing is, using mmap for pyfits didn't used to be a thing at all--either the file fit in memory or it didn't (CFITSIO has its own tricks to deal with this). But so in general users just don't care--it's something that I made to work as a way to silently improve matters in the average case, though it currently isn't guaranteed to work in all cases. I think a better solution here might just be better documentation as two when it will benefit and when it won't. |
|
memmap is invaluable for taking views into large fits files, and it's hugely problematic that the presence of From my perspective, it seems really important to permit memory mapping in the presence of I also consider it a bug that I can explicitly set What are your feelings about a 3-tier system for the |
|
FWIW, I'm +1 on the idea of making sure that if memmap is explicilty set to True, it should either work or raise an exception. I'd also vote that BLANK should be ignored for floating-point data. |
|
I'll need to give it a little more thought, but I think I'm okay with that. I'd also definitely accept a patch that checks the user's available system memory and compares it against the size of the data so as to not even try to load the data into memory if it looks like it won't be able. |
|
Note also that for images anyway the It might be better eventually to drop the |
|
@embray I've removed the |
There was a problem hiding this comment.
The new test file has a NaN, so == here doesn't work
|
@ChrisBeaumont - is this still relevant, or was it fixed by another PR? If this is still needed, can you rebase? |
|
This is still relevant; we just haven't agreed on a resolution. |
|
Rebased (though like @embray mentions, this isn't necessarily the final solution. I'm still in support of it) |
|
Just to briefly clarify my position on this, as the discussion has been spread around a few places: I completely agree with this approach in principle. But in practice I know from experience that it will cause trouble. There used to be a warning when mmap was enabled but would not be useful for that particular data, and it became a pain for users of software that uses pyfits, because those warnings would be sent to users who don't actually care about such details. This meant it was up to application developers to check/anticipate when it would or would not be safe to use mmap with pyfits, which itself is an undue burden. In most practical applications it has been less of a burden to explain why in some cases using a particular FITS file requires more memory than others. So in general I'd rather just avoid the problem while I work toward an overall better solution for transparently mapping raw FITS data to the data seen by users. |
|
Thanks -- to summarize my perspective: The solution in this PR doesn't add any burden by default (no warnings or error messages should be displayed if the user omits the memmap kwarg -- memmap is used if possible, and transparently ignored if not). If a user or application developer explicitly provides I think this is the right burden balance to strike. The application developer shouldn't have to worry about memory issues in the default case, but he/she should be able to worry about it if the application is designed for large datasets. I think most application developers would agree that raising an exception is better than running out of memory. |
|
I'm in favor of @ChrisBeaumont's approach here - only advanced users will have existing code with |
|
Ah right, got it. In that case I think I'm okay with that--but let me test out the change in PyFITS first. |
|
Sorry I sort of dropped the ball on this one. I'm going to see if I can get it integrated locally to see what effect it has on some of our software. |
|
@embray - any updates on this? I'd like to also have this behavior available for software I'm working on. |
|
I'm okay with merging this (with the proper changelog entry, etc.) provisionally and just seeing how it works out in practice for a bit. I think it should be fine though. |
|
@ChrisBeaumont - could you add a changelog entry for 1.0? |
|
Ok, changelog entry added |
|
@ChrisBeaumont - thanks! @embray - what else is needed to merge this? |
Raise error if fits.open(memmap=True) is impossible.
Also ignore BLANK if do_not_scale_image_data=True
Fixes #2295