Downloading and plotting an HMI magnetogram

This example shows how to download a HMI magnetogram data with Fido and make a plot.

import matplotlib.pyplot as plt

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

To download the required data, we use Fido, a downloader client, to query the Joint Science Operations Center, or JSOC, where HMI data are stored. First define the search variables, a timerange, a data series, keywords, and your e-mail address (to notify you when the download is complete). See the JSOC e-mail address registration page here.

result = Fido.search(a.Time('2014/11/20 00:00:00', '2014/11/20 00:04:00'),
                     a.jsoc.Series("hmi.M_720s"),
                     a.jsoc.Keys(["T_REC, CROTA2"]),
                     a.jsoc.Notify("[email protected]"))

Now we can see what results we obtained from our search. Notice we have two files.

print(result)

Out:

Results from 1 Provider:

1 Results from the JSOCClient:
         T_REC            CROTA2
         str23           float64
----------------------- ---------
2014.11.20_00:00:00_TAI 180.01355

The following shows how to download the results. If we don’t provide a path it will download the file into the sunpy data directory. The output provides the path of the downloaded files. The result can be from several data clients, so we have to index the client first and then index the file.

# Slice the first record returned by the first client.
downloaded_file = Fido.fetch(result[0])
print(downloaded_file)

Out:

Export request pending. [id="JSOC_20200219_269", status=2]
Waiting for 0 seconds...
1 URLs found for download. Full request totalling 15MB

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

hmi.m_720s.20141120_000000_TAI.1.magnetogram.fits:   0%|          | 0.00/15.2M [00:00<?, ?B/s]

hmi.m_720s.20141120_000000_TAI.1.magnetogram.fits:   0%|          | 10.0k/15.2M [00:00<03:22, 75.2kB/s]

hmi.m_720s.20141120_000000_TAI.1.magnetogram.fits:   0%|          | 25.8k/15.2M [00:00<03:00, 84.5kB/s]

hmi.m_720s.20141120_000000_TAI.1.magnetogram.fits:   0%|          | 44.4k/15.2M [00:00<02:38, 95.8kB/s]

hmi.m_720s.20141120_000000_TAI.1.magnetogram.fits:   0%|          | 70.2k/15.2M [00:00<02:14, 113kB/s] 

hmi.m_720s.20141120_000000_TAI.1.magnetogram.fits:   1%|          | 106k/15.2M [00:00<01:50, 137kB/s] 

hmi.m_720s.20141120_000000_TAI.1.magnetogram.fits:   1%|          | 146k/15.2M [00:00<01:32, 163kB/s]

hmi.m_720s.20141120_000000_TAI.1.magnetogram.fits:   1%|1         | 202k/15.2M [00:00<01:15, 200kB/s]

hmi.m_720s.20141120_000000_TAI.1.magnetogram.fits:   2%|1         | 274k/15.2M [00:01<01:00, 246kB/s]

hmi.m_720s.20141120_000000_TAI.1.magnetogram.fits:   2%|2         | 356k/15.2M [00:01<00:49, 300kB/s]

hmi.m_720s.20141120_000000_TAI.1.magnetogram.fits:   3%|2         | 447k/15.2M [00:01<00:41, 360kB/s]

hmi.m_720s.20141120_000000_TAI.1.magnetogram.fits:   4%|3         | 543k/15.2M [00:01<00:34, 423kB/s]

hmi.m_720s.20141120_000000_TAI.1.magnetogram.fits:   4%|4         | 640k/15.2M [00:01<00:30, 483kB/s]

hmi.m_720s.20141120_000000_TAI.1.magnetogram.fits:   5%|5         | 771k/15.2M [00:01<00:25, 570kB/s]

hmi.m_720s.20141120_000000_TAI.1.magnetogram.fits:   6%|5         | 900k/15.2M [00:01<00:22, 649kB/s]

hmi.m_720s.20141120_000000_TAI.1.magnetogram.fits:   7%|6         | 1.03M/15.2M [00:02<00:19, 719kB/s]

hmi.m_720s.20141120_000000_TAI.1.magnetogram.fits:   8%|7         | 1.16M/15.2M [00:02<00:18, 778kB/s]

hmi.m_720s.20141120_000000_TAI.1.magnetogram.fits:   8%|8         | 1.29M/15.2M [00:02<00:16, 825kB/s]

hmi.m_720s.20141120_000000_TAI.1.magnetogram.fits:  10%|9         | 1.48M/15.2M [00:02<00:14, 945kB/s]

hmi.m_720s.20141120_000000_TAI.1.magnetogram.fits:  11%|#         | 1.67M/15.2M [00:02<00:12, 1.05MB/s]

