add random objects instead
This commit is contained in:
parent
88f5330366
commit
678e30c891
|
|
@ -18,6 +18,25 @@ from libs.spacemap import SpaceBlock
|
|||
from libs.plotting import plotSpace
|
||||
|
||||
|
||||
def addRandomObject(floormap):
|
||||
'''
|
||||
'''
|
||||
loss_p = np.random.randint(-20, -5)
|
||||
loss_r = np.random.randint(-20, -5)
|
||||
i = np.random.randint(2, 62)
|
||||
j = np.random.randint(2, 62)
|
||||
for ii in range(i-2, i+2):
|
||||
floormap.setLoss(ii, j-2, loss_p, loss_r)
|
||||
floormap.setOrientation(ii, j-2, 0)
|
||||
floormap.setLoss(ii, j+2, loss_p, loss_r)
|
||||
floormap.setOrientation(ii, j+2, 0)
|
||||
for jj in range(j-2, j+2):
|
||||
floormap.setLoss(i-2, jj, loss_p, loss_r)
|
||||
floormap.setOrientation(i-2, jj, 90)
|
||||
floormap.setLoss(i+2, jj, loss_p, loss_r)
|
||||
floormap.setOrientation(i+2, jj, 90)
|
||||
|
||||
|
||||
def getRandomTXLocs(
|
||||
num: int,
|
||||
width: float,
|
||||
|
|
@ -57,22 +76,11 @@ def log_gamma_floorplan_multi(floormap, rx_loc, tx_loc, power, gaussian_noise, r
|
|||
|
||||
def floormap_noise_injection(floormap, args):
|
||||
if not args.floormap_rand:
|
||||
return
|
||||
for i in range(floormap.map.shape[0]):
|
||||
for j in range(floormap.map.shape[1]):
|
||||
if np.random.random() < (1-args.floormap_rand_prob):
|
||||
continue
|
||||
loss_p, loss_r = floormap.getLoss(i, j)
|
||||
loss_r = np.random.randint(-3, 3) - 10
|
||||
floormap.setLoss(
|
||||
i, j,
|
||||
min(loss_p + np.random.randint(-10, 5), 0.0),
|
||||
loss_r
|
||||
)
|
||||
floormap.setOrientation(
|
||||
i, j,
|
||||
np.random.random() * 2 * np.pi - np.pi
|
||||
)
|
||||
return 0
|
||||
num_of_objects_to_add = np.random.randint(5, 20)
|
||||
for __ in range(num_of_objects_to_add):
|
||||
addRandomObject(floormap)
|
||||
return num_of_objects_to_add
|
||||
|
||||
|
||||
def generateData(floormap, tx_locs, args):
|
||||
|
|
@ -104,12 +112,13 @@ def generateData(floormap, tx_locs, args):
|
|||
fp_base = "{0}/img_{1:.2f}_{2:.2f}_2.0".format(folderp, tx_locs[i, 0] - 3.2, tx_locs[i, 1] - 3.2)
|
||||
for power in powers:
|
||||
rss_vec = []
|
||||
num_of_objs = 0
|
||||
starttime = int(time.time())
|
||||
# tx_loc = SpaceBlock(3.2, 3.2)
|
||||
tx_loc = SpaceBlock(tx_locs[i, 0], tx_locs[i, 1])
|
||||
if args.floormap_rand:
|
||||
floormap = getFloormap(args)
|
||||
floormap_noise_injection(floormap, args)
|
||||
num_of_objs = floormap_noise_injection(floormap, args)
|
||||
floormap.traceRays(power, tx_loc)
|
||||
for j in range(0, rx_locs.shape[0], args.procnum):
|
||||
procs = []
|
||||
|
|
@ -155,7 +164,7 @@ def generateData(floormap, tx_locs, args):
|
|||
orient = floormap.getOrientations()
|
||||
|
||||
with open("{}_{}_floormap.pickle".format(fp_base, int(power)), 'wb') as f:
|
||||
pickle.dump([loss_p, loss_r, orient], f, pickle.HIGHEST_PROTOCOL)
|
||||
pickle.dump([loss_p, loss_r, orient, num_of_objs], f, pickle.HIGHEST_PROTOCOL)
|
||||
|
||||
|
||||
def getFloormap(args):
|
||||
|
|
|
|||
|
|
@ -8,14 +8,60 @@ sys.path.append("../..") # Adds higher directory to python modules path
|
|||
import os
|
||||
import time
|
||||
import numpy as np
|
||||
from multiprocessing import Process
|
||||
from multiprocessing import Manager
|
||||
|
||||
from libs.util import convert_vector_to_mat
|
||||
from libs.models import log_gamma_floorplan
|
||||
from libs.spacemap import SpaceBlock
|
||||
from libs.spacemap import SpaceRay
|
||||
from libs.spacemap import SpaceMap
|
||||
from libs.plotting import plotSpace
|
||||
from libs.plotting import plotRSS
|
||||
|
||||
|
||||
def getLocs(loc_x_range, loc_y_range, step_size: float = 0.3):
|
||||
loc_xs = np.arange(loc_x_range[0], loc_x_range[1] + step_size, step_size)
|
||||
loc_ys = np.arange(loc_y_range[0], loc_y_range[1] + step_size, step_size)
|
||||
return np.stack(np.meshgrid(loc_xs, loc_ys), -1).reshape(-1, 2)
|
||||
|
||||
|
||||
def log_gamma_floorplan_multi(floormap, rx_loc, tx_loc, power, gaussian_noise, results, kk):
|
||||
rss, __ = log_gamma_floorplan(
|
||||
floormap,
|
||||
rx_loc,
|
||||
tx_loc,
|
||||
power,
|
||||
gaussian_noise=gaussian_noise
|
||||
)
|
||||
# print(kk, rss)
|
||||
results[kk] = rss
|
||||
|
||||
|
||||
def test():
|
||||
|
||||
def addRandomObject(penetrations, reflections, orientations):
|
||||
'''
|
||||
'''
|
||||
loss_p = np.random.randint(-20, -5)
|
||||
loss_r = np.random.randint(-20, -5)
|
||||
i = np.random.randint(2, 62)
|
||||
j = np.random.randint(2, 62)
|
||||
for ii in range(i-2, i+2):
|
||||
penetrations[ii, j-2] = loss_p
|
||||
reflections[ii, j-2] = wall_reflection
|
||||
orientations[ii, j-2] = 0
|
||||
penetrations[ii, j+2] = loss_p
|
||||
reflections[ii, j+2] = wall_reflection
|
||||
orientations[ii, j+2] = 0
|
||||
for jj in range(j-2, j+2):
|
||||
penetrations[i-2, jj] = loss_p
|
||||
reflections[i-2, jj] = wall_reflection
|
||||
orientations[i-2, jj] = 90
|
||||
penetrations[i+2, jj] = loss_p
|
||||
reflections[i+2, jj] = wall_reflection
|
||||
orientations[i+2, jj] = 90
|
||||
|
||||
def setWalls(i, j, orientation_deg):
|
||||
penetrations[i, j] = wall_penetration
|
||||
reflections[i, j] = wall_reflection
|
||||
|
|
@ -30,7 +76,7 @@ def test():
|
|||
reflections = np.ones((64, 64), dtype=float) * -100.0
|
||||
orientations = np.empty((64, 64), dtype=float) * float('nan')
|
||||
|
||||
spacemap = SpaceMap(width=6.4, length=6.4, block_size=0.1)
|
||||
floormap = SpaceMap(width=6.4, length=6.4, block_size=0.1)
|
||||
|
||||
# add walls
|
||||
wall_penetration = -20.0
|
||||
|
|
@ -48,24 +94,41 @@ def test():
|
|||
setGlasses(61, j, 90)
|
||||
for i in range(7, 62): # down
|
||||
setWalls(i, 5, 0)
|
||||
spacemap.setLosses(penetrations, reflections)
|
||||
spacemap.setOrientations(orientations)
|
||||
|
||||
plotSpace(spacemap, cminmax=(-50, 0.0))
|
||||
np.random.seed(None)
|
||||
num_of_objects_to_add = np.random.randint(5, 20)
|
||||
for __ in range(num_of_objects_to_add):
|
||||
addRandomObject(penetrations, reflections, orientations)
|
||||
|
||||
floormap.setLosses(penetrations, reflections)
|
||||
floormap.setOrientations(orientations)
|
||||
|
||||
plotSpace(floormap, cminmax=(-50, 0.0))
|
||||
|
||||
rx_locs = getLocs([0, 6.3], [0, 6.3], step_size=0.1)
|
||||
rss_vec = []
|
||||
power = -40.0
|
||||
starttime = int(time.time())
|
||||
tx_loc = SpaceBlock(3.2, 3.2)
|
||||
floormap.traceRays(power, tx_loc)
|
||||
for j in range(0, rx_locs.shape[0], 8):
|
||||
procs = []
|
||||
results = Manager().dict()
|
||||
actual_num = min(8, rx_locs.shape[0] - j)
|
||||
for kk in range(actual_num):
|
||||
rx_loc = SpaceBlock(rx_locs[j + kk, 0], rx_locs[j + kk, 1])
|
||||
proc = Process(
|
||||
target=log_gamma_floorplan_multi,
|
||||
args=(floormap, rx_loc, tx_loc, power, False, results, kk)
|
||||
)
|
||||
proc.start()
|
||||
procs.append(proc)
|
||||
for proc in procs:
|
||||
proc.join()
|
||||
rss_vec.extend([results[kk] for kk in range(actual_num)])
|
||||
rss_map = convert_vector_to_mat(rx_locs, np.array(rss_vec), (64, 64))
|
||||
plotRSS(rss_map, cminmax=(-85,-30))
|
||||
|
||||
rx_locs = []
|
||||
for i in range(64):
|
||||
rx_locs.append(SpaceBlock(0 + i * 0.1, 4.4))
|
||||
spacemap.traceRays(-40, SpaceBlock(3.2, 3.2))
|
||||
for rx_loc in rx_locs:
|
||||
rx_loc_rss, rx_loc_paths = spacemap.traceRay(rx_loc)
|
||||
multipaths = []
|
||||
for path in rx_loc_paths:
|
||||
# print("found path: {}".format(path))
|
||||
multipaths.extend(list(path))
|
||||
print("{:.6f}".format(rx_loc_rss))
|
||||
plotSpace(spacemap, space_rays=multipaths, cminmax=(-50, 0.0))
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
|
|||
Loading…
Reference in New Issue