def make_data(fmt): base_dir = os.path.join(EXAMPLES_DIR, fmt, *RELPATHS[fmt][:-1]) in_fn = os.path.join(base_dir, RELPATHS[fmt][-1]) conf_fn = os.path.join(base_dir, config.RELPATH) conf = config.get_conf(conf_fn=conf_fn) reader = readfile.TracksReader(in_fn, conf=conf) d = {'reader': reader} for k in 'objects', 'links': d['%s_path' % k] = os.path.join(base_dir, 'dp', '%s.csv' % k) return d
def make_data(fmt): base_dir = os.path.join(EXAMPLES_DIR, fmt, *RELPATHS[fmt][:-1]) dp_dir = os.path.join(base_dir, 'dp') d = {'dp_dir': dp_dir} d['obj_df'] = pd.read_csv(os.path.join(dp_dir, 'objects.csv')) d['links_df'] = pd.read_csv(os.path.join(dp_dir, 'links.csv')) d['tracks_df'] = pd.read_csv(os.path.join(dp_dir, 'tracks.csv')) conf_fn = os.path.join(base_dir, config.RELPATH) d['conf'] = config.get_conf(conf_fn=conf_fn) return d
def make_data(fmt): base_dir = os.path.join(EXAMPLES_DIR, fmt, *RELPATHS[fmt][:-1]) exp_dp_dir = os.path.join(base_dir, 'dp') dp_fn = os.path.join(exp_dp_dir, 'dp.json') dp = datapackage.DataPackage(dp_fn) in_fn = os.path.join(base_dir, RELPATHS[fmt][-1]) conf_fn = os.path.join(base_dir, config.RELPATH) conf = config.get_conf(conf_fn=conf_fn) reader = readfile.TracksReader(in_fn, conf=conf) reader.read() return {'reader': reader, 'dp': dp, 'dp_dir': str(tmpdir)}
def main(argv): parser = make_parser() args = parser.parse_args(argv[1:]) logger = get_logger('create_dpkg', level=args.log_level, f=sys.stdout) input_dir = os.path.dirname(os.path.abspath(args.track_fn)) if args.out_dir is None: args.out_dir = DEFAULT_OUTPUT_BASENAME if not args.config: args.config = os.path.join(input_dir, config.RELPATH) logger.info('Trying default config file location: "%s"', args.config) if not os.path.isfile(args.config): logger.info('Config file not found, using defaults') args.config = None conf = config.get_conf(conf_fn=args.config) # joint_id = cmso.OBJECT_ID # link_id = cmso.LINK_ID # track_id = cmso.TRACK_ID reader = readfile.TracksReader( args.track_fn, conf=conf, log_level=args.log_level ) reader.read() createdp.create(reader, args.out_dir, log_level=args.log_level)
def main(argv): parser = make_parser() args = parser.parse_args(argv[1:]) logger = get_logger('create_dpkg', level=args.log_level, f=sys.stdout) input_dir = os.path.dirname(os.path.abspath(args.track_fn)) if args.out_dir is None: args.out_dir = DEFAULT_OUTPUT_BASENAME if not args.config: args.config = os.path.join(input_dir, config.RELPATH) logger.info('Trying default config file location: "%s"', args.config) if not os.path.isfile(args.config): logger.info('Config file not found, using defaults') args.config = None conf = config.get_conf(conf_fn=args.config) joint_id = cmso.OBJECT_ID link_id = cmso.LINK_ID track_id = cmso.TRACK_ID reader = readfile.TracksReader( args.track_fn, conf=conf, log_level=args.log_level ) reader.read() createdp.create(reader, args.out_dir, log_level=args.log_level) # push to pandas results_dict = pushtopandas.push_to_pandas( args.out_dir, joint_id, log_level=args.log_level ) logger.debug('Datapackage pushed to pandas') objects = results_dict['objects'] links = results_dict['links'] tracks = results_dict['tracks'] logger.debug('Number of rows: %d', objects.shape[0]) logger.debug('Number of columns: %d', objects.shape[1]) # aggregation of objects and links for further analytics objects_links = pd.merge(links, objects, how='outer', on=joint_id) # aggregation of tracks as well for further analytics objects_links_tracks = pd.merge( objects_links, tracks, how='outer', on=link_id ) x = cmso.X_COORD y = cmso.Y_COORD frame = cmso.FRAME_ID # basic visualizations objects_links_tracks.sort_values(frame, axis=0, inplace=True) cum_df = plot.compute_cumulative_displacements( objects_links_tracks, link_id, x, y ) plot.plotXY(cum_df, track_id, 'x_cum', 'y_cum') plot.plotXY(cum_df[cum_df[link_id] == 0], track_id, 'x_cum', 'y_cum') plot.plotXY(objects_links_tracks, track_id, x, y) plot.plotXY(objects_links_tracks, link_id, x, y) logger.info( 'normalizing dataset to the origin of the coordinate system...' ) norm = plot.normalize(objects_links_tracks, track_id, x, y) plot.plotXY(norm, track_id, 'x_norm', 'y_norm') plot.plotXY(norm, link_id, 'x_norm', 'y_norm') logger.info('computing displacements in the two directions of motion...') norm = plot.compute_displacements(norm, track_id, x, y) logger.info('computing turning angles...') norm = plot.compute_turning_angle(norm, track_id) theta = pd.DataFrame(norm.ta[~np.isnan(norm.ta)]) plot.plot_polar(theta, 10)