def get_matching_bag(fmftime, bagdir):
    bags = []
    for bag in glob.glob(os.path.join(bagdir,'*.bag')):
        btime = madplot.strptime_bagfile(bag)
        try:
            dt = abs(time.mktime(fmftime) - time.mktime(btime))
        except:
            print 'fmftime',fmftime
            print 'btime',btime
            raise
        bags.append( (bag, dt) )

    #sort based on dt (smallest dt first)
    bags.sort(key=operator.itemgetter(1))
    bag,dt = bags[0]

    if dt < 10:
        return bag
    else:
        return None
def get_matching_bag(fmftime, bagdir):
    bags = []
    for bag in glob.glob(os.path.join(bagdir, '*.bag')):
        btime = madplot.strptime_bagfile(bag)
        try:
            dt = abs(time.mktime(fmftime) - time.mktime(btime))
        except:
            print 'fmftime', fmftime
            print 'btime', btime
            raise
        bags.append((bag, dt))

    #sort based on dt (smallest dt first)
    bags.sort(key=operator.itemgetter(1))
    bag, dt = bags[0]

    if dt < 10:
        return bag
    else:
        return None
Example #3
0
    ts = fmffile.get_all_timestamps().tolist()

    arena = madplot.Arena(False)

    cuts = []
    for bag in sorted(bags):
        geom, dfs = madplot.load_bagfile(bag, arena)
        h_df = dfs["ttm"]

        fn = h_df['h_framenumber']
        start = fn.ix[0]
        stop = fn.ix[-1]

        dn = os.path.dirname(bag)
        btime = madplot.strptime_bagfile(bag)
        destfmfname = "%s%d%02d%02d_%02d%02d%02d.fmf" % (os.path.basename(dn),
                        btime.tm_year,btime.tm_mon,btime.tm_mday,
                        btime.tm_hour,btime.tm_min,btime.tm_sec)

        destfmf = os.path.join(dn,'..',destfmfname)

        cuts.append( Cut(start,stop,os.path.abspath(destfmf)) )

    #many iterations, yuck. meh.
    while cuts:
        try:
            cut = cuts.pop(0)
        except IndexError:
            continue