1
0
Fork 0
plot-freely/polar-plot

147 lines
3.9 KiB
Plaintext
Raw Normal View History

#!/usr/bin/env python3
#
2023-01-29 14:32:28 -07:00
# polar-plot
#
2023-01-29 16:11:49 -07:00
# Copyright (C) 2022, 2023, Jeff Moe
# Copyright (C) 2023, Cees Bassa
2023-01-29 14:32:28 -07:00
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# polar_plot
# Generate graphical plot of radio interference.
#
# Usage:
2023-01-29 16:11:49 -07:00
# polar_plot [filename]
2023-01-29 14:32:28 -07:00
#
# Example:
2023-01-29 16:11:49 -07:00
# ./polar-plot data/sample.csv
# ./polar-plot data/rtl_power-sample.csv
2023-01-29 14:32:28 -07:00
2023-01-29 19:06:35 -07:00
2023-01-29 17:50:29 -07:00
import argparse
2023-01-29 16:33:06 -07:00
import locale
import matplotlib.pyplot as plt
2023-01-29 16:33:06 -07:00
import numpy as np
2023-01-29 16:11:49 -07:00
import pandas as pd
import re
2023-01-29 19:06:35 -07:00
import scipy
2023-01-29 16:33:06 -07:00
import seaborn as sns
import sys
2023-01-29 16:11:49 -07:00
2023-01-29 19:06:35 -07:00
from pandas.plotting import scatter_matrix
2023-01-29 16:33:06 -07:00
locale.setlocale(locale.LC_ALL, "en_US.utf8")
2023-01-29 16:52:46 -07:00
plt.rcParams["axes.formatter.use_locale"] = True
2023-01-29 17:50:29 -07:00
def load_samples():
parser = argparse.ArgumentParser(
description="Radio Interference Polar Plotter.",
formatter_class=argparse.RawTextHelpFormatter,
)
parser.add_argument(
"infile",
nargs="?",
type=argparse.FileType("r"),
default=sys.stdin,
help="filename, default stdin",
)
args = parser.parse_args()
datafile = args.infile.name
2023-01-29 16:11:49 -07:00
with open(datafile) as f:
firstline = f.readline().rstrip()
2023-01-29 19:06:35 -07:00
if firstline == "1, 38.93":
2023-01-29 16:11:49 -07:00
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()
2023-01-29 19:06:35 -07:00
return df
2023-01-29 17:56:38 -07:00
def print_table(df):
2023-01-29 16:11:49 -07:00
# Print the Dataframe loaded from CSV
with pd.option_context("display.max_rows", None, "display.max_columns", None):
print(df)
2023-01-29 17:50:29 -07:00
2023-01-29 19:06:35 -07:00
def display_plot(df):
2023-01-29 16:52:46 -07:00
sns.set_theme()
fig = plt.figure(figsize=(8, 8), facecolor="xkcd:off white")
ax = fig.add_subplot(111, projection="polar")
2023-01-29 17:50:29 -07:00
ax.set_facecolor("xkcd:powder blue")
2023-01-29 16:52:46 -07:00
ax.set_title(
"Radio Interference Polar Plot".format("seaborn"),
color="xkcd:cornflower blue",
fontsize="large",
fontweight="bold",
)
ax.set_theta_offset(np.pi / 2.0)
ax.set_rticks([90, 60, 30, 0])
ax.set_rgrids([90, 60, 30, 0], ["", "30$^\circ$", "60$^\circ$", ""], angle=22.5)
ax.grid(True)
2023-01-29 19:06:35 -07:00
ax.bar(1 / 60, 38.93, width=0.25)
ax.bar(15 / 60, 38.31, width=0.25)
ax.bar(30 / 60, 37.77, width=0.25)
ax.bar(45 / 60, 37.33, width=0.25)
ax.bar(60 / 60, 38.54, width=0.25)
ax.bar(75 / 60, 38.81, width=0.25)
ax.bar(90 / 60, 37.55, width=0.25)
ax.bar(105 / 60, 29.18, width=0.25)
ax.bar(120 / 60, 29.32, width=0.25)
ax.bar(135 / 60, 37.00, width=0.25)
ax.bar(150 / 60, 36.48, width=0.25)
ax.bar(165 / 60, 32.46, width=0.25)
ax.bar(180 / 60, 34.92, width=0.25)
ax.bar(195 / 60, 38.65, width=0.25)
ax.bar(210 / 60, 39.07, width=0.25)
ax.bar(225 / 60, 39.50, width=0.25)
ax.bar(240 / 60, 39.42, width=0.25)
ax.bar(255 / 60, 37.33, width=0.25)
ax.bar(270 / 60, 38.96, width=0.25)
ax.bar(285 / 60, 38.14, width=0.25)
ax.bar(300 / 60, 36.32, width=0.25)
ax.bar(315 / 60, 35.26, width=0.25)
ax.bar(330 / 60, 39.14, width=0.25)
ax.bar(345 / 60, 39.60, width=0.25)
ax.set_ylim(0.0, 40.0)
2023-01-29 16:52:46 -07:00
plt.tight_layout()
plt.show()
2023-01-29 17:50:29 -07:00
def main():
2023-01-29 17:56:38 -07:00
df = load_samples()
print_table(df)
2023-01-29 19:06:35 -07:00
display_plot(df)
2023-01-29 17:50:29 -07:00
if __name__ == "__main__":
main()