Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update for SCS-106 change and new power commands #41

Merged
merged 7 commits into from
Oct 18, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
150 changes: 29 additions & 121 deletions acis_thermal_check/state_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def get_prediction_states(self, tbegin):
class ACISStateBuilder(StateBuilder):

def __init__(self, interrupt=False, backstop_file=None, nlet_file=None,
logger=None):
verbose = 2, logger=None):
jzuhone marked this conversation as resolved.
Show resolved Hide resolved
"""
Give the ACISStateBuilder arguments that were passed in
from the command line and get the backstop commands from the load
Expand All @@ -215,6 +215,9 @@ def __init__(self, interrupt=False, backstop_file=None, nlet_file=None,
file will be searched for within this directory.
nlet_file : string
full path to the Non-Load Event Tracking file
verbose: int
Verbosity level to be used by the ACIS state builder
- obtained from the model invocation command line arguments.
logger : Logger object, optional
The Python Logger object to be used when logging.
"""
Expand All @@ -224,49 +227,39 @@ def __init__(self, interrupt=False, backstop_file=None, nlet_file=None,
# Capture the full path to the NLET file to be used
self.nlet_file = nlet_file

# Create an instance of the Backstop Command class
self.BSC = BackstopHistory.BackstopHistory('ACIS-Continuity.txt', self.nlet_file)

# The Review Load backstop name
self.rev_bs_name = None
# Normally I would have created the self.rev_bs_cmds attribute
# and used that however to work with ATC I changed it to bs_cmds.
# Create an instance of the Backstop command History Class
self.BSC = BackstopHistory.Backstop_History_Class('ACIS-Continuity.txt', self.nlet_file, verbose)
super(ACISStateBuilder, self).__init__()

super(ACISStateBuilder, self).__init__(logger=logger)
# Save some arguments to class attributes
self.interrupt = interrupt
self.backstop_file = backstop_file

# if the user supplied a full path to the backstop file then
# Read Review File - if the user supplied a full path to the backstop file then
# capture the backstop file name and the commands within the backstop file.
if backstop_file is not None:
# Get tstart, tstop, commands from backstop file in args.oflsdir
# These are the REVIEW backstop commands. This returns a list of dict
# representing the commands.
rev_bs_cmds, self.rev_bs_name = self.BSC.get_bs_cmds(self.backstop_file)
self.BSC.Read_Review_Load(self.backstop_file)

# Store the Review Load backstop commands in the class attribute and
# also capture the Review load time of first command (TOFC) and
# Time of Last Command (TOLC).
self.bs_cmds = rev_bs_cmds
self.tstart = rev_bs_cmds[0]['time']
self.tstop = rev_bs_cmds[-1]['time']
# Capture the times of the first and last commands in the Review load
self.tstart = self.BSC.get_review_tstart()
self.tstop = self.BSC.get_review_tstop()

# Initialize the end time attribute for event searches within the BSC object
# At the beginning, it will be the time of the last command in the Review Load
self.BSC.end_event_time = rev_bs_cmds[-1]['time']

def get_prediction_states(self, tbegin):
"""
Get the states used for the prediction. This includes both the
states from the review load backstop file and all the
states between the latest telemetry data and the beginning
Get the statess used for the prediction. This includes both the
jzuhone marked this conversation as resolved.
Show resolved Hide resolved
commandss from the review load backstop file and all the
commandss between the latest telemetry data and the beginning
of that review load backstop file.

The Review Backstop commands already obtained.
Telemtry from 21 days back to the latest in Ska obtained.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Telemetry misspelled

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed


So now the task is to backchain through the loads and assemble
any states missing between the end of telemetry through the start
any commandss missing between the end of telemetry through the start
jzuhone marked this conversation as resolved.
Show resolved Hide resolved
of the review load.

Parameters
Expand All @@ -287,105 +280,19 @@ def get_prediction_states(self, tbegin):

import copy

# List of dict representing commands at this point
bs_cmds = copy.copy(self.bs_cmds)

# Capture the start time of the review load
bs_start_time = bs_cmds[0]['time']

# Capture the path to the ofls directory
present_ofls_dir = copy.copy(self.backstop_file)

# So long as the earliest command in bs_cmds is after the state0 time
# (which is the same as tbegin), keep concatenating continuity commands
# to bs_cmds based upon the type of load. Note that as you march back in
# time along the load chain, "present_ofls_dir" will change.

# WHILE
# The big while loop that backchains through previous loads and concatenates the
# proper load sections to the review load.
while CxoTime(tbegin).secs < bs_start_time:

# Read the Continuity information of the present ofls directory
cont_load_path, present_load_type, scs107_date = self.BSC.get_continuity_file_info(present_ofls_dir)

#---------------------- NORMAL ----------------------------------------
# If the load type is "normal" then grab the continuity command
# set and concatenate those commands to the start of bs_cmds
if present_load_type.upper() == 'NORMAL':
# Obtain the continuity load commands
cont_bs_cmds, cont_bs_name = self.BSC.get_bs_cmds(cont_load_path)

# Combine the continuity commands with the bs_cmds. The result
# is stored in bs_cmds
bs_cmds = self.BSC.CombineNormal(cont_bs_cmds, bs_cmds)

# Reset the backstop collection start time for the While loop
bs_start_time = bs_cmds[0]['time']
# Now point the operative ofls directory to the Continuity directory
present_ofls_dir = cont_load_path

#---------------------- TOO ----------------------------------------
# If the load type is "too" then grab the continuity command
# set and concatenate those commands to the start of bs_cmds
elif present_load_type.upper() == 'TOO':
# Obtain the continuity load commands
cont_bs_cmds, cont_bs_name = self.BSC.get_bs_cmds(cont_load_path)

# Combine the continuity commands with the bs_cmds
bs_cmds = self.BSC.CombineTOO(cont_bs_cmds, bs_cmds)

# Reset the backstop collection start time for the While loop
bs_start_time = bs_cmds[0]['time']
# Now point the operative ofls directory to the Continuity directory
present_ofls_dir = cont_load_path

#---------------------- STOP ----------------------------------------
# If the load type is "STOP" then grab the continuity command
# set and concatenate those commands to the start of bs_cmds
# Take into account the SCS-107 commands which shut ACIS down
# and any LTCTI run
elif present_load_type.upper() == 'STOP':

# Obtain the continuity load commands
cont_bs_cmds, cont_bs_name = self.BSC.get_bs_cmds(cont_load_path)

# CombineSTOP the continuity commands with the bs_cmds
bs_cmds = self.BSC.CombineSTOP(cont_bs_cmds, bs_cmds, scs107_date )

# Reset the backstop collection start time for the While loop
bs_start_time = bs_cmds[0]['time']
# Now point the operative ofls directory to the Continuity directory
present_ofls_dir = cont_load_path

#---------------------- SCS-107 ----------------------------------------
# If the load type is "STOP" then grab the continuity command
# set and concatenate those commands to the start of bs_cmds
# Take into account the SCS-107 commands which shut ACIS down
# and any LTCTI run
elif present_load_type.upper() == 'SCS-107':
# Obtain the continuity load commands
cont_bs_cmds, cont_bs_name = self.BSC.get_bs_cmds(cont_load_path)
# Store the continuity bs commands as a chunk in the chunk list

# Obtain the CONTINUITY load Vehicle-Only file
vo_bs_cmds, vo_bs_name = self.BSC.get_vehicle_only_bs_cmds(cont_load_path)

# Combine107 the continuity commands with the bs_cmds
bs_cmds = self.BSC.Combine107(cont_bs_cmds, vo_bs_cmds, bs_cmds, scs107_date)

# Reset the backstop collection start time for the While loop
bs_start_time = bs_cmds[0]['time']
# Now point the operative ofls directory to the Continuity directory
present_ofls_dir = cont_load_path

# Convert backstop commands from a list of dict to a CommandTable and
# store in self.
bs_cmds = kadi.commands.CommandTable(bs_cmds)
# Ask Backstop History to assemble the history for this loa
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"loa" --> "load"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

self.BSC.Assemble_History(self.backstop_file, tbegin, self.interrupt)

# Read in the assembled history file as kadi commands
bs_cmds = kadi.commands.get_cmds_from_backstop( self.BSC.assembled_hist_file_path)

bs_cmds['time'] = CxoTime(bs_cmds['date']).secs

self.bs_cmds = bs_cmds

# Clip commands to tbegin
bs_cmds = bs_cmds[bs_cmds['date'] > tbegin]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So in the old version we were clipping commands to tbegin. Based on your changes, do we not want to do this anymore, or is in being done in backstop_history now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Backstop history was supposed to do that but the ~30 minute backoff caused it to backchain one
extra Continuity load and, without the clipping, that caused the kadi_states.get_states to return the time-disrupted result.

Putting the line back in and clipping the bs_cmds seems to have fixed it.

I will re-run the regression tests and check the FEP plot to be sure.

Thanks

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok--sounds good. Probably a good idea in the future to revisit the -5 element backoff and find something to do that maybe makes more sense (or at least is easier to understand)

# This is a kadi.commands.CommandTable (subclass of astropy Table)
bs_cmds = self.bs_cmds
jzuhone marked this conversation as resolved.
Show resolved Hide resolved
bs_dates = bs_cmds['date']

# Scheduled stop time is the end of propagation, either the explicit
# time as a pseudo-command in the loads or the last backstop command time.
Expand All @@ -398,6 +305,7 @@ def get_prediction_states(self, tbegin):
# corresponding to the commands. This includes continuity commanding
# from the end of telemetry along with the in-review load backstop
# commands.

states = kadi_states.get_states(cmds=bs_cmds, start=tbegin, stop=sched_stop,
state_keys=STATE_KEYS)

Expand Down
4 changes: 3 additions & 1 deletion acis_thermal_check/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,10 +423,12 @@ def make_state_builder(name, args):
# Instantiate the ACIS OPS History Builder: ACISStateBuilder
elif name == "acis":
# Create a state builder using the ACIS Ops backstop history
# modules
# modules and send in some of the switches from the model invocation
# argument list
state_builder = builder_class(interrupt=args.interrupt,
backstop_file=args.backstop_file,
nlet_file=args.nlet_file,
verbose = args.verbose,
jzuhone marked this conversation as resolved.
Show resolved Hide resolved
logger=mylog)
else:
raise RuntimeError("No such state builder with name %s!" % name)
Expand Down