"""
====================================
Downloading and plotting a HMI image
====================================

In this example, we will demonstrate how to download and plot
line of sight magnetic field data from HMI.
"""
# Start by importing the necessary modules.
import astropy.units as u
import matplotlib.pyplot as plt

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

###############################################################################
# Now we will download some data with `sunpy.net.Fido`.
# A `Fido.search` requires us to specify a `~sunpy.net.attr.Time`,
# `~sunpy.net.attr.Sample`, `~sunpy.net.attr.Instrument`
# and the `~sunpy.net.attr.vso.Physobs`.

# We set a time range from ``2015/11/04 12:00:00`` to ``2015/11/04 12:10:00``
# for HMI ``LOS_magnetic_field`` with the images spaced every 720 seconds.
result = Fido.search(a.Time('2018/11/04 12:00:00', '2018/11/04 12:10: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. One is the full disk image we plan to display
# and the other is a synoptic version of said image.

print(result)

###############################################################################
# Once we are happy with the results obtained from the search.
# We can download the data with `Fido.fetch` .
# In this case we only want one file so we can index the result.
# A `Fido` result can be from several clients, so we have to index the first
# client and then index the first result.

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

###############################################################################
# The ``downloaded_files`` variables returns a list with the path for the file
# that was downloaded.

print(downloaded_file)

###############################################################################
# Now we are going to create a `sunpy.map.Map` object out of the first result.

hmi_map = sunpy.map.Map(downloaded_file)

###############################################################################
# Once we have created our Map, we can plot it quite simply doing:

fig = plt.figure()
hmi_map.plot()

plt.show()

"""
===========================================
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 <sunpy.net.fido_factory.UnifiedDownloaderFactory>`, 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)

###############################################################################
# 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)

###############################################################################
# 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()

Update skip_hmi.py