|
12 | 12 | pytest.importorskip('pysiaf')
|
13 | 13 |
|
14 | 14 | from astropy.io import fits # noqa: E402
|
| 15 | +from astropy.table import Table # noqa: E402 |
15 | 16 | from astropy.time import Time # noqa: E402
|
16 | 17 |
|
17 | 18 | from stdatamodels.jwst import datamodels # noqa: E402
|
@@ -586,6 +587,46 @@ def test_mirim_tamrs_siaf_values(eng_db_ngas, data_file_nosiaf):
|
586 | 587 | assert model.meta.wcsinfo.crpix2 == 993.5
|
587 | 588 |
|
588 | 589 |
|
| 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 | + |
589 | 630 | # ######################
|
590 | 631 | # Utilities and fixtures
|
591 | 632 | # ######################
|
@@ -789,6 +830,46 @@ def data_file_acq1(tmp_path):
|
789 | 830 | yield file_path
|
790 | 831 |
|
791 | 832 |
|
| 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 | + |
792 | 873 | @pytest.fixture()
|
793 | 874 | def eng_db_jw703():
|
794 | 875 | """Setup the test engineering database"""
|
|
0 commit comments