def create_report_delayed(exp_id, delayed, description):

    delays = numpy.array(sorted(delayed.keys()))

    r = Report(exp_id)
    r.text("description", description)

    f = r.figure(cols=3)

    # max and sum of correlation for each delay
    # corr_max = []
    corr_mean = []

    for delay in delays:
        data = delayed[delay]

        a = data["action_image_correlation"]

        id = "delay%d" % delay

        # rr = r.node('delay%d' % delay)
        r.data(id, a).data_rgb("retina", add_reflines(posneg(values2retina(a))))

        corr_mean.append(numpy.abs(a).mean())

        caption = "delay: %d (max: %.3f, sum: %f)" % (delay, numpy.abs(a).max(), numpy.abs(a).sum())
        f.sub(id, caption=caption)

    timestamp2ms = lambda x: x * (1.0 / 60) * 1000

    peak = numpy.argmax(corr_mean)
    peak_ms = timestamp2ms(delays[peak])
    with r.data_pylab("mean") as pylab:
        T = timestamp2ms(delays)
        pylab.plot(T, corr_mean, "o-")
        pylab.ylabel("mean correlation field")
        pylab.xlabel("delay (ms) ")

        a = pylab.axis()

        pylab.plot([0, 0], [a[2], a[3]], "k-")

        y = a[2] + (a[3] - a[2]) * 0.1
        pylab.text(+5, y, "causal", horizontalalignment="left")
        pylab.text(-5, y, "non causal", horizontalalignment="right")

        pylab.plot([peak_ms, peak_ms], [a[2], max(corr_mean)], "b--")

        y = a[2] + (a[3] - a[2]) * 0.2
        pylab.text(peak_ms + 10, y, "%d ms" % peak_ms, horizontalalignment="left")

    f = r.figure("stats")
    f.sub("mean")

    a = delayed[int(delays[peak])]["action_image_correlation"]
    r.data_rgb("best_delay", add_reflines(posneg(values2retina(a))))

    return r
Example #2
0
 def testFigures(self):
     rgb = numpy.zeros((4, 4, 3), "uint8")
     r = Report("test")
     f = r.figure()
     f.data_rgb("rgb", rgb, caption="ciao")
     assert len(f.get_subfigures()) == 1
     r.data_rgb("rgb", rgb, caption="ciao2")
     r.last().add_to(f)
     assert len(f.get_subfigures()) == 2
Example #3
0
 def testFigures(self):
     rgb = numpy.zeros((4, 4, 3), 'uint8')
     r = Report('test')
     f = r.figure()
     f.data_rgb('rgb', rgb, caption='ciao')
     assert len(f.get_subfigures()) == 1
     r.data_rgb('rgb', rgb, caption='ciao2')
     r.last().add_to(f)
     assert len(f.get_subfigures()) == 2
def creation_suite(fid, f):  # @UnusedVariable
    shape = [50, 50]
    D = diffeomorphism_from_function(shape, f)
    from reprep import Report

    name = f.__name__
    r = Report(name)
    fig = r.figure()

    M = 1
    n1 = 10
    n2 = 100
    bx = [-.99, +.99]  # depends on fmod
    by = bx
    params = dict(figsize=(3, 3))

    def common_settings(pylab):
        pylab.axis('equal')
        pylab.axis((-M, M, -M, M))
        turn_all_axes_off(pylab)

    with fig.plot('grid1', **params) as pylab:
        curved = CurvedPylab(pylab, f)
        plot_grid(curved, n1=n1, n2=n2, bx=bx, by=by, hcol='k-', vcol='k-')
        common_settings(pylab)

    with fig.plot('grid2', caption="different colors", **params) as pylab:
        plot_grid(curved, n1=n1, n2=n2, bx=bx, by=by, hcol='r-', vcol='b-')
        common_settings(pylab)

    with fig.plot('grid3', caption="smiley", **params) as pylab:
        plot_grid(curved, n1=n1, n2=n2, bx=bx, by=by, hcol='r-', vcol='b-')
        common_settings(pylab)
        plot_smiley(curved)

    with fig.plot('grid4', caption="smiley", **params) as pylab:
        plot_grid(curved, n1=n1, n2=n2, bx=bx, by=by, hcol='k-', vcol='k-')
        common_settings(pylab)
        plot_smiley(curved, '0.5')

    rgb = diffeomorphism_to_rgb(D)
    r.data_rgb('diffeomorphism_rgb', rgb).add_to(fig)
    filename = 'out/diffeo_creation_suite/%s.html' % name
    print('Writing to %r.' % filename)
    r.to_html(filename)
