This repository has been archived on 2023-08-28. You can view files and clone it, but cannot push or open issues or pull requests.
ntr-interferences/plot/main.py

117 lines
3.3 KiB
Python
Raw Normal View History

2023-03-24 10:37:35 +01:00
import os
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
2023-04-14 21:01:23 +02:00
nb_files = os.listdir("PF")
2023-03-24 10:37:35 +01:00
size = len(nb_files)
def mean_mkn(arr: list[tuple[int, np.ndarray]]) -> np.ndarray:
2023-03-24 11:12:40 +01:00
averages_mkn = np.empty((size, 2))
nb = 0
for nb_users, data in arr:
2023-03-24 11:12:40 +01:00
rb = data[:, 4]
total = 0.0
for x in rb:
total = total + x
average = total / len(rb)
averages_mkn[nb, 0] = nb_users
2023-03-24 11:12:40 +01:00
averages_mkn[nb, 1] = average
nb += 1
return averages_mkn
def rb_available(arr: list[tuple[int, np.ndarray]]) -> np.ndarray:
2023-03-24 11:41:34 +01:00
available = np.zeros((size, 2))
nb = 0
for nb_users, data in arr:
available[nb, 0] = nb_users
2023-04-14 21:01:23 +02:00
available[nb, 1] = (data.shape[0] / (200 * 20000)) * 100
2023-03-24 11:41:34 +01:00
nb += 1
return available
def delay(arr: list[tuple[int, np.ndarray]]) -> np.ndarray:
2023-03-28 09:25:04 +02:00
delays = np.zeros((size, 2))
nb = 0
for nb_users, data in arr:
2023-03-28 09:25:04 +02:00
d = data[:, 5]
for x in d:
delays[nb, 0] = nb_users
2023-03-28 09:25:04 +02:00
delays[nb, 1] = float(x)
nb += 1
return delays
2023-03-24 11:41:34 +01:00
def rb_allocate_distance(arr: list[tuple[int, np.ndarray]], distance) -> np.ndarray:
allocate = np.zeros((size, 2))
nb = 0
arr.sort()
for nb_users, data in arr:
n = 0
for x in data[:,6]:
if int(x) == distance:
n+=1
allocate[nb, 0] = nb_users
allocate[nb, 1] = n
# print(n/data.shape[0])
nb += 1
return allocate
np_arr: list[tuple[int, np.ndarray]] = list()
for i in nb_files:
2023-04-14 21:01:23 +02:00
np_arr.append((int(i.split(".")[0]), pd.read_csv("PF" + os.sep + i, delimiter=';').to_numpy()))
averages = mean_mkn(np_arr)
available = rb_available(np_arr)
2023-04-14 21:01:23 +02:00
allocate_lp1 = rb_allocate_distance(np_arr, 100)
allocate_lp2 = rb_allocate_distance(np_arr, 500)
allocate_total = allocate_lp1[:, 1] + allocate_lp2[:, 1]
delays = delay(np_arr)
2023-03-28 09:35:26 +02:00
delays.sort(axis=0)
2023-03-24 10:37:35 +01:00
# Data for plotting
averages.sort(axis=0)
available.sort(axis=0)
2023-03-24 10:37:35 +01:00
del np_arr
2023-03-31 12:04:57 +02:00
fig, ax = plt.subplots(2, 2)
ax[0, 0].plot(averages[:, 0], averages[:, 1], marker="o")
2023-04-14 21:01:23 +02:00
ax[0, 0].set(xlabel='number of users', ylabel='% Spectral efficiency', title='Spectral efficiency PF')
2023-03-31 12:04:57 +02:00
ax[0, 0].grid()
2023-04-14 21:01:23 +02:00
ax[0, 0].set_ylim([0, 40])
2023-03-31 12:04:57 +02:00
ax[0, 1].plot(available[:, 0], available[:, 1], marker="o")
2023-04-14 21:01:23 +02:00
ax[0, 1].set(xlabel='number of users', ylabel=' % RB used', title='Percentage of RB used PF')
2023-03-31 12:04:57 +02:00
ax[0, 1].grid()
2023-04-14 21:01:23 +02:00
ax[0, 1].set_ylim([0, 105])
2023-03-31 12:04:57 +02:00
ax[1, 0].plot(delays[:, 0], delays[:, 1], marker="o")
2023-04-14 21:01:23 +02:00
ax[1, 0].set(xlabel='number of users', ylabel='delay(ms)', title='Delay PF')
2023-03-31 12:04:57 +02:00
ax[1, 0].grid()
available.sort(axis=0)
#ax[1, 1].scatter(allocate_lp1[:, 0], (allocate_lp1[:, 1]/(allocate_lp1[:, 1])+allocate_lp2[:, 1])*100)
2023-04-14 21:01:23 +02:00
ax[1, 1].plot(available[:, 0], (allocate_lp1[:, 1]/(allocate_lp1[:, 1]+allocate_lp2[:, 1])*100), label="100 meters group")
#ax[1, 1].scatter(allocate_lp2[:, 0], (allocate_lp2[:, 1]/(allocate_lp1[:, 1])+allocate_lp2[:, 1])*100)
2023-04-14 21:01:23 +02:00
#ax[1, 1].plot(available[:, 0], available[:, 1], marker="o", label="RB used")
2023-04-14 21:01:23 +02:00
ax[1, 1].plot(available[:, 0], (allocate_lp2[:, 1]/(allocate_lp1[:, 1]+allocate_lp2[:, 1])*100), label="500 meters group")
ax[1, 1].set(xlabel='number of users', ylabel='% RB used', title='RB used depending on the distance PF')
ax[1, 1].grid()
2023-04-14 21:01:23 +02:00
ax[1, 1].set_ylim([0, 105])
ax[1, 1].legend(loc="upper left")
2023-04-14 21:01:23 +02:00
plt.show()