-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathorbital_parameters.py
180 lines (164 loc) · 4.65 KB
/
orbital_parameters.py
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
from bokeh.layouts import column, gridplot, layout
from bokeh.models import Div, Button
from bokeh.models.callbacks import CustomJS
from bokeh.plotting import save, output_file
from jinja2 import Environment, FileSystemLoader
import plots
import constants
import datasources
import widgets
# Set up widgets
sma_widget, sma = widgets.build_orbital_parameter(
title="a: semi-major axis (km)",
value=42164,
start=0,
end=constants.MAX_SMA,
step=1,
css_class="sma",
)
eccentricity_widget, eccentricity = widgets.build_orbital_parameter(
title="e: eccentricity (-)",
value=0.7,
start=0,
end=1,
step=0.01,
css_class="ecc",
)
aop_widget, aop = widgets.build_orbital_parameter(
title="ω: argument of perigee (deg)",
value=195,
start=0,
end=360,
step=1,
css_class="omega",
)
inclination_widget, inclination = widgets.build_orbital_parameter(
title="i: inclination (deg)",
value=10,
start=0,
end=180,
step=1,
css_class="inc",
)
raan_widget, raan = widgets.build_orbital_parameter(
title="Ω: right ascension of ascending node (deg)",
value=95,
start=0,
end=360,
step=1,
css_class="Gomega",
)
anomaly_widget, anomaly = widgets.build_orbital_parameter(
title="𝜈: true anomaly (deg)",
value=70,
start=0,
end=359,
step=1,
css_class="anomaly",
)
plot_shape = plots.create_plot(
datasources.orbit_shape,
"x",
"y",
"+z",
datasources.position_in_orbital_plane,
"orbit shape in orbital plane",
)
plots.add_ascending_node_direction(plot_shape)
plots.add_apsides_line(plot_shape, datasources.apsides_in_orbital_plane)
plots.add_sma(plot_shape, datasources.orbital_parameters)
plots.add_eccentricity(plot_shape, datasources.orbital_parameters)
plots.add_omega(plot_shape, datasources.orbital_parameters)
plots.add_anomaly(
plot_shape, datasources.orbital_parameters, datasources.position_in_orbital_plane
)
plot_pole = plots.create_plot(
datasources.orbit_3d,
"x",
"y",
"+z",
datasources.position_3d,
"orbit seen from North direction",
)
plots.add_vernal_direction(plot_pole)
plots.add_Gomega(plot_pole, datasources.orbital_parameters)
plots.add_nodes_line(plot_pole, datasources.nodes_in_equatorial_plane)
plots.add_equatorial_plane(plot_pole)
plot_vernal = plots.create_plot(
datasources.orbit_3d,
"y",
"z",
"+x",
datasources.position_3d,
"orbit seen from Vernal equinox",
)
plots.add_north_direction(plot_vernal)
plots.add_equator_line(plot_vernal)
plot_xz = plots.create_plot(
datasources.orbit_3d, "x", "z", "-y", datasources.position_3d, ""
)
plots.add_north_direction(plot_xz)
plots.add_vernal_direction(plot_xz)
plots.add_equator_line(plot_xz)
# Set up callbacks
with open("callback.js", "r") as f:
sliders_callback_code = f.read()
orbit_description_div = Div(
css_classes=["orbit-description"],
text="""
<h2>Orbital Data</h2>
<p>Please manipulate the sliders to update this data.</p>
""",
)
callback_args = dict(
orbit_shape=datasources.orbit_shape,
orbit_3d=datasources.orbit_3d,
position_in_orbital_plane=datasources.position_in_orbital_plane,
position_3d=datasources.position_3d,
apsides_in_orbital_plane=datasources.apsides_in_orbital_plane,
nodes_in_equatorial_plane=datasources.nodes_in_equatorial_plane,
sma=sma,
eccentricity=eccentricity,
aop=aop,
inclination=inclination,
raan=raan,
anomaly=anomaly,
N=datasources.N,
orbit_description_div=orbit_description_div,
orbital_parameters=datasources.orbital_parameters,
)
for w in [sma, eccentricity, aop, inclination, raan, anomaly]:
w.js_on_change("value", CustomJS(args=callback_args, code=sliders_callback_code))
# Set up layouts and add to document
inputs = column(
Div(text="<h2>Orbital Parameters</h2>"),
sma_widget,
eccentricity_widget,
inclination_widget,
aop_widget,
raan_widget,
anomaly_widget,
sizing_mode="stretch_width",
height=400,
css_classes=["inputs"],
)
plots = gridplot(
[[inputs, plot_vernal, plot_xz], [plot_shape, orbit_description_div, plot_pole]],
toolbar_options=dict(logo=None),
)
intro = Div(
text="""
<h1>Orbit Visualization</h1>
<p>A dashed line means the orbit is below the plane of the screen.</p>
""",
sizing_mode="stretch_width",
)
button = Button(label="Update", css_classes=["update_button"], width=1, height=1)
button.js_on_click(CustomJS(args=callback_args, code=sliders_callback_code))
_env = Environment(loader=FileSystemLoader("templates"))
output_file("index.html")
save(
layout(intro, button, plots),
title="Orbital Parameters Visualization",
template=_env.get_template("template.html.j2"),
)