From 51afbfc8671f252708e95d7009b9048d095f41b8 Mon Sep 17 00:00:00 2001 From: Jeff Moe Date: Sun, 29 Jan 2023 16:11:49 -0700 Subject: [PATCH] Read sample CSV file as dataframe --- README.md | 2 ++ polar-plot | 36 +++++++++++++++++++++++++++++++++--- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 3dcb7f2..9323f81 100644 --- a/README.md +++ b/README.md @@ -78,6 +78,8 @@ rx_tools # Upstream Sections of code and clues from Cees Bassa. +* https://github.com/cbassa + Primary author and errors in code from Jeff Moe. diff --git a/polar-plot b/polar-plot index 5a8d88b..92917b5 100755 --- a/polar-plot +++ b/polar-plot @@ -2,7 +2,7 @@ # # polar-plot # -# Copyright (C) 2023, Jeff Moe +# Copyright (C) 2022, 2023, Jeff Moe # Copyright (C) 2023, Cees Bassa # # This program is free software: you can redistribute it and/or modify @@ -22,15 +22,45 @@ # Generate graphical plot of radio interference. # # Usage: -# polar_plot +# polar_plot [filename] # # Example: -# polar_plot +# ./polar-plot data/sample.csv +# ./polar-plot data/rtl_power-sample.csv import numpy as np import matplotlib.pyplot as plt +import pandas as pd +import sys +import re + if __name__ == "__main__": + # Determine what type of file to load to dataframe + datafile = sys.argv[1] + + with open(datafile) as f: + firstline = f.readline().rstrip() + + if firstline == "1, -38.93": + print("Test data from sample.csv") + df = pd.read_csv( + datafile, skiprows=0, usecols=[0, 1], names=("Azimuth", "Energy") + ) + + elif re.match(re.compile("20*"), firstline): + print("rtl_power CSV file. Not yet supported.") + exit() + + else: + print("Unknown file type.") + exit() + + # Print the Dataframe loaded from CSV + with pd.option_context("display.max_rows", None, "display.max_columns", None): + print(df) + + # (Empty) Plot here fig = plt.figure(figsize=(8, 8)) ax = fig.add_subplot(111, projection="polar")