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 create_and_write_report(flydra_db, sample, image_name):
    
    view_start = 'saccades_view_start_%s' % image_name
    view_stop = 'saccades_view_stop_%s' % image_name
    view_rstop = 'saccades_view_rstop_%s' % image_name    


    db = FlydraDB(flydra_db, False) 
    
    saccades = db.get_saccades(sample)
    values_start = db.get_table(sample, view_start)
    values_stop = db.get_table(sample, view_stop)
    values_rstop = db.get_table(sample, view_rstop)
    
    
    r = Report(sample)
    
    for i in range(len(saccades)):
        
        ri = r.node("saccade-%04d" % i)
        
        ri.data_rgb('start', plot_luminance(values_start[i]['value']))
        ri.data_rgb('stop', plot_luminance(values_stop[i]['value']))
        ri.data_rgb('rstop', plot_luminance(values_rstop[i]['value']))
        
        f = ri.figure(shape=(1, 3))
        f.sub('start', 'At saccade start')
        f.sub('stop', 'At saccade stop')
        #f.sub('rstop', '(random stop)')


    db.release_table(saccades)
    db.release_table(values_start)
    db.release_table(values_stop)
    db.release_table(values_rstop)
    

    filename = "%s/out/saccade_view_show/%s_%s.html" % (flydra_db, image_name, sample)
    print "Writing to %s" % filename
    r.to_html(filename)
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)