예제 #1
0
def main():
    rho_max = 8.0
    args = getParserArgs()
    filepath = args.filepath
    sys.path.append(filepath)
    namefile = args.namefile
    geoFile = args.geoname
    trajpath = args.trajpath
    #geoLocation = filepath.split("Output")[0]
    trajName = namefile.split(".")[0]
    trajType = namefile.split(".")[1].split("_")[0]
    trajFile = os.path.join(trajpath, trajName+"."+trajType) #trajpath+trajName+"."+trajType
    plotIndex = args.index
    logging.info("plot_cell_rho trajpath %s", trajpath)
    logging.info("plot_cell_rho  trajName %s", trajName+"."+trajType)
    logging.info("plot_cell_rho trajFile %s", trajFile)
    try:
        frameNr = int(namefile.split("_")[-1])
    except ValueError:
        exit("ERROR: Could not parse fps")

    geominX, geomaxX, geominY, geomaxY = get_geometry_boundary(geoFile)
    fig = plt.figure(figsize=(16*(geomaxX-geominX)/(geomaxY-geominY)+2, 16), dpi=100)
    ax1 = fig.add_subplot(111, aspect='equal')
    #plt.rc("font", size=30)
    #plt.rc('pdf', fonttype=42)
    #ax1.set_yticks([int(1*j) for j in range(-2, 5)])
    #for label in ax1.get_xticklabels() + ax1.get_yticklabels():
    #    label.set_fontsize(30)

    #for tick in ax1.get_xticklines() + ax1.get_yticklines():
    #    tick.set_markeredgewidth(2)
    #    tick.set_markersize(6)
    #    ax1.set_aspect("equal")

    plot_geometry(geoFile)

    density = np.array([])
    density_orig = np.array([])
    polygons = [] # polygons converted from string
    polygon_filename = os.path.join(filepath, "polygon"+namefile+".dat")
    File = open(polygon_filename)
    polys = File.readlines()
    File.close()
    # plot the blue dots (head) first, to avoid intervening with "text"
    # ---------------------------------------------------
    # if  not plotIndex:
    #     if(trajType == "xml"):
    #         fps, N, Trajdata = parse_xml_traj_file(trajFile)
    #     elif(trajType == "txt"):
    #         try:
    #             Trajdata = np.array(pd.read_csv(trajFile, comment="#", delimiter=r"\s+"))
    #         except:
    #             Trajdata = np.loadtxt(trajFile)

    #     Trajdata = Trajdata[Trajdata[:, 1] == frameNr]
    #     ax1.plot(Trajdata[:, 2], Trajdata[:, 3], "bo", markersize=20, markeredgewidth=2)
    # ---------------------------------------------------

    #polys = open("%s/polygon%s.dat"%(filepath,namefile)).readlines()
    poly_index = []
    areas = []
    for poly in polys:
        poly = poly.split("|")
        poly_index.append(poly[0].strip())
        Poly = poly[1].strip()
        exec("p = %s"%Poly)
        pp = locals()['p']
        polygons.append(pp)
        area = pol.Polygon(pp).area()
        xx = 1.0/area
        if xx > rho_max:
            xx = rho_max

        density = np.append(density, xx)
        areas.append(area)

    density_orig = np.copy(density)
    Maxd = density.max()
    Mind = density.min()
    erro = np.ones(np.shape(density))*Mind
    density = rho_max*(density-erro)/(Maxd-Mind)
    sm = cm.ScalarMappable(cmap=cm.jet)
    sm.set_array(density)
    sm.autoscale_None()
    sm.set_clim(vmin=0, vmax=10)
    maxArea = np.max(areas)
    meanArea = np.mean(areas)
    for j, poly in enumerate(polys):
        ax1.add_patch(pgon(polygons[j], fc=sm.to_rgba(density_orig[j]), ec='white', lw=2))
        bcolor = sm.to_rgba(density_orig[j]) #inverse background color
        icolor = [1 - c for c in bcolor]
        icolor[-1] = bcolor[-1] # alpha
        if plotIndex:
            ax1.text(pol.Polygon(polygons[j]).center()[0],
                     pol.Polygon(polygons[j]).center()[1],
                     poly_index[j],
                     fontsize=25*areas[j]/maxArea, color=icolor)

    ax1.set_xlim(geominX-0.2, geomaxX+0.2)
    ax1.set_ylim(geominY-0.2, geomaxY+0.2)
    plt.xlabel("x [m]")
    plt.ylabel("y [m]")
    plt.axhline(y=2.5)
    plt.axvline(x=0.0)
    plt.title("%s"%namefile)
    divider = make_axes_locatable(ax1)
    cax = divider.append_axes("right", size="2.5%", pad=0.2)
    cb = fig.colorbar(sm, ax=ax1, cax=cax, format='%.1f')
    cb.set_label('Density [$m^{-2}$]')
    figname = os.path.join(filepath, "rho_"+namefile+".png")
    logging.info("SAVE: %s", figname)
    plt.savefig(figname)
    plt.close()
예제 #2
0
    polys = File.readlines()
    velocity_filename = os.path.join(filepath, "speed"+namefile+".dat")
    velocity = np.loadtxt(velocity_filename)
    sm = cm.ScalarMappable(cmap=cm.jet)
    sm.set_array(velocity)
    sm.autoscale_None()
    sm.set_clim(vmin=0, vmax=1.5)
    index = 0
    for poly in polys:
        poly = poly.split("|")
        poly_index = poly[0].strip()
        Poly = poly[1].strip()
        exec("p = %s"%Poly)
        xx = velocity[index]
        index += 1
        ax1.add_patch(pgon(p,facecolor=sm.to_rgba(xx), edgecolor='white',linewidth=2))
        # todo
        #if plotIndex:
        # ax1.text(pol.Polygon(polygons[j]).center()[0], pol.Polygon(polygons[j]).center()[1], poly_index,
        #          horizontalalignment='center',
        #          verticalalignment='center',
        #          fontsize=20, color='red',
        #          transform=ax1.transAxes)

    if(trajType == "xml"):
        fps, N, Trajdata = parse_xml_traj_file(trajFile)
    elif(trajType == "txt"):
        Trajdata = np.loadtxt(trajFile)

    Trajdata = Trajdata[Trajdata[:, 1] == frameNr]
    ax1.plot(Trajdata[:, 2], Trajdata[:, 3], "bo", markersize=20, markeredgewidth=2)
