Skip to content
Open
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
13 changes: 12 additions & 1 deletion exoctk/contam_visibility/new_vis_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import warnings

from astropy.time import Time
from erfa import ErfaWarning

from bokeh.models import Band, ColumnDataSource, HoverTool
from bokeh.plotting import figure, show
Expand Down Expand Up @@ -145,7 +146,17 @@ def get_exoplanet_positions(ra, dec, in_FOR=None):
while dec[-1] not in ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '.']:
dec = dec[:-1]

eph = BoundedEphemeris()
# jwst_gtvt validates its future maximum date during construction, which
# can emit ERFA's expected "dubious year" warning. Keep this suppression
# local so other ERFA warnings remain visible to callers.
with warnings.catch_warnings():
warnings.filterwarnings(
'ignore',
message=(r'ERFA function "dtf2d" yielded .*'
r'"dubious year \(Note 6\)"'),
category=ErfaWarning,
)
eph = BoundedEphemeris()
exoplanet_data = eph.get_fixed_target_positions(ra, dec)

if in_FOR is None:
Expand Down
27 changes: 27 additions & 0 deletions exoctk/tests/test_contam_visibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import pytest
import pysiaf
import requests
from erfa import ErfaWarning

from pandas import DataFrame
from astropy.io import fits
Expand Down Expand Up @@ -359,6 +360,32 @@ def test_build_visibility_plot_reuses_positions(monkeypatch):
assert 'times' not in positions


def test_visibility_ephemeris_suppresses_only_expected_erfa_warning(monkeypatch):
"""The jwst_gtvt future-date warning must not hide other warnings."""

class WarningEphemeris:
def __init__(self, *args, **kwargs):
warnings.warn(
'ERFA function "dtf2d" yielded 1 of "dubious year (Note 6)"',
ErfaWarning,
)
warnings.warn('unrelated ERFA warning', ErfaWarning)

def get_fixed_target_positions(self, ra, dec):
return DataFrame({'in_FOR': [True]})

monkeypatch.setattr(new_vis_plot, 'BoundedEphemeris', WarningEphemeris)
with warnings.catch_warnings(record=True) as caught:
warnings.simplefilter('ignore')
warnings.simplefilter('always', ErfaWarning)
result = new_vis_plot.get_exoplanet_positions('24.3544618',
'-45.6777937')
Comment thread
taylorbell57 marked this conversation as resolved.

assert isinstance(result, DataFrame)
assert [str(w.message) for w in caught] == [
'unrelated ERFA warning']


@pytest.mark.skipif(ON_GITHUB_ACTIONS, reason='Need access to trace data FITS files. Please try running locally')
def test_field_simulation():
"""Tests the ``field_simulation`` function in the ``field_simulator`` module"""
Expand Down
Loading