def average_diode_sep():
    clust_eps = 0.2
    min_dist = 2.0
    min_samples = 3.0
    thold = 240
    
    FRAMES =  np.arange(4000)*2
    
    dataset = "bukowski_02.C"
    cf = pickle.load(open(os.path.join(ddir(dataset), 'config.pickle')))
    region = pickle.load(open(os.path.join(ddir(dataset), 'region.pickle')))
    
    env = util.Environmentz(cf['field_dim_m'], cf['frame_dim_pix'])
    x_min, y_min = env.gc.real_to_image(region['x_pos_min'], region['y_pos_min'])
    x_max, y_max = env.gc.real_to_image(region['x_pos_max'], region['y_pos_max'])
    print x_min, x_max
    print y_min, y_max
    if y_min < 0:
        y_min = 0
    frame_images = organizedata.get_frames(ddir(dataset), FRAMES)
    num_clusters = np.zeros(len(FRAMES))
    dists = []
    for fi, im in enumerate(frame_images):
        im = im[y_min:y_max+1, x_min:x_max+1]

        centers = frame_clust_points(im, 240, min_dist,
                                     clust_eps, min_samples)

        num_clusters[fi] = len(centers)
        if len(centers) == 2:
            dists.append(distance.pdist(centers)[0])
    dists = np.array(dists)
    pylab.hist(dists[dists < 50], bins=20)

    pylab.savefig("average_diode_sep.%s.png" % dataset, dpi=300)
def find_params():

    FRAMES =  np.arange(30)*100

    frame_images = organizedata.get_frames(ddir("bukowski_04.W2"), FRAMES)
    print "DONE READING DATA"

    CLUST_EPS = np.linspace(0, 0.5, 10)
    MIN_SAMPLES = [2, 3, 4, 5]
    MIN_DISTS = [2, 3, 4, 5, 6]
    THOLD = 240

    fracs_2 = np.zeros((len(CLUST_EPS), len(MIN_SAMPLES), len(MIN_DISTS)))

    for cei, CLUST_EP in enumerate(CLUST_EPS):
        for msi, MIN_SAMPLE in enumerate(MIN_SAMPLES):
            for mdi, MIN_DIST in enumerate(MIN_DISTS):
                print cei, msi, mdi
                numclusters = np.zeros(len(FRAMES))
                for fi, im in enumerate(frame_images):
                    centers = frame_clust_points(im, THOLD, MIN_DIST, 
                                                 CLUST_EP, MIN_SAMPLE)
                    # cluster centers
                    numclusters[fi] = len(centers)
                fracs_2[cei, msi, mdi] = float(np.sum(numclusters == 2))/len(numclusters)
    pylab.figure(figsize=(12, 8))
    for mdi, MIN_DIST in enumerate(MIN_DISTS):
        pylab.subplot(len(MIN_DISTS), 1, mdi+1)

        for msi in range(len(MIN_SAMPLES)):
            pylab.plot(CLUST_EPS, fracs_2[:, msi, mdi], label='%d' % MIN_SAMPLES[msi])
        pylab.title("min_dist= %3.2f" % MIN_DIST)
    pylab.legend()
    pylab.savefig('test.png', dpi=300)
Exemple #3
0
def average_diode_sep():
    clust_eps = 0.2
    min_dist = 2.0
    min_samples = 3.0
    thold = 240

    FRAMES = np.arange(4000) * 2

    dataset = "bukowski_02.C"
    cf = pickle.load(open(os.path.join(ddir(dataset), 'config.pickle')))
    region = pickle.load(open(os.path.join(ddir(dataset), 'region.pickle')))

    env = util.Environmentz(cf['field_dim_m'], cf['frame_dim_pix'])
    x_min, y_min = env.gc.real_to_image(region['x_pos_min'],
                                        region['y_pos_min'])
    x_max, y_max = env.gc.real_to_image(region['x_pos_max'],
                                        region['y_pos_max'])
    print x_min, x_max
    print y_min, y_max
    if y_min < 0:
        y_min = 0
    frame_images = organizedata.get_frames(ddir(dataset), FRAMES)
    num_clusters = np.zeros(len(FRAMES))
    dists = []
    for fi, im in enumerate(frame_images):
        im = im[y_min:y_max + 1, x_min:x_max + 1]

        centers = frame_clust_points(im, 240, min_dist, clust_eps, min_samples)

        num_clusters[fi] = len(centers)
        if len(centers) == 2:
            dists.append(distance.pdist(centers)[0])
    dists = np.array(dists)
    pylab.hist(dists[dists < 50], bins=20)

    pylab.savefig("average_diode_sep.%s.png" % dataset, dpi=300)
Exemple #4
0
def find_params():

    FRAMES = np.arange(30) * 100

    frame_images = organizedata.get_frames(ddir("bukowski_04.W2"), FRAMES)
    print "DONE READING DATA"

    CLUST_EPS = np.linspace(0, 0.5, 10)
    MIN_SAMPLES = [2, 3, 4, 5]
    MIN_DISTS = [2, 3, 4, 5, 6]
    THOLD = 240

    fracs_2 = np.zeros((len(CLUST_EPS), len(MIN_SAMPLES), len(MIN_DISTS)))

    for cei, CLUST_EP in enumerate(CLUST_EPS):
        for msi, MIN_SAMPLE in enumerate(MIN_SAMPLES):
            for mdi, MIN_DIST in enumerate(MIN_DISTS):
                print cei, msi, mdi
                numclusters = np.zeros(len(FRAMES))
                for fi, im in enumerate(frame_images):
                    centers = frame_clust_points(im, THOLD, MIN_DIST, CLUST_EP,
                                                 MIN_SAMPLE)
                    # cluster centers
                    numclusters[fi] = len(centers)
                fracs_2[cei, msi, mdi] = float(
                    np.sum(numclusters == 2)) / len(numclusters)
    pylab.figure(figsize=(12, 8))
    for mdi, MIN_DIST in enumerate(MIN_DISTS):
        pylab.subplot(len(MIN_DISTS), 1, mdi + 1)

        for msi in range(len(MIN_SAMPLES)):
            pylab.plot(CLUST_EPS,
                       fracs_2[:, msi, mdi],
                       label='%d' % MIN_SAMPLES[msi])
        pylab.title("min_dist= %3.2f" % MIN_DIST)
    pylab.legend()
    pylab.savefig('test.png', dpi=300)
Exemple #5
0
    d = np.zeros(FRAMES_TO_ANALYZE, dtype=DTYPE_POS_CONF)
    FRAMES_AT_A_TIME = 10
    frames = np.arange(FRAMES_TO_ANALYZE)
    for frame_subset in util.chunk(frames, FRAMES_AT_A_TIME):
        fs = organizedata.get_frames(basedir, frame_subset)
        for fi, frame_no in enumerate(frame_subset):
            real_x, real_y, conf = func(fs[fi], env, **config)
            d[frame_no]['x'] = real_x
            d[frame_no]['y'] = real_y
            d[frame_no]['confidence'] = conf
            
    return d


@transform(ddir("*/positions.npy"), 
           regex(r".+/(.+)/positions.npy$"), 
           [os.path.join(REPORT_DIR, 
                         r"\1", "truth.npy")], 
           r"\1"
           )
def get_truth(positions_file, (output_file, ), basedir):
    truth_data = truth(ddir(basedir))
    try:
        os.makedirs(rdir(basedir))
    except OSError:
        pass
    np.save(output_file, truth_data)

def algodir(basedir):
    try:
Exemple #6
0
    d = np.zeros(FRAMES_TO_ANALYZE, dtype=DTYPE_POS_CONF)
    FRAMES_AT_A_TIME = 10
    frames = np.arange(FRAMES_TO_ANALYZE)
    for frame_subset in util.chunk(frames, FRAMES_AT_A_TIME):
        fs = organizedata.get_frames(basedir, frame_subset)
        for fi, frame_no in enumerate(frame_subset):
            real_x, real_y, conf = func(fs[fi], env, **config)
            d[frame_no]['x'] = real_x
            d[frame_no]['y'] = real_y
            d[frame_no]['confidence'] = conf

    return d


@transform(ddir("*/positions.npy"), regex(r".+/(.+)/positions.npy$"),
           [os.path.join(REPORT_DIR, r"\1", "truth.npy")], r"\1")
def get_truth(positions_file, (output_file, ), basedir):
    truth_data = truth(ddir(basedir))
    try:
        os.makedirs(rdir(basedir))
    except OSError:
        pass
    np.save(output_file, truth_data)


def algodir(basedir):
    try:
        os.makedirs(rdir(os.path.join(basedir, "algo")))
    except OSError:
        pass