Skip to content

Commit

Permalink
Merge branch 'main' into instrument-response-topic-guide
Browse files Browse the repository at this point in the history
  • Loading branch information
wtbarnes authored Sep 3, 2024
2 parents d73a66e + 542463f commit 3c55cd6
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 13 deletions.
1 change: 1 addition & 0 deletions changelog/126.breaking.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Increased the minimum version of ``sunpy`` to 6.0.0.
5 changes: 5 additions & 0 deletions changelog/128.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
In the ``fermi``, the function ``get_detector_sun_angles_for_time`` returns the angle with respect to the Sun of each Fermi/GBM detector.
However, these files contain gaps due to the South Atlantic Anomaly.
If the time requested falls in one of these gaps, the code will return the detector angles for the next available time.
This can be several minutes different from the time requested.
Now, a warning to the user will be raised if the time returned by the code is more than 1 minute different from the time requested (1 minute is the nominal cadence of the spacecraft weekly file), and explains that this is likely due to a South Atlantic Anomaly encounter.
1 change: 1 addition & 0 deletions changelog/130.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The function ``plot_detector_sun_angles`` was broken, due to the formatting of the time axis.
6 changes: 3 additions & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

# -- Non stdlib imports --------------------------------------------------------
from sunkit_instruments import __version__ # NOQA
from sunpy_sphinx_theme import PNG_ICON # NOQA

# -- Project information -------------------------------------------------------
project = "sunkit_instruments"
Expand Down Expand Up @@ -85,7 +86,7 @@
default_role = "obj"

# -- Options for HTML output ---------------------------------------------------
from sunpy_sphinx_theme.conf import * # NOQA
html_theme = "sunpy"

# -- Graphviz Output ------------------------------------------------------------
graphviz_output_format = "svg"
Expand All @@ -105,8 +106,7 @@
"examples_dirs": os.path.join("..", "examples"),
"gallery_dirs": os.path.join("generated", "gallery"),
"matplotlib_animations": True,
# Comes from the theme.
"default_thumb_file": png_icon,
"default_thumb_file": PNG_ICON,
"abort_on_example_error": False,
"plot_gallery": "True",
"remove_config_comments": True,
Expand Down
6 changes: 2 additions & 4 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ setup_requires =
setuptools_scm
install_requires =
scipy
sunpy[map,net,timeseries,visualization]>=5.0.0
sunpy[map,net,timeseries,visualization]>=6.0.0

[options.extras_require]
tests =
Expand All @@ -45,8 +45,6 @@ docs =
sphinx-changelog
sphinx-gallery
sunpy-sphinx-theme
# Remove next line when fixed in towncrier; see https://github.com/twisted/towncrier/issues/528
importlib-resources<6

[options.packages.find]
exclude = sunkit_instruments._dev
Expand Down Expand Up @@ -82,7 +80,7 @@ filterwarnings =
ignore:distutils Version classes are deprecated. Use packaging.version instead:DeprecationWarning
ignore:Unknown units for CHANNEL:sunpy.util.exceptions.SunpyUserWarning
ignore:.*is deprecated and slated for removal in Python 3:DeprecationWarning

ignore:.*Something went wrong.*

[isort]
line_length = 110
Expand Down
28 changes: 22 additions & 6 deletions sunkit_instruments/fermi/fermi.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from sunpy.time import TimeRange, parse_time
from sunpy.time.time import _variables_for_parse_time_docstring
from sunpy.util.decorators import add_common_docstring
from sunpy.util.exceptions import warn_user

__all__ = [
"download_weekly_pointing_file",
Expand Down Expand Up @@ -116,6 +117,18 @@ def get_detector_sun_angles_for_time(time, file):

time = parse_time(time)
scx, scz, tt = get_scx_scz_at_time(time, file)

# Fermi LAT spacecraft files have gaps due to SAA. If the requested time falls
# in one of these gaps, the time and angles returned will be the next available
# time in the file. This may be several minutes different from the request.
# If the returned time is > 60s different from the time requested, raise a warning.
if np.abs((tt - time).sec) > 60.0:
warn_user(
"The time requested is missing from the Fermi spacecraft file. "
"The requested time probably occurs during the South Atlantic Anomaly. "
f"Returning detector angles for the next available time: {tt}"
)

# retrieve the detector angle information in spacecraft coordinates
detectors = nai_detector_angles()

Expand Down Expand Up @@ -225,23 +238,26 @@ def plot_detector_sun_angles(angles):
function of time. Obtained from the
`~sunkit_instruments.fermi.get_detector_separation_angles` function.
"""

# make a plot showing the angles vs time
figure = plt.figure(1)
# Reformat the time array so we can plot it
angle_times = []
for t in angles["time"]:
angle_times.append(t.datetime)
# Make a plot showing the angles vs time
figure = plt.figure(1, figsize=(12, 6), layout="constrained")
for n in angles.keys():
if not n == "time":
plt.plot(
angles["time"],
angle_times,
angles[n].value,
label="{lab} ({val})".format(
lab=n, val=str(np.mean(angles[n].value))[0:5]
),
)
plt.ylim(180, 0)
plt.ylabel("angle (degrees)")
plt.xlabel("Start time: " + angles["time"][0].isoformat())
plt.xlabel("Start time: " + angle_times[0].isoformat())
plt.title("Detector pointing angle from Sun")
plt.legend(fontsize=10)
figure.legend(fontsize=10, loc="outside center right")
figure.autofmt_xdate()
plt.show()

Expand Down

0 comments on commit 3c55cd6

Please sign in to comment.