Skip to content

Commit

Permalink
Added warning to Fermi detector angle calculation code, for when time…
Browse files Browse the repository at this point in the history
… returned is different from time requested (#128)

* added warning for when a time requested for Fermi detector angles is not available in the spacecraft file

* changelog

* ignore warning

* Update setup.cfg

* Update setup.cfg

---------

Co-authored-by: Nabil Freij <[email protected]>
  • Loading branch information
aringlis and nabobalis authored Aug 22, 2024
1 parent 20f1ec8 commit 542463f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
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 setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +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
13 changes: 13 additions & 0 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

0 comments on commit 542463f

Please sign in to comment.