Skip to content

Commit

Permalink
Add "HRC not run" event to handle HRC being disabled (#309)
Browse files Browse the repository at this point in the history
* Add "HRC not run" event

* Include cmds to shut off HRC

* Remove 24V ON cmd which does not happen w/ 15V OFF

* Improve test w/ before/after and in middle of HRC obs
  • Loading branch information
taldcroft authored Dec 29, 2023
1 parent 612ecb7 commit 13267aa
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 4 deletions.
10 changes: 10 additions & 0 deletions kadi/commands/command_sets.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,16 @@ def cmd_set_observing_not_run(load_name, date=None):
return (cmd,)


def cmd_set_hrc_not_run(load_name, date=None):
cmds = (
{"type": "COMMAND_HW", "tlmsid": "215PCAOF"}, # 15 V off
{"type": "COMMAND_HW", "tlmsid": "224PCAOF"}, # 24 V off
{"type": "COMMAND_HW", "tlmsid": "2IMHVOF"}, # HRC-I off
{"type": "COMMAND_HW", "tlmsid": "2SPHVOF"}, # HRC-S off
)
return cmds


def cmd_set_command(*args, date=None):
params_str = args[0]
cmd_type, args_str = params_str.split("|", 1)
Expand Down
18 changes: 14 additions & 4 deletions kadi/commands/commands_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,12 +350,12 @@ def update_archive_and_get_cmds_recent(
# E.g. an SCS-107 near end of loads where next week vehicle loads only were
# uplinked.
not_run_loads = {}
for not_run_type in ("Load", "Observing"):
not_run_loads[not_run_type] = set(
cmd_event["Params"]
for not_run_type in ("Load", "Observing", "HRC"):
not_run_loads[not_run_type] = {
cmd_event["Params"]: cmd_event["Date"]
for cmd_event in cmd_events
if cmd_event["Event"] == f"{not_run_type} not run"
)
}

# Update loads table and download/archive backstop files from OCCweb
loads = update_loads(scenario, cmd_events=cmd_events, lookback=lookback, stop=stop)
Expand All @@ -376,6 +376,16 @@ def update_archive_and_get_cmds_recent(
# Cut observing commands
bad = np.isin(cmds["scs"], [131, 132, 133])
cmds = cmds[~bad]
elif load_name in not_run_loads["HRC"]:
# Cut HRC state-changing commands
date = not_run_loads["HRC"][load_name]
bad = (
(cmds["tlmsid"] == "224PCAON")
| ((cmds["tlmsid"] == "COACTSX") & (cmds["coacts1"] == 134))
| ((cmds["tlmsid"] == "COENASX") & (cmds["coenas1"] == 89))
| ((cmds["tlmsid"] == "COENASX") & (cmds["coenas1"] == 90))
) & (cmds["date"] > date)
cmds = cmds[~bad]

if len(cmds) > 0:
rltt = cmds.meta["rltt"] = cmds.get_rltt()
Expand Down
88 changes: 88 additions & 0 deletions kadi/commands/tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -1329,3 +1329,91 @@ def test_get_rltt_scheduled_stop_time():
cmds = commands.get_cmds("2023:009:12:00:00", "2023:010")
assert cmds.get_rltt() is None
assert cmds.get_scheduled_stop_time() is None


# For HRC not run testing
stop_date_2023200 = stop_date_fixture_factory("2023:200")


@pytest.mark.skipif(not HAS_INTERNET, reason="No internet connection")
def test_hrc_not_run_scenario(stop_date_2023200): # noqa: ARG001
"""Test custom scenario with HRC not run"""
from kadi.commands.states import get_states

# Baseline states WITHOUT the HRC not run command events
states_exp = [
" datestart hrc_i hrc_s hrc_24v hrc_15v",
"--------------------- ----- ----- ------- -------",
"2023:183:00:00:00.000 OFF OFF OFF OFF",
"2023:184:18:42:15.224 OFF OFF OFF ON", # JUL0323A
"2023:184:18:43:41.224 ON OFF OFF ON",
"2023:184:22:43:49.224 OFF OFF OFF ON",
"2023:184:22:44:01.224 OFF OFF OFF OFF",
"2023:190:23:39:43.615 OFF OFF OFF ON",
"2023:190:23:39:44.615 OFF OFF ON ON", # Note 24V transition
"2023:190:23:41:17.615 OFF OFF OFF ON",
"2023:190:23:42:45.615 OFF ON OFF ON",
"2023:191:03:46:13.615 OFF OFF OFF ON",
"2023:191:03:46:26.615 OFF OFF OFF OFF",
"2023:194:20:03:50.666 OFF OFF OFF ON", # JUL1023A
"2023:194:20:03:51.666 OFF OFF ON ON",
"2023:194:20:05:24.666 OFF OFF OFF ON",
"2023:194:20:06:52.666 ON OFF OFF ON",
"2023:194:23:13:40.666 OFF OFF OFF ON",
"2023:194:23:13:52.666 OFF OFF OFF OFF",
]

keys = ["hrc_i", "hrc_s", "hrc_24v", "hrc_15v"]
states = get_states(
start="2023:183",
stop="2023:195",
state_keys=keys,
merge_identical=True,
)
states_out = states[["datestart"] + keys].pformat_all()
assert states_out == states_exp

# First make the cmd_events.csv file for the scenario where F_HRC_SAFING is run at
# 2023:184:20:00:00.000.
# Note that JUL0323A runs from 2023:183:16:39:00.000 to 2023:191:03:46:28.615.
# We expect the HRC to be off from 2023:184 2000z until the first observation in the
# JUL1023A loads which start at 2023:191:03:43:28.615

scenario = "hrc_not_run"
cmds_dir = Path(commands_v2.conf.commands_dir) / scenario
cmds_dir.mkdir(exist_ok=True, parents=True)
# Note variation in format of date, since this comes from humans.
cmd_evts_text = """\
State,Date,Event,Params,Author,Reviewer,Comment
Definitive,2023:184:20:00:00.000,HRC not run,JUL0323A,Tom,Jean,F_HRC_SAFING 2023:184:20:00:00
"""
(cmds_dir / "cmd_events.csv").write_text(cmd_evts_text)

# Now get states in same time range for the HRC not run scenario.
keys = ["hrc_i", "hrc_s", "hrc_24v", "hrc_15v"]
states = get_states(
start="2023:183",
stop="2023:195",
state_keys=keys,
merge_identical=True,
scenario=scenario,
)
states_exp = [
" datestart hrc_i hrc_s hrc_24v hrc_15v",
"--------------------- ----- ----- ------- -------",
"2023:183:00:00:00.000 OFF OFF OFF OFF",
"2023:184:18:42:15.224 OFF OFF OFF ON", # JUL0323A
"2023:184:18:43:41.224 ON OFF OFF ON",
"2023:184:20:00:00.000 OFF OFF OFF OFF", # Shut off by HRC not run
"2023:194:20:03:50.666 OFF OFF OFF ON", # JUL1023A
"2023:194:20:03:51.666 OFF OFF ON ON",
"2023:194:20:05:24.666 OFF OFF OFF ON",
"2023:194:20:06:52.666 ON OFF OFF ON",
"2023:194:23:13:40.666 OFF OFF OFF ON",
"2023:194:23:13:52.666 OFF OFF OFF OFF",
]

states_out = states[["datestart"] + keys].pformat_all()
assert states_out == states_exp

commands_v2.clear_caches()

0 comments on commit 13267aa

Please sign in to comment.