Esempio n. 1
0
def generate_json(path: str, metric: str = "amplitude") -> str:
    """
        This function converts a csi_trace into the json format. It works for single entry or the whole trace.

        Parameters:
            path (str): Path to CSI file location.
    """
    def default(prop):
        if "complex" in str(type(prop)):
            return str(prop)
        if "numpy" in str(type(prop)):
            return prop.tolist()
        if "__dict__" in dir(prop):
            return prop.__dict__
        else:
            print("Prop has no __dict__ {}: \n {}".format(type(prop), prop))

    reader = get_reader(path)
    csi_data = reader.read_file(path)
    csi_matrix, no_frames, no_subcarriers = get_CSI(csi_data, metric)

    print("CSI Shape: {}".format(csi_matrix.shape))
    print("Number of Frames: {}".format(no_frames))
    print("Generating CSI {}...".format(metric))

    json_str = json.dumps(csi_matrix, default=default, indent=True)
    return json_str
Esempio n. 2
0
def generate_npz(path: str, dest: str, metric: str = "amplitude"):
    reader = get_reader(path)
    csi_data = reader.read_file(path)

    if dest[-4:] != ".npz":
        dest += ".npz"

    csi_matrix, _, _ = get_CSI(csi_data, metric)
    np.savez_compressed(dest, csi_matrix)

    print("CSI matrix with shape: {}".format(csi_matrix.shape))
    print("Generating CSI {}...".format(metric))
    print("File written to: {}".format(dest))
Esempio n. 3
0
def display_info(path: str):
    reader = get_reader(path)
    csi_data = reader.read_file(path, scaled=True)
    metadata = csi_data.get_metadata()

    print("Hardware: {}".format(metadata.chipset))
    print("Bandwidth: {}MHz".format(metadata.bandwidth))
    print("Antenna Configuration: {}".format(metadata.antenna_config))
    print("Frame Count: {}".format(metadata.frames))
    print("Subcarrier Count: {}".format(metadata.subcarriers))
    print("Length: {0:.2f}s".format(metadata.time_length))
    print("Average Sample Rate: {0:.2f}Hz".format(
        metadata.average_sample_rate))
    print("Average RSSI: {}dBm".format(metadata.average_rssi))
    print("CSI Shape: {}".format((metadata.frames, *metadata.csi_shape)))
Esempio n. 4
0
def generate_csv(path: str, dest: str, metric: str = "amplitude"):
    reader = get_reader(path)
    csi_data = reader.read_file(path)

    csi_matrix, no_frames, no_subcarriers = get_CSI(csi_data, metric)
    no_rx, no_tx = csi_matrix.shape[2:]

    print("CSI Shape: {}".format(csi_matrix.shape))
    print("Number of Frames: {}".format(no_frames))
    print("Generating CSI {}...".format(metric))
    print("CSV dimensions: {} Rows, {} Columns".format(
        no_frames, no_subcarriers * no_rx * no_tx))

    csv_header = []
    for subcarrier in range(no_subcarriers):
        for rx in range(no_rx):
            for tx in range(no_tx):
                csv_header.append("Sub {} RXTX {}/{}".format(
                    subcarrier, rx, tx))

    with open(dest, "w", newline="") as csv_file:
        writer = csv.writer(csv_file, delimiter=",")
        writer.writerow(csv_header)

        for frame in range(no_frames):
            frame_data = csi_matrix[frame]
            row_data = []

            for subcarrier in range(no_subcarriers):
                subcarrier_data = frame_data[subcarrier]
                for rx in range(no_rx):
                    rx_data = subcarrier_data[rx]
                    for tx in range(no_tx):
                        tx_data = rx_data[tx]
                        row_data.append(tx_data)

            writer.writerow(row_data)

    print("File written to: {}".format(dest))
Esempio n. 5
0
 def __init__(self, path: str = DEFAULT_PATH):
     reader = get_reader(path)
     self.csi_data = reader.read_file(path)