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:

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

go1520110607.fits:   0%|          | 0.00/694k [00:00<?, ?B/s]/home/docs/checkouts/readthedocs.org/user_builds/sunpy/conda/stable/lib/python3.7/asyncio/events.py:111: ResourceWarning: unclosed <socket.socket fd=14, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=6, laddr=('172.17.0.2', 47462), raddr=('198.118.248.134', 443)>
  super().__init__(callback, args, loop, context)
/home/docs/checkouts/readthedocs.org/user_builds/sunpy/conda/stable/lib/python3.7/asyncio/selector_events.py:655: ResourceWarning: unclosed transport <_SelectorSocketTransport fd=14 read=idle write=<idle, bufsize=0>>
  source=self)


                                                             
Files Downloaded: 100%|##########| 1/1 [00:00<00:00,  7.97file/s]
/home/docs/checkouts/readthedocs.org/user_builds/sunpy/conda/stable/lib/python3.7/functools.py:827: UserWarning: Discarding nonzero nanoseconds in conversion
  return dispatch(args[0].__class__)(*args, **kw)
/home/docs/checkouts/readthedocs.org/user_builds/sunpy/conda/stable/lib/python3.7/functools.py:827: 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()
../../../_images/sphx_glr_goes_hek_m25_001.png

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

Gallery generated by Sphinx-Gallery