Beispiel #1
0
def update_plot(data):
    """
    This function is the blood and guts of the program. It mines the information
    from the input stream and updates the plot data for each step of the
    animation.
    """
    # update the data
    update_plot.exec_path
    update_plot.filepos
    update_plot.pause
    update_plot.isstep
    if not update_plot.pause:
        while 1:
            path_and_error = []
            # Read the first line after the previous parse. This line should
            # contain the block label (SD), (SE), (LG) or (TR).
            if not options.stdintrue:
                curpos = instream.tell()
            line = instream.readline()
            if len(line) == 0:
                update_plot.pause = True
                return ax1xy, ax1xryr, execp, ax2xy, ax2xryr
            if '(SE)' in line:
                if not options.stdintrue:
                    update_plot.filepos.append(curpos)
                if len(se_meta) == 0:
                    if (nop.get_block_meta(instream, se_meta)):
                        update_plot.pause = True
                        return ax1xy, ax1xryr, execp, ax2xy, ax2xryr
                    del se_meta['k']
                    # I hate doing this, but for now, parse_path_and_error()
                    # doesn't store k, it needs to be taken from the metadata.
                    for key in se_meta:
                        se_meta[key] -= 1
                nop.parse_path_and_error(instream, nmpc, path_and_error)
                path_and_error = np.array(path_and_error)
                break

        # xmin, xmax = ax.get_xlim()
        xrdata = path_and_error[:, se_meta['x']] - path_and_error[:, se_meta['ex']]
        yrdata = path_and_error[:, se_meta['y']] - path_and_error[:, se_meta['ey']]
        ax1xy.set_data(path_and_error[:, se_meta['x']],
                       path_and_error[:, se_meta['y']])
        ax1xryr.set_data(xrdata, yrdata)
        ax2xy.set_data(path_and_error[:, se_meta['x']]
                            - path_and_error[0, se_meta['x']],
                       path_and_error[:, se_meta['y']]
                            - path_and_error[0, se_meta['y']])
        ax2xryr.set_data(xrdata - path_and_error[0, se_meta['x']],
                       yrdata - path_and_error[0, se_meta['y']])
        for k in range(0, nmpc['C']):
            update_plot.exec_path[0].append(path_and_error[k, se_meta['x']])
            update_plot.exec_path[1].append(path_and_error[k, se_meta['y']])
        execp.set_data(update_plot.exec_path[0], update_plot.exec_path[1])
    if update_plot.isstep:
        update_plot.isstep = False
        update_plot.pause = True
    return ax1xy, ax1xryr, execp, ax2xy, ax2xryr
Beispiel #2
0
     if len(sd_meta) == 0:
         if (nop.get_block_meta(instream, sd_meta)):
             break
     if (nop.parse_sd_stats(instream, sd_loops, sd_loop_time)):
         break
 # Detect the state and error output block (SE)
 if '(SE)' in line:
     if len(se_meta) == 0:
         if (nop.get_block_meta(instream, se_meta)):
             break
         del se_meta['k']
         # I hate doing this, but for now, parse_path_and_error() doesn't
         # store k, so it needs to be taken from the meta data.
         for key in se_meta:
             se_meta[key] -= 1
     if (nop.parse_path_and_error(instream, nmpc, path_and_error)):
         break
     # Pull first C x,y,v,Dth into the executed path.
     for k in range(0, nmpc["C"]):
         executed_path.append(path_and_error[k])
 # Detect the (LG) Lagrangian and Gradient output block
 if '(LG)' in line:
     if len(lg_meta) == 0:
         if (nop.get_block_meta(instream, lg_meta)):
             break
         del lg_meta['k']
         # I hate doing this, but for now, parse_lagrangian_and_gradient()
         # doesn't store k, so it needs to be taken from the meta data.
         for key in lg_meta:
             lg_meta[key] -= 1
     if (nop.parse_lagrangian_and_gradient(instream, nmpc,