Esempio n. 1
0
def plotAngleEstimationError(X, Y, U_AoA, V_AoA, U_AoU, V_AoU, ERR):
    # Cosmetics
    # plt.title("Bearing error")
    plt.xlabel("x [m]")
    plt.ylabel("y [m]")
    plt.grid(linestyle=':', linewidth=1, color='gainsboro')
    plt.axis('equal')
    plt.axis([0, 650, 0, 500])

    plot.plot_scenario()
    plt.quiver(X, Y, U_AoA, V_AoA, zorder=3, alpha=0.2)

    # Plot terminal
    opt = {
        "marker": "*",
        "markeredgewidth": 2,
        "markersize": 20,
        "color": 'white',
        "markeredgecolor": 'black'
    }
    plot.plot_terminals([TERMINALS[USER]], bsOpt=opt)

    # Weakest-user
    plot.plot_heatmap(X,
                      Y,
                      map(abs, ERR),
                      np.ones(len(X)) * STEP,
                      np.ones(len(X)) * STEP,
                      legend="Bearing error [$^\circ$]")
Esempio n. 2
0
def main(csvPath, resultDir):
    time, sim, drone, users, rss = readData(csvPath)

    df = pd.read_csv(DB_FILE, index_col=0)

    df['rss'] = (df[['re',
                     'im']].apply(lambda row: getRss(row['re'], row['im']),
                                  axis=1))
    df = df.groupby('id').apply(criterion)

    # Cosmetics
    # plt.title("Flight trajectory")
    plt.xlabel("x [m]")
    plt.ylabel("y [m]")
    plt.grid(linestyle=':', linewidth=1, color='gainsboro')
    plt.axis('equal')
    plt.axis([0, 650, 0, 500])

    # Plot
    plot.plot_scenario()

    plot.plot_flight(drone,
                     insideOpt={
                         "color": "black",
                         "markerfacecolor": 'black',
                         "markeredgecolor": 'black'
                     })

    # Plot terminals
    bsOpt = {
        "markeredgewidth": 2,
        "markersize": 15,
        "color": 'white',
        "markeredgecolor": 'black'
    }
    userOpt = {
        "markeredgewidth": 2,
        "markersize": 20,
        "color": 'white',
        "markeredgecolor": 'black'
    }
    plot.plot_terminals(users, bsOpt=bsOpt, userOpt=userOpt)

    # Plot the ground-truth
    plot.plot_heatmap(df['x'].values,
                      df['y'].values,
                      df['rss'].values,
                      np.ones(len(df['x'])) * STEP,
                      np.ones(len(df['x'])) * STEP,
                      legend='RSS [dBm]')

    figureName = os.path.join(resultDir, "flight.png")
    plt.savefig(figureName, bbox_inches='tight', dpi=300)
def plotQuantile(initJob, df, X):
    quantile = df['rss'].quantile(1 - X / 100)

    # print quantile
    d = {}
    for i in range(0, 101):
        d[i] = df['rss'].quantile(i / 100)
    # print(d)

    minRss = min(df['rss'])

    def isHigherQuantile(row):
        return row['rss'] if row['rss'] >= quantile else minRss

    df['rss_quantile'] = df.apply(isHigherQuantile, axis=1)

    # Figure
    plt.title("Top " + str(X) + " % positions")
    plt.xlabel("x [m]")
    plt.ylabel("y [m]")
    plt.grid(linestyle=':', linewidth=1, color='gainsboro')
    plt.axis('equal')
    plt.axis([0, 650, 0, 500])

    # Plot the city
    plot.plot_scenario()

    # Plot terminals
    bsOpt = {
        "markeredgewidth": 2,
        "markersize": 15,
        "color": 'white',
        "markeredgecolor": 'black'
    }
    userOpt = {
        "markeredgewidth": 2,
        "markersize": 20,
        "color": 'white',
        "markeredgecolor": 'black'
    }
    plot.plot_terminals(initJob['terminals'], bsOpt=bsOpt, userOpt=userOpt)

    # Plot the ground-truth
    plot.plot_heatmap(
        df['x'].values,
        df['y'].values,
        df['rss_quantile'].values,
        np.ones(len(df['x'])) * STEP,
        np.ones(len(df['x'])) * STEP,
        legend='RSS [dBm]'
    )
def plotWeakestUser(initJob, df):
    # Figure
    # plt.title("Weakest user")
    plt.xlabel("x [m]")
    plt.ylabel("y [m]")
    plt.grid(linestyle=':', linewidth=1, color='gainsboro')
    plt.axis('equal')
    plt.axis([0, 650, 0, 500])

    # Plot the city
    plot.plot_scenario()

    # Plot terminals
    bsOpt = {
        "marker": "o",
        "markeredgewidth": 1,
        "markersize": 15,
        "color": 'white',
        "markeredgecolor": 'black'
    }
    userOpt = {
        "marker": "*",
        "markeredgewidth": 1,
        "markersize": 20,
        "color": 'white',
        "markeredgecolor": 'black'
    }

    for idx, t in enumerate(initJob['terminals']):
        opt = bsOpt if idx == 0 else userOpt
        color = matplotlib.colors.to_hex(
            plot.CMAP(float(idx) / (len(initJob['terminals']) - 1))
        )
        opt["color"] = color
        # opt["markeredgecolor"] = color
        plot.plot_terminals([t], bsOpt=opt, userOpt={})

    # Plot the weakest-user
    plot.plot_heatmap(
        df['x'].values,
        df['y'].values,
        df['user'].values,
        np.ones(len(df['x'])) * STEP,
        np.ones(len(df['x'])) * STEP,
    )
