bug fix (finally)

This commit is contained in:
HappyZ 2019-05-23 19:34:35 -05:00
parent 45a83d473c
commit bb0af93707
5 changed files with 60 additions and 39 deletions

View File

@ -17,11 +17,15 @@ class SpaceBlock():
self.x = float(x)
self.y = float(y)
self.z = float('nan') if z is None else float(z)
self.map_i = None
self.map_j = None
self.map_k = None
self.mat = material
self.has_transmitter = False
self.loss_penetration = 0.0
self.loss_reflection = -100.0
self.orientation = None
self.passthrough_rays = []
# backup linked list
self.left = None # <-
self.right = None # ->
@ -30,6 +34,9 @@ class SpaceBlock():
self.top = None # . (3d on top)
self.bottom = None # o (3d underneath)
def __hash__(self):
return int(self.x + 100000 + self.y * 1000)
def __mul__(self, val):
return SpaceBlock(self.x * val, self.y * val, self.z * val)
@ -372,6 +379,8 @@ class SpaceMap():
y = self.bs * (j + 0.5)
for i in range(self.map.shape[0]):
self.map[i, j] = SpaceBlock(self.bs * (i + 0.5), y)
self.map[i, j].map_i = i
self.map[i, j].map_j = j
for j in range(self.map.shape[1]):
for i in range(self.map.shape[0]):
self.map[i, j].up = self.map[i, j+1] if j < self.map.shape[1]-1 else None
@ -425,6 +434,34 @@ class SpaceMap():
def setEnvGamma(self, val: float):
self.env_gamma = val
def __traceRaysPostAnalysis(self):
'''
'''
# going through all paths once
passthrough_rays = {}
for path in self.endpaths:
current_p = path
target_blks = {}
while current_p is not None:
for blk in current_p.passthrough_blks:
target_p = getPathFromRay(current_p, blk, self)
if target_p is None or target_p.getEndingPower() < NOISE_FLOOR:
continue
target_blks[blk] = target_p
current_p = current_p.prev_ray
for blk in target_blks:
if blk not in passthrough_rays:
passthrough_rays[blk] = []
passthrough_rays[blk].append(target_blks[blk])
# update blocks
for j in range(self.map.shape[1]):
for i in range(self.map.shape[0]):
if self.map[i, j] not in passthrough_rays:
self.map[i, j].passthrough_rays = []
continue
self.map[i, j].passthrough_rays = passthrough_rays[self.map[i, j]]
def traceRays(self, tx_power: float, tx_loc: SpaceBlock):
'''
'''
@ -471,6 +508,7 @@ class SpaceMap():
if ray_r is not None:
rays.append(ray_r)
print("size of all found rays: {}".format(len(self.endpaths)))
self.__traceRaysPostAnalysis()
def traceRay(self, rx_loc: SpaceBlock):
'''
@ -518,24 +556,10 @@ class SpaceMap():
if not self.endpaths:
return NOISE_FLOOR, []
rx_loc_paths = []
for path in self.endpaths:
current_p = path
target_p_found = None
original_path_flag = True
while current_p is not None:
target_p = getPathFromRay(current_p, rx_loc, self)
if target_p is None:
break
angle_diff = abs(target_p.getAngle() % (2 * np.pi) - current_p.getAngle() % (2 * np.pi))
if angle_diff < self.ray_trace_deg_tol * max(target_p.getTraveledDistance(), 2):
if target_p.getEndingPower() < NOISE_FLOOR:
continue
target_p_found = target_p
current_p = current_p.prev_ray
original_path_flag = False
if target_p_found is not None and target_p_found not in rx_loc_paths:
rx_loc_paths.append(target_p_found)
i = int(round((rx_loc.x / self.bs)))
j = int(round((rx_loc.y / self.bs)))
# clean up for too nearby paths
removeRedundantPaths(rx_loc_paths)
return aggreatePower(rx_loc_paths), rx_loc_paths
removeRedundantPaths(self.map[i, j].passthrough_rays)
return aggreatePower(self.map[i, j].passthrough_rays), self.map[i, j].passthrough_rays

View File

@ -35,20 +35,18 @@ def convert_mat_to_vector(
def convert_vector_to_mat(
rx_locs: np.ndarray,
rx_rsses: np.ndarray,
shape: tuple,
block_size: float = 0.1,
offset: np.ndarray = None
shape: tuple
):
'''
'''
result = np.ones(shape) * -85.0
for i in range(rx_locs.shape[0]):
if offset is None:
x, y = rx_locs[i, :] / block_size
print(x, y)
else:
x, y = (rx_locs[i, :] + offset) / block_size
result[int(round(x)), int(round(y))] = rx_rsses[i]
# if offset is None:
# x, y = rx_locs[i, :] / block_size
# else:
# x, y = (rx_locs[i, :] + offset) / block_size
# x, y = int(round(x)), int(round(y))
result[i % shape[0], int(i / shape[0])] = rx_rsses[i]
return result

View File

@ -51,13 +51,14 @@ def log_gamma_floorplan_multi(floormap, rx_loc, tx_loc, power, gaussian_noise, r
power,
gaussian_noise=gaussian_noise
)
print(kk, rss)
# print(kk, rss)
results[kk] = rss
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() < 0.8:
continue
@ -104,8 +105,8 @@ def generateData(floormap, tx_locs, args):
for power in powers:
rss_vec = []
starttime = int(time.time())
tx_loc = SpaceBlock(3.2, 3.2)
# tx_loc = SpaceBlock(tx_locs[i, 0], tx_locs[i, 1])
# 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)
@ -141,16 +142,14 @@ def generateData(floormap, tx_locs, args):
# plotSpace(floormap, space_rays=paths, cminmax=(-50, 0.0))
# rss_vec.append(rss)
duration = (int(time.time()) - starttime)
print("duration: {}s ({:.2f}%) - len {}".format(duration, j/rx_locs.shape[0]*100.0, len(rss_vec)))
# print("results: {}".format(rss_vec))
rss_map = convert_vector_to_mat(rx_locs, np.array(rss_vec), (64, 64))
duration = (int(time.time()) - starttime)
print("duration: {}s ({:.2f}%) - len {}".format(duration, j/rx_locs.shape[0]*100.0, len(rss_vec)))
with open("{}_{}.pickle".format(fp_base, int(power)), 'wb') as f:
pickle.dump(rss_map, f, pickle.HIGHEST_PROTOCOL)
sys.exit()
def getFloormap(args):
'''

View File

@ -66,7 +66,7 @@ def generateData(tx_locs, args):
fp_base = "{0}/img_{1:.2f}_{2:.2f}_{3:.1f}".format(folderp, tx_locs[i, 0], tx_locs[i, 1], args.gamma)
for power in powers:
rss_vec = log_gamma_loc(rx_locs, tx_locs[i, :], power, args.gamma, gaussian_noise=args.withnoise)
rss_map = convert_vector_to_mat(rx_locs, rss_vec, (64, 64), offset=np.array([3.2, 3.2]))
rss_map = convert_vector_to_mat(rx_locs, rss_vec, (64, 64))
with open("{}_{}.pickle".format(fp_base, int(power)), 'wb') as f:
pickle.dump(rss_map, f, pickle.HIGHEST_PROTOCOL)

View File

@ -33,7 +33,7 @@ def test():
spacemap = SpaceMap(width=6.4, length=6.4, block_size=0.1)
# add walls
wall_penetration = -30.0
wall_penetration = -20.0
wall_reflection = -15.0
glass_penetration = -3.0
glass_reflection = -3.0
@ -64,7 +64,7 @@ def test():
# print("found path: {}".format(path))
multipaths.extend(list(path))
print("{:.6f}".format(rx_loc_rss))
# plotSpace(spacemap, space_rays=multipaths, cminmax=(-50, 0.0))
plotSpace(spacemap, space_rays=multipaths, cminmax=(-50, 0.0))