hmi.m_720s.20141120_000000_TAI.1.magnetogram.fits:  12%|#2        | 1.87M/15.2M [00:02<00:11, 1.14MB/s]

hmi.m_720s.20141120_000000_TAI.1.magnetogram.fits:  14%|#3        | 2.11M/15.2M [00:02<00:10, 1.28MB/s]

hmi.m_720s.20141120_000000_TAI.1.magnetogram.fits:  16%|#5        | 2.36M/15.2M [00:02<00:09, 1.41MB/s]

hmi.m_720s.20141120_000000_TAI.1.magnetogram.fits:  17%|#7        | 2.63M/15.2M [00:03<00:08, 1.53MB/s]

hmi.m_720s.20141120_000000_TAI.1.magnetogram.fits:  19%|#8        | 2.88M/15.2M [00:03<00:07, 1.61MB/s]

hmi.m_720s.20141120_000000_TAI.1.magnetogram.fits:  21%|##        | 3.14M/15.2M [00:03<00:07, 1.70MB/s]

hmi.m_720s.20141120_000000_TAI.1.magnetogram.fits:  22%|##2       | 3.40M/15.2M [00:03<00:06, 1.76MB/s]

hmi.m_720s.20141120_000000_TAI.1.magnetogram.fits:  24%|##3       | 3.65M/15.2M [00:03<00:06, 1.81MB/s]

hmi.m_720s.20141120_000000_TAI.1.magnetogram.fits:  26%|##6       | 3.98M/15.2M [00:03<00:05, 1.95MB/s]

hmi.m_720s.20141120_000000_TAI.1.magnetogram.fits:  29%|##8       | 4.36M/15.2M [00:03<00:05, 2.15MB/s]

hmi.m_720s.20141120_000000_TAI.1.magnetogram.fits:  31%|###1      | 4.75M/15.2M [00:04<00:04, 2.32MB/s]

hmi.m_720s.20141120_000000_TAI.1.magnetogram.fits:  34%|###3      | 5.14M/15.2M [00:04<00:04, 2.47MB/s]

hmi.m_720s.20141120_000000_TAI.1.magnetogram.fits:  36%|###6      | 5.52M/15.2M [00:04<00:03, 2.58MB/s]

hmi.m_720s.20141120_000000_TAI.1.magnetogram.fits:  40%|###9      | 6.04M/15.2M [00:04<00:03, 2.85MB/s]

hmi.m_720s.20141120_000000_TAI.1.magnetogram.fits:  43%|####2     | 6.55M/15.2M [00:04<00:02, 3.07MB/s]

hmi.m_720s.20141120_000000_TAI.1.magnetogram.fits:  46%|####6     | 7.07M/15.2M [00:04<00:02, 3.27MB/s]

hmi.m_720s.20141120_000000_TAI.1.magnetogram.fits:  50%|####9     | 7.58M/15.2M [00:04<00:02, 3.42MB/s]

hmi.m_720s.20141120_000000_TAI.1.magnetogram.fits:  54%|#####3    | 8.22M/15.2M [00:04<00:01, 3.74MB/s]

hmi.m_720s.20141120_000000_TAI.1.magnetogram.fits:  58%|#####8    | 8.87M/15.2M [00:05<00:01, 4.00MB/s]

hmi.m_720s.20141120_000000_TAI.1.magnetogram.fits:  63%|######2   | 9.57M/15.2M [00:05<00:01, 4.31MB/s]

hmi.m_720s.20141120_000000_TAI.1.magnetogram.fits:  68%|######7   | 10.3M/15.2M [00:05<00:01, 4.65MB/s]

hmi.m_720s.20141120_000000_TAI.1.magnetogram.fits:  73%|#######3  | 11.2M/15.2M [00:05<00:00, 5.02MB/s]

hmi.m_720s.20141120_000000_TAI.1.magnetogram.fits:  79%|#######9  | 12.1M/15.2M [00:05<00:00, 5.42MB/s]

hmi.m_720s.20141120_000000_TAI.1.magnetogram.fits:  86%|########5 | 13.0M/15.2M [00:05<00:00, 5.84MB/s]

hmi.m_720s.20141120_000000_TAI.1.magnetogram.fits:  92%|#########2| 14.1M/15.2M [00:05<00:00, 6.28MB/s]

hmi.m_720s.20141120_000000_TAI.1.magnetogram.fits: 100%|#########9| 15.2M/15.2M [00:06<00:00, 6.75MB/s]

                                                                                                       
Files Downloaded: 100%|##########| 1/1 [00:06<00:00,  6.21s/file]
Files Downloaded: 100%|##########| 1/1 [00:06<00:00,  6.21s/file]
['/home/docs/sunpy/data/hmi.m_720s.20141120_000000_TAI.1.magnetogram.fits']

