-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot.py
More file actions
119 lines (107 loc) · 4.29 KB
/
plot.py
File metadata and controls
119 lines (107 loc) · 4.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import datetime
from matplotlib.animation import FuncAnimation
import matplotlib.pyplot as plt
from wind_database import WindDatabase
from tele_csv import TeleCsv
class WindTelemtryPlotter:
def __init__(self, tele_data_path, wind_data_param):
# if type(wind_data_param) == "tuple" and len(wind_data_param) == 2:
self.wind_database = WindDatabase(remote_path=wind_data_param)
# else:
# self.wind_database = WindDatabase(database_file=wind_data_param)
self.tele_csv = TeleCsv(tele_data_path)
def compute_interval(self, date_tuple):
weather_data = self.wind_database.query(date_tuple)
max_wind = max(weather_data[1]) if len(weather_data[1]) > 0 else ""
tele_data = self.tele_csv.query(date_tuple)
max_ra_err = max(tele_data[1]) if len(tele_data[1]) > 0 else ""
max_dec_err = max(tele_data[2]) if len(tele_data[2]) > 0 else ""
max_comp_err = max(tele_data[3]) if len(tele_data[3]) > 0 else ""
return [max_wind, max_ra_err, max_dec_err, max_comp_err]
def plot_interval(self, date_tuple, show=True):
weather_data = self.wind_database.query(date_tuple)
tele_data = self.tele_csv.query(date_tuple)
fig = plt.figure(figsize=(10, 5))
axes = fig.subplots(2)
axes[0].plot(
tele_data[0],
tele_data[1],
label="RA Error",
linestyle="None",
marker=".",
color="red",
)
axes[0].plot(
tele_data[0],
tele_data[2],
label="Dec Error",
linestyle="None",
marker=".",
color="blue",
)
axes[0].plot(
tele_data[0], tele_data[3], label="Composite Error", color="darkviolet"
)
axes[0].set_xlim(date_tuple)
axes[0].set_ylabel("Error (arcsec)")
axes[0].legend(loc="upper left")
ln_spd = axes[1].plot(
weather_data[0], weather_data[1], label="Wind Speed", color="green"
)
axes[1].set_xlim(date_tuple)
axes[1].set_ylabel("Wind Speed (km/h)")
ax1_2 = axes[1].twinx()
ln_dir = ax1_2.plot(
weather_data[0],
weather_data[2],
label="Wind Direction",
linestyle="None",
marker=".",
color="deeppink",
)
ax1_2.set_ylim(0, 360)
ax1_2.set_yticks([0, 90, 180, 270, 360])
ax1_2.set_ylabel("Wind Direction (degrees)")
ax1_2.legend(
ln_spd + ln_dir, [l.get_label() for l in ln_spd + ln_dir], loc="upper left"
)
if show:
plt.show()
return fig
def plot_dynamic(self, interval=1):
frame_time = 250
now = datetime.datetime.now() # - datetime.timedelta(hours=40)
fig = self.plot_interval(
(now - datetime.timedelta(minutes=interval), now), False
)
def update(frame):
nonlocal fig, frame_time
now = datetime.datetime.now() # - datetime.timedelta(hours=40)
axes = fig.get_axes()
tele_data = self.tele_csv.query(
(now - datetime.timedelta(minutes=interval), now)
)
weather_data = self.wind_database.query(
(now - datetime.timedelta(minutes=interval), now)
)
tele_ax = axes[0]
ln_ra = tele_ax.lines[0]
ln_ra.set_xdata(tele_data[0])
ln_ra.set_ydata(tele_data[1])
ln_dec = tele_ax.lines[1]
ln_dec.set_xdata(tele_data[0])
ln_dec.set_ydata(tele_data[2])
ln_comp = tele_ax.lines[2]
ln_comp.set_xdata(tele_data[0])
ln_comp.set_ydata(tele_data[3])
tele_ax.set_xlim(now - datetime.timedelta(minutes=interval), now)
wind_ax = axes[1]
ln_wind_speed = wind_ax.lines[0]
ln_wind_speed.set_xdata(weather_data[0])
ln_wind_speed.set_ydata(weather_data[1])
ln_wind_dir = wind_ax.get_shared_x_axes().get_siblings(wind_ax)[0].lines[0]
ln_wind_dir.set_xdata(weather_data[0])
ln_wind_dir.set_ydata(weather_data[2])
wind_ax.set_xlim(now - datetime.timedelta(minutes=interval), now)
anim = FuncAnimation(fig, update, interval=frame_time)
plt.show()