예제 #1
0
def create_report_fields(result, report_id=None):
    report = Node(report_id)
    
    fields = [('x_y', result.lattice_x_y, result.fields_x_y),
              ('x_theta', result.lattice_x_theta, result.fields_x_theta),
              ('theta_y', result.lattice_theta_y, result.fields_theta_y) ]

    fig_fields = report.figure('fields', caption='Inner products', shape=(3, 3))
    # Compute inner product w/ right direction
    fig_inner = report.figure(id='inner', caption='Inner products')

    fig_success = report.figure(id='success', caption='Success')
 
    
    for field_name, lattice, field in fields:
        field = array(field)
        average = numpy.mean(field, 0)
        #print "List  shape: %s " % str(field.shape)
        #print "Mean shape: %s " % str(average.shape)
        require_shape((gt(0), gt(0), 3), average)

        for i, cmd_name in [(0, 'vx'), (1, 'vy'), (2, 'vtheta')]:
            image_name = '%s-%s' % (field_name, cmd_name)

            fi = average[:, :, i].squeeze()
            require_shape((gt(0), gt(0)), fi)
            
            max_value = abs(fi).max()
            # let's allow a matrix with all 0
            if max_value == 0:
                max_value = 1

            report.data(image_name, fi)
            fig_fields.sub(image_name, display='posneg', max_value=max_value,
                           caption=field_name)
    
    def lattice2pose(lattice):
        def rbs2pose(rbs):
            p = rbs.get_2d_position()
            theta = rbs.get_2d_orientation()
            return array([p[0, 0], p[1, 0], theta])
        return map(lambda x: map(rbs2pose, x), lattice)
        
    for field_name, lattice, field in fields:
        lattice = array(lattice2pose(lattice))
        inners = []
        for commands in field:
            print "lattice shape", lattice.shape
            #print "commands shape", commands.shape
            inner = numpy.sum(lattice * commands, axis=2) 
            inners.append(inner)
        
        average_inner = numpy.mean(array(inners), 0)
        require_shape((gt(0), gt(0)), average_inner)
        
        success = numpy.mean(array(inners) > 0, 0) # XXX should be < 0
        require_shape((gt(0), gt(0)), success)
            
        image_name = 'inner-%s' % (field_name)
        
        max_value = abs(fi).max()
        # let's allow a matrix with all 0
        if max_value == 0:
            max_value = 1
        
        report.data(image_name, average_inner)
        fig_inner.sub(image_name, display='posneg',
                      max_value=max_value, caption=field_name)


        image_name = 'success-%s' % (field_name)
        
        report.data(image_name, success)
        fig_success.sub(image_name, display='success')


    return report