source: ReferenceDesigns/w3_802.11/python/examples/chan_est_viewer/chan_ests_to_HDF5.py

Last change on this file was 6320, checked in by chunter, 5 years ago

1.8.0 release wlan-exp

File size: 3.5 KB
Line 
1import sys
2import os
3import datetime
4import numpy as np
5import wlan_exp.util as wlan_exp_util
6import wlan_exp.log.util as log_util
7import wlan_exp.log.util_hdf as hdf_util
8import wlan_exp.log.util_sample_data as sample_data_util
9
10DEFAULT_LOGFILE = 'ap_one_node_capture.hdf5'
11logfile_error   = False
12
13# Use log file given as command line argument, if present
14if(len(sys.argv) > 1):
15    LOGFILE = str(sys.argv[1])
16
17    # Check if the string argument matchs a local file
18    if not os.path.isfile(LOGFILE):
19        # User specified non-existant file - give up and exit
20        logfile_error = True
21
22else:
23    # No command line argument - check if default file name exists locally
24    LOGFILE = DEFAULT_LOGFILE
25
26    if not os.path.isfile(LOGFILE):
27        # No local file specified or found - check for matching sample data file
28        try:
29            LOGFILE = sample_data_util.get_sample_data_file(DEFAULT_LOGFILE)
30            print("Local log file not found - Using sample data file!")
31        except IOError as e:
32            logfile_error = True
33
34if logfile_error:
35    print("ERROR: Logfile {0} not found".format(LOGFILE))
36    sys.exit()
37else:
38    print("Reading log file '{0}' ({1:5.1f} MB)\n".format(LOGFILE, (os.path.getsize(LOGFILE)/2**20)))
39
40if len(sys.argv) == 3:
41    HDF5_FILE_OUT = str(sys.argv[2])
42else:
43    HDF5_FILE_OUT = 'np_rx_ofdm_entries.hdf5'
44
45print("WLAN Exp Log Example: OFDM Rx Entry Exporter")
46
47
48# Extract the raw log data and log index from the HDF5 file
49log_data      = hdf_util.hdf5_to_log_data(filename=LOGFILE)
50raw_log_index = hdf_util.hdf5_to_log_index(filename=LOGFILE)
51
52# Generate indexes with only Rx_OFDM events
53log_index_rx = log_util.filter_log_index(raw_log_index, include_only=['RX_OFDM'],
54                                         merge={'RX_OFDM': ['RX_OFDM', 'RX_OFDM_LTG']})
55
56# Generate numpy array of all OFDM Rx entries
57log_np = log_util.log_data_to_np_arrays(log_data, log_index_rx)
58log_rx_ofdm = log_np['RX_OFDM']
59
60#################################################################
61# Filter the OFDM Rx Entries
62#  Find the source address for the most receptions
63
64# Extract unique values for address 2 (transmitting address in received MAC headers)
65uniq_addrs = np.unique(log_rx_ofdm['addr2'])
66
67# Count the number of receptions per source address
68num_rx = list()
69for ii,ua in enumerate(uniq_addrs):
70    num_rx.append(np.sum(log_rx_ofdm['addr2'] == ua))
71
72# Find the source address responsible for the most receptions
73most_rx = max(num_rx)
74most_common_addr = uniq_addrs[num_rx.index(most_rx)]
75
76print("Found {0} receptions from {1}".format(most_rx, wlan_exp_util.mac_addr_to_str(most_common_addr)))
77
78# Create new numpy array of all receptions from most-common source
79arr_rx_one_src = np.empty(most_rx, dtype=log_rx_ofdm.dtype)
80arr_rx_one_src[:] = log_rx_ofdm[(log_rx_ofdm['addr2'] == most_common_addr)]
81
82# Create some strings to use as attributes in the HDF5 file
83#     - attributes are only for convenience - they aren't required for writing or reading HDF5 files
84root_desc = 'Source Log file: {0}\n'.format(LOGFILE)
85root_desc += 'HDF5 file written at {0}\n'.format(datetime.datetime.now())
86
87ds_desc = 'All Rx OFDM entries from addr {0}\n'.format(wlan_exp_util.mac_addr_to_str(most_common_addr))
88
89# Construct dictionaries to feed the HDF5 exporter
90#     - The dict key names are used as HDF5 dataset names
91log_dict = {'RX_OFDM': arr_rx_one_src}
92attr_dict = {'/': root_desc, 'RX_OFDM': ds_desc}
93
94print('Generating HDF5 file {0}'.format(HDF5_FILE_OUT))
95hdf_util.np_arrays_to_hdf5(HDF5_FILE_OUT, np_log_dict=log_dict, attr_dict=attr_dict)
Note: See TracBrowser for help on using the repository browser.