48 lines
995 B
Python
48 lines
995 B
Python
#!/usr/bin/python
|
|
|
|
|
|
import numpy as np
|
|
from libs.consts import NOISE_FLOOR
|
|
|
|
|
|
def touch(filepath):
|
|
try:
|
|
open(filepath, 'a').close()
|
|
return True
|
|
except BaseException:
|
|
pass
|
|
return False
|
|
|
|
|
|
def convert_mat_to_vector(
|
|
mat: np.ndarray,
|
|
block_size: float = 0.1
|
|
):
|
|
'''
|
|
'''
|
|
rx_locs = []
|
|
rx_rsses = []
|
|
width, length = mat.shape
|
|
for i in range(width):
|
|
for j in range(length):
|
|
if mat[i, j] <= NOISE_FLOOR:
|
|
continue
|
|
rx_locs.append([(i + 0.5) * block_size, (j + 0.5) * block_size])
|
|
rx_rsses.append(mat[i, j])
|
|
return np.array(rx_locs), np.array(rx_rsses)
|
|
|
|
|
|
def convert_vector_to_mat(
|
|
rx_locs: np.ndarray,
|
|
rx_rsses: np.ndarray,
|
|
shape: tuple,
|
|
block_size: float = 0.1
|
|
):
|
|
'''
|
|
'''
|
|
result = np.ones(shape) * -85.0
|
|
for i in range(rx_locs.shape[0]):
|
|
x, y = rx_locs[i, :] / block_size
|
|
result[int(x), int(y)] = rx_rsses[i]
|
|
return result
|