Skip to content

Commit 2fdf693

Browse files
JP-2928: Move test for moving target updates to unit test (#8873)
2 parents 7669260 + e56eea6 commit 2fdf693

File tree

2 files changed

+81
-33
lines changed

2 files changed

+81
-33
lines changed

jwst/lib/tests/test_set_telescope_pointing.py

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
pytest.importorskip('pysiaf')
1313

1414
from astropy.io import fits # noqa: E402
15+
from astropy.table import Table # noqa: E402
1516
from astropy.time import Time # noqa: E402
1617

1718
from stdatamodels.jwst import datamodels # noqa: E402
@@ -586,6 +587,46 @@ def test_mirim_tamrs_siaf_values(eng_db_ngas, data_file_nosiaf):
586587
assert model.meta.wcsinfo.crpix2 == 993.5
587588

588589

590+
def test_moving_target_update(caplog, eng_db_ngas, data_file_moving_target):
591+
"""Test moving target table updates."""
592+
with datamodels.open(data_file_moving_target) as model:
593+
stp.update_mt_kwds(model)
594+
595+
expected_ra = 6.200036603575057e-05
596+
expected_dec = 1.7711407285091175e-10
597+
assert np.isclose(model.meta.wcsinfo.mt_ra, expected_ra)
598+
assert np.isclose(model.meta.wcsinfo.mt_dec, expected_dec)
599+
assert np.isclose(model.meta.target.ra, expected_ra)
600+
assert np.isclose(model.meta.target.dec, expected_dec)
601+
602+
assert "Moving target RA and Dec updated" in caplog.text
603+
604+
605+
def test_moving_target_no_mtt(caplog, eng_db_ngas, data_file):
606+
"""Test moving target table updates, no table present."""
607+
with datamodels.open(data_file) as model:
608+
stp.update_mt_kwds(model)
609+
610+
# No update without table
611+
assert model.meta.wcsinfo.mt_ra is None
612+
assert model.meta.wcsinfo.mt_dec is None
613+
614+
assert "Moving target position table not found" in caplog.text
615+
616+
617+
def test_moving_target_tnotinrange(caplog, eng_db_ngas, data_file_moving_target):
618+
"""Test moving target table updates, time not in range."""
619+
with datamodels.open(data_file_moving_target) as model:
620+
model.meta.exposure.mid_time -= 0.2
621+
stp.update_mt_kwds(model)
622+
623+
# No update without times in range
624+
assert model.meta.wcsinfo.mt_ra is None
625+
assert model.meta.wcsinfo.mt_dec is None
626+
627+
assert "is not in the moving_target table range" in caplog.text
628+
629+
589630
# ######################
590631
# Utilities and fixtures
591632
# ######################
@@ -789,6 +830,46 @@ def data_file_acq1(tmp_path):
789830
yield file_path
790831

791832

833+
@pytest.fixture
834+
def data_file_moving_target(tmp_path):
835+
"""Example data from simulation."""
836+
# Values are from simulated data file jw00634_nrcblong_mttest_uncal.fits
837+
model = datamodels.Level1bModel()
838+
model.meta.exposure.start_time = 58738.82598848102
839+
model.meta.exposure.end_time = 58738.82747969907
840+
model.meta.exposure.mid_time = 58738.82673409005
841+
model.meta.target.ra = 0.0
842+
model.meta.target.dec = 0.0
843+
model.meta.guidestar.gs_ra = 0.0001
844+
model.meta.guidestar.gs_dec = 0.0001
845+
model.meta.aperture.name = "MIRIM_FULL"
846+
model.meta.observation.date = '2019-09-12'
847+
model.meta.exposure.type = "MIR_IMAGE"
848+
model.meta.ephemeris.velocity_x = 0.00651191175424979
849+
model.meta.ephemeris.velocity_y = 0.160769793796114
850+
model.meta.ephemeris.velocity_z = 0.147663026601154
851+
852+
model.meta.target.type = 'MOVING'
853+
model.meta.moving_target = None
854+
855+
times = ['2019-09-12T19:49:25.405', '2019-09-12T19:50:29.825', '2019-09-12T19:51:34.246']
856+
apparent_ra = [0.0, 6.2e-5, 1.24e-4]
857+
apparent_dec = [-6.2e-5, 0.0, 3.0e-5]
858+
default = [0.0, 0.0, 0.0]
859+
col_names = [item['name'] for item in model.schema['properties']['moving_target']['datatype']]
860+
mt_table = Table([times, apparent_ra, apparent_dec],
861+
names=('time', 'mt_apparent_RA', 'mt_apparent_Dec'))
862+
for column in col_names:
863+
if column not in {'time', 'mt_apparent_RA', 'mt_apparent_Dec'}:
864+
mt_table.add_column(default, name=column)
865+
model.moving_target = mt_table.as_array()
866+
867+
file_path = tmp_path / 'file.fits'
868+
model.save(file_path)
869+
model.close()
870+
yield file_path
871+
872+
792873
@pytest.fixture()
793874
def eng_db_jw703():
794875
"""Setup the test engineering database"""

jwst/regtest/test_nircam_mtimage.py

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import pytest
22
from astropy.io.fits.diff import FITSDiff
33

4-
from stdatamodels.jwst import datamodels
5-
6-
from jwst.lib.set_telescope_pointing import update_mt_kwds
74
from jwst.stpipe import Step
85

96

@@ -21,33 +18,3 @@ def test_nircam_image_moving_target_i2d(rtdata, fitsdiff_default_kwargs, in_memo
2118
fitsdiff_default_kwargs["atol"] = 2e-4
2219
diff = FITSDiff(rtdata.output, rtdata.truth, **fitsdiff_default_kwargs)
2320
assert diff.identical, diff.report()
24-
25-
26-
@pytest.mark.parametrize("input_file",
27-
[
28-
'jw00634_nrcblong_mttest_tnotinrange_uncal.fits',
29-
'jw00634_nrcblong_no_mtt_uncal.fits',
30-
'jw00634_nrcblong_mttest_uncal.fits',
31-
],
32-
ids=["midpt_not_in_mt_table_range", "no_mt_table", "with_mt_table"]
33-
)
34-
@pytest.mark.bigdata
35-
def test_nircam_image_moving_target_kwds(input_file, rtdata, fitsdiff_default_kwargs):
36-
"""Tests for moving target table nkeyword additions"""
37-
38-
# Get the input file
39-
rtdata.get_data(f"nircam/image/{input_file}")
40-
41-
# The add_mt_kwds function overwrites its input, so output = input
42-
rtdata.output = rtdata.input
43-
44-
with datamodels.open(rtdata.output) as model:
45-
update_mt_kwds(model)
46-
# since the model is updated in place we need to write out the update
47-
model.write(rtdata.input)
48-
49-
rtdata.get_truth(f"truth/test_nircam_mtimage/{input_file}")
50-
51-
# Compare the results and the truth
52-
diff = FITSDiff(rtdata.output, rtdata.truth, **fitsdiff_default_kwargs)
53-
assert diff.identical, diff.report()

0 commit comments

Comments
 (0)