|
| 1 | +# |
| 2 | +# HRC_Txing_Check.py - Check of the Txing activation to HRC HV Powerup timing. |
| 3 | + |
| 4 | +import argparse |
| 5 | +import numpy as np |
| 6 | +import shutil |
| 7 | +import sys |
| 8 | + |
| 9 | +# Import the BackstopHistory class |
| 10 | +from backstop_history import BackstopHistory |
| 11 | + |
| 12 | +# ACIS Ops Imports |
| 13 | +import apt_date_secs as apt |
| 14 | +import Backstop_File_Processing as bfp |
| 15 | +import Calc_Delta as cd |
| 16 | + |
| 17 | +import Insert_Comment_In_ALR as icia |
| 18 | + |
| 19 | +import ORP_File_Class as ofc |
| 20 | +import OFLS_File_Utilities as oflsu |
| 21 | + |
| 22 | +""" |
| 23 | +The basic structure of an SI mode command sequence is: |
| 24 | +
|
| 25 | +AA00000000 < START OF THE BIAS |
| 26 | +AA00000000 |
| 27 | +WSPOW00000 |
| 28 | +WSPOW08812 <--- The last digits of the power command change with different SI modes |
| 29 | +RS_0000001 |
| 30 | +RH_0000001 |
| 31 | +WT00D96014 <--- The last digits of the parameter block command change with different SI modes |
| 32 | +XTZ0000005 <---- Start Science Command; would be XCZ if it's continuous clocking |
| 33 | +
|
| 34 | +The structure is identical for all SI modes. The only items that change from one SI mode |
| 35 | +to another are the second WSPOWxxxxx, the WTxxxxxxxx, and the Start Science command. |
| 36 | +
|
| 37 | +This program assumes that no ACISPKT command will be inserted inside the block of SI mode |
| 38 | +commands by mission planning. |
| 39 | +
|
| 40 | +You would use those differences to identify the SI mode being loaded by this sequence of commands. |
| 41 | +
|
| 42 | +As of the first iteration of this program, SI modes H1C_001(B) and H2C_001(B) will be the ONLY |
| 43 | +ones used to set up Txings for HRC science observations. And these two SI modes will only be used |
| 44 | +for that purpose. |
| 45 | +
|
| 46 | +The time delta between the loading of the SI mode and the SCSD-134 activation for |
| 47 | + Event Histograms run during HRC science observatgions is = bias time + 1152seconds. |
| 48 | +The bias time differs from one SI mode to another if the number of chips differ. |
| 49 | +The bias time calculation starts at the time of the first command of the SI mode load. |
| 50 | +
|
| 51 | +The 1152 seconds is the time it takes for txings to have taken enough samples (6) to |
| 52 | +determine that a storm is bad enough to trigger a shutdown. |
| 53 | +
|
| 54 | +""" |
| 55 | +# Parser code |
| 56 | + |
| 57 | +hrc_txing_parser = argparse.ArgumentParser() |
| 58 | + |
| 59 | +# Path to the ofls directory |
| 60 | +hrc_txing_parser.add_argument("review_load_path", help="Path to the Review load directory. e.g. /data/acis/LoadReviews/2022/FEB2122/ofls'") |
| 61 | + |
| 62 | +# Add the TEST argument as NON-POSITIONAL. |
| 63 | +hrc_txing_parser.add_argument("-t", "--test", help="In test mode", action="store_true") |
| 64 | + |
| 65 | +args = hrc_txing_parser.parse_args() |
| 66 | + |
| 67 | +load_week_path = args.review_load_path |
| 68 | + |
| 69 | +# |
| 70 | +# Inits |
| 71 | +# |
| 72 | + |
| 73 | +# Create the list which will contain all the HRC/Txing time delta comments |
| 74 | +# which will appear in the ACIS-LoadReview.txt file. |
| 75 | +comment_list = [] |
| 76 | + |
| 77 | +# The following dictionary contains the WT parameter block commands which |
| 78 | +# appear in all of the Event Histogram SI modes run during an HRC is science |
| 79 | +# observation. Each entry consists of the parameter block packet name and |
| 80 | +# the bias time for that SI mode. |
| 81 | +ev_parameter_block_dict = {"WT00D98014": 454, "WT00D96014": 919} |
| 82 | + |
| 83 | +# Create an instance of the Backstop History class |
| 84 | +BSC = BackstopHistory.Backstop_History_Class( outdir = load_week_path, verbose = 0) |
| 85 | + |
| 86 | +# Create an instance of the ORP File Class |
| 87 | +ofci = ofc.ORP_File_Class() |
| 88 | + |
| 89 | +# Extract the load week out from the path |
| 90 | +load_week = load_week_path.split('/')[5] |
| 91 | + |
| 92 | +# Read the review load - results are in BSC.master_list |
| 93 | +rev_load_commands = BSC.Read_Review_Load(BSC.outdir) |
| 94 | + |
| 95 | +# Capture the start date and time of the Review load |
| 96 | +rev_start_date = rev_load_commands[0]['date'] |
| 97 | +rev_start_time = rev_load_commands[0]['time'] |
| 98 | + |
| 99 | +# Calculate a tbegin time such that you will backchain one Continuity load. |
| 100 | +# 50 hours will be enough - you want to capture any Event History activation |
| 101 | +# that may have occurred |
| 102 | +tbegin_time = rev_start_time - (50.0 * 3600) |
| 103 | +tbegin = apt.date(tbegin_time) |
| 104 | + |
| 105 | +# Assemble the command history going back one Continuity Load. |
| 106 | +assembled_commands = BSC.Assemble_History(BSC.outdir, tbegin, False) |
| 107 | + |
| 108 | +# Tell the user what we are checking |
| 109 | +print('\n HRC/Txing Check for load week: ', load_week) |
| 110 | + |
| 111 | +# Make a new numpy array which will contain any command that is either an ACISPKT |
| 112 | +# command or has COACTS1=134 in the command string |
| 113 | +extracted_cmds = np.array([], dtype = assembled_commands.dtype) |
| 114 | + |
| 115 | +# Run through the commands and assemble the array |
| 116 | +for eachcmd in assembled_commands: |
| 117 | + # Test to see if this is one of the commands we want to keep |
| 118 | + if ("ACISPKT" in eachcmd["commands"]) or \ |
| 119 | + ("COACTS1=134" in eachcmd["commands"]): |
| 120 | + new_row = np.array( [ (eachcmd["commands"], |
| 121 | + eachcmd["time"], |
| 122 | + eachcmd["date"]) ], dtype = BSC.CR_DTYPE) |
| 123 | + |
| 124 | + extracted_cmds = np.append(extracted_cmds, new_row, axis=0) |
| 125 | + |
| 126 | + |
| 127 | +# Initialize the event histogram found flag to False |
| 128 | +evh_found_flag = False |
| 129 | + |
| 130 | +# Now step through the array and look for any command which contains one of the |
| 131 | +# parameter block WT commands that are presently used for HRC observation |
| 132 | +# Event Histograms. |
| 133 | +for index, each_cmd in enumerate(extracted_cmds): |
| 134 | + # If any Event History WT packet name exists in this backstop command, |
| 135 | + # save it. Otherwise the list will be empty |
| 136 | + key_list = [eachkey for eachkey in ev_parameter_block_dict.keys() if eachkey in each_cmd["commands"] ] |
| 137 | + |
| 138 | + # If one of the HRC Event Histogram SI modes parameter blocks appears in this |
| 139 | + # command line but we already found an Event Histogram but have not yet seen |
| 140 | + # its corresponding SCS-134 activation command, we found an error |
| 141 | + if key_list and (evh_found_flag == True): |
| 142 | + # We foung an error. Place an error statement in the comments list, and print it out for the log file. |
| 143 | + full_comment = " ".join((">>> ERROR -", each_cmd["date"], "Multiple Event Histogram SI Mode loads without an intervening SCS-134 activation")) |
| 144 | + print("\n", full_comment) |
| 145 | + # Append the comment to the comment list |
| 146 | + comment_list.append([each_cmd["date"], each_cmd["time"], full_comment]) |
| 147 | + # Set the bias start date and time to this latest Event Histogram SI Mode load |
| 148 | + # That way when the next COACT1=134 is observed, the correct actual delta T |
| 149 | + # will be calculated from this SI mode load. |
| 150 | + bias_start_date = extracted_cmds[index - 6]["date"] |
| 151 | + bias_start_time = extracted_cmds[index - 6]["time"] |
| 152 | + |
| 153 | + # Else if this is the first Event Histogram SI Mode load since the start of |
| 154 | + # the load or the first since the last EV Load/SCS-134 activation pair. |
| 155 | + elif key_list and (evh_found_flag == False): |
| 156 | + |
| 157 | + # Calculate the index of the first start science command in the SI mode load |
| 158 | + first_start_science_index = index - 6 |
| 159 | + |
| 160 | + # Calculate the required delta t given the SI mode bias time |
| 161 | + required_dt = ev_parameter_block_dict[key_list[0]] + 1152.0 |
| 162 | + |
| 163 | + # You have found one of the event histogram modes used during an HRC science observation |
| 164 | + # Set the Event History SI mode found flag to True |
| 165 | + evh_found_flag = True |
| 166 | + |
| 167 | + # The next step is to find the corresponding COACTS1=134 command that subsequently |
| 168 | + # appears in the load. This will allow you to calculate the time delta between the start |
| 169 | + # of loading that SI mode and the activation of SCS-134 |
| 170 | + |
| 171 | + # Record the start date and time of the first command in the SI mode load |
| 172 | + bias_start_date = extracted_cmds[index - 6]["date"] |
| 173 | + bias_start_time = extracted_cmds[index - 6]["time"] |
| 174 | + |
| 175 | + # Else you see an SCS-134 activation but you have NOT seen the Event Histogram |
| 176 | + # load that should have come prior to this command. This is an error. Add an error |
| 177 | + # comment, and print it out for the log file. This will catch all errors of this type if there |
| 178 | + # are one or more HRC observations in the load. |
| 179 | + elif ("COACTS1=134" in each_cmd["commands"]) and \ |
| 180 | + ( evh_found_flag == False): |
| 181 | + |
| 182 | + # Write the SCS-134 activation information line |
| 183 | + scs134_act_string = each_cmd["date"] + " SCS-134 Activation" |
| 184 | + |
| 185 | + full_comment = " ".join(("\n", scs134_act_string, "\n>>> ERROR - SCS-134 activation without a prior Event Histogram SI Mode Load")) |
| 186 | + print("\n", full_comment) |
| 187 | + # Append the comment to the comment list |
| 188 | + comment_list.append([each_cmd["date"], each_cmd["time"], full_comment]) |
| 189 | + |
| 190 | + # Else, if you have found an Event Histogram Mode used for HRC observations |
| 191 | + # and this command is the corresponding SCS-134 activation, you can calculate |
| 192 | + # the delta time |
| 193 | + elif ("COACTS1=134" in each_cmd["commands"]) and \ |
| 194 | + ( evh_found_flag == True): |
| 195 | + |
| 196 | + # Calculate the time between the start of SI mode load and the activation of |
| 197 | + # SCS-134 |
| 198 | + delta_t = round(each_cmd["time"] - bias_start_time, 2) |
| 199 | + |
| 200 | + # Write the SCS-134 activation information line |
| 201 | + scs134_act_string = each_cmd["date"] + " SCS-134 Activation" |
| 202 | + |
| 203 | + # Check to see if the time is long enough and write the corresponding comment. |
| 204 | + if delta_t < required_dt: |
| 205 | + # ERROR - Time delta is not long enough |
| 206 | + full_comment = " ".join((scs134_act_string, "\n",">>> ERROR - Time between SI mode load start and SCS-134 activation is too short\n SI Mode Load Start: ", bias_start_date, "\n SCS-134 Activation: ", each_cmd["date"], "\n Required Delta T:", str(required_dt), " Actual Delta T:" , str(delta_t))) |
| 207 | + print("\n",full_comment) |
| 208 | + |
| 209 | + else: # The time delta is long enough |
| 210 | + full_comment = " ".join((scs134_act_string, "\n", " Time between SI Mode load start and SCS-134 activation is good: \n Required Delta T:", str(required_dt), " Actual Delta T:" , str(delta_t))) |
| 211 | + |
| 212 | + # Append the comment to the comment list |
| 213 | + comment_list.append([each_cmd["date"], each_cmd["time"], full_comment]) |
| 214 | + |
| 215 | + # Set the evh_found_flag to False so that you can find the next SI mode load. |
| 216 | + evh_found_flag = False |
| 217 | + |
| 218 | +# Done scanning all the commands in the load. In a legal load, where each HRC Event Histogram SI mode |
| 219 | +# load is paired with an SCS-134 activation, evh_found_flag == False at this point. |
| 220 | +# So if you get to this point and evh_found_flag == True, then there exists an Event Histogram load |
| 221 | +# which has no corresponding scs-134 activation. This check handles the case where there |
| 222 | +# was only one HRC science observation in the load but the SCS-134 activation is missing. |
| 223 | +if evh_found_flag == True: |
| 224 | + # ERROR - One of the HRC Event Histograms were loaded but there was never a corresponding SCS-134 activation |
| 225 | + full_comment = " ".join(("\n",">>> ERROR - HRC Observation Event Histogram SI mode was loaded at but SCS-134 was not activated.\n SI Mode Load Start: ", bias_start_date)) |
| 226 | + print("\n",full_comment) |
| 227 | + |
| 228 | + # Append the comment to the comment list |
| 229 | + comment_list.append([bias_start_date, bias_start_time, full_comment]) |
| 230 | + |
| 231 | + |
| 232 | +# Done finding all HRC Txing delta t's. If there are lines in the comment_list, insert |
| 233 | +# them in a copy of ACIS_LoadReview.txt called ACIS_LoadReview.txt.TXING_COMMENT |
| 234 | +if len(comment_list)> 0: |
| 235 | + icia.Insert_Comment_In_ALR(comment_list, load_week_path, "HRC_TXING") |
| 236 | + |
| 237 | + # Copy the updated ACIS-LoadReview.txt file |
| 238 | + # If the test flag was False, and there were comments, then copy the .HRC_TXING |
| 239 | + # file to ACIS-LoadReview.txt. |
| 240 | + # If the test flag was True then we leave the original ACIS-LoadReview.txt and the |
| 241 | + # ACIS-LoadReview.txt.HRC_TXING (if there is one) files intact for comparison. |
| 242 | + if (args.test == False): |
| 243 | + try: |
| 244 | + print('\n Moving ACIS-LoadReview.txt.HRC_TXING to ACIS-LoadReview.txt') |
| 245 | + shutil.copy(load_week_path+'/ACIS-LoadReview.txt.HRC_TXING', load_week_path+'/ACIS-LoadReview.txt') |
| 246 | + except OSError as err: |
| 247 | + print(err) |
| 248 | + print('Examine the ofls directory and look for the HRC_TXING file.') |
| 249 | + else: |
| 250 | + print(' Copy was successful') |
| 251 | + else: |
| 252 | + print('\n Leaving the ACIS-LoadReview.txt unchanged') |
| 253 | + |
| 254 | +else: |
| 255 | + print(">>> Warning - No Event Histogram/SCS-134 Activation pairs found in this load.") |
| 256 | + |
| 257 | + |
0 commit comments