Downloading and plotting an HMI magnetogram

How to download an HMI magnetogram data with Fido and make a plot.

import astropy.units as u
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. First define the search variables, a timerange, the instrument, the observation type, and a cadence of images spaced every 720 seconds.

result = Fido.search(a.Time('2011/11/09 17:40:00', '2011/11/09 17:55:00'),
                     a.Instrument('hmi'),
                     a.Sample(720*u.s),
                     a.vso.Physobs('LOS_magnetic_field'))

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

print(result)

Out:

Results from 1 Provider:

2 Results from the VSOClient:
   Start Time [1]       End Time [1]    Source ...   Type    Wavelength [2]
                                               ...              Angstrom
       str19               str19         str3  ...   str8       float64
------------------- ------------------- ------ ... -------- ----------------
2011-11-09 17:40:13 2011-11-09 17:40:14    SDO ... FULLDISK 6173.0 .. 6174.0
2011-11-09 17:52:13 2011-11-09 17:52:14    SDO ... FULLDISK 6173.0 .. 6174.0

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 client and then index the file.

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

Out:

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

hmi_m_45s_2011_11_09_17_41_15_tai_magnetogram.fits:   0%|          | 0.00/15.7M [00:00<?, ?B/s]

hmi_m_45s_2011_11_09_17_41_15_tai_magnetogram.fits:   0%|          | 47.9k/15.7M [00:00<00:48, 324kB/s]

hmi_m_45s_2011_11_09_17_41_15_tai_magnetogram.fits:   1%|          | 96.6k/15.7M [00:00<00:43, 359kB/s]

hmi_m_45s_2011_11_09_17_41_15_tai_magnetogram.fits:   1%|1         | 179k/15.7M [00:00<00:35, 432kB/s] 

hmi_m_45s_2011_11_09_17_41_15_tai_magnetogram.fits:   2%|1         | 246k/15.7M [00:00<00:31, 484kB/s]

hmi_m_45s_2011_11_09_17_41_15_tai_magnetogram.fits:   2%|2         | 351k/15.7M [00:00<00:26, 578kB/s]

hmi_m_45s_2011_11_09_17_41_15_tai_magnetogram.fits:   3%|2         | 456k/15.7M [00:00<00:22, 668kB/s]

hmi_m_45s_2011_11_09_17_41_15_tai_magnetogram.fits:   4%|3         | 587k/15.7M [00:00<00:19, 783kB/s]

hmi_m_45s_2011_11_09_17_41_15_tai_magnetogram.fits:   4%|4         | 702k/15.7M [00:00<00:17, 867kB/s]

hmi_m_45s_2011_11_09_17_41_15_tai_magnetogram.fits:   5%|5         | 855k/15.7M [00:00<00:14, 996kB/s]

hmi_m_45s_2011_11_09_17_41_15_tai_magnetogram.fits:   6%|6         | 991k/15.7M [00:01<00:13, 1.08MB/s]

hmi_m_45s_2011_11_09_17_41_15_tai_magnetogram.fits:   7%|7         | 1.14M/15.7M [00:01<00:12, 1.19MB/s]

hmi_m_45s_2011_11_09_17_41_15_tai_magnetogram.fits:   8%|8         | 1.27M/15.7M [00:01<00:11, 1.22MB/s]

hmi_m_45s_2011_11_09_17_41_15_tai_magnetogram.fits:   9%|9         | 1.46M/15.7M [00:01<00:10, 1.36MB/s]

hmi_m_45s_2011_11_09_17_41_15_tai_magnetogram.fits:  11%|#         | 1.66M/15.7M [00:01<00:09, 1.51MB/s]

hmi_m_45s_2011_11_09_17_41_15_tai_magnetogram.fits:  12%|#2        | 1.89M/15.7M [00:01<00:08, 1.67MB/s]

hmi_m_45s_2011_11_09_17_41_15_tai_magnetogram.fits:  13%|#3        | 2.08M/15.7M [00:01<00:07, 1.75MB/s]

