Querying the GOES flare event list#

How to retrieve the GOES flare event list, sort and save the results.

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

We use Fido to to query the HEK catalogue. We define our event type as a flare (“FL”). We also set up the start and end times over which we will search for flare events. We want the list of events that were detected by the GOES X-ray Sensor (XRS) instrument between tstart and tend and GOES class > M1.0.

event_type = "FL"
tstart = "2013/10/28"
tend = "2013/10/29"
result = Fido.search(a.Time(tstart, tend),
                     a.hek.EventType(event_type),
                     a.hek.FL.GOESCls > "M1.0",
                     a.hek.OBS.Observatory == "GOES")

The result is returned as a UnifiedResponse, from which we can see a table from one provider is found and returned.

# Here we only show two columns due there being over 100 columns returned normally.
print(result.show("hpc_bbox", "refs"))

# It"s also possible to access the HEK results from the
# `~sunpy.net.fido_factory.UnifiedResponse` by name.
hek_results = result["hek"]
Results from 1 Provider:

7 Results from the HEKClient:

                                              hpc_bbox                                               ...
---------------------------------------------------------------------------------------------------- ...
POLYGON((16.92036 -63.6504,16.92036 -63.6504,16.92036 -63.6504,16.92036 -63.6504,16.92036 -63.6504)) ...
     POLYGON((16.9209 -63.4614,16.9209 -63.4614,16.9209 -63.4614,16.9209 -63.4614,16.9209 -63.4614)) ...
POLYGON((16.92216 -62.9952,16.92216 -62.9952,16.92216 -62.9952,16.92216 -62.9952,16.92216 -62.9952)) ...
                  POLYGON((0.000084 -961.62,-0.000084 -961.62,0 962.358,0 962.358,0.000084 -961.62)) ...
                 POLYGON((0.000084 -961.632,-0.000084 -961.632,0 962.37,0 962.37,0.000084 -961.632)) ...
               POLYGON((0.000084 -961.638,-0.000084 -961.638,0 962.376,0 962.376,0.000084 -961.638)) ...
               POLYGON((0.000084 -961.734,-0.000084 -961.734,0 962.466,0 962.466,0.000084 -961.734)) ...

We can also print the key names that correspond to the HEK parameters returned by the query.

# We only print every 10th key to avoid the output being too long.
print(hek_results.colnames[::10])
['gs_thumburl', 'ar_polarity', 'skel_chaincode', 'obs_dataprepurl', 'eventtype', 'frm_identifier', 'event_maskurl', 'event_probability', 'intenstotal', 'ar_noaanum', 'hgs_y', 'hpc_radius', 'event_pixelunit', 'ar_zurichcls', 'area_unit']

The results returned contain a lot of information and we may only want to keep some main results such as start time, end time, peak time, GOES-class, and active region number. This can be done as so:

filtered_results = hek_results["event_starttime", "event_peaktime",
                               "event_endtime", "fl_goescls", "ar_noaanum"]

hek_result is already sorted by date, if one wants to sort by magnitude, one can do the following:

# Sorting is done by using the flare class from "fl_goescls"
# By converting the flare class to a number using ord()
# and adding the flare strength, we can sort by value
by_magnitude = sorted(filtered_results, key=lambda x: ord(x['fl_goescls'][0]) + float(x['fl_goescls'][1:]), reverse=True)

for flare in by_magnitude:
    print(f"Class {flare['fl_goescls']} occurred on {flare['event_starttime']}")
Class X1.0 occurred on 2013-10-28 01:41:00.000
Class M5.1 occurred on 2013-10-28 04:32:00.000
Class M4.4 occurred on 2013-10-28 15:07:00.000
Class M2.8 occurred on 2013-10-28 14:00:00.000
Class M2.7 occurred on 2013-10-28 14:46:00.000
Class M1.5 occurred on 2013-10-28 20:48:00.000
Class M1.4 occurred on 2013-10-28 11:32:00.000

These results can then be saved to a CSV file, or any other file format that Table supports.

filtered_results.write("october_M1_flares.csv", format="csv")

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

Gallery generated by Sphinx-Gallery