Spaces:
Sleeping
Sleeping
forrestfwilliams
commited on
Commit
•
17da4a9
1
Parent(s):
40c8a38
Upload 2 files
Browse files- app.py +16 -54
- los_palette.py +39 -0
app.py
CHANGED
@@ -5,52 +5,12 @@ from matplotlib.figure import Figure
|
|
5 |
from matplotlib.colors import LinearSegmentedColormap
|
6 |
from matplotlib.markers import MarkerStyle
|
7 |
|
|
|
|
|
8 |
WIDTH = 800
|
9 |
BG_COLOR = '#646464'
|
10 |
|
11 |
|
12 |
-
# los_palette.py ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
|
13 |
-
def angles_to_unit_vector(heading_angle_degrees, grazing_angle_degrees, left_looking=True):
|
14 |
-
# Convert angles to radians
|
15 |
-
heading_angle_start_at_east = 90 - heading_angle_degrees
|
16 |
-
look_offset = 90 if left_looking else -90
|
17 |
-
heading_los = heading_angle_start_at_east + look_offset
|
18 |
-
heading_angle_radians = np.radians(heading_los)
|
19 |
-
|
20 |
-
grazing_angle_sensor_to_ground = -(90 - grazing_angle_degrees)
|
21 |
-
grazing_angle_radians = np.radians(grazing_angle_sensor_to_ground)
|
22 |
-
|
23 |
-
# Calculate the vector components
|
24 |
-
x_component = np.cos(heading_angle_radians) * np.cos(grazing_angle_radians)
|
25 |
-
y_component = np.sin(heading_angle_radians) * np.cos(grazing_angle_radians)
|
26 |
-
z_component = np.sin(grazing_angle_radians)
|
27 |
-
|
28 |
-
# Create a NumPy array for the vector
|
29 |
-
vector = np.array([x_component, y_component, z_component])
|
30 |
-
|
31 |
-
# Normalize the vector to obtain the unit vector
|
32 |
-
unit_vector = (vector / np.linalg.norm(vector)).round(5)
|
33 |
-
|
34 |
-
return unit_vector
|
35 |
-
|
36 |
-
|
37 |
-
def unit_vector_to_hex(unit_vector):
|
38 |
-
centered_rgb = (unit_vector * 127.5) + 127.5
|
39 |
-
# r, g, b = centered_rgb.round(0).astype(int)
|
40 |
-
r, b, g = centered_rgb.round(0).astype(int)
|
41 |
-
hex_color = f'#{r:02X}{g:02X}{b:02X}'
|
42 |
-
return hex_color
|
43 |
-
|
44 |
-
|
45 |
-
def angles_to_hex(heading_angle_degrees, grazing_angle_degrees, left_looking=True):
|
46 |
-
unit_vector = angles_to_unit_vector(heading_angle_degrees, grazing_angle_degrees, left_looking)
|
47 |
-
hex = unit_vector_to_hex(unit_vector)
|
48 |
-
return hex
|
49 |
-
|
50 |
-
|
51 |
-
# end los_palette.py~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
|
52 |
-
|
53 |
-
|
54 |
def get_heading_line(vector):
|
55 |
if vector[0] == 0 and vector[1] == 0:
|
56 |
return [0, 0], [0, 0]
|
@@ -112,8 +72,8 @@ def plot_look_direction(params):
|
|
112 |
fig = Figure(figsize=(6, 6))
|
113 |
ax = fig.subplots()
|
114 |
ax.plot(np.cos(unit_circle), np.sin(unit_circle), linewidth=1, color=BG_COLOR, zorder=2)
|
115 |
-
ax.plot(
|
116 |
-
ax.plot(
|
117 |
angle = np.rad2deg(np.arctan2(away_vector[1], away_vector[0]))
|
118 |
satellite_marker(ax, angle)
|
119 |
|
@@ -124,7 +84,7 @@ def plot_look_direction(params):
|
|
124 |
ax.spines['right'].set_visible(False)
|
125 |
ax.xaxis.set_ticks([-1, 1], labels=[270, 90], zorder=5)
|
126 |
ax.yaxis.set_ticks([-1, 1], labels=[180, 0])
|
127 |
-
ax.legend(loc='upper left')
|
128 |
|
129 |
fig.patch.set_alpha(0.0)
|
130 |
fig.tight_layout()
|
@@ -157,8 +117,8 @@ def plot_grazing_angle(params):
|
|
157 |
|
158 |
fig = Figure(figsize=(6, 6))
|
159 |
ax = fig.subplots()
|
160 |
-
ax.plot(x[:2], y[:2], linewidth=
|
161 |
-
ax.plot(x[1:], y[1:], linewidth=
|
162 |
angle = np.rad2deg(np.arccos(away_vector[2]))
|
163 |
angle = angle if left_looking else angle + (2 * (180 - angle))
|
164 |
satellite_marker(ax, angle, (0, 1))
|
@@ -170,7 +130,7 @@ def plot_grazing_angle(params):
|
|
170 |
ax.spines['right'].set_visible(False)
|
171 |
ax.xaxis.set_ticks([])
|
172 |
ax.yaxis.set_ticks([])
|
173 |
-
ax.legend(loc='upper left')
|
174 |
|
175 |
fig.patch.set_alpha(0.0)
|
176 |
fig.tight_layout()
|
@@ -223,7 +183,7 @@ def reset_widgets(menu_value):
|
|
223 |
'we': (0, 90, 'Left Looking'),
|
224 |
'sn': (90, 90, 'Left Looking'),
|
225 |
}
|
226 |
-
|
227 |
|
228 |
|
229 |
def on_menu_change(event):
|
@@ -231,9 +191,11 @@ def on_menu_change(event):
|
|
231 |
reset_widgets(selected_option)
|
232 |
|
233 |
|
234 |
-
opts = dict(align=('
|
235 |
-
|
236 |
-
|
|
|
|
|
237 |
look_switch = pn.widgets.ToggleGroup(options=['Left Looking', 'Right Looking'], behavior='radio', **opts)
|
238 |
menu_items = [
|
239 |
('Sentinel-1 Ascending', 's1a'),
|
@@ -245,12 +207,12 @@ menu_items = [
|
|
245 |
menu = pn.widgets.MenuButton(name='Presets', items=menu_items, button_type='primary', **opts)
|
246 |
menu.on_click(on_menu_change)
|
247 |
|
248 |
-
params = pn.bind(get_params,
|
249 |
interactive_look = pn.bind(plot_look_direction, params)
|
250 |
interactive_grazing = pn.bind(plot_grazing_angle, params)
|
251 |
interactive_color = pn.bind(plot_color_gradient, params)
|
252 |
pn.Column(
|
253 |
-
pn.Row(menu,
|
254 |
pn.Row(interactive_look, interactive_grazing),
|
255 |
pn.Row(interactive_color),
|
256 |
).servable()
|
|
|
5 |
from matplotlib.colors import LinearSegmentedColormap
|
6 |
from matplotlib.markers import MarkerStyle
|
7 |
|
8 |
+
from los_palette import angles_to_unit_vector, unit_vector_to_hex
|
9 |
+
|
10 |
WIDTH = 800
|
11 |
BG_COLOR = '#646464'
|
12 |
|
13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
def get_heading_line(vector):
|
15 |
if vector[0] == 0 and vector[1] == 0:
|
16 |
return [0, 0], [0, 0]
|
|
|
72 |
fig = Figure(figsize=(6, 6))
|
73 |
ax = fig.subplots()
|
74 |
ax.plot(np.cos(unit_circle), np.sin(unit_circle), linewidth=1, color=BG_COLOR, zorder=2)
|
75 |
+
ax.plot(x, y, color=away_color, linestyle='--', label='Look Direction', linewidth=3, zorder=3)
|
76 |
+
ax.plot(az_x, az_y, color='darkgray', linestyle='--', label='Azimuth Direction', linewidth=3, zorder=4)
|
77 |
angle = np.rad2deg(np.arctan2(away_vector[1], away_vector[0]))
|
78 |
satellite_marker(ax, angle)
|
79 |
|
|
|
84 |
ax.spines['right'].set_visible(False)
|
85 |
ax.xaxis.set_ticks([-1, 1], labels=[270, 90], zorder=5)
|
86 |
ax.yaxis.set_ticks([-1, 1], labels=[180, 0])
|
87 |
+
ax.legend(loc='upper left', fontsize='large', markerscale=1.5, framealpha=0.5)
|
88 |
|
89 |
fig.patch.set_alpha(0.0)
|
90 |
fig.tight_layout()
|
|
|
117 |
|
118 |
fig = Figure(figsize=(6, 6))
|
119 |
ax = fig.subplots()
|
120 |
+
ax.plot(x[:2], y[:2], linewidth=3, linestyle='--', color=away_color, label='Away from Satellite', zorder=2)
|
121 |
+
ax.plot(x[1:], y[1:], linewidth=3, linestyle='--', color=towards_color, label='Towards Satellite', zorder=3)
|
122 |
angle = np.rad2deg(np.arccos(away_vector[2]))
|
123 |
angle = angle if left_looking else angle + (2 * (180 - angle))
|
124 |
satellite_marker(ax, angle, (0, 1))
|
|
|
130 |
ax.spines['right'].set_visible(False)
|
131 |
ax.xaxis.set_ticks([])
|
132 |
ax.yaxis.set_ticks([])
|
133 |
+
ax.legend(loc='upper left', fontsize='large', markerscale=1.5, framealpha=0.5)
|
134 |
|
135 |
fig.patch.set_alpha(0.0)
|
136 |
fig.tight_layout()
|
|
|
183 |
'we': (0, 90, 'Left Looking'),
|
184 |
'sn': (90, 90, 'Left Looking'),
|
185 |
}
|
186 |
+
heading_input.value, grazing_input.value, look_switch.value = options[menu_value]
|
187 |
|
188 |
|
189 |
def on_menu_change(event):
|
|
|
191 |
reset_widgets(selected_option)
|
192 |
|
193 |
|
194 |
+
opts = dict(align=('end', 'end'), width=int(WIDTH / 4.5))
|
195 |
+
heading_input = pn.widgets.IntInput(name='Satellite Heading (0-360)', start=0, end=360, step=5, value=360 - 12, **opts)
|
196 |
+
grazing_input = pn.widgets.IntInput(name='Grazing Angle (0-90)', start=0, end=90, step=5, value=34, **opts)
|
197 |
+
# heading_input = pn.widgets.IntSlider(name='Satellite Heading', start=0, end=360, step=1, value=360 - 12, **opts)
|
198 |
+
# grazing_input = pn.widgets.IntSlider(name='Grazing Angle', start=0, end=90, step=1, value=34, **opts)
|
199 |
look_switch = pn.widgets.ToggleGroup(options=['Left Looking', 'Right Looking'], behavior='radio', **opts)
|
200 |
menu_items = [
|
201 |
('Sentinel-1 Ascending', 's1a'),
|
|
|
207 |
menu = pn.widgets.MenuButton(name='Presets', items=menu_items, button_type='primary', **opts)
|
208 |
menu.on_click(on_menu_change)
|
209 |
|
210 |
+
params = pn.bind(get_params, heading_input, grazing_input, look_switch)
|
211 |
interactive_look = pn.bind(plot_look_direction, params)
|
212 |
interactive_grazing = pn.bind(plot_grazing_angle, params)
|
213 |
interactive_color = pn.bind(plot_color_gradient, params)
|
214 |
pn.Column(
|
215 |
+
pn.Row(menu, heading_input, grazing_input, look_switch, height=100),
|
216 |
pn.Row(interactive_look, interactive_grazing),
|
217 |
pn.Row(interactive_color),
|
218 |
).servable()
|
los_palette.py
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
|
3 |
+
|
4 |
+
def angles_to_unit_vector(heading_angle_degrees, incidence_angle_degrees, left_looking=True):
|
5 |
+
# Convert angles to radians
|
6 |
+
heading_angle_start_at_east = 90 - heading_angle_degrees
|
7 |
+
look_offset = 90 if left_looking else -90
|
8 |
+
heading_los = heading_angle_start_at_east + look_offset
|
9 |
+
heading_angle_radians = np.radians(heading_los)
|
10 |
+
|
11 |
+
incidence_angle_sensor_to_ground = -(90 - incidence_angle_degrees)
|
12 |
+
incidence_angle_radians = np.radians(incidence_angle_sensor_to_ground)
|
13 |
+
|
14 |
+
# Calculate the vector components
|
15 |
+
x_component = np.cos(heading_angle_radians) * np.cos(incidence_angle_radians)
|
16 |
+
y_component = np.sin(heading_angle_radians) * np.cos(incidence_angle_radians)
|
17 |
+
z_component = np.sin(incidence_angle_radians)
|
18 |
+
|
19 |
+
# Create a NumPy array for the vector
|
20 |
+
vector = np.array([x_component, y_component, z_component])
|
21 |
+
|
22 |
+
# Normalize the vector to obtain the unit vector
|
23 |
+
unit_vector = (vector / np.linalg.norm(vector)).round(5)
|
24 |
+
|
25 |
+
return unit_vector
|
26 |
+
|
27 |
+
|
28 |
+
def unit_vector_to_hex(unit_vector):
|
29 |
+
centered_rgb = (unit_vector * 127.5) + 127.5
|
30 |
+
# r, g, b = centered_rgb.round(0).astype(int)
|
31 |
+
r, b, g = centered_rgb.round(0).astype(int)
|
32 |
+
hex_color = f'#{r:02X}{g:02X}{b:02X}'
|
33 |
+
return hex_color
|
34 |
+
|
35 |
+
|
36 |
+
def angles_to_hex(heading_angle_degrees, incidence_angle_degrees, left_looking=True):
|
37 |
+
unit_vector = angles_to_unit_vector(heading_angle_degrees, incidence_angle_degrees, left_looking)
|
38 |
+
hex = unit_vector_to_hex(unit_vector)
|
39 |
+
return hex
|