예제 #3
0
def main():
    rho_max = 8.0
    args = getParserArgs()
    filepath = args.filepath
    sys.path.append(filepath)
    namefile = args.namefile
    geoFile = args.geoname
    trajpath = args.trajpath
    #geoLocation = filepath.split("Output")[0]
    trajName = namefile.split(".")[0]
    trajType = namefile.split(".")[1].split("_")[0]
    trajFile = os.path.join(trajpath, trajName + "." +
                            trajType)  #trajpath+trajName+"."+trajType
    plotIndex = args.index
    logging.info("plot_cell_rho trajpath %s", trajpath)
    logging.info("plot_cell_rho  trajName %s", trajName + "." + trajType)
    logging.info("plot_cell_rho trajFile %s", trajFile)
    try:
        frameNr = int(namefile.split("_")[-1])
    except ValueError:
        exit("ERROR: Could not parse fps")

    geominX, geomaxX, geominY, geomaxY = get_geometry_boundary(geoFile)
    fig = plt.figure(figsize=(16 * (geomaxX - geominX) / (geomaxY - geominY) +
                              2, 16),
                     dpi=100)
    ax1 = fig.add_subplot(111, aspect='equal')
    #plt.rc("font", size=30)
    #plt.rc('pdf', fonttype=42)
    #ax1.set_yticks([int(1*j) for j in range(-2, 5)])
    #for label in ax1.get_xticklabels() + ax1.get_yticklabels():
    #    label.set_fontsize(30)

    #for tick in ax1.get_xticklines() + ax1.get_yticklines():
    #    tick.set_markeredgewidth(2)
    #    tick.set_markersize(6)
    #    ax1.set_aspect("equal")

    plot_geometry(geoFile)

    density = np.array([])
    density_orig = np.array([])
    polygons = []  # polygons converted from string
    polygon_filename = os.path.join(filepath, "polygon" + namefile + ".dat")
    File = open(polygon_filename)
    polys = File.readlines()
    File.close()
    # plot the blue dots (head) first, to avoid intervening with "text"
    # ---------------------------------------------------
    # if  not plotIndex:
    #     if(trajType == "xml"):
    #         fps, N, Trajdata = parse_xml_traj_file(trajFile)
    #     elif(trajType == "txt"):
    #         try:
    #             Trajdata = np.array(pd.read_csv(trajFile, comment="#", delimiter=r"\s+"))
    #         except:
    #             Trajdata = np.loadtxt(trajFile)

    #     Trajdata = Trajdata[Trajdata[:, 1] == frameNr]
    #     ax1.plot(Trajdata[:, 2], Trajdata[:, 3], "bo", markersize=20, markeredgewidth=2)
    # ---------------------------------------------------

    #polys = open("%s/polygon%s.dat"%(filepath,namefile)).readlines()
    poly_index = []
    areas = []
    for poly in polys:
        poly = poly.split("|")
        poly_index.append(poly[0].strip())
        Poly = poly[1].strip()
        exec("p = %s" % Poly)
        pp = locals()['p']
        polygons.append(pp)
        area = pol.Polygon(pp).area()
        xx = 1.0 / area
        if xx > rho_max:
            xx = rho_max

        density = np.append(density, xx)
        areas.append(area)

    density_orig = np.copy(density)
    Maxd = density.max()
    Mind = density.min()
    erro = np.ones(np.shape(density)) * Mind
    density = rho_max * (density - erro) / (Maxd - Mind)
    sm = cm.ScalarMappable(cmap=cm.jet)
    sm.set_array(density)
    sm.autoscale_None()
    sm.set_clim(vmin=0, vmax=10)
    maxArea = np.max(areas)
    meanArea = np.mean(areas)
    for j, poly in enumerate(polys):
        ax1.add_patch(
            pgon(polygons[j], fc=sm.to_rgba(density_orig[j]), ec='white',
                 lw=2))
        bcolor = sm.to_rgba(density_orig[j])  #inverse background color
        icolor = [1 - c for c in bcolor]
        icolor[-1] = bcolor[-1]  # alpha
        if plotIndex:
            ax1.text(pol.Polygon(polygons[j]).center()[0],
                     pol.Polygon(polygons[j]).center()[1],
                     poly_index[j],
                     fontsize=25 * areas[j] / maxArea,
                     color=icolor)

    ax1.set_xlim(geominX - 0.2, geomaxX + 0.2)
    ax1.set_ylim(geominY - 0.2, geomaxY + 0.2)
    plt.xlabel("x [m]")
    plt.ylabel("y [m]")
    plt.axhline(y=2.5)
    plt.axvline(x=0.0)
    plt.title("%s" % namefile)
    divider = make_axes_locatable(ax1)
    cax = divider.append_axes("right", size="2.5%", pad=0.2)
    cb = fig.colorbar(sm, ax=ax1, cax=cax, format='%.1f')
    cb.set_label('Density [$m^{-2}$]')
    figname = os.path.join(filepath, "rho_" + namefile + ".png")
    logging.info("SAVE: %s", figname)
    plt.savefig(figname)
    plt.close()