Flare times on a GOES XRS plot

How to plot flare times as provided by the HEK on a GOES XRS plot.

import matplotlib.pyplot as plt

from sunpy.timeseries import TimeSeries
from sunpy.time import TimeRange, parse_time
from sunpy.net import hek, Fido, attrs as a

Let’s first grab GOES XRS data for a particular time of interest

tr = TimeRange(['2011-06-07 04:00', '2011-06-07 12:00'])
results = Fido.search(a.Time(tr), a.Instrument('XRS'))

Then download the data and load it into a TimeSeries

files = Fido.fetch(results)
goes = TimeSeries(files)

Out:

/home/docs/checkouts/readthedocs.org/user_builds/sunpy/conda/v1.1.4/lib/python3.8/site-packages/parfive/downloader.py:100: DeprecationWarning: The loop argument is deprecated since Python 3.8, and scheduled for removal in Python 3.10.
  self.http_queue = asyncio.Queue(loop=self.loop)
/home/docs/checkouts/readthedocs.org/user_builds/sunpy/conda/v1.1.4/lib/python3.8/asyncio/queues.py:48: DeprecationWarning: The loop argument is deprecated since Python 3.8, and scheduled for removal in Python 3.10.
  self._finished = locks.Event(loop=loop)
/home/docs/checkouts/readthedocs.org/user_builds/sunpy/conda/v1.1.4/lib/python3.8/site-packages/parfive/downloader.py:101: DeprecationWarning: The loop argument is deprecated since Python 3.8, and scheduled for removal in Python 3.10.
  self.http_tokens = asyncio.Queue(maxsize=self.max_conn, loop=self.loop)
/home/docs/checkouts/readthedocs.org/user_builds/sunpy/conda/v1.1.4/lib/python3.8/asyncio/queues.py:48: DeprecationWarning: The loop argument is deprecated since Python 3.8, and scheduled for removal in Python 3.10.
  self._finished = locks.Event(loop=loop)
/home/docs/checkouts/readthedocs.org/user_builds/sunpy/conda/v1.1.4/lib/python3.8/site-packages/parfive/downloader.py:102: DeprecationWarning: The loop argument is deprecated since Python 3.8, and scheduled for removal in Python 3.10.
  self.ftp_queue = asyncio.Queue(loop=self.loop)
/home/docs/checkouts/readthedocs.org/user_builds/sunpy/conda/v1.1.4/lib/python3.8/asyncio/queues.py:48: DeprecationWarning: The loop argument is deprecated since Python 3.8, and scheduled for removal in Python 3.10.
  self._finished = locks.Event(loop=loop)
/home/docs/checkouts/readthedocs.org/user_builds/sunpy/conda/v1.1.4/lib/python3.8/site-packages/parfive/downloader.py:103: DeprecationWarning: The loop argument is deprecated since Python 3.8, and scheduled for removal in Python 3.10.
  self.ftp_tokens = asyncio.Queue(maxsize=self.max_conn, loop=self.loop)
/home/docs/checkouts/readthedocs.org/user_builds/sunpy/conda/v1.1.4/lib/python3.8/asyncio/queues.py:48: DeprecationWarning: The loop argument is deprecated since Python 3.8, and scheduled for removal in Python 3.10.
  self._finished = locks.Event(loop=loop)

Files Downloaded:   0%|          | 0/1 [00:00<?, ?file/s]/home/docs/checkouts/readthedocs.org/user_builds/sunpy/conda/v1.1.4/lib/python3.8/site-packages/parfive/downloader.py:312: DeprecationWarning: The loop argument is deprecated since Python 3.8, and scheduled for removal in Python 3.10.
  done, _ = await asyncio.wait(futures, loop=self.loop)