hmi_m_45s_2011_11_09_17_41_15_tai_magnetogram.fits:  15%|#4        | 2.34M/15.7M [00:01<00:06, 1.94MB/s]

hmi_m_45s_2011_11_09_17_41_15_tai_magnetogram.fits:  17%|#6        | 2.61M/15.7M [00:01<00:06, 2.11MB/s]

hmi_m_45s_2011_11_09_17_41_15_tai_magnetogram.fits:  19%|#8        | 2.91M/15.7M [00:01<00:05, 2.32MB/s]

hmi_m_45s_2011_11_09_17_41_15_tai_magnetogram.fits:  21%|##        | 3.24M/15.7M [00:02<00:04, 2.54MB/s]

hmi_m_45s_2011_11_09_17_41_15_tai_magnetogram.fits:  23%|##2       | 3.58M/15.7M [00:02<00:04, 2.76MB/s]

hmi_m_45s_2011_11_09_17_41_15_tai_magnetogram.fits:  25%|##5       | 3.96M/15.7M [00:02<00:03, 2.99MB/s]

hmi_m_45s_2011_11_09_17_41_15_tai_magnetogram.fits:  28%|##7       | 4.38M/15.7M [00:02<00:03, 3.28MB/s]

hmi_m_45s_2011_11_09_17_41_15_tai_magnetogram.fits:  31%|###       | 4.83M/15.7M [00:02<00:03, 3.58MB/s]

hmi_m_45s_2011_11_09_17_41_15_tai_magnetogram.fits:  34%|###4      | 5.34M/15.7M [00:02<00:02, 3.93MB/s]

hmi_m_45s_2011_11_09_17_41_15_tai_magnetogram.fits:  37%|###7      | 5.87M/15.7M [00:02<00:02, 4.24MB/s]

hmi_m_45s_2011_11_09_17_41_15_tai_magnetogram.fits:  41%|####1     | 6.48M/15.7M [00:02<00:01, 4.67MB/s]

hmi_m_45s_2011_11_09_17_41_15_tai_magnetogram.fits:  45%|####4     | 7.06M/15.7M [00:02<00:01, 4.97MB/s]

hmi_m_45s_2011_11_09_17_41_15_tai_magnetogram.fits:  50%|####9     | 7.79M/15.7M [00:02<00:01, 5.49MB/s]

hmi_m_45s_2011_11_09_17_41_15_tai_magnetogram.fits:  55%|#####4    | 8.58M/15.7M [00:03<00:01, 6.04MB/s]

hmi_m_45s_2011_11_09_17_41_15_tai_magnetogram.fits:  60%|######    | 9.43M/15.7M [00:03<00:00, 6.61MB/s]

hmi_m_45s_2011_11_09_17_41_15_tai_magnetogram.fits:  65%|######5   | 10.3M/15.7M [00:03<00:00, 7.08MB/s]

hmi_m_45s_2011_11_09_17_41_15_tai_magnetogram.fits:  72%|#######1  | 11.3M/15.7M [00:03<00:00, 7.77MB/s]

hmi_m_45s_2011_11_09_17_41_15_tai_magnetogram.fits:  78%|#######7  | 12.2M/15.7M [00:03<00:00, 8.16MB/s]

hmi_m_45s_2011_11_09_17_41_15_tai_magnetogram.fits:  85%|########4 | 13.3M/15.7M [00:03<00:00, 8.88MB/s]

hmi_m_45s_2011_11_09_17_41_15_tai_magnetogram.fits:  92%|#########1| 14.4M/15.7M [00:03<00:00, 9.30MB/s]

hmi_m_45s_2011_11_09_17_41_15_tai_magnetogram.fits: 100%|#########9| 15.6M/15.7M [00:03<00:00, 10.1MB/s]

                                                                                                        
Files Downloaded: 100%|##########| 1/1 [00:04<00:00,  4.64s/file]
['/home/docs/sunpy/data/hmi_m_45s_2011_11_09_17_41_15_tai_magnetogram.fits']

Now load it into a map and plot it

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

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

Gallery generated by Sphinx-Gallery