def creation_suite(fid, f):  # @UnusedVariable
    shape = [50, 50]
    D = diffeomorphism_from_function(shape, f)
    from reprep import Report

    name = f.__name__
    r = Report(name)
    fig = r.figure()

    M = 1
    n1 = 10
    n2 = 100
    bx = [-.99, +.99]  # depends on fmod
    by = bx
    params = dict(figsize=(3, 3))

    def common_settings(pylab):
        pylab.axis('equal')
        pylab.axis((-M, M, -M, M))
        turn_all_axes_off(pylab)

    with fig.plot('grid1', **params) as pylab:
        curved = CurvedPylab(pylab, f)
        plot_grid(curved, n1=n1, n2=n2, bx=bx, by=by, hcol='k-', vcol='k-')
        common_settings(pylab)

    with fig.plot('grid2', caption="different colors", **params) as pylab:
        plot_grid(curved, n1=n1, n2=n2, bx=bx, by=by, hcol='r-', vcol='b-')
        common_settings(pylab)

    with fig.plot('grid3', caption="smiley", **params) as pylab:
        plot_grid(curved, n1=n1, n2=n2, bx=bx, by=by, hcol='r-', vcol='b-')
        common_settings(pylab)
        plot_smiley(curved)

    with fig.plot('grid4', caption="smiley", **params) as pylab:
        plot_grid(curved, n1=n1, n2=n2, bx=bx, by=by, hcol='k-', vcol='k-')
        common_settings(pylab)
        plot_smiley(curved, '0.5')

    rgb = diffeomorphism_to_rgb(D)
    r.data_rgb('diffeomorphism_rgb', rgb).add_to(fig)
    filename = 'out/diffeo_creation_suite/%s.html' % name
    print('Writing to %r.' % filename)
    r.to_html(filename)
def group_turnogram(group, configuration, saccades, #@UnusedVariable
                    image_width=250, zoom=8):
    r = Report()
    attach_description(r, description.format(width=image_width))
        
    num_saccades = 0
    num_samples = 0
    signs = []
    for sample, saccades_for_sample in iterate_over_samples(saccades): #@UnusedVariable
        num_samples += 1
        num_saccades += len(saccades_for_sample)
        signs.append(saccades_for_sample['sign'])

    colors = {-1: [0, 0, 255, 255], 1: [255, 0, 0, 255]}
    bgcolor = [240, 240, 240, 240]
    chunks = []
    
    for i in range(num_samples):
        sign = signs[i]
        num_lines = int(numpy.ceil(len(sign) * 1.0 / image_width))
        num_lines *= 2
        chunk = numpy.ndarray(shape=(num_lines, image_width, 4) , dtype='uint8')
        # white transparent
        chunk[:, :, :] = bgcolor
        for k in range(len(sign)):
            x = k % image_width
            y = ((k - x) / image_width) * 2
            chunk[y, x, :] = colors[sign[k]] 
        chunks.append(chunk)
        # add empty chunk
        chunk = numpy.ndarray((2, image_width, 4), dtype='uint8')
        chunk[:, :, :] = bgcolor
        chunks.append(chunk)
        
    img = numpy.vstack(chunks)

    img_zoomed = zoom_rgb(img, zoom)

    r.data_rgb('turnogram', img_zoomed)
    return r