Now load it into a map and plot it. We see that solar North is pointed down instead of up in this image, which is indicated by the coordinates (that range from positive to negative, rather than negative to positive).

hmi_map = sunpy.map.Map(downloaded_file[0])
fig = plt.figure()
hmi_map.plot()
plt.show()
../../../_images/sphx_glr_downloading_hmi_001.png

Out:

/home/docs/checkouts/readthedocs.org/user_builds/sunpy/conda/stable/lib/python3.7/site-packages/astropy/wcs/wcs.py:466: FITSFixedWarning: CRDER1 = 'nan '
a floating-point value was expected.
  colsel=colsel)
/home/docs/checkouts/readthedocs.org/user_builds/sunpy/conda/stable/lib/python3.7/site-packages/astropy/wcs/wcs.py:466: FITSFixedWarning: CRDER2 = 'nan '
a floating-point value was expected.
  colsel=colsel)

Now rotate the image such that solar North is pointed up. We have to do this because the HMI instrument is mounted upside-down relative to the AIA instrument on the SDO satellite, which means most of the images are taken with solar North pointed up. The roll angle of the instrument is reported in the FITS header keyword CROTA2 (see Figure 17 of Couvidat et al. (2016), which states that “the nominal CROTA2 for HMI is ≈179.93”).

The order keyword, below, specifies the type of interpolation; in this case, 3 refers to bi-cubic.

hmi_rotated = hmi_map.rotate(order=3)
hmi_rotated.plot()
plt.show()
../../../_images/sphx_glr_downloading_hmi_002.png

Out:

/home/docs/checkouts/readthedocs.org/user_builds/sunpy/conda/stable/lib/python3.7/site-packages/astropy/wcs/wcs.py:466: FITSFixedWarning: CRDER1 = 'nan '
a floating-point value was expected.
  colsel=colsel)
/home/docs/checkouts/readthedocs.org/user_builds/sunpy/conda/stable/lib/python3.7/site-packages/astropy/wcs/wcs.py:466: FITSFixedWarning: CRDER2 = 'nan '
a floating-point value was expected.
  colsel=colsel)
/home/docs/checkouts/readthedocs.org/user_builds/sunpy/conda/stable/lib/python3.7/site-packages/astropy/wcs/wcs.py:466: FITSFixedWarning: CRDER1 = 'nan '
a floating-point value was expected.
  colsel=colsel)
/home/docs/checkouts/readthedocs.org/user_builds/sunpy/conda/stable/lib/python3.7/site-packages/astropy/wcs/wcs.py:466: FITSFixedWarning: CRDER2 = 'nan '
a floating-point value was expected.
  colsel=colsel)
/home/docs/checkouts/readthedocs.org/user_builds/sunpy/conda/stable/lib/python3.7/site-packages/astropy/wcs/wcs.py:466: FITSFixedWarning: CRDER1 = 'nan '
a floating-point value was expected.
  colsel=colsel)
/home/docs/checkouts/readthedocs.org/user_builds/sunpy/conda/stable/lib/python3.7/site-packages/astropy/wcs/wcs.py:466: FITSFixedWarning: CRDER2 = 'nan '
a floating-point value was expected.
  colsel=colsel)
/home/docs/checkouts/readthedocs.org/user_builds/sunpy/conda/stable/lib/python3.7/site-packages/astropy/wcs/wcs.py:466: FITSFixedWarning: CRDER1 = 'nan '
a floating-point value was expected.
  colsel=colsel)
/home/docs/checkouts/readthedocs.org/user_builds/sunpy/conda/stable/lib/python3.7/site-packages/astropy/wcs/wcs.py:466: FITSFixedWarning: CRDER2 = 'nan '
a floating-point value was expected.
  colsel=colsel)
/home/docs/checkouts/readthedocs.org/user_builds/sunpy/conda/stable/lib/python3.7/site-packages/astropy/wcs/wcs.py:466: FITSFixedWarning: CRDER1 = 'nan '
a floating-point value was expected.
  colsel=colsel)
/home/docs/checkouts/readthedocs.org/user_builds/sunpy/conda/stable/lib/python3.7/site-packages/astropy/wcs/wcs.py:466: FITSFixedWarning: CRDER2 = 'nan '
a floating-point value was expected.
  colsel=colsel)

Total running time of the script: ( 1 minutes 19.815 seconds)

Gallery generated by Sphinx-Gallery