def main(normfile, output, wikiuni, jar, fasttext): fcfg = fileconfig.Configuration() fh.is_file(normfile) if output: fh.is_folder(output) else: output = dirname(normfile) if wikiuni: fh.is_file(wikiuni) else: wikiuni = fcfg.get('MODEL_WIKI_UNIGRAMS') if jar: fh.is_file(jar) else: jar = fcfg.get('SNLP_TAGGER_JAR') if fasttext: fh.is_file(fasttext) else: fasttext = fcfg.get('FASTTEXT_EXEC_PATH') embeddings.embeddings_from_norms(normfile, output, wikiuni, jar, fasttext)
def main_plot(bagname): bagname = fh.is_file(bagname) fname, ext = fh.filename(bagname) if ext == '.bag': dirout = fh.mkdir_from_file(bagname) fileinput = join(dirout, fname + '.pkl') elif ext == '.pkl': dirout = dirname(bagname) fileinput = bagname else: logger.error('File {} is not pickle or bag'.format(bagname)) sys.exit() fileinput = fh.is_file(fileinput) logger.info('Reading file: %s' % fileinput) with open(fileinput, 'rb') as f: dic = pickle.load(f) fplot = join(dirout, fname + '_trajectory.pdf') logger.info('Saving plot: {}'.format(fplot)) plot_trajectories(dic['boat1'], dic['boat2'], fplot, angle1=120, angle2=30) fplot = join(dirout, fname + '_dcpa.pdf') logger.info('Saving plot: {}'.format(fplot)) plot_distribution(dic['stats'].dic['dcpa'], 'Valor de DCPA', fplot, color='tab:blue') fplot = join(dirout, fname + '_tcpa.pdf') logger.info('Saving plot: {}'.format(fplot)) plot_distribution(dic['stats'].dic['tcpa'], 'Valor de TCPA', fplot, color='tab:orange') fplot = join(dirout, fname + '_distance.pdf') logger.info('Saving plot: {}'.format(fplot)) plot_distribution(dic['stats'].dic['distance'], 'Distancia em metros', fplot, color='tab:green', mode=True) fplot = join(dirout, fname + '_computation.pdf') logger.info('Saving plot: {}'.format(fplot)) plot_distribution(dic['stats'].dic['computation'], 'Custo computacional', fplot, color='tab:red')
def main(normfile, fembed, output): normfile = fh.is_file(normfile) if fembed: fembed = fh.is_file(fembed) else: fembed = fh.check_output(None, normfile, prefix='emb') fembed = fh.is_file(fembed) if output: output = fh.is_file(output) else: output = fh.check_output(None, normfile, prefix='offset') embeddings.generate_offset_from_file(normfile, fembed, output)
def main_extract(bagname): bagname = fh.is_file(bagname) fname, ext = fh.filename(bagname) if ext == '.bag': dirout = fh.mkdir_from_file(bagname) logger.info('Reading bag %s' % bagname) bag = rosbag.Bag(bagname) boat1 = Boat('Boat 1') boat2 = Boat('Boat 2') sim = Stats(fname) dtopics = bag.get_type_and_topic_info()[1] bag_messages = bag.read_messages() for topic, msg, timestamp in bag_messages: if topic == 'diffboat1/state': boat1.add_x(msg.pose.pose.position.x) boat1.add_y(msg.pose.pose.position.y) elif topic == '/diffboat2/state': boat2.add_x(msg.pose.pose.position.x) boat2.add_y(msg.pose.pose.position.y) elif topic == '/diffboat1/move_base/RRAPlannerROS/d_cpa': sim.add('dcpa', msg.data) elif topic == '/diffboat1/move_base/RRAPlannerROS/t_cpa': sim.add('tcpa', msg.data) elif topic == '/diffboat1/move_base/RRAPlannerROS/distance': sim.add('distance', msg.data) elif topic == '/diffboat1/move_base/RRAPlannerROS/computation_time': sim.add('computation', msg.data) fout = join(dirout, fname + '.pkl') logger.info('Saving file: {}'.format(fout)) d = {'boat1': boat1, 'boat2': boat2, 'stats': sim} with open(fout, 'wb') as f: pickle.dump(d, f)
elif topic == '/diffboat1/move_base/RRAPlannerROS/distance': sim.add('distance', msg.data) elif topic == '/diffboat1/move_base/RRAPlannerROS/computation_time': sim.add('computation', msg.data) fout = join(dirout, fname + '.pkl') logger.info('Saving file: {}'.format(fout)) d = {'boat1': boat1, 'boat2': boat2, 'stats': sim} with open(fout, 'wb') as f: pickle.dump(d, f) def main(bagfolder): fhandler = fh.FolderHandler(bagfolder, ext='bag') for bagname in fhandler: main_extract(bagname) if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument('bagfile', metavar='bag_file', help='Bag or folder containing several bags') args = parser.parse_args() if fh.is_folder(args.bagfile): main(args.bagfile) elif fh.is_file(args.bagfile): main_extract(args.bagfile) else: logger.info('Path does not contain bag files')