Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Use CenteredNorm for magnetic-field maps#8447

Merged
Cadair merged 1 commit into
sunpy:mainfrom
ayshih:centerednorm
Dec 4, 2025
Merged

Use CenteredNorm for magnetic-field maps#8447
Cadair merged 1 commit into
sunpy:mainfrom
ayshih:centerednorm

Conversation

@ayshih
Copy link
Copy Markdown
Member

@ayshih ayshih commented Dec 3, 2025

To have a symmetric plotting range for magnetic-field maps of HMI and MDI, we currently manually set the vmin and vmax on the norm (e.g., #5825), but that requires us to read in the data array during instantiation. I just found out that matplotlib.colors.CenteredNorm has 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.

@ayshih ayshih added the map Affects the map submodule label Dec 3, 2025
Copy link
Copy Markdown
Member

@Cadair Cadair left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well this is excellent.

@Cadair Cadair added the backport 7.1 on-merge: backport to 7.1 label Dec 3, 2025
@Cadair Cadair added this to the 7.1.0 milestone Dec 3, 2025
@ayshih
Copy link
Copy Markdown
Member Author

ayshih commented Dec 3, 2025

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 MB

After 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

@ayshih ayshih marked this pull request as ready for review December 3, 2025 18:27
@Cadair Cadair added the Minor Change PR only needs one approval to merge. label Dec 4, 2025
@Cadair Cadair merged commit 9a331fe into sunpy:main Dec 4, 2025
43 of 45 checks passed
meeseeksmachine pushed a commit to meeseeksmachine/sunpy that referenced this pull request Dec 4, 2025
@Cadair Cadair removed this from the 7.1.0 milestone 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)
@ayshih ayshih deleted the centerednorm branch December 4, 2025 14:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport 7.1 on-merge: backport to 7.1 map Affects the map submodule Minor Change PR only needs one approval to merge.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants