-
-
Notifications
You must be signed in to change notification settings - Fork 573
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fits reading emits a warning when the data array is not actually memory mapped #6837
Conversation
Thanks for the PR! There are issues with how your use of metadata keywords, but it's moot because you should instead explicitly check whether the data array is memory mapped. Please see #6110 (comment) for one way to do so. I'm going to switch this PR to draft status so that it will not be critically reviewed before it is ready (e.g., with unit tests). We continue to pay attention to all PRs as they are developed, even draft PRs. |
Thanks for helping me @ayshih. I have updated the approach. Will this approach work? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to add one or more unit tests to verify that this PR works as intended. The code I wrote in #6110 (comment) uses recursion because in general you could be inspecting a view of a non-memory-mapped array, and then base
would not be None
, but that doesn't mean memory mapping is being used.
Also, the warning to the user shouldn't blindly suggest using disable_image_compression=True
or do_not_scale_image_data=True
. The suggestion should be tailored to why we believe the array was not memory mapped. That is, don't suggest to a user that they turn off image compression when the image wasn't actually compressed in the first place.
@ayshih Is this okay? I have added the Also, how should I approach testing on this? I did some test on |
In our sample data set (as opposed to our test data set), Additionally, be aware that:
|
sunpy/io/_fits.py
Outdated
if memmap == True and not (isinstance(pairs[0].data.base, mmap.mmap) and pairs[0].data.base is not None): | ||
try: | ||
if pairs[0].header['BZERO'] != 0: | ||
warn_user("Data array is not memory mapped. Use 'disable_image_compression=True' to preserve memory mapping.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can preserve the memmap, but it would be entirely useless as you wont be able to see the image any more? I don't think this is a good warning to throw.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This warning is raised by sunpy.io.read_file()
, which could conceivably be used by a user with some other purpose for the file contents than to use it as a Map
. Plus, note that it would only get triggered when a user explicitly specifies memmap=True
, versus the default of memmap=None
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All that's true, but I don't think that this warning is helpful as written for someone who doesn't have a good understanding of FITS internals. I can just see someone doing that and then being like waaaat
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The easy "fix" would be to elaborate in the warning, e.g.:
Data array is not memory mapped because it is stored in the file using compression. Specify
disable_image_compression=True
to preserve memory mapping, but only if you do not need the data array to be decompressed.
sunpy/io/_fits.py
Outdated
@@ -99,6 +100,15 @@ def read(filepath, hdus=None, memmap=None, **kwargs): | |||
message += repr(e) | |||
warn_user(message) | |||
|
|||
if memmap == True and not (isinstance(pairs[0].data.base, mmap.mmap) and pairs[0].data.base is not None): | |||
try: | |||
if pairs[0].header['BZERO'] != 0: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this actually a reliable way to detect a compressed image header?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it isn't for two reasons. See #6837 (comment)
How are these changes? |
No, they should be in this PR. |
@ayshih can you review this again? |
Hello 👋, Thanks for your contribution to sunpy! |
Hello again 👋, We want to thank you again for your contribution to sunpy! |
This adds a warning to the read function in
sunpy.io
. This warning is emitted whenmemmap=True
and the data array is not actually memory mapped.Merging this PR:
Closes #6141