Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/179.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Updated GOES event list to account for change in the HEK results from sunpy 7.0.
7 changes: 6 additions & 1 deletion sunkit_instruments/goes_xrs/goes_xrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def get_goes_event_list(timerange, goes_class_filter=None):
A list of all the flares found for the given time range.
"""
# Importing hek here to avoid calling code that relies on optional dependencies.
from sunpy import __version__ as sunpy_version
from sunpy.net import attrs, hek

# use HEK module to search for GOES events
Expand Down Expand Up @@ -69,13 +70,17 @@ def get_goes_event_list(timerange, goes_class_filter=None):
goes_event_list = []

for r in result:
if sunpy_version < "7.0.0":
event_coord = (r["event_coord1"], r["event_coord2"])
else:
event_coord = (r["event_coord"])
Comment on lines +73 to +76
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could just use the raw attribute on the results to get back the pre 7.0.0 output.

goes_event = {
"event_date": parse_time(r["event_starttime"]).strftime("%Y-%m-%d"),
"start_time": parse_time(r["event_starttime"]),
"peak_time": parse_time(r["event_peaktime"]),
"end_time": parse_time(r["event_endtime"]),
"goes_class": str(r["fl_goescls"]),
"goes_location": (r["event_coord1"], r["event_coord2"]),
"goes_location": (event_coord),
"noaa_active_region": r["ar_noaanum"],
}
goes_event_list.append(goes_event)
Expand Down
13 changes: 9 additions & 4 deletions sunkit_instruments/goes_xrs/tests/test_goes_xrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,21 +148,26 @@ def test_comparison_with_IDL_version(goes_files, idl_files):
# Test the other GOES-XRS functionality
@pytest.mark.remote_data
def test_goes_event_list():
from astropy.coordinates import SkyCoord

from sunpy import __version__ as sunpy_version

# Set a time range to search
trange = TimeRange("2011-06-07 00:00", "2011-06-08 00:00")
# Test case where GOES class filter is applied
result = goes.get_goes_event_list(trange, goes_class_filter="M1")
base_type = tuple if sunpy_version < "7.0.0" else SkyCoord
assert isinstance(result, list)
assert isinstance(result[0], dict)
assert isinstance(result[0]["event_date"], str)
assert isinstance(result[0]["goes_location"], tuple)
assert isinstance(result[0]["goes_location"], base_type)
assert isinstance(result[0]["peak_time"], Time)
assert isinstance(result[0]["start_time"], Time)
assert isinstance(result[0]["end_time"], Time)
assert isinstance(result[0]["goes_class"], str)
assert isinstance(result[0]["noaa_active_region"], np.int64)
assert result[0]["event_date"] == "2011-06-07"
assert result[0]["goes_location"] == (54, -21)
assert result[0]["goes_location"] in [(54, -21), SkyCoord(54 * u.deg, -21 * u.deg, frame="heliographic_stonyhurst", obstime=result[0]["start_time"])]
# float error
assert is_time_equal(result[0]["start_time"], parse_time((2011, 6, 7, 6, 16)))
assert is_time_equal(result[0]["peak_time"], parse_time((2011, 6, 7, 6, 41)))
Expand All @@ -174,14 +179,14 @@ def test_goes_event_list():
assert isinstance(result, list)
assert isinstance(result[0], dict)
assert isinstance(result[0]["event_date"], str)
assert isinstance(result[0]["goes_location"], tuple)
assert isinstance(result[0]["goes_location"], base_type)
assert isinstance(result[0]["peak_time"], Time)
assert isinstance(result[0]["start_time"], Time)
assert isinstance(result[0]["end_time"], Time)
assert isinstance(result[0]["goes_class"], str)
assert isinstance(result[0]["noaa_active_region"], np.int64)
assert result[0]["event_date"] == "2011-06-07"
assert result[0]["goes_location"] == (54, -21)
assert result[0]["goes_location"] in [(54, -21), SkyCoord(54 * u.deg, -21 * u.deg, frame="heliographic_stonyhurst", obstime=result[0]["start_time"])]
assert is_time_equal(result[0]["start_time"], parse_time((2011, 6, 7, 6, 16)))
assert is_time_equal(result[0]["peak_time"], parse_time((2011, 6, 7, 6, 41)))
assert is_time_equal(result[0]["end_time"], parse_time((2011, 6, 7, 6, 59)))
Expand Down