HMI PFSS solutions#

Calculating a PFSS solution from a HMI synoptic map.

This example shows how to calculate a PFSS solution from a HMI synoptic map. There are a couple of important things that this example shows:

  • HMI maps have non-standard metadata, so this needs to be fixed

  • HMI synoptic maps are very big (1440 x 3600), so need to be downsampled in order to calculate the PFSS solution in a reasonable time.

import os

import matplotlib.pyplot as plt

import astropy.units as u

import sunpy.map
from sunpy.net import Fido
from sunpy.net import attrs as a

from sunkit_magex import pfss

Set up the search.

The synoptic maps are labelled by Carrington rotation number instead of time.

series = a.jsoc.Series('hmi.synoptic_mr_polfil_720s')
crot = a.jsoc.PrimeKey('CAR_ROT', 2210)

Do the search.

If you use this code, please replace this email address with your own one, registered here: http://jsoc.stanford.edu/ajax/register_email.html

2026-06-11 15:38:01 - drms - INFO: Export request pending. [id=JSOC_20260611_010878_X_IN, status=2]
2026-06-11 15:38:01 - drms - INFO: Waiting for 5 seconds...
2026-06-11 15:38:06 - drms - INFO: Export request finished. [id=JSOC_20260611_010878_X_IN, status=0]
INFO: 1 URLs found for download. Full request totaling 4MB [sunpy.net.jsoc.jsoc]
2026-06-11 15:38:06 - sunpy - INFO: 1 URLs found for download. Full request totaling 4MB

Files Downloaded:   0%|          | 0/1 [00:00<?, ?file/s]

hmi.synoptic_mr_polfil_720s.2210.Mr_polfil.fits:   0%|          | 0.00/4.26M [00:00<?, ?B/s]

hmi.synoptic_mr_polfil_720s.2210.Mr_polfil.fits:   0%|          | 1.02k/4.26M [00:00<24:38, 2.88kB/s]

hmi.synoptic_mr_polfil_720s.2210.Mr_polfil.fits:   2%|▏         | 99.0k/4.26M [00:00<00:15, 270kB/s]

hmi.synoptic_mr_polfil_720s.2210.Mr_polfil.fits:  10%|█         | 427k/4.26M [00:00<00:03, 1.11MB/s]

hmi.synoptic_mr_polfil_720s.2210.Mr_polfil.fits:  42%|████▏     | 1.80M/4.26M [00:00<00:00, 4.52MB/s]


Files Downloaded: 100%|██████████| 1/1 [00:01<00:00,  1.27s/file]
Files Downloaded: 100%|██████████| 1/1 [00:01<00:00,  1.27s/file]

Read in a file. This will read in the first file downloaded to a sunpy Map object.

hmi_map = sunpy.map.Map(files[0])

Since this map is far to big to calculate a PFSS solution quickly, lets resample it down to a smaller size.

print('Old shape: ', hmi_map.data.shape)
hmi_map = hmi_map.resample([360, 180] * u.pix)
print('New shape: ', hmi_map.data.shape)
Old shape:  (1440, 3600)
New shape:  (180, 360)

Now calculate the PFSS solution

nrho = 35
rss = 2.5
pfss_in = pfss.Input(hmi_map, nrho, rss)
pfss_out = pfss.pfss(pfss_in)

Using the Output object we can plot the source surface field, and the polarity inversion line.

ss_br = pfss_out.source_surface_br

fig = plt.figure()
ax = fig.add_subplot(projection=ss_br)

ss_br.plot(axes=ax)
# Plot the polarity inversion line
ax.plot_coord(pfss_out.source_surface_pils[0])
plt.colorbar()
ax.set_title('Source surface magnetic field')

plt.show()
Source surface magnetic field
INFO: Missing metadata for solar radius: assuming the standard radius of the photosphere. [sunpy.map.mapbase]
2026-06-11 15:38:14 - sunpy - INFO: Missing metadata for solar radius: assuming the standard radius of the photosphere.
/home/docs/checkouts/readthedocs.org/user_builds/sunkit-magex/conda/latest/lib/python3.12/site-packages/sunpy/map/mapbase.py:671: SunpyMetadataWarning: Missing metadata for observer: assuming Earth-based observer.
For frame 'heliographic_stonyhurst' the following metadata is missing: dsun_obs,hglt_obs,hgln_obs
For frame 'heliographic_carrington' the following metadata is missing: crlt_obs,crln_obs,dsun_obs

  obs_coord = self.observer_coordinate

Total running time of the script: (0 minutes 23.311 seconds)

Gallery generated by Sphinx-Gallery