def plotGroundTruth(initJob, df):
    # Figure
    # plt.title("Ground truth")
    plt.xlabel("x [m]")
    plt.ylabel("y [m]")
    plt.grid(linestyle=':', linewidth=1, color='gainsboro')
    plt.axis('equal')
    plt.axis([0, 650, 0, 500])

    # Plot the city
    plot.plot_scenario()

    # Plot terminals
    bsOpt = {
        "markeredgewidth": 2,
        "markersize": 15,
        "color": 'white',
        "markeredgecolor": 'black'
    }
    userOpt = {
        "markeredgewidth": 2,
        "markersize": 20,
        "color": 'white',
        "markeredgecolor": 'black'
    }
    plot.plot_terminals(initJob['terminals'], bsOpt=bsOpt, userOpt=userOpt)

    # Plot the ground-truth
    plot.plot_heatmap(
        df['x'].values,
        df['y'].values,
        df['rss'].values,
        np.ones(len(df['x'])) * STEP,
        np.ones(len(df['x'])) * STEP,
        legend='RSS [dBm]'
    )
def main():

    exp = utils.readJson(INITIAL_CONF)
    simFiles = [os.path.join(OUTPUT_DIR, f) for f in os.listdir(OUTPUT_DIR)]

    heatmap = np.zeros((MAP_X // STEP, MAP_Y // STEP))

    initRss, finalRss = [], []
    nSucceed = np.zeros(len(QUANTILES))
    N = 0
    for simFile in simFiles:
        N += 1

        df_sim = pd.read_csv(simFile, names=COLS)
        posA = df_sim.iloc[-1]
        posB = df_sim.iloc[-2]
        posC = df_sim.iloc[1]
        posAMinRss = utils.nat2db(
            float(min(posA[['ant.0', 'ant.1', 'ant.2', 'ant.3']])))
        posBMinRss = utils.nat2db(
            float(min(posB[['ant.0', 'ant.1', 'ant.2', 'ant.3']])))
        posCMinRss = utils.nat2db(
            float(min(posC[['ant.0', 'ant.1', 'ant.2', 'ant.3']])))
        for i in range(len(QUANTILES)):
            # if posBMinRss >= QUANTILE or posAMinRss >= QUANTILE:
            if posAMinRss >= QUANTILES[i]:
                nSucceed[i] += 1

        finalRss.append(posAMinRss)
        initRss.append(posCMinRss)

        i = int(float(posA['drone.x']) // STEP)
        j = int(float(posA['drone.y']) // STEP)

        # TODO fix this
        if i == 65:
            i -= 1
        if j == 50:
            j -= 1

        # plt.plot([i*10], [j*10], 'og')

        heatmap[i, j] += 1

    # print("{:.2f}% of simulation endup in top {:d}% positions"
    #       .format(float(nSucceed) / N * 100, TOP))

    # OMG Really ? xD
    # TODO learn meshgrid
    X, Y, Z = [], [], []
    for x in range(0, 650, STEP):
        for y in range(0, 500, STEP):
            i = x // 10
            j = y // 10
            X.append(x)
            Y.append(y)
            Z.append(heatmap[i, j] * 100 / N)

    # Plot
    # Cumulative sum
    plt.figure()
    plotCdfRss(finalRss)
    plotCdfRss(initRss)
    # Cosmetics
    # plt.title("RSS Empirical CDF for d = " + d)
    plt.xlabel("RSS [dBm]")
    plt.ylabel("Percentage [%]")
    plt.grid(linestyle=':', linewidth=1, color='gainsboro')

    figureName = os.path.join(os.getcwd(), "cdf-" + d + ".png")
    plt.savefig(figureName, bbox_inches='tight', dpi=300)
    plt.close()

    # Cosmetics
    # plt.title("Arrival density - d = " + d + " (" + str(N) + " simulations)")
    plt.xlabel("x [m]")
    plt.ylabel("y [m]")
    plt.grid(linestyle=':', linewidth=1, color='gainsboro')
    plt.axis('equal')
    plt.axis([0, 650, 0, 500])

    # Plot map
    plot.plot_scenario(edge='gainsboro', face='whitesmoke')

    # Plot terminals
    bsOpt = {
        "markeredgewidth": 2,
        "markersize": 15,
        "color": 'white',
        "markeredgecolor": 'black'
    }
    userOpt = {
        "markeredgewidth": 2,
        "markersize": 20,
        "color": 'white',
        "markeredgecolor": 'black'
    }
    plot.plot_terminals(exp['terminals'], bsOpt=bsOpt, userOpt=userOpt)

    # Plot heatmap of arrival
    plot.plot_heatmap(X,
                      Y,
                      Z,
                      np.ones(len(X)) * STEP,
                      np.ones(len(X)) * STEP,
                      legend="Arrival density [%]")

    figureName = os.path.join(os.getcwd(), "monteCarlo-" + d + ".png")
    plt.savefig(figureName, bbox_inches='tight', dpi=300)
    plt.close()