/home/docs/checkouts/readthedocs.org/user_builds/sunpy/conda/v1.1.4/lib/python3.8/site-packages/aiohttp/connector.py:964: DeprecationWarning: The loop argument is deprecated since Python 3.8, and scheduled for removal in Python 3.10.
  hosts = await asyncio.shield(self._resolve_host(
/home/docs/checkouts/readthedocs.org/user_builds/sunpy/conda/v1.1.4/lib/python3.8/site-packages/aiohttp/locks.py:21: DeprecationWarning: The loop argument is deprecated since Python 3.8, and scheduled for removal in Python 3.10.
  self._event = asyncio.Event(loop=loop)


go1520110607.fits:   0%|          | 0.00/694k [00:00<?, ?B/s]/home/docs/checkouts/readthedocs.org/user_builds/sunpy/conda/v1.1.4/lib/python3.8/site-packages/aiohttp/connector.py:964: DeprecationWarning: The loop argument is deprecated since Python 3.8, and scheduled for removal in Python 3.10.
  hosts = await asyncio.shield(self._resolve_host(
/home/docs/checkouts/readthedocs.org/user_builds/sunpy/conda/v1.1.4/lib/python3.8/site-packages/aiohttp/connector.py:964: DeprecationWarning: The loop argument is deprecated since Python 3.8, and scheduled for removal in Python 3.10.
  hosts = await asyncio.shield(self._resolve_host(
/home/docs/checkouts/readthedocs.org/user_builds/sunpy/conda/v1.1.4/lib/python3.8/site-packages/aiohttp/connector.py:964: DeprecationWarning: The loop argument is deprecated since Python 3.8, and scheduled for removal in Python 3.10.
  hosts = await asyncio.shield(self._resolve_host(
/home/docs/checkouts/readthedocs.org/user_builds/sunpy/conda/v1.1.4/lib/python3.8/site-packages/aiohttp/connector.py:964: DeprecationWarning: The loop argument is deprecated since Python 3.8, and scheduled for removal in Python 3.10.
  hosts = await asyncio.shield(self._resolve_host(
/home/docs/checkouts/readthedocs.org/user_builds/sunpy/conda/v1.1.4/lib/python3.8/site-packages/aiohttp/connector.py:964: DeprecationWarning: The loop argument is deprecated since Python 3.8, and scheduled for removal in Python 3.10.
  hosts = await asyncio.shield(self._resolve_host(


go1520110607.fits:  49%|####8     | 339k/694k [00:00<00:00, 3.39MB/s]

                                                                     
Files Downloaded: 100%|##########| 1/1 [00:00<00:00,  5.33file/s]
Files Downloaded: 100%|##########| 1/1 [00:00<00:00,  5.32file/s]
/home/docs/checkouts/readthedocs.org/user_builds/sunpy/conda/v1.1.4/lib/python3.8/functools.py:874: UserWarning: Discarding nonzero nanoseconds in conversion
  return dispatch(args[0].__class__)(*args, **kw)
/home/docs/checkouts/readthedocs.org/user_builds/sunpy/conda/v1.1.4/lib/python3.8/functools.py:874: UserWarning: Discarding nonzero nanoseconds in conversion
  return dispatch(args[0].__class__)(*args, **kw)

Next lets grab the HEK flare data for this time from the NOAA Space Weather Prediction Center (SWPC)

client = hek.HEKClient()
flares_hek = client.search(hek.attrs.Time(tr.start, tr.end),
                           hek.attrs.FL, hek.attrs.FRM.Name == 'SWPC')

Lets plot everything together

fig, ax = plt.subplots()
goes.plot()
ax.axvline(parse_time(flares_hek[0].get('event_peaktime')).plot_date)
ax.axvspan(parse_time(flares_hek[0].get('event_starttime')).plot_date,
           parse_time(flares_hek[0].get('event_endtime')).plot_date,
           alpha=0.2, label=flares_hek[0].get('fl_goescls'))
ax.legend(loc=2)
ax.set_yscale('log')
plt.show()
goes hek m25

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

Gallery generated by Sphinx-Gallery