Example #7
0
def estimation(fid, f):  # @UnusedVariable
    shape = [50, 50]
    diffeo = diffeomorphism_from_function(shape, f)

    K = 50
    epsilon = 1
    de = DiffeomorphismEstimator([0.2, 0.2], MATCH_CONTINUOUS)
    for y0, y1 in generate_input(shape, K, diffeo, epsilon=epsilon):
        de.update(y0, y1)

    diff2d = de.summarize()
    diffeo_learned = diff2d.d

    from reprep import Report

    name = f.__name__
    r = Report(name)
    fig = r.figure(cols=4)

    diffeo_learned_rgb = diffeomorphism_to_rgb_cont(diffeo_learned)
    diffeo_rgb = diffeomorphism_to_rgb_cont(diffeo)
    r.data_rgb('diffeo_rgb', diffeo_rgb).add_to(fig)
    r.data_rgb('diffeo_learned_rgb', diffeo_learned_rgb).add_to(fig)
    L = r.data('diffeo_learned_uncertainty', diff2d.variance)
    L.display('scale').add_to(fig, caption='uncertainty')
    r.data('last_y0', y0).display('scale').add_to(fig, caption='last y0')
    r.data('last_y1', y1).display('scale').add_to(fig, caption='last y1')

    cs = [(0, 25), (10, 25), (25, 25), (25, 5)]
    for c in cs:
        M25 = de.get_similarity(c)
        r.data('cell-%s-%s' % c,
               M25).display('scale').add_to(fig,
                                            caption='Example similarity field')

    filename = 'out/diffeo_estimation_suite/%s.html' % name
    print('Writing to %r.' % filename)
    r.to_html(filename)
def estimation(fid, f):  # @UnusedVariable
    shape = [50, 50]
    diffeo = diffeomorphism_from_function(shape, f)

    K = 50
    epsilon = 1
    de = DiffeomorphismEstimator([0.2, 0.2], MATCH_CONTINUOUS)
    for y0, y1 in generate_input(shape, K, diffeo, epsilon=epsilon):
        de.update(y0, y1)

    diff2d = de.summarize()
    diffeo_learned = diff2d.d

    from reprep import Report

    name = f.__name__
    r = Report(name)
    fig = r.figure(cols=4)

    diffeo_learned_rgb = diffeomorphism_to_rgb_cont(diffeo_learned)
    diffeo_rgb = diffeomorphism_to_rgb_cont(diffeo)
    r.data_rgb('diffeo_rgb', diffeo_rgb).add_to(fig)
    r.data_rgb('diffeo_learned_rgb', diffeo_learned_rgb).add_to(fig)
    L = r.data('diffeo_learned_uncertainty', diff2d.variance)
    L.display('scale').add_to(fig, caption='uncertainty')
    r.data('last_y0', y0).display('scale').add_to(fig, caption='last y0')
    r.data('last_y1', y1).display('scale').add_to(fig, caption='last y1')

    cs = [(0, 25), (10, 25), (25, 25), (25, 5)]
    for c in cs:
        M25 = de.get_similarity(c)
        r.data('cell-%s-%s' % c, M25).display('scale').add_to(fig,
                                         caption='Example similarity field')

    filename = 'out/diffeo_estimation_suite/%s.html' % name
    print('Writing to %r.' % filename)
    r.to_html(filename)
def main(): 
    
    cp = ClientProcess()    
    cp.config_stimulus_xml(example_stim_xml)
    position = [0.5, 0.5, 0.5]
    linear_velocity_body = [0, 0, 0]
    angular_velocity_body = [0, 0, 0]
    
    
    r = Report('am-I-crazy-test')
    f = r.figure('varying theta', shape=(3, 3))
    f2 = r.figure('varying x', shape=(3, 3))
    f3 = r.figure('varying y', shape=(3, 3))
    
    desc = lambda position, theta: 'At x: %.2f, y: %.2f, z: %.2f, theta: %d deg' % \
              (position[0], position[1], position[2], numpy.degrees(theta))
    idm = lambda position, theta, t: "%s-x:%.2f,y:%.2f,z:%.2f,th:%.3f" % (t, position[0], position[1], position[2], theta)
        
    for theta in numpy.linspace(0, 2 * numpy.pi, 16):
        position = [0.5, 0.5, 0.5]
        attitude = rotz(theta)
        
        res = cp.render(position, attitude,
                        linear_velocity_body, angular_velocity_body)
        lum = res['luminance']
        id = idm(position, theta, 'theta')
        r.data_rgb(id, plot_luminance(lum))
        f.sub(id, desc(position, theta)) 
              
    for x in numpy.linspace(0, 1, 20):
        position = [x, 0, 0.1]
        theta = 0
        
        res = cp.render(position, attitude,
                        linear_velocity_body, angular_velocity_body)
        id = idm(position, theta, 'x')
        r.data_rgb(id, plot_luminance(res['luminance']))
        f2.sub(id, desc(position, theta))
    
    for y in numpy.linspace(0, 1, 20):
        position = [0, y, 0.1]
        theta = 0
        
        res = cp.render(position, attitude,
                        linear_velocity_body, angular_velocity_body)
        id = idm(position, theta, 'y')
        r.data_rgb(id, plot_luminance(res['luminance']))
        f3.sub(id, desc(position, theta))
    
    
    filename = 'demo_pipe_rotation_experimenting.html'
    print "Writing to %s" % filename
    r.to_html(filename)
    
    cp.close()
