Exemple #1
0
 def load(vidname):
     import reader, trace, traj
     vname, wname, mname = fnames(vidname)
     v = reader.Reader(vname, adjuststipple=0)
     w = trace.Load_Whiskers(wname)
     try:
         m = traj.MeasurementsTable(mname)
     except:
         traceback.print_exc(file=sys.stdout)
         sys.stdout.flush()
         m = None
     return v, w, m
Exemple #2
0
                dst)[0]
    if not all(map(os.path.exists, args)):
        raise IOError, "Could not find one or more input source files."

    if all(
            map(
                lambda f: os.path.splitext(f)[-1] in
                ['.trajectories', '.whiskers'], args)):
        if len(args) == 1:
            src = args[0]
            tfile = None
        else:
            src = args[
                1]  #know the order b.c. already sorted by file extenstion
            tfile = args[0]
        w = trace.Load_Whiskers(src)
        data = numpy.array(list(summary.features(w, options.face)))
        if tfile:
            t, tid = load_trajectories(tfile)
            summary.commit_traj_to_data_table(t, data)

    elif all(
            map(
                lambda f: os.path.splitext(f)[-1] in
                ['.trajectories', '.measurements'], args)):
        sources = dict(map(lambda f: (os.path.splitext(f)[-1], f), args))

        try:
            data = traj.MeasurementsTable(sources['.measurements']).asarray()
        except KeyError:
            raise UserException, "A .measurements file must be provided as one of the source files."
Exemple #3
0
    wrowcmp = lambda a, b: wcmp(a[1], b[1])
    for fid, wv in wvd.iteritems():
        #print fid
        seq = wid_sequence_from_frame(wv)  #ordered wid's
        labels, p, vp = model.viterbi_by_lookup(fid, seq)
        tids = map(statemap.get, labels)
        logp[fid] = p
        vlogp[fid] = vp

        for tid, wid in zip(tids, seq):
            if not tid is None:
                traj.setdefault(tid, {})[fid] = wid

    return traj, logp, vlogp


if __name__ == '__main__':
    import sys, traj, trace
    name, whisker_src, measurements_src, dest = sys.argv
    wvd = trace.Load_Whiskers(whisker_src)
    table = traj.MeasurementsTable(measurements_src)

    data = table.asarray()
    traj = table.get_trajectories()
    model = LeftRightModel()
    model.train(wvd, traj, data=data)
    traj_hmm, logp, vlogp = apply_model(wvd, model)
    table.commit_trajectories(traj)

    table.save(dest)
Exemple #4
0
import trace

# Other imports
import matplotlib.pyplot as plt
import numpy as np, os.path, pandas

# Data location
session = '0509A_cropped_truncated_4'
side = 'top'
#~ session = '0527_cropped_truncated_5'; side = 'left'
whisk_rootdir = os.path.expanduser('~/mnt/bruno-nix/whisker_video/processed')
whisk_file = os.path.join(whisk_rootdir, session, session + '.whiskers')
measure_file = os.path.join(whisk_rootdir, session, session + '.measurements')

# Load the traces
frame2segment_id2whisker_seg = trace.Load_Whiskers(whisk_file)

# Load the correspondence between traces and identified whiskers
tmt = traj.MeasurementsTable(measure_file)
whisker_id2frame2segment_id = tmt.get_trajectories()

# Identify any missing frames
frames_l = frame2segment_id2whisker_seg.keys()
sorted_frames = np.sort(frames_l)

# Iterate over frames
rec_l = []

# Iterate over whiskers
# It looks like it numbers them from Bottom to Top for side == 'left'
# whiski colors them R, G, B