def checkFolder(): import PostProcessor, logger #monitor a selected folder for 'snatched' files that haven't been processed logger.info('Checking folder ' + mylar.CHECK_FOLDER + ' for newly snatched downloads') PostProcess = PostProcessor.PostProcessor('Manual Run', mylar.CHECK_FOLDER) result = PostProcess.Process() logger.info('Finished checking for newly snatched downloads')
def resumePostProcessors(): """ Pickup left off Post Processors that were cancelled via CTRL-C """ # FIXME: with the new queue, could kill the processing dir sym links (for windows) from Hellanzb.NZBLeecher.NZBModel import NZB for archiveDirName in os.listdir(Hellanzb.PROCESSING_DIR): if archiveDirName[0] == '.': continue archive = NZB.fromStateXML('processing', archiveDirName) troll = PostProcessor.PostProcessor(archive) info('Resuming post processor: ' + archiveName(archiveDirName)) troll.start()
def handleNZBDone(nzb): """ Hand-off from the downloader -- make a dir for the NZB with its contents, then post process it in a separate thread""" disconnectUnAntiIdleFactories() if nzb.downloadStartTime: downloadAndDecodeTime = time.time() - nzb.downloadStartTime if not nzb.isParRecovery: nzb.downloadAndDecodeTime = downloadAndDecodeTime else: nzb.downloadAndDecodeTime += downloadAndDecodeTime # Make our new directory, minus the .nzb processingDir = os.path.join(Hellanzb.PROCESSING_DIR, nzb.archiveName) # Move our nzb contents to their new location for post processing hellaRename(processingDir) move(Hellanzb.WORKING_DIR, processingDir) nzb.destDir = processingDir nzb.archiveDir = processingDir nzbFileName = os.path.join(processingDir, os.path.basename(nzb.nzbFileName)) # We may have downloaded an NZB file of the same name: # http://hellanzb.com/trac/hellanzb/ticket/425 hellaRename(nzbFileName) move(nzb.nzbFileName, nzbFileName) nzb.nzbFileName = nzbFileName os.mkdir(Hellanzb.WORKING_DIR) # The list of skipped pars is maintained in the state XML as only the subjects of the # nzbFiles. PostProcessor only knows to look at the NZB.skippedParSubjects list, # created here nzb.skippedParSubjects = nzb.getSkippedParSubjects() # Finally unarchive/process the directory in another thread, and continue # nzbing troll = PostProcessor.PostProcessor(nzb) # Give NZBLeecher some time (another reactor loop) to killHistory() & scrollEnd() # without any logging interference from PostProcessor reactor.callLater(0, troll.start) reactor.callLater(0, writeStateXML) reactor.callLater(0, scanQueueDir)
# mean_course_deg = 200; # vec_2_1 = np.random.uniform(meanPercentage*0.9, meanPercentage*1.1,sample_sz); # vec_2_2 = np.random.uniform(mean_course_deg*0.9, mean_course_deg*1.1,sample_sz) # meanTimeStep = 6; # vec_3 = np.random.exponential(meanTimeStep,sample_sz) # var_vec = []; # for i in range(sample_sz): # var_vec.append([ [vec_1_1[i],vec_1_2[i]], [vec_2_1[i],vec_2_2[i]], vec_3[i] ]); # args = [ac_list,time_pause,var_name,var_vec,fpwidx]; ''' RUN MONTE CARLO''' '''This is deprecated. However, will still run. We have upgraded it with the function below.''' #MC_interface.runMCSims(args) '''Handles all kinds of MC Simulations. If you want to perturb IC you can do it. If you want to perturb states and controls at runtime you can also do that. You need to specify times when you want to do that.''' MC_interface.MCManager(args) '''Post Processing and plotting the MC examples.''' for ac in ac_list: post_process = pp.PostProcessor(file_path = ".", \ ac_name = ac, auto_detect_server_folder_flag = False) # post_process.plotRoutine(); # post_process.plotSingleAircraftTrajectory(); # # post_process.plotVariable('departure_delay') post_process.plotFinalHistograms(['latitude', \ 'longitude', \ 'altitude'])
def post_process_CDNR(dirPath): ac_list = ["SWA1897", "SWA6516"] AllTrajs = {} for ac in ac_list: AllTrajs[ac] = [] for ac in ac_list: # post_process = pp.PostProcessor(file_path = "../NATS_Server", \ # ac_name = ac); post_process = pp.PostProcessor(file_path = dirPath, \ ac_name = ac) # post_process.plotRoutine(); # post_process.plotSingleAircraftTrajectory(); AllTrajs[ac].extend(post_process.LatLonAltSamp) nfiles = len(AllTrajs[ac_list[0]]) fig, axs = plt.subplots(nrows=2, ncols=1) lv = [] AllLon = [] AllLat = [] AllT = [] for file in range(nfiles): traj1 = copy.deepcopy(AllTrajs[ac_list[0]][file]) traj2 = copy.deepcopy(AllTrajs[ac_list[1]][file]) if len(traj1) > len(traj2): ntime = len(traj2) T = [] RD = [] Lat = [] Lon = [] for k in range(ntime): val1 = [a for a in traj2[k]] idx = -1 for j in range(len(traj1)): if abs(traj1[j][0] - val1[0]) < 1e-3: idx = j break if idx >= 0: val2 = [a for a in traj1[idx]] T.append(val2[0]) reldist = compute_distance_gc(val1[1], val1[2], val2[1], val2[2], (val1[3] + val2[3]) / 2.) RD.append(reldist) Lat.append([val1[1], val2[1]]) Lon.append([val1[2], val2[2]]) line, = axs[0].plot(T, RD, '-x') lv.append(line) Lat = np.array(Lat) Lon = np.array(Lon) axs[1].plot(Lon[:, 1], Lat[:, 1], '--r') axs[1].plot(Lon[:, 0], Lat[:, 0], '--b') AllLat.append(Lat) AllLon.append(Lon) AllT.append(T) else: ntime = len(traj1) T = [] RD = [] Lat = [] Lon = [] for k in range(ntime): val1 = [a for a in traj1[k]] idx = -1 for j in range(len(traj2)): if abs(traj2[j][0] - val1[0]) < 1e-3: idx = j break if idx >= 0: val2 = [a for a in traj2[idx]] T.append(val2[0]) reldist = compute_distance_gc(val1[1], val1[2], val2[1], val2[2], (val1[3] + val2[3]) / 2.) RD.append(reldist) Lat.append([val1[1], val2[1]]) Lon.append([val1[2], val2[2]]) line, = axs.plot(T, RD, '-x') lv.append(line) Lat = np.array(Lat) Lon = np.array(Lon) axs[1].plot(Lon[:, 1], Lat[:, 1], '--r') axs[1].plot(Lon[:, 0], Lat[:, 0], '--b') AllLat.append(Lat) AllLon.append(Lon) AllT.append(T) axs[0].set_xlabel('Time(s)') axs[0].set_ylabel('Relative distance between two aircraft (ft)') axs[0].grid(True) axs[0].set_xlabel('Longitude (deg)') axs[0].set_ylabel('Latitude (deg)') axs[0].grid(True) lh = axs[0].axhline(5 * 6076, ls='--') # fig.legend( (lv[0],lv[1],lh), ('w CDNR', 'w/o CDNR','resolution threshold'), # 'upper center', ncol = 3) # plt.show() try: assert len(AllLat) == len(AllLon) == len(AllT) == 2 except AssertionError: print('Please remove the *.csv files in the server folder') raise frame_num = len(AllT[0]) minlon = min(np.min(AllLon[0]), np.min(AllLon[1])) maxlon = max(np.max(AllLon[0]), np.max(AllLon[1])) minlat = min(np.min(AllLat[0]), np.min(AllLat[1])) maxlat = max(np.max(AllLat[0]), np.max(AllLat[1])) fig = plt.figure() ax = plt.axes(xlim=(minlon, maxlon), ylim=(minlat, maxlat)) line11, = ax.plot([], [], linestyle='--', color='r', marker='x', linewidth=2) line12, = ax.plot([], [], linestyle='--', color='g', marker='o', linewidth=2) line21, = ax.plot([], [], linestyle='--', color='k', marker='d', linewidth=2) line22, = ax.plot([], [], linestyle='--', color='b', marker='+', linewidth=2) lines = [line11, line12, line21, line22] def init(): for line in lines: line.set_data([], []) return lines def animate(i): xlist = [ AllLon[0][:i, 0], AllLon[0][:i, 1], AllLon[1][:i, 0], AllLon[1][:i, 1] ] ylist = [ AllLat[0][:i, 0], AllLat[0][:i, 1], AllLat[1][:i, 0], AllLat[1][:i, 1] ] for lnum, line in enumerate(lines): line.set_data(xlist[lnum], ylist[lnum]) # set data for each line separately. return lines # call the animator. blit=True means only re-draw the parts that have changed. anim = animation.FuncAnimation(fig, animate, init_func=init, frames=frame_num, interval=10, blit=True) plt.show()
# ========================================================= # The following statements read the result trajectory files and display plotting. # Notice!!!! # The following statements assume that NATS_Client and NATS_Server are installed on the same machine. # If NATS_Server is installed on another machine, the following Python codes will not work due to inability to access the server files. # Create temp directory on NATS_Server side and copy the result trajectory file into it planned_dirname = "tmp_" + planned_dirname os.makedirs(NATS_SERVER_DIR + "/" + planned_dirname) copyfile( NATS_SERVER_DIR + "/" + output_filename_before, NATS_SERVER_DIR + "/" + planned_dirname + "/" + output_filename_before) copyfile( NATS_SERVER_DIR + "/" + output_filename_after, NATS_SERVER_DIR + "/" + planned_dirname + "/" + output_filename_after) post_process = pp.PostProcessor(file_path=NATS_SERVER_DIR + "/" + planned_dirname, ac_name='SWA1897') post_process.plotSingleAircraftTrajectory() # Delete temp directory print "Deleting directory:", planned_dirname rmtree(NATS_SERVER_DIR + "/" + planned_dirname) # Close connection from NATS Server natsClient.disConnect() shutdownJVM()
time.sleep(1) # Close connection from NATS Server natsClient.disConnect() # ========================================================= # The following statements read the result trajectory files and display plotting. # Notice!!!! # The following statements assume that NATS_Client and NATS_Server are installed on the same machine. # If NATS_Server is installed on another machine, the following Python codes will not work due to inability to access the server files. # Create temp directory on NATS_Server side and copy the result trajectory file into it planned_dirname = "tmp_" + planned_dirname os.makedirs(planned_dirname) local_trajectory_filename = output_filename copyfile(local_trajectory_filename, planned_dirname + "/" + local_trajectory_filename) post_process = pp.PostProcessor(file_path=planned_dirname, ac_name='SWA1897') post_process.plotSingleAircraftTrajectory() # Delete temp directory print "Deleting directory:", planned_dirname rmtree(planned_dirname) shutdownJVM()
if __name__ == '__main__': MC_interface = GNATS_MonteCarlo_Interface(); curr_ac = "SWA1897"; '''Flight Plan Latitude''' fpwpidx = 6; mean_lat = 40.995819091796875; std_dev_lat = 0.01*mean_lat; sample_sz_lat = 5; k=0; lat_vec = np.random.normal(mean_lat,std_dev_lat,sample_sz_lat) '''args = [ac_name, var_name, var_vals, fpindex (optional)]''' args = [[curr_ac],args_dict[6],lat_vec,fpwpidx] MC_interface.runMCSims(args) post_process = pp.PostProcessor(file_path = "../GNATS_Server", \ ac_name = curr_ac); post_process.plotRoutine();
aircraftInterface.release_aircraft() environmentInterface.release_rap() # Close connection from NATS Server natsClient.disConnect() # ========================================================= # The following statements read the result trajectory files and display plotting. # Notice!!!! # The following statements assume that NATS_Client and NATS_Server are installed on the same machine. # If NATS_Server is installed on another machine, the following Python codes will not work due to inability to access the server files. # Create temp directory on NATS_Server side and copy the result trajectory file into it planned_dirname = "tmp_" + planned_dirname os.makedirs("../NATS_Server/" + planned_dirname) copyfile("../NATS_Server/" + output_filename_before, "../NATS_Server/" + planned_dirname + "/" + output_filename_before) copyfile("../NATS_Server/" + output_filename_after, "../NATS_Server/" + planned_dirname + "/" + output_filename_after) post_process = pp.PostProcessor(file_path="../NATS_Server/" + planned_dirname, ac_name='SWA1897') post_process.plotSingleAircraftTrajectory() # Delete temp directory print "Deleting directory:", planned_dirname rmtree("../NATS_Server/" + planned_dirname) shutdownJVM()
std_dev_3 = 0.01*np.abs(mean_3); mean = [mean_1,mean_2,mean_3]; cov = [[std_dev_1**2,0,0],[0,std_dev_2**2,0],[0,0,std_dev_3**2]]; sample_sz = 5; vec_1,vec_2,vec_3 = np.random.multivariate_normal(mean, cov, sample_sz).T var_vec = [] for i in range(sample_sz): var_vec.append([vec_1[i],vec_2[i],vec_3[i]]) args = [ac_list,time_pause,var_name,var_vec,fpwidx]; ''' RUN MONTE CARLO''' '''This is deprecated. However, will still run. We have upgraded it with the function below.''' #MC_interface.runMCSims(args) '''Handles all kinds of MC Simulations. If you want to perturb IC you can do it. If you want to perturb states and controls at runtime you can also do that. You need to specify times when you want to do that.''' MC_interface.MCManager(args) '''Post Processing and plotting the MC examples.''' for ac in ac_list: post_process = pp.PostProcessor(file_path = "../NATS_Server_20180909_1532", \ ac_name = ac); # post_process.plotRoutine(); post_process.plotSingleAircraftTrajectory(); # post_process.plotVariable('departure_delay')
else: if isinstance(checker_arg[0], basestring): self.runMCSims(args) else: self.runMCSimsWithPause(args) else: print 'Wrong number of arguments please refer to the usage.' if __name__ == '__main__': MC_interface = NATS_MonteCarlo_Interface() curr_ac = "SWA1897" '''Flight Plan Latitude''' fpwpidx = 6 mean_lat = 40.995819091796875 std_dev_lat = 0.01 * mean_lat sample_sz_lat = 5 k = 0 lat_vec = np.random.normal(mean_lat, std_dev_lat, sample_sz_lat) '''args = [ac_name, var_name, var_vals, fpindex (optional)]''' args = [[curr_ac], args_dict[6], lat_vec, fpwpidx] MC_interface.runMCSims(args) post_process = pp.PostProcessor(file_path = "../NATS_Server_20180903_2037", \ ac_name = curr_ac) post_process.plotRoutine()
# The trajectory output file will be saved on NATS_Server side simulationInterface.write_trajectories(output_filename) aircraftInterface.release_aircraft() environmentInterface.release_rap() # Close connection from NATS Server natsClient.disConnect() # ========================================================= # The following statements read the result trajectory files and display plotting. # Notice!!!! # The following statements assume that NATS_Client and NATS_Server are installed on the same machine. # If NATS_Server is installed on another machine, the following Python codes will not work due to inability to access the server files. # Create temp directory on NATS_Server side and copy the result trajectory file into it planned_dirname = "tmp_" + planned_dirname os.makedirs("../NATS_Server/" + planned_dirname) copyfile("../NATS_Server/" + output_filename, "../NATS_Server/" + planned_dirname + "/" + output_filename) post_process = pp.PostProcessor(file_path = "../NATS_Server/" + planned_dirname, ac_name = 'ULI-3E6A0495F1'); post_process.plotSingleAircraftTrajectory(); # Delete temp directory print "Deleting directory:", planned_dirname rmtree("../NATS_Server/" + planned_dirname) shutdownJVM()
else: if isinstance(checker_arg[0], basestring): self.runMCSims(args) else: self.runMCSimsWithPause(args) else: print('Wrong number of arguments please refer to the usage.') if __name__ == '__main__': MC_interface = NATS_MonteCarlo_Interface() curr_ac = "AC0001" '''Flight Plan Latitude''' fpwpidx = 6 mean_lat = 40.995819091796875 std_dev_lat = 0.01 * mean_lat sample_sz_lat = 5 k = 0 lat_vec = np.random.normal(mean_lat, std_dev_lat, sample_sz_lat) '''args = [ac_name, var_name, var_vals, fpindex (optional)]''' args = [[curr_ac], args_dict[6], lat_vec, fpwpidx] MC_interface.runMCSims(args) post_process = pp.PostProcessor(file_path = "../Server/", \ ac_name = curr_ac) post_process.plotRoutine()
if __name__ == '__main__': MC_interface = GNATS_MonteCarlo_Interface(); curr_ac = "SQ12"; '''Flight Plan Latitude''' fpwpidx = 6; mean_lat = 40.995819091796875; std_dev_lat = 0.01*mean_lat; sample_sz_lat = 5; k=0; lat_vec = np.random.normal(mean_lat,std_dev_lat,sample_sz_lat) '''args = [ac_name, var_name, var_vals, fpindex (optional)]''' args = [[curr_ac],args_dict[6],lat_vec,fpwpidx] MC_interface.runMCSims(args) post_process = pp.PostProcessor(file_path = ".", \ ac_name = curr_ac); post_process.plotRoutine();
else: self.runMCSimsWithPause(args) else: print('Wrong number of arguments please refer to the usage.') if __name__ == '__main__': MC_interface = NATS_MonteCarlo_Interface() curr_ac = "AC0001" '''Flight Plan Latitude''' fpwpidx = 6 mean_lat = 40.995819091796875 std_dev_lat = 0.01 * mean_lat sample_sz_lat = 5 k = 0 rv = centaur.Distribution() rv.new_Normal(mean_lat, std_dev_lat) lat_vec = rv.sample(sample_sz_lat) '''args = [ac_name, var_name, var_vals, fpindex (optional)]''' args = [[curr_ac], args_dict[6], lat_vec, fpwpidx] MC_interface.runMCSims(args) post_process = pp.PostProcessor(file_path = "/home/dyn.datasys.swri.edu/mhartnett/NASA_ULI/NASA_ULI_InfoFusion/src/NATS/Server/", \ ac_name = curr_ac) post_process.plotRoutine()
# The trajectory output file will be saved on NATS_Server side simulationInterface.write_trajectories(output_filename) aircraftInterface.release_aircraft() environmentInterface.release_rap() # Close connection from NATS Server natsClient.disConnect() # ========================================================= # The following statements read the result trajectory files and display plotting. # Notice!!!! # The following statements assume that NATS_Client and NATS_Server are installed on the same machine. # If NATS_Server is installed on another machine, the following Python codes will not work due to inability to access the server files. # Create temp directory on NATS_Server side and copy the result trajectory file into it planned_dirname = "tmp_" + planned_dirname os.makedirs("../NATS_Server/" + planned_dirname) copyfile("../NATS_Server/" + output_filename, "../NATS_Server/" + planned_dirname + "/" + output_filename) post_process = pp.PostProcessor(file_path="../NATS_Server/" + planned_dirname, ac_name='ULI-3AFSD3DC24') post_process.plotSingleAircraftTrajectory() # Delete temp directory print "Deleting directory:", planned_dirname rmtree("../NATS_Server/" + planned_dirname) shutdownJVM()