forrestfwilliams commited on
Commit
40c8a38
·
1 Parent(s): ce90b3f

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -23
app.py CHANGED
@@ -5,26 +5,25 @@ from matplotlib.figure import Figure
5
  from matplotlib.colors import LinearSegmentedColormap
6
  from matplotlib.markers import MarkerStyle
7
 
8
- # pn.extension(design='material')
9
  WIDTH = 800
10
  BG_COLOR = '#646464'
11
 
12
 
13
- # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
14
- def angles_to_unit_vector(heading_angle_degrees, incidence_angle_degrees, left_looking=True):
15
  # Convert angles to radians
16
  heading_angle_start_at_east = 90 - heading_angle_degrees
17
  look_offset = 90 if left_looking else -90
18
  heading_los = heading_angle_start_at_east + look_offset
19
  heading_angle_radians = np.radians(heading_los)
20
 
21
- incidence_angle_sensor_to_ground = -(90 - incidence_angle_degrees)
22
- incidence_angle_radians = np.radians(incidence_angle_sensor_to_ground)
23
 
24
  # Calculate the vector components
25
- x_component = np.cos(heading_angle_radians) * np.cos(incidence_angle_radians)
26
- y_component = np.sin(heading_angle_radians) * np.cos(incidence_angle_radians)
27
- z_component = np.sin(incidence_angle_radians)
28
 
29
  # Create a NumPy array for the vector
30
  vector = np.array([x_component, y_component, z_component])
@@ -43,13 +42,13 @@ def unit_vector_to_hex(unit_vector):
43
  return hex_color
44
 
45
 
46
- def angles_to_hex(heading_angle_degrees, incidence_angle_degrees, left_looking=True):
47
- unit_vector = angles_to_unit_vector(heading_angle_degrees, incidence_angle_degrees, left_looking)
48
  hex = unit_vector_to_hex(unit_vector)
49
  return hex
50
 
51
 
52
- # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
53
 
54
 
55
  def get_heading_line(vector):
@@ -94,11 +93,11 @@ def satellite_marker(axis, angle=0, center=(0, 0)):
94
  axis.scatter(center[0], center[1], marker=MarkerStyle('o'), s=200, color='black', zorder=1001)
95
 
96
 
97
- def get_params(heading_angle, incidence_angle, look_direction):
98
  left_looking = look_direction == 'Left Looking'
99
- away_vector = angles_to_unit_vector(heading_angle, incidence_angle, left_looking)
100
  away_color = unit_vector_to_hex(away_vector)
101
- towards_vector = angles_to_unit_vector(heading_angle, 180 + incidence_angle, left_looking)
102
  towards_color = unit_vector_to_hex(towards_vector)
103
  return away_vector, left_looking, (away_color, towards_color)
104
 
@@ -133,7 +132,7 @@ def plot_look_direction(params):
133
  return mpl_pane
134
 
135
 
136
- def get_incidence_line(vector, left_looking, vertical_offset=1):
137
  if vector[2] == 0:
138
  x = np.array([100, 0, -100])
139
  y = np.array([0, 0, 0])
@@ -152,9 +151,9 @@ def get_incidence_line(vector, left_looking, vertical_offset=1):
152
  return x, y
153
 
154
 
155
- def plot_incidence_angle(params):
156
  away_vector, left_looking, (away_color, towards_color) = params
157
- x, y = get_incidence_line(away_vector, left_looking)
158
 
159
  fig = Figure(figsize=(6, 6))
160
  ax = fig.subplots()
@@ -224,7 +223,7 @@ def reset_widgets(menu_value):
224
  'we': (0, 90, 'Left Looking'),
225
  'sn': (90, 90, 'Left Looking'),
226
  }
227
- heading_slider.value, incidence_slider.value, look_switch.value = options[menu_value]
228
 
229
 
230
  def on_menu_change(event):
@@ -234,7 +233,7 @@ def on_menu_change(event):
234
 
235
  opts = dict(align=('center', 'center'), width=int(WIDTH / 4.5))
236
  heading_slider = pn.widgets.IntSlider(name='Satellite Heading', start=0, end=360, step=1, value=360 - 12, **opts)
237
- incidence_slider = pn.widgets.IntSlider(name='Incidence Angle', start=0, end=90, step=1, value=34, **opts)
238
  look_switch = pn.widgets.ToggleGroup(options=['Left Looking', 'Right Looking'], behavior='radio', **opts)
239
  menu_items = [
240
  ('Sentinel-1 Ascending', 's1a'),
@@ -246,12 +245,12 @@ menu_items = [
246
  menu = pn.widgets.MenuButton(name='Presets', items=menu_items, button_type='primary', **opts)
247
  menu.on_click(on_menu_change)
248
 
249
- params = pn.bind(get_params, heading_slider, incidence_slider, look_switch)
250
  interactive_look = pn.bind(plot_look_direction, params)
251
- interactive_incidence = pn.bind(plot_incidence_angle, params)
252
  interactive_color = pn.bind(plot_color_gradient, params)
253
  pn.Column(
254
- pn.Row(menu, heading_slider, incidence_slider, look_switch, height=100),
255
- pn.Row(interactive_look, interactive_incidence),
256
  pn.Row(interactive_color),
257
  ).servable()
 
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])
 
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):
 
93
  axis.scatter(center[0], center[1], marker=MarkerStyle('o'), s=200, color='black', zorder=1001)
94
 
95
 
96
+ def get_params(heading_angle, grazing_angle, look_direction):
97
  left_looking = look_direction == 'Left Looking'
98
+ away_vector = angles_to_unit_vector(heading_angle, grazing_angle, left_looking)
99
  away_color = unit_vector_to_hex(away_vector)
100
+ towards_vector = angles_to_unit_vector(heading_angle, 180 + grazing_angle, left_looking)
101
  towards_color = unit_vector_to_hex(towards_vector)
102
  return away_vector, left_looking, (away_color, towards_color)
103
 
 
132
  return mpl_pane
133
 
134
 
135
+ def get_grazing_line(vector, left_looking, vertical_offset=1):
136
  if vector[2] == 0:
137
  x = np.array([100, 0, -100])
138
  y = np.array([0, 0, 0])
 
151
  return x, y
152
 
153
 
154
+ def plot_grazing_angle(params):
155
  away_vector, left_looking, (away_color, towards_color) = params
156
+ x, y = get_grazing_line(away_vector, left_looking)
157
 
158
  fig = Figure(figsize=(6, 6))
159
  ax = fig.subplots()
 
223
  'we': (0, 90, 'Left Looking'),
224
  'sn': (90, 90, 'Left Looking'),
225
  }
226
+ heading_slider.value, grazing_slider.value, look_switch.value = options[menu_value]
227
 
228
 
229
  def on_menu_change(event):
 
233
 
234
  opts = dict(align=('center', 'center'), width=int(WIDTH / 4.5))
235
  heading_slider = pn.widgets.IntSlider(name='Satellite Heading', start=0, end=360, step=1, value=360 - 12, **opts)
236
+ grazing_slider = pn.widgets.IntSlider(name='Grazing Angle', start=0, end=90, step=1, value=34, **opts)
237
  look_switch = pn.widgets.ToggleGroup(options=['Left Looking', 'Right Looking'], behavior='radio', **opts)
238
  menu_items = [
239
  ('Sentinel-1 Ascending', 's1a'),
 
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, heading_slider, grazing_slider, look_switch)
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, heading_slider, grazing_slider, look_switch, height=100),
254
+ pn.Row(interactive_look, interactive_grazing),
255
  pn.Row(interactive_color),
256
  ).servable()