コード例 #1
0
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
コード例 #2
0
def pub_tensor2(pub, name, V):
    """ Publishes a generic 2D tensor """
    with pub.subsection(name) as section:
        section.array("value", V)  # TODO
        value_rgb = posneg(V)
        pub_save_versions(section, value_rgb)
        pub_stats(section, V)
コード例 #3
0
ファイル: ros_simulation.py プロジェクト: ajaycharan/vehicles
 def publish_ros_commands(self, commands):
     from reprep import posneg
     # commands = commands.reshape((1, commands.size))
     z = 4
     commands = np.kron(commands, np.ones((z, z)))
     commands_image = posneg(commands)
     ros_image = numpy_to_imgmsg(commands_image, stamp=None)
     self.pub_commands_image.publish(ros_image)
コード例 #4
0
def pub_tensor3_slice2(pub, name, V):
    """ Displays a 3D tensor, with shape [nxnxk] """
    with pub.subsection(name) as section:
        section.array("value", V)

        nslices = V.shape[2]
        max_value = np.nanmax(np.abs(V))

        if not np.isfinite(max_value):
            msg = "Expected a finite value."
            raise ValueError(msg)

        fu = section.figure("unnormalized", cols=nslices)
        fn = section.figure("normalized", cols=nslices)
        fug = section.figure("unnormalizedg", cols=nslices)
        fng = section.figure("normalizedg", cols=nslices)

        with section.subsection("slices") as slices:

            for i in range(nslices):
                tslice = V[:, :, i]

                with slices.subsection("%d" % i) as s:

                    s.array("value", tslice)

                    rgbu = posneg(tslice)
                    rgbn = posneg(tslice, max_value=max_value)

                    dn = pub_save_versions2(s, "normalized", rgbn)
                    fn.sub(dn)

                    du = pub_save_versions2(s, "unnormalized", rgbu)
                    fu.sub(du)

                    gray_u = posneg_hinton(tslice)
                    gray_n = posneg_hinton(tslice, max_value=max_value)

                    dng = pub_save_versions2(s, "normalizedg", gray_n)
                    fug.sub(dng)
                    dug = pub_save_versions2(s, "unnormalizedg", gray_u)
                    fng.sub(dug)

    pub_stats(section, V)
def add_posneg(report, id, x, **kwargs):
    n = report.data(id, x)
    
    n.data_rgb('retina',
            add_reflines(posneg(values2retina(x), **kwargs)))
    
    #with n.data_pylab('plot') as pylab:
    #    pylab.plot(x, '.')
        
    return n
コード例 #6
0
def pub_tensor2_cov(pub, name, V, rcond=None):
    """ Publishes a tensor which is supposed to represent a covariance. """
    with pub.subsection(name) as sub:
        sub.array_as_image("posneg", V)  # XXX: redundant, but don't want to change code
        sub.array("value", V)

        rgb = posneg(V)
        pub_save_versions(sub, rgb)

        pub_svd_decomp(sub, V, rcond=rcond)
        pub_stats(sub, V)
コード例 #7
0
ファイル: rcl_detect_meat.py プロジェクト: AndreaCensi/rcl
 def write_image(name, values):    
     time_us = timestamp * 1000 * 1000
     dirname2 = os.path.join(dirname, name) 
     if not os.path.exists(dirname2):
         os.makedirs(dirname2)
     filename = os.path.join(dirname2, 'ms%08d.png' % time_us)
     if np.nanmin(values) < 0:
         rgb = posneg(values)
     else:
         rgb = scale(values)
     rgb = rgb_zoom(rgb, K=4)
     imwrite(rgb, filename)
     logger.debug('print to %r' % filename)
コード例 #8
0
 def write_image(name, values):
     time_us = timestamp * 1000 * 1000
     dirname2 = os.path.join(dirname, name)
     if not os.path.exists(dirname2):
         os.makedirs(dirname2)
     filename = os.path.join(dirname2, 'ms%08d.png' % time_us)
     if np.nanmin(values) < 0:
         rgb = posneg(values)
     else:
         rgb = scale(values)
     rgb = rgb_zoom(rgb, K=4)
     imwrite(rgb, filename)
     logger.debug('print to %r' % filename)
コード例 #9
0
def get_rgb(field, colors, **kwargs):
    ''' Returns a dict with values 'rgb' (rgb in [0,1]), 'colorbar', etc.. '''
    properties = {}
    if colors == 'posneg':
        rgb = posneg(field, properties=properties, **kwargs) / 255.0
    elif colors == 'scale':
        rgb = scale(field, properties=properties, **kwargs) / 255.0
    elif colors == 'cmap':
        rgb = filter_colormap(field,
                              properties=properties, **kwargs) / 255.0
    else:
        raise ValueError('No known colors %r. ' % colors)
    
    properties['rgb'] = rgb
    return properties
コード例 #10
0
ファイル: bds.py プロジェクト: AndreaCensi/boot_agents
def template_bds_P(frag, id_set, id_robot, id_agent, width="3cm"):
    report = load_report_phase(id_set=id_set, agent=id_agent, robot=id_robot, phase="learn")
    gid = "%s-%s-%s-P" % (id_set, id_robot, id_agent)
    V = report["estimator/tensors/P/value"].raw_data

    n = V.shape[0]
    rgb = posneg(V)

    if n > 50:
        frag.save_graphics_data(jpg_data(rgb), MIME_JPG, gid)
    else:
        rgb = rgb_zoom(rgb, 16)
        frag.save_graphics_data(png_data(rgb), MIME_PNG, gid)

    #    frag.save_graphics_data(node.raw_data, node.mime, gid)
    tensor_figure(frag, gid=gid, xlabel="s", ylabel="v", width=width, label="\TPe^{sv}")
コード例 #11
0
 def add_pieces(sub, V, n, zoom=16):
     pieces = get_pieces(V, n)
     for k, piece in enumerate(pieces):
         with sub.subsection("%d" % k) as subk:
             value = piece["value"]
             rgb = posneg(value)
             rgb = rgb_zoom(rgb, zoom)
             # XXX
             subk.r.data_rgb("png", rgb, mime=MIME_PNG)
             rel = subk.section("rel")
             rel.r.data("x", piece["xfrac"])
             rel.r.data("y", piece["yfrac"])
             rel.r.data("width", piece["wfrac"])
             rel.r.data("height", piece["wfrac"])
             pixels = subk.section("pixels")
             pixels.r.data("x", piece["x"])
             pixels.r.data("y", piece["y"])
             pixels.r.data("width", piece["w"])
             pixels.r.data("height", piece["h"])
コード例 #12
0
def diffeo_to_rgb_curv(D):
    stats = diffeo_stats(D)
    return posneg(stats.curv)
コード例 #13
0
ファイル: bds.py プロジェクト: AndreaCensi/boot_agents
 def render(x):
     return posneg(x, skim=skim)
コード例 #14
0
ファイル: basic.py プロジェクト: AndreaCensi/diffeo
def diffeo_to_rgb_curv(D):
    stats = diffeo_stats(D)
    return posneg(stats.curv)
コード例 #15
0
def draw_correlation_figure(pylab, xlabels, ylabels, R):
    rgb = posneg(R, max_value=1)
    draw_matrix_and_labels(pylab, xlabels, ylabels, rgb)