def main():
    sigma_deg = 6
    kernel1 = get_contrast_kernel(sigma_deg=sigma_deg, eyes_interact=True)
    kernel2 = get_contrast_kernel(sigma_deg=sigma_deg, eyes_interact=False) # better
    
    kernel1 = kernel1.astype('float32')
    kernel2 = kernel2.astype('float32')
    
    meany = Expectation()
    ex1 = Expectation()
    ex2 = Expectation()
    
    cp = ClientProcess()
    cp.config_use_white_arena()    
    cp.config_stimulus_xml(example_stim_xml)
    #position = [0.15, 0.5, 0.25]
    position = [0.35, 0.5, 0.25]
    linear_velocity_body = [0, 0, 0]
    angular_velocity_body = [0, 0, 0]
    
    #from flydra_render.contrast import  intrinsic_contrast
    from fast_contrast import  intrinsic_contrast #@UnresolvedImport

    
    N = 360
    
    pb = progress_bar('Computing contrast', N)
    
    orientation = numpy.linspace(0, 2 * numpy.pi, N)
    for i, theta in enumerate(orientation):
        attitude = rotz(theta)
        
        pb.update(i)
        res = cp.render(position, attitude,
                        linear_velocity_body, angular_velocity_body)
    
        y = numpy.array(res['luminance']).astype('float32')
        
        meany.update(y)
        #y = numpy.random.rand(1398)
        
        c1 = intrinsic_contrast(y, kernel1)
        c2 = intrinsic_contrast(y, kernel2)
        
    
        ex1.update(c1)
        ex2.update(c2)

    r = Report()
    r.data_rgb('meany', scale(values2retina(meany.get_value())))
    r.data_rgb('mean1', plot_contrast(ex1.get_value()))
    r.data_rgb('mean2', plot_contrast(ex2.get_value()))
    r.data_rgb('one-y', (plot_luminance(y)))
    r.data_rgb('one-c1', plot_contrast(c1))
    r.data_rgb('one-c2', plot_contrast(c2))
    
    r.data_rgb('kernel', scale(values2retina(kernel2[100, :])))
    
    f = r.figure(shape=(2, 3))
    f.sub('one-y', 'One random image')
    f.sub('one-c1', 'Contrast of random image')
    f.sub('one-c2', 'Contrast of random image')
    f.sub('meany', 'Mean luminance')
    f.sub('mean1', 'Mean over %s samples' % N)
    f.sub('mean2', 'Mean over %s samples' % N)
    f.sub('kernel')
    
    filename = 'compute_contrast_demo.html'
    print("Writing on %s" % filename)
    r.to_html(filename)
Example #11
0
 def testImageRGBCaption(self):
     rgb = numpy.zeros((4, 4, 3), "uint8")
     r = Report("test")
     r.data_rgb("rgb", rgb, caption="ciao")
Example #12
0
 def testImageRGBCaption(self):
     rgb = numpy.zeros((4, 4, 3), 'uint8')
     r = Report('test')
     r.data_rgb('rgb', rgb, caption='ciao')