########################################################################################### # make_SWA_STP_IORs_v02.py # v3 - updated with new MIB # v4 - updated with new MIB # v5 - updated with new MIB, and TMC and EFECS version numbers # v6 - updated with new MIB # v7 - updated with new author list # v8 - updated with new MIB, TMC and EFECS versions for STP154 onwards # v9 - updated with new MIB version for STP158 onwards ########################################################################################### import xml.etree.ElementTree as ET import datetime import sys from ElementTree_Pretty import prettify import json ################################## Start Main function ############################################################## def main(): in_file = sys.argv[1] print ('Processing file: ', in_file) process_inputs(in_file) ################################## End Main function ############################################################## ################################## Start of PDOR/MDOR making module ########################################## def process_inputs(infile): with open(infile,'r') as fp: args_input = json.load(fp) source = args_input.get('source') dest = args_input.get('destination') outfile = args_input.get('filename') file_type = args_input.get('type') #uniqID_input = args_input.get('uniqID') OccList = args_input.get('occurrenceList') iorVer = outfile[-5:-4] iorSlotinSTP = outfile[11:13] STPnum = outfile[7:10] uniqID_input = "SSWA_S" + STPnum + "_F" + iorSlotinSTP + "_" generated_on = str(datetime.datetime.now().strftime('%Y-%jT%H:%M:%SZ')) # Create 'planningData' Element planData_tag = ET.Element('planningData') planData_tag.set('xmlns', 'soc.solarorbiter.org') planData_tag.set('xsi:schemaLocation', 'soc.solarorbiter.org IOR_schema.xsd') planData_tag.set('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance') # Create 'commandRequests' Element CommRequests_tag = ET.SubElement(planData_tag, 'commandRequests') # Create 'header' Element header = ET.SubElement(CommRequests_tag, 'header') #Set 'header' attributes header.set('type', file_type) header.set('formatVersion', "01") #Create header sub-Elements genTime = ET.SubElement(header, 'genTime') genTime.text = generated_on # Set genTime text (value) validrange = ET.SubElement(header, 'validityRange') validrange.set('type','absoluteTime') valstart = ET.SubElement(validrange, 'startTime') valstop = ET.SubElement(validrange, 'stopTime') valstart.text = args_input.get('stTime') valstop.text = args_input.get('spTime') # Create 'header' Element header2 = ET.SubElement(CommRequests_tag, 'header2') header2.set('ICDVersion','v1_1') header2.set('VSTP_slot_count','0') header2.set('planningCycle','S') header2.set('missionSTP',STPnum) header2.set('IORorSlotNumberInSTP',iorSlotinSTP) header2.set('instrument','SSWA') header2.set('IORVersion',iorVer) # header2.set('MIBVersion','24420PFM 20200831-CSW3.1.1_MAS7.21 0 22720 721') # header2.set('MIBVersion','30320PFM 20201029-CSW3.1.1_MAS7.21 0 30320 711') # header2.set('MIBVersion','32520PFM 20201120-CSW3.1.1_MAS7.21 0 32520 711') # header2.set('MIBVersion','33720PFM 20201202-CSW3.1.1_MAS7.21 0 33720 721') # header2.set('MIBVersion','06121PFM 20210302-CSW3.1.2_MAS7.33 0 06121 733') # header2.set('MIBVersion','08921PFM 20210330-CSW3.1.2_MAS7.33 0 8921 733') # header2.set('MIBVersion','13221PFM 20210512-CSW3.1.2_MAS7.33 0 13221 733') # header2.set('MIBVersion','13921PFM 20210519-CSW3.1.2_MAS7.33 0 13921 733') # header2.set('MIBVersion','17821PFM 20210627-CSW3.1.2_MAS7.33 0 17821 733') # header2.set('MIBVersion','18921PFM 20210708-CSW3.1.2_MAS7.33 0 18921 733') header2.set('MIBVersion','21821PFM 20210806-CSW3.1.2_MAS7.33 0 21821 733') header2.set('TMCVersion','02') header2.set('EFECSVersion','02') # Create 'OccurrenceList' tag OccurrenceList_tag = ET.SubElement(CommRequests_tag, 'occurrenceList') #Set 'occurrenceList' attributes OccListCount = len(OccList) OccurrenceList_tag.set('count', str(OccListCount)) OccurrenceList_tag.set('creationTime',generated_on) OccurrenceList_tag.set('author', 'C Anekallu, G Watson and C Kelly,SWA') occ_count = 0 int_uniqID = 1 while occ_count < OccListCount: com_type = OccList[occ_count].get('com_type') com_name = OccList[occ_count].get('com_name') com_time = OccList[occ_count].get('time') paramList = OccList[occ_count].get('parameterList') paramList_count = len(paramList) param_count = 0 commands_tag = ET.SubElement(OccurrenceList_tag,com_type) commands_tag.set('name',com_name) obsID_tag = ET.SubElement(commands_tag, 'observationID') obsID_tag.text = OccList[occ_count].get('ObsID') #uniqID_input = OccList[occ_count].get('UniqID') uniqID_tag = ET.SubElement(commands_tag, 'uniqueID') length_remaining = 20 - len(uniqID_input) uniqid_count = str(int_uniqID).rjust(length_remaining, '0') uniqIDText = uniqID_input + uniqid_count uniqID_tag.text = uniqIDText source_tag = ET.SubElement(commands_tag, 'source') source_tag.text = source dest_tag = ET.SubElement(commands_tag, 'destination') dest_tag.text = dest release_tag = ET.SubElement(commands_tag, 'executionTime') actTime_tag = ET.SubElement(release_tag, 'actionTime') actTime_tag.text = com_time if(paramList_count != 0): paramList_tag = ET.SubElement(commands_tag,'parameterList') paramList_tag.set('count',str(paramList_count)) while param_count < paramList_count: param_tag = ET.SubElement(paramList_tag, 'parameter') param_name = paramList[param_count].get('param_name') param_value = paramList[param_count].get('param_value') param_rep = paramList[param_count].get('param_rep') param_position = param_count + 1 param_tag.set('name', param_name) param_tag.set('position', str(param_position)) paramValue_tag = ET.SubElement(param_tag, 'value') paramValue_tag.set('representation',param_rep) if param_rep == "Raw": param_rad = paramList[param_count].get('radix') paramValue_tag.set('radix',param_rad) paramValue_tag.text = param_value param_count = param_count + 1 occ_count = occ_count + 1 int_uniqID = int_uniqID + 1 print ('Making : ', outfile) with open(outfile, 'w') as of: of.write(prettify(planData_tag)) #of.write(CommRequests_tag) #print(CommRequests_tag) ################################## End of PDOR/MDOR making module ########################################## ################################## Start the Program here ################################################## if __name__ == "__main__": #start the program main() ################################## End the Program here ##################################################