File tree 1 file changed +29
-0
lines changed
1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change 28
28
"filter_cmd_events_by_event" ,
29
29
"SCS107_EVENTS" ,
30
30
"filter_scs107_events" ,
31
+ "set_time_now" ,
31
32
]
32
33
33
34
@@ -1194,3 +1195,31 @@ def filter_cmd_events_state(cmd_events: Table) -> np.ndarray[bool]:
1194
1195
allowed_states .append ("In-work" )
1195
1196
ok = np .isin (cmd_events ["State" ], allowed_states )
1196
1197
return ok
1198
+
1199
+
1200
+ def set_time_now (date ):
1201
+ """Context manager to temporarily set CXOTIME_NOW to ``date``.
1202
+
1203
+ This temporarily sets the CXOTIME_NOW environment variable to ``date`` within the
1204
+ context block. This is a very thin wrapper around ska_helpers.utils.temp_env_var.
1205
+ This effectively makes ``date`` serve as the current time and is useful for testing.
1206
+
1207
+ In this example we get the observation history as if the 2025:012:14:37:04 SCS-107
1208
+ run never happened::
1209
+
1210
+ import kadi.commands as kc
1211
+ start = "2025:012"
1212
+ stop = "2025:018"
1213
+ with kc.set_time_now(stop):
1214
+ obss_as_planned = kc.get_observations(
1215
+ start, stop, event_filter=kc.filter_scs107_events
1216
+ )
1217
+
1218
+ Parameters
1219
+ ----------
1220
+ date : CxoTimeLike
1221
+ Date in CxoTime-compatible format.
1222
+ """
1223
+ from ska_helpers .utils import temp_env_var
1224
+
1225
+ return temp_env_var ("CXOTIME_NOW" , date )
You can’t perform that action at this time.
0 commit comments