|
| 1 | +# Use data file from parse_cm.test for get_cmds_from_backstop test. |
| 2 | +# This package is a dependency |
| 3 | +import astropy.table as apt |
| 4 | +import numpy as np |
| 5 | +import pytest |
| 6 | +from testr.test_helper import has_internet |
| 7 | + |
| 8 | +import kadi.commands as kc |
| 9 | +import kadi.commands.commands_v2 as kcc2 |
| 10 | +import kadi.commands.observations as kco |
| 11 | + |
| 12 | +HAS_INTERNET = has_internet() |
| 13 | + |
| 14 | + |
| 15 | +@pytest.mark.skipif(not HAS_INTERNET, reason="No internet connection") |
| 16 | +def test_filter_scs107_2024366(cmds_dir): |
| 17 | + """Filter the command events associated with SCS-107 on 2024:366""" |
| 18 | + start = "2024:365" |
| 19 | + stop = "2025:003" |
| 20 | + |
| 21 | + obss_as_run = apt.Table(kc.get_observations(start, stop)) |
| 22 | + |
| 23 | + with kc.set_time_now(stop), kc.conf.set_temp("default_lookback", 20): |
| 24 | + obss_planned = apt.Table( |
| 25 | + kc.get_observations(start, stop, event_filter=kc.filter_scs107_events) |
| 26 | + ) |
| 27 | + |
| 28 | + # As-run gets an extra observation because the manual obsid update at |
| 29 | + # 2025:001:12:48:34.040 breaks the observation into two. |
| 30 | + assert len(obss_as_run) == 34 |
| 31 | + assert len(obss_planned) == 33 |
| 32 | + |
| 33 | + # Now get rid of the 2nd of the observation that was split into two. The source of |
| 34 | + # CMD_EVT is from the Obsid command event at 2025:001:12:48:34.040. |
| 35 | + ok = obss_as_run["source"] != "CMD_EVT" |
| 36 | + obss_as_run = obss_as_run[ok] |
| 37 | + |
| 38 | + # Make sure that the source and starcat_date are the same. |
| 39 | + assert set(obss_as_run.colnames) == set(obss_planned.colnames) |
| 40 | + for name in obss_as_run.colnames: |
| 41 | + if name in ["obsid", "simpos"]: |
| 42 | + continue |
| 43 | + assert np.all(obss_as_run[name] == obss_planned[name]) |
| 44 | + |
| 45 | + # Now filter out the two observations that have no star catalog. These are both |
| 46 | + # the gyro hold in the high-IR zone. |
| 47 | + ok = ~obss_as_run["starcat_date"].mask |
| 48 | + obss_as_run = obss_as_run[ok] |
| 49 | + obss_planned = obss_planned[ok] |
| 50 | + |
| 51 | + obss_run_planned = apt.join(obss_as_run, obss_planned, keys="starcat_date") |
| 52 | + lines = obss_run_planned[ |
| 53 | + "obsid_1", "obsid_2", "simpos_1", "simpos_2", "starcat_date" |
| 54 | + ].pformat() |
| 55 | + |
| 56 | + assert lines == [ |
| 57 | + "obsid_1 obsid_2 simpos_1 simpos_2 starcat_date ", |
| 58 | + "------- ------- -------- -------- ---------------------", |
| 59 | + " 30693 30693 92904 92904 2024:364:21:02:54.559", |
| 60 | + " 30699 30699 92560 92560 2024:365:00:21:34.399", |
| 61 | + " 28631 28631 92904 92904 2024:365:03:49:22.699", |
| 62 | + " 30486 30486 -50504 -50504 2024:365:12:13:55.474", |
| 63 | + " 30497 30497 75624 75624 2024:365:16:49:40.474", |
| 64 | + " 42815 42815 -99616 -99616 2024:365:21:32:34.599", |
| 65 | + " 42814 42814 -99616 -99616 2024:365:23:24:58.901", |
| 66 | + " 42813 42813 -99616 -99616 2024:366:01:17:07.965", |
| 67 | + " 42812 42812 -99616 -99616 2024:366:02:58:28.076", |
| 68 | + " 42810 42810 -99616 -99616 2024:366:05:08:36.000", |
| 69 | + " 42809 42809 -99616 -99616 2024:366:05:48:15.632", |
| 70 | + " 30700 30700 92560 92560 2024:366:08:26:39.076", |
| 71 | + " 30690 30690 92904 92904 2024:366:11:55:08.999", |
| 72 | + " 30550 30550 -99616 -99616 2024:366:15:21:03.938", |
| 73 | + " 30550 28803 -99616 92904 2024:366:18:05:04.938", |
| 74 | + " 30550 28365 -99616 75624 2024:366:21:21:07.538", |
| 75 | + " 30550 29835 -99616 92560 2025:001:08:44:07.810", |
| 76 | + " 65518 25501 -99616 -50504 2025:001:13:08:09.384", |
| 77 | + " 65518 26975 -99616 92904 2025:001:16:38:50.384", |
| 78 | + " 65518 30500 -99616 75624 2025:001:20:54:41.492", |
| 79 | + " 65518 25505 -99616 -50504 2025:002:01:35:29.276", |
| 80 | + " 65518 29904 -99616 92904 2025:002:03:07:54.276", |
| 81 | + " 65518 30688 -99616 92904 2025:002:04:53:45.276", |
| 82 | + " 65518 30082 -99616 92904 2025:002:08:11:25.231", |
| 83 | + " 65518 42808 -99616 -99616 2025:002:12:59:42.571", |
| 84 | + " 65518 42807 -99616 -99616 2025:002:14:17:07.525", |
| 85 | + " 65518 42806 -99616 -99616 2025:002:17:17:25.479", |
| 86 | + " 65518 42805 -99616 -99616 2025:002:18:36:19.655", |
| 87 | + " 65518 42803 -99616 -99616 2025:002:20:37:36.000", |
| 88 | + " 65518 42802 -99616 -99616 2025:002:21:24:48.840", |
| 89 | + " 65518 42801 -99616 -99616 2025:002:23:18:02.848", |
| 90 | + ] |
| 91 | + |
| 92 | + keys = [ |
| 93 | + (None, None, 30, None), |
| 94 | + (None, "2025:003", 20, kc.filter_scs107_events), |
| 95 | + ] |
| 96 | + assert list(kcc2.CMDS_RECENT) == keys |
| 97 | + assert list(kco.OBSERVATIONS) == keys |
0 commit comments