Created
December 31, 2020 19:07
-
-
Save kevincroissant/28d828e1569539695a17cab0d8b6f1b8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#AUTHOR: Kevin Croissant | |
from gs_functions import setupDBConnection, nearest | |
def analyse_azel(data): | |
azimuth1 = data['azimuth1'] | |
sortedAz1 = sorted(azimuth1) | |
elevation1 = data['elevation1'] | |
azimuth2 = data['azimuth2'] | |
sortedAz2 = sorted(azimuth2) | |
elevation2 = data['elevation2'] | |
# azel1 = sorted(zip(data['azimuth1'], data['elevation1'])) | |
# azel2 = sorted(zip(data['azimuth2'], data['elevation2'])) | |
#combine both radio az/el-s | |
azel = sorted(zip(data['azimuth1']+data['azimuth2'], data['elevation1']+data['elevation2'])) | |
azel_minElevations = [] | |
stepDeg = 5 | |
for az_test in range(0,360): | |
#find indices of azelN where azimuth is between [idx, idx+1) | |
found_az = False | |
currentMinElevation = 90 | |
for idx in range(1, len(azel)): | |
#check every azimuth within this search range | |
if(azel[idx][0] >= az_test and azel[idx][0] < az_test + stepDeg): | |
#we found at least one az in this range | |
found_az = True | |
#check the elevation | |
currentMinElevation = min(currentMinElevation, azel[idx][1]) | |
azel_minElevations.append((az_test, currentMinElevation)) | |
return azel_minElevations | |
def polar_scatterplots(data): | |
import matplotlib.pyplot as plt | |
import matplotlib.colors as mcolors | |
import matplotlib.image as mpimg | |
import matplotlib.dates as mdates | |
from matplotlib.colors import LogNorm | |
from scipy.stats import gaussian_kde | |
import numpy as np | |
from matplotlib.lines import Line2D | |
#https://matplotlib.org/gallery/statistics/hist.html | |
azimuth1 = data['azimuth1'] | |
elevation1 = data['elevation1'] | |
azimuth2 = data['azimuth2'] | |
elevation2 = data['elevation2'] | |
azimuthMin = data['azimuthMin'] | |
elevationMin = data['elevationMin'] | |
############################################## | |
legend_loc = 'upper right' | |
ring_step_in_deg = 10 | |
# # #scatter: | |
fig, axs = plt.subplots(2,2, subplot_kw=dict(polar=True), constrained_layout=True) | |
fig.suptitle('Bobcat-1 Groundstation Received Packet Locations') | |
fig.set_size_inches(12,12) | |
#top left | |
ax = axs[0,0] | |
ax.set_theta_direction(-1) | |
ax.set_theta_zero_location('N') | |
ax.plot(np.radians(azimuth1), | |
([(90-idx) for idx in elevation1]), | |
'.', | |
markersize=3, color='blue', label='RX1') | |
ax.set_yticks(range(0, 90, ring_step_in_deg)) | |
ax.set_yticklabels(map(str, range(90, 0, -ring_step_in_deg))) | |
ax.set_rmax(90) | |
ax.legend(loc=legend_loc) | |
ax.set_title('GS100 Radio 1 Packets') | |
#top right | |
ax = axs[0,1] | |
ax.set_theta_direction(-1) | |
ax.set_theta_zero_location('N') | |
ax.plot(np.radians(azimuth2), | |
([(90-idx) for idx in elevation2]), | |
'.', | |
markersize=2, color='red', label='RX2') | |
ax.set_yticks(range(0, 90, ring_step_in_deg)) | |
ax.set_yticklabels(map(str, range(90, 0, -ring_step_in_deg))) | |
ax.set_rmax(90) | |
ax.legend(loc=legend_loc) | |
ax.set_title('GS100 Radio 2 Packets') | |
#bottom left | |
ax = axs[1,0] | |
ax.set_theta_direction(-1) | |
ax.set_theta_zero_location('N') | |
ax.plot(np.radians(azimuth1), | |
([(90-idx) for idx in elevation1]), | |
'.', | |
markersize=3, color='blue', label='RX1') | |
ax.plot(np.radians(azimuth2), | |
([(90-idx) for idx in elevation2]), | |
'.', | |
markersize=2, color='red', label='RX2') | |
ax.set_yticks(range(0, 90, ring_step_in_deg)) | |
ax.set_yticklabels(map(str, range(90, 0, -ring_step_in_deg))) | |
ax.set_rmax(90) | |
ax.legend(loc=legend_loc) | |
ax.set_title('GS100 Packets') | |
#bottom right | |
ax = axs[1,1] | |
ax.set_theta_direction(-1) | |
ax.set_theta_zero_location('N') | |
ax.plot(np.radians(azimuthMin), | |
([(90-idx) for idx in elevationMin]), | |
'-', | |
markersize=2, color='black', label='MIN') | |
ax.set_yticks(range(0, 90, ring_step_in_deg)) | |
ax.set_yticklabels(map(str, range(90, 0, -ring_step_in_deg))) | |
ax.set_rmax(90) | |
ax.legend(loc=legend_loc) | |
ax.set_title('Minimum Elevation Required for Contact') | |
plt.savefig('/groundstation/groundstation-website/polar_scatterplots.png', bbox_inches='tight') | |
plt.clf() | |
plt.close() | |
######################################################################## | |
def main(): | |
#Get data from DB | |
db = setupDBConnection() | |
cursor = db.cursor() | |
data = {} | |
query = "SELECT time, azimuth, elevation FROM radio_stats WHERE radio=1 ORDER BY packetid ASC" | |
cursor.execute(query) | |
results = cursor.fetchall() | |
azel = list(zip(*results)) | |
data['time1'] = list(azel[0]) | |
# data['azimuth1'] = list(azel[1]) | |
data['azimuth1'] = [(x % 360) for x in list(azel[1])] | |
data['elevation1'] = list(azel[2]) | |
query = "SELECT time, azimuth, elevation FROM radio_stats WHERE radio=2 ORDER BY packetid ASC" | |
cursor.execute(query) | |
results = cursor.fetchall() | |
azel = list(zip(*results)) | |
data['time2'] = list(azel[0]) | |
# data['azimuth2'] = list(azel[1]) | |
data['azimuth2'] = [(x % 360) for x in list(azel[1])] | |
data['elevation2'] = list(azel[2]) | |
#calculate minimum elevation required at each azimuth | |
min_azel = analyse_azel(data) | |
min_azel_unzipped = list(zip(*min_azel)) | |
data['azimuthMin'] = min_azel_unzipped[0] | |
data['elevationMin'] = min_azel_unzipped[1] | |
#Run plot | |
polar_scatterplots(data) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment