Use CenteredNorm for magnetic-field maps#8447
Merged
Merged
Conversation
Member
Author
|
I have confirmed that this PR fixes when RAM is used by Maps that are able to be memory mapped (e.g., HMI). The Virtual Memory Size (VMS) should always go up during instantiation because the data array can now be addressed, so the question is whether the Resident Set Size (RSS) increases during instantiation as well. Before this PR>>> import psutil
>>> import sunpy.map
>>> from sunpy.data.sample import AIA_171_IMAGE, HMI_LOS_IMAGE
>>> # Initial memory usage
>>> process = psutil.Process()
>>> print(f"RSS: {process.memory_info().rss / 2**20} MB, VMS: {process.memory_info().vms / 2**20} MB")
RSS: 239.68359375 MB, VMS: 197.84765625 MB
>>> # AIA maps are unable to be memory mapped, so both RSS and VMS go up
>>> aia = sunpy.map.Map(AIA_171_IMAGE)
WARNING: VerifyWarning: Invalid 'BLANK' keyword in header. The 'BLANK' keyword is only applicable to integer data, and will be ignored in this HDU. [astropy.io.fits.hdu.image]
>>> print(f"RSS: {process.memory_info().rss / 2**20} MB, VMS: {process.memory_info().vms / 2**20} MB")
RSS: 244.15625 MB, VMS: 202.86328125 MB
>>> # HMI maps are able to be memory mapped, so RSS should not go up as much as VMS goes up
>>> hmi = sunpy.map.Map(HMI_LOS_IMAGE)
>>> print(f"RSS: {process.memory_info().rss / 2**20} MB, VMS: {process.memory_info().vms / 2**20} MB")
RSS: 252.5 MB, VMS: 211.41796875 MBAfter this PR>>> import psutil
>>> import sunpy.map
>>> from sunpy.data.sample import AIA_171_IMAGE, HMI_LOS_IMAGE
>>> # Initial memory usage
>>> process = psutil.Process()
>>> print(f"RSS: {process.memory_info().rss / 2**20} MB, VMS: {process.memory_info().vms / 2**20} MB")
RSS: 240.86328125 MB, VMS: 199.66796875 MB
>>> # AIA maps are unable to be memory mapped, so both RSS and VMS should go up
>>> aia = sunpy.map.Map(AIA_171_IMAGE)
WARNING: VerifyWarning: Invalid 'BLANK' keyword in header. The 'BLANK' keyword is only applicable to integer data, and will be ignored in this HDU. [astropy.io.fits.hdu.image]
>>> print(f"RSS: {process.memory_info().rss / 2**20} MB, VMS: {process.memory_info().vms / 2**20} MB")
RSS: 245.15625 MB, VMS: 203.68359375 MB
>>> # HMI maps are able to be memory mapped, so RSS should not go up as much as VMS goes up
>>> hmi = sunpy.map.Map(HMI_LOS_IMAGE)
>>> print(f"RSS: {process.memory_info().rss / 2**20} MB, VMS: {process.memory_info().vms / 2**20} MB")
RSS: 245.359375 MB, VMS: 211.9765625 MB |
meeseeksmachine
pushed a commit
to meeseeksmachine/sunpy
that referenced
this pull request
Dec 4, 2025
Cadair
added a commit
that referenced
this pull request
Dec 4, 2025
…7-on-7.1 Backport PR #8447 on branch 7.1 (Use `CenteredNorm` for magnetic-field maps)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
To have a symmetric plotting range for magnetic-field maps of HMI and MDI, we currently manually set the
vminandvmaxon the norm (e.g., #5825), but that requires us to read in the data array during instantiation. I just found out thatmatplotlib.colors.CenteredNormhas existed for many years, so is the far better approach, because then the plotting range is determined only when the data is actually being plotted.