add ways to dump visualizable figures to assist data selections
also filters need to set to "6" to generate all, some other syntax changes in files
This commit is contained in:
parent
4384589cf0
commit
100faef84e
|
|
@ -59,18 +59,23 @@ def load_rss_data_with_pkt_types(fp: str, orientation: int) -> dict:
|
|||
return result
|
||||
|
||||
|
||||
def blocking_display_rss_map(rss_map: np.ndarray):
|
||||
def blocking_display_rss_map(rss_map: np.ndarray, visualize: bool = False, output_map: bool = False, fp: str = None):
|
||||
'''
|
||||
'''
|
||||
plt.imshow(
|
||||
np.transpose(rss_map),
|
||||
cmap='hot',
|
||||
origin='lower',
|
||||
interpolation='nearest'
|
||||
interpolation='nearest',
|
||||
vmin=-80.0,
|
||||
vmax=-40.0
|
||||
)
|
||||
plt.colorbar()
|
||||
# plt.show()
|
||||
plt.draw()
|
||||
if output_map:
|
||||
plt.savefig("{}.png".format(fp), dpi=50)
|
||||
if visualize:
|
||||
plt.pause(0.1)
|
||||
q = input("press Enter to continue... type q to quit: ")
|
||||
if q == 'q':
|
||||
|
|
@ -79,7 +84,14 @@ def blocking_display_rss_map(rss_map: np.ndarray):
|
|||
print()
|
||||
|
||||
|
||||
def convert_to_pickle_rss(fp: str, orientation: int, visualize: bool = False, filters: int = None):
|
||||
def convert_to_pickle_rss(
|
||||
fp: str,
|
||||
orientation: int,
|
||||
visualize: bool = False,
|
||||
output_map: bool = False,
|
||||
filters: int = None,
|
||||
sampling: bool = False
|
||||
):
|
||||
'''
|
||||
modified from Zhuolin
|
||||
'''
|
||||
|
|
@ -149,18 +161,25 @@ def convert_to_pickle_rss(fp: str, orientation: int, visualize: bool = False, fi
|
|||
elif filters is 5:
|
||||
data_fullfilled = data_fullfilled[(orientation_fullfilled > 0.5 * np.pi) & (orientation_fullfilled < 1.5 * np.pi)]
|
||||
if data_fullfilled.size:
|
||||
if sampling:
|
||||
rss_map[i, j] = max(np.random.choice(data_fullfilled, 1)[0], -85.0)
|
||||
else:
|
||||
rss_map[i, j] = max(np.median(data_fullfilled), -85.0)
|
||||
|
||||
if visualize:
|
||||
blocking_display_rss_map(rss_map)
|
||||
filepath = fp.replace(
|
||||
".csv", "{}_pkt_{}_map{}_{}"
|
||||
.format(
|
||||
"_s{}".format(np.random.randint(0, 999999)) if sampling else "",
|
||||
pkt_types[0][0],
|
||||
"" if filters is None else "_{}".format(filters),
|
||||
"h" if (orientation % 2) is 0 else "v"
|
||||
)
|
||||
)
|
||||
|
||||
with open(
|
||||
fp.replace(
|
||||
".csv", "_pkttype_{}_map{}.pickle"
|
||||
.format(pkt_types[0][0], "" if filters is None else "_{}".format(filters))
|
||||
),
|
||||
"wb"
|
||||
) as f:
|
||||
if visualize or output_map:
|
||||
blocking_display_rss_map(rss_map, visualize=visualize, output_map=output_map, fp=filepath)
|
||||
|
||||
with open("{}.pickle".format(filepath), "wb") as f:
|
||||
pickle.dump(rss_map, f)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -65,7 +65,16 @@ def generate_floorplan_map(f_map, f_loc, f_sig_extracted, is_csi):
|
|||
f.write(augmented_map.getvalue())
|
||||
|
||||
|
||||
def convert_to_pickle(filepaths, orientation, visualize, is_csi):
|
||||
def convert_to_pickle(
|
||||
filepaths,
|
||||
orientation,
|
||||
filters=None,
|
||||
visualize=False,
|
||||
is_csi=False,
|
||||
output_map=False,
|
||||
sampling=False,
|
||||
sampling_num=5
|
||||
):
|
||||
'''
|
||||
'''
|
||||
if is_csi:
|
||||
|
|
@ -73,16 +82,30 @@ def convert_to_pickle(filepaths, orientation, visualize, is_csi):
|
|||
return
|
||||
for filepath in filepaths:
|
||||
print("parsing file: {}".format(filepath))
|
||||
if not sampling:
|
||||
sampling_num = 1
|
||||
for __ in range(sampling_num):
|
||||
try:
|
||||
convert_to_pickle_rss(filepath, orientation, visualize=visualize, filters=None)
|
||||
convert_to_pickle_rss(filepath, orientation, visualize=visualize, filters=0)
|
||||
convert_to_pickle_rss(filepath, orientation, visualize=visualize, filters=1)
|
||||
convert_to_pickle_rss(filepath, orientation, visualize=visualize, filters=2)
|
||||
convert_to_pickle_rss(filepath, orientation, visualize=visualize, filters=3)
|
||||
convert_to_pickle_rss(filepath, orientation, visualize=visualize, filters=4)
|
||||
convert_to_pickle_rss(filepath, orientation, visualize=visualize, filters=5)
|
||||
if filters is 6:
|
||||
for fff in range(0, 6):
|
||||
convert_to_pickle_rss(
|
||||
filepath, orientation,
|
||||
visualize=visualize,
|
||||
output_map=output_map,
|
||||
filters=fff,
|
||||
sampling=sampling
|
||||
)
|
||||
else:
|
||||
convert_to_pickle_rss(
|
||||
filepath, orientation,
|
||||
visualize=visualize,
|
||||
output_map=output_map,
|
||||
filters=filters,
|
||||
sampling=sampling
|
||||
)
|
||||
except KeyboardInterrupt:
|
||||
print("KeyboardInterrupt happened")
|
||||
return
|
||||
|
||||
|
||||
def main(args):
|
||||
|
|
@ -101,7 +124,16 @@ def main(args):
|
|||
|
||||
if args.pickle:
|
||||
# f_sig_extracted = [x for x in f_sig_extracted if '98fc11691fc5' in x]
|
||||
convert_to_pickle(f_sig_extracted, args.orientation, args.visualize, is_csi)
|
||||
convert_to_pickle(
|
||||
f_sig_extracted,
|
||||
args.orientation,
|
||||
filters=args.filters,
|
||||
visualize=args.visualize,
|
||||
is_csi=is_csi,
|
||||
output_map=args.visualize_dump,
|
||||
sampling=args.sampling,
|
||||
sampling_num=args.sampling_num
|
||||
)
|
||||
|
||||
# generate path in map for visualization
|
||||
if args.map:
|
||||
|
|
@ -130,6 +162,27 @@ if __name__ == '__main__':
|
|||
default=False,
|
||||
help='Enable to dump into pickle images'
|
||||
)
|
||||
parser.add_argument(
|
||||
'--filters',
|
||||
dest='filters',
|
||||
type=int,
|
||||
default=None,
|
||||
help='Set filters to extract only 0: >, 1: v, 2: <, 3: ^, 4: <^>, 5: <v>, 6: all'
|
||||
)
|
||||
parser.add_argument(
|
||||
'--sampling',
|
||||
dest='sampling',
|
||||
action='store_true',
|
||||
default=False,
|
||||
help='Enable subsampling to generate more data'
|
||||
)
|
||||
parser.add_argument(
|
||||
'--sampling-num',
|
||||
dest='sampling_num',
|
||||
type=int,
|
||||
default=10,
|
||||
help='If subsampling enabled, set the number of random samples performed'
|
||||
)
|
||||
parser.add_argument(
|
||||
'--visualize', '-v',
|
||||
dest='visualize',
|
||||
|
|
@ -137,6 +190,13 @@ if __name__ == '__main__':
|
|||
default=False,
|
||||
help='Enable to visualize map images while dumping to pickles'
|
||||
)
|
||||
parser.add_argument(
|
||||
'--visualize-dump', '-vd',
|
||||
dest='visualize_dump',
|
||||
action='store_true',
|
||||
default=False,
|
||||
help='Enable to dump images while dumping to pickles'
|
||||
)
|
||||
parser.add_argument(
|
||||
'--orient',
|
||||
dest='orientation',
|
||||
|
|
|
|||
Loading…
Reference in New Issue