add floorplan syn gen, still very slow :(
This commit is contained in:
parent
0f86737da0
commit
2c3aea76c9
|
|
@ -0,0 +1,62 @@
|
|||
#!/usr/bin/python
|
||||
|
||||
import pickle
|
||||
import argparse
|
||||
import numpy as np
|
||||
|
||||
|
||||
def main(args):
|
||||
exproom()
|
||||
print("bazinga!")
|
||||
|
||||
|
||||
def exproom():
|
||||
|
||||
def setWalls(i, j, orientation_deg):
|
||||
penetrations[i, j] = wall_penetration
|
||||
reflections[i, j] = wall_reflection
|
||||
orientations[i, j] = orientation_deg / 180 * np.pi
|
||||
|
||||
def setGlasses(i, j, orientation_deg):
|
||||
penetrations[i, j] = glass_penetration
|
||||
reflections[i, j] = glass_reflection
|
||||
orientations[i, j] = orientation_deg / 180 * np.pi
|
||||
|
||||
# manualllyyyyyyyy
|
||||
penetrations = np.zeros((64, 64), dtype=float)
|
||||
reflections = np.ones((64, 64), dtype=float) * -100.0
|
||||
orientations = np.empty((64, 64), dtype=float) * float('nan')
|
||||
|
||||
wall_penetration = -20.0
|
||||
wall_reflection = -3.0
|
||||
glass_penetration = -3.0
|
||||
glass_reflection = -3.0
|
||||
# walls
|
||||
for j in range(5, 61): # left
|
||||
setWalls(7, j, 90)
|
||||
for i in range(7, 62): # up
|
||||
setWalls(i, 60, 0)
|
||||
for j in range(29, 60): # right
|
||||
setWalls(61, j, 90)
|
||||
for j in range(5, 29): # right
|
||||
setGlasses(61, j, 90)
|
||||
for i in range(7, 62): # down
|
||||
setWalls(i, 5, 0)
|
||||
|
||||
pickle.dump(
|
||||
[penetrations, reflections, orientations],
|
||||
open("./floormaps/exp_room.pickle", "wb"), pickle.HIGHEST_PROTOCOL
|
||||
)
|
||||
|
||||
return
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
p = argparse.ArgumentParser(description='Floormap Editor')
|
||||
try:
|
||||
args = p.parse_args()
|
||||
except BaseException as e:
|
||||
print(e)
|
||||
sys.exit()
|
||||
|
||||
main(args)
|
||||
Binary file not shown.
|
|
@ -46,3 +46,18 @@ def log_gamma_dist(
|
|||
rss[rss < NOISE_FLOOR] = NOISE_FLOOR
|
||||
rss[rss > pwr] = pwr
|
||||
return rss
|
||||
|
||||
|
||||
def log_gamma_floorplan(
|
||||
floorplan,
|
||||
rx_loc,
|
||||
tx_loc,
|
||||
pwr: float,
|
||||
gaussian_noise: bool = False
|
||||
):
|
||||
if isinstance(rx_loc, list) or isinstance(rx_loc, tuple):
|
||||
print("err: only support a single loc")
|
||||
return
|
||||
noise = normal(GAUSSIAN_NOISE_MEAN, GAUSSIAN_NOISE_STD) if gaussian_noise else 0.0
|
||||
rss, paths = floorplan.traceRay(pwr, tx_loc, rx_loc)
|
||||
return max(rss + noise, NOISE_FLOOR), paths
|
||||
|
|
|
|||
|
|
@ -359,7 +359,14 @@ class SpaceMap():
|
|||
for i in range(self.map.shape[0]):
|
||||
self.setLoss(i, j, penetrations[i ,j], reflections[i, j])
|
||||
|
||||
def setOrientations(self, orientations):
|
||||
for j in range(self.map.shape[1]):
|
||||
for i in range(self.map.shape[0]):
|
||||
self.setOrientation(i, j, orientations[i ,j])
|
||||
|
||||
def setOrientation(self, i, j, orientation):
|
||||
if np.isnan(orientation):
|
||||
orientation = None
|
||||
self.map[i, j].setOrientation(orientation)
|
||||
|
||||
def setLoss(self, i, j, penetration, reflection):
|
||||
|
|
@ -377,7 +384,7 @@ class SpaceMap():
|
|||
def setEnvGamma(self, val: float):
|
||||
self.env_gamma = val
|
||||
|
||||
def traceRay(self, tx_power: float, tx_loc: SpaceBlock, rx_loc: SpaceBlock, debug: bool = False):
|
||||
def traceRay(self, tx_power: float, tx_loc: SpaceBlock, rx_loc: SpaceBlock):
|
||||
def getPathFromRay(ray, stop_blk):
|
||||
path = SpaceRay(ray.start, stop_blk)
|
||||
# prevent 0 distance
|
||||
|
|
@ -503,4 +510,3 @@ class SpaceMap():
|
|||
# clean up for too nearby paths
|
||||
removeRedundantPaths(rx_loc_paths)
|
||||
return aggreatePower(rx_loc_paths), rx_loc_paths
|
||||
|
||||
|
|
@ -0,0 +1,213 @@
|
|||
#!/usr/bin/python
|
||||
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
import pickle
|
||||
import argparse
|
||||
import numpy as np
|
||||
from multiprocessing import Process
|
||||
|
||||
from libs.util import convert_vector_to_mat
|
||||
from libs.consts import RANDOM_SEED_TEST
|
||||
from libs.consts import RANDOM_SEED_TRAIN
|
||||
from libs.models import log_gamma_floorplan
|
||||
from libs.spacemap import SpaceMap
|
||||
from libs.spacemap import SpaceBlock
|
||||
from libs.plotting import plotSpace
|
||||
|
||||
|
||||
def getRandomTXLocs(
|
||||
num: int,
|
||||
width: float,
|
||||
length: float,
|
||||
offset_w: float = 0.0,
|
||||
offset_l: float = 0.0
|
||||
):
|
||||
'''
|
||||
'''
|
||||
xys = np.random.rand(num, 2)
|
||||
xys[:, 0] = xys[:, 0] * width + offset_w
|
||||
xys[:, 1] = xys[:, 1] * length + offset_l
|
||||
return xys
|
||||
|
||||
|
||||
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 getPowers(power_range, step_size: float = 2):
|
||||
return np.arange(power_range[0], power_range[1] + step_size, step_size)
|
||||
|
||||
|
||||
def log_gamma_floorplan_multi(floormap, rx_loc, tx_loc, power, gaussian_noise, results, idx):
|
||||
rss, __ = log_gamma_floorplan(
|
||||
floormap,
|
||||
rx_loc,
|
||||
tx_loc,
|
||||
power,
|
||||
gaussian_noise=gaussian_noise
|
||||
)
|
||||
results[idx] = rss
|
||||
|
||||
|
||||
def generateData(floormap, tx_locs, args):
|
||||
'''
|
||||
'''
|
||||
if args.train:
|
||||
tag = "input_synthetic_train"
|
||||
elif args.train_real:
|
||||
tag = "input_real_emu_train"
|
||||
elif args.test:
|
||||
tag = "testing_real_emu"
|
||||
tag = "{0}".format(tag)
|
||||
if args.withnoise:
|
||||
tag = "{}_noise_10dBvar".format(tag)
|
||||
|
||||
# create folder
|
||||
folderp = "{}/{}".format(args.outfolder, tag)
|
||||
if not os.path.isdir(folderp):
|
||||
try:
|
||||
os.makedirs(folderp)
|
||||
except BaseException as e:
|
||||
print("err: {}".format(e))
|
||||
sys.exit(-1)
|
||||
|
||||
# generate
|
||||
rx_locs = getLocs([0, 6.3], [0, 6.3], step_size=0.1)
|
||||
powers = getPowers([-40, 30])
|
||||
for i in range(tx_locs.shape[0]):
|
||||
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 = []
|
||||
starttime = int(time.time())
|
||||
for j in range(0, rx_locs.shape[0], args.procnum):
|
||||
procs = []
|
||||
results = [None] * args.procnum
|
||||
for kk in range(args.procnum):
|
||||
rx_loc = SpaceBlock(rx_locs[j, 0], rx_locs[j, 1])
|
||||
tx_loc = SpaceBlock(rx_locs[i, 0], rx_locs[i, 1])
|
||||
proc = Process(
|
||||
target=log_gamma_floorplan_multi,
|
||||
args=(floormap, rx_loc, tx_loc, power, args.withnoise, results, kk,)
|
||||
)
|
||||
proc.start()
|
||||
procs.append(proc)
|
||||
for proc in procs:
|
||||
proc.join()
|
||||
rss_vec.extend(results)
|
||||
# rss, multipaths = log_gamma_floorplan(
|
||||
# floormap,
|
||||
# rx_loc,
|
||||
# tx_loc,
|
||||
# power,
|
||||
# gaussian_noise=args.withnoise
|
||||
# )
|
||||
# if args.visualize:
|
||||
# paths = []
|
||||
# for path in multipaths:
|
||||
# paths.extend(list(path))
|
||||
# plotSpace(floormap, space_rays=paths, cminmax=(-50, 0.0))
|
||||
duration = (int(time.time()) - starttime)
|
||||
print("duration: {}s ({:.2f}%) - len {}".format(duration, j/rx_locs.shape[0], len(rss_vec)))
|
||||
# rss_vec.append(rss)
|
||||
rss_map = convert_vector_to_mat(rx_locs, np.array(rss_vec), (64, 64))
|
||||
|
||||
with open("{}_{}.pickle".format(fp_base, int(power)), 'wb') as f:
|
||||
pickle.dump(rss_map, f, pickle.HIGHEST_PROTOCOL)
|
||||
|
||||
sys.exit()
|
||||
|
||||
|
||||
def getFloormap(args):
|
||||
'''
|
||||
'''
|
||||
floormap = SpaceMap(width=6.4, length=6.4, block_size=0.1)
|
||||
penetrations, reflections, orientations = pickle.load(open(args.floormap, "rb"))
|
||||
floormap.setLosses(penetrations, reflections)
|
||||
floormap.setOrientations(orientations)
|
||||
return floormap
|
||||
|
||||
|
||||
def main(args):
|
||||
tx_locs = None
|
||||
|
||||
if args.train:
|
||||
np.random.seed(RANDOM_SEED_TRAIN)
|
||||
tx_locs = getLocs([0.2, 6.2], [0.2, 6.2], step_size=0.3)
|
||||
elif args.train_real:
|
||||
np.random.seed(RANDOM_SEED_TRAIN)
|
||||
tx_locs = getRandomTXLocs(400, 6.4, 6.4, offset_w=0.0, offset_l=0.0)
|
||||
elif args.test:
|
||||
np.random.seed(RANDOM_SEED_TEST)
|
||||
tx_locs = getRandomTXLocs(400, 6.4, 6.4, offset_w=0.0, offset_l=0.0)
|
||||
else:
|
||||
print("nothing specified")
|
||||
return
|
||||
|
||||
generateData(getFloormap(args), tx_locs, args)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
p = argparse.ArgumentParser(description='Data Generator with Log Gamma Distance Model')
|
||||
p.add_argument(
|
||||
'outfolder',
|
||||
help='output generated data to folder'
|
||||
)
|
||||
p.add_argument(
|
||||
'--training',
|
||||
dest='train',
|
||||
action='store_true',
|
||||
default=False,
|
||||
help='generate training data (synthetic part)'
|
||||
)
|
||||
p.add_argument(
|
||||
'--training-real',
|
||||
dest='train_real',
|
||||
action='store_true',
|
||||
default=False,
|
||||
help='emulating training data (real data part)'
|
||||
)
|
||||
p.add_argument(
|
||||
'--testing',
|
||||
dest='test',
|
||||
action='store_true',
|
||||
default=False,
|
||||
help='emulating testing data (real data part)'
|
||||
)
|
||||
p.add_argument(
|
||||
'--visualize', '-v',
|
||||
dest='visualize',
|
||||
action='store_true',
|
||||
default=False,
|
||||
help='visualize'
|
||||
)
|
||||
p.add_argument(
|
||||
'--floormap', '-f',
|
||||
dest='floormap',
|
||||
default=None,
|
||||
help='floormap data'
|
||||
)
|
||||
p.add_argument(
|
||||
'--with-noise',
|
||||
dest='withnoise',
|
||||
action='store_true',
|
||||
default=False,
|
||||
help='add 10dB noise to generated data'
|
||||
)
|
||||
p.add_argument(
|
||||
'--proc', '-p',
|
||||
dest='procnum',
|
||||
type=int,
|
||||
default=1,
|
||||
help='number of parallel process'
|
||||
)
|
||||
try:
|
||||
args = p.parse_args()
|
||||
except BaseException as e:
|
||||
print(e)
|
||||
sys.exit()
|
||||
|
||||
main(args)
|
||||
|
|
@ -15,14 +15,44 @@ from libs.plotting import plotSpace
|
|||
|
||||
|
||||
def test():
|
||||
|
||||
def setWalls(i, j, orientation_deg):
|
||||
penetrations[i, j] = wall_penetration
|
||||
reflections[i, j] = wall_reflection
|
||||
orientations[i, j] = orientation_deg / 180 * np.pi
|
||||
|
||||
def setGlasses(i, j, orientation_deg):
|
||||
penetrations[i, j] = glass_penetration
|
||||
reflections[i, j] = glass_reflection
|
||||
orientations[i, j] = orientation_deg / 180 * np.pi
|
||||
|
||||
penetrations = np.zeros((64, 64), dtype=float)
|
||||
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)
|
||||
|
||||
# add walls
|
||||
for i in range(0, 64):
|
||||
spacemap.setLoss(i, 10, penetration=-5.0, reflection=-100.0)
|
||||
spacemap.setOrientation(i, 10, orientation=0.0)
|
||||
spacemap.setLoss(i, 50, penetration=-50.0, reflection=-10.0)
|
||||
spacemap.setOrientation(i, 50, orientation=0.0)
|
||||
wall_penetration = -20.0
|
||||
wall_reflection = -3.0
|
||||
glass_penetration = -3.0
|
||||
glass_reflection = -3.0
|
||||
# walls
|
||||
for j in range(5, 61): # left
|
||||
setWalls(7, j, 90)
|
||||
for i in range(7, 62): # up
|
||||
setWalls(i, 60, 0)
|
||||
for j in range(29, 60): # right
|
||||
setWalls(61, j, 90)
|
||||
for j in range(5, 29): # right
|
||||
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))
|
||||
return
|
||||
rx_loc = SpaceBlock(6.25, 3.2)
|
||||
rx_loc_rss, rx_loc_paths = spacemap.traceRay(0.0, SpaceBlock(0.0, 0.0), rx_loc)
|
||||
multipaths = []
|
||||
|
|
|
|||
Loading…
Reference in New Issue