150 lines
5.0 KiB
Python
Executable File
150 lines
5.0 KiB
Python
Executable File
#!/usr/bin/python3
|
|
|
|
import random
|
|
import urllib.request
|
|
import dash
|
|
import dash_html_components as html
|
|
import dash_core_components as dcc
|
|
from dash.dependencies import Input, Output
|
|
from datetime import datetime, timedelta
|
|
from satellite_czml import satellite_czml
|
|
from satellite_czml import satellite
|
|
|
|
url = 'https://celestrak.com/NORAD/elements/galileo.txt'
|
|
apikey = open('cesium.key').read().strip()
|
|
tles = [l.decode("utf-8").strip() for l in urllib.request.urlopen(url).readlines()]
|
|
tle_list = [[tles[i],tles[i+1],tles[i+2]] for i,_ in enumerate(tles) if i%3==0]
|
|
small_tle_list = tle_list
|
|
|
|
single_tle = [tle_list[0]]
|
|
single_tle
|
|
|
|
single_czml = satellite_czml(tle_list=single_tle).get_czml()
|
|
|
|
multiple_czml = satellite_czml(tle_list=small_tle_list).get_czml()
|
|
|
|
name_list = [t[0] for t in small_tle_list]
|
|
description_list = ['Station: ' + t[0] for t in small_tle_list]
|
|
color_list = [[random.randrange(256) for x in range(3)] for x in range(len(small_tle_list))]
|
|
size_list = [7] * len(small_tle_list)
|
|
|
|
czml_obj = satellite_czml(tle_list=small_tle_list, name_list=name_list, description_list=description_list,
|
|
color_list=color_list, speed_multiplier=1, use_default_image=False,
|
|
marker_scale_list=size_list, show_label=False, show_path=False,
|
|
ignore_bad_tles=True)
|
|
multiple_czml_p = czml_obj.get_czml()
|
|
|
|
multiple_sats=[]
|
|
for tle in small_tle_list:
|
|
sat = satellite(tle,
|
|
description='Station: ' + tle[0],
|
|
color = [random.randrange(256) for x in range(3)],
|
|
marker_scale=12,
|
|
use_default_image=False,
|
|
start_time=datetime.strptime('2020-01-01 00:00:00','%Y-%m-%d %H:%M:%S'),
|
|
end_time=datetime.strptime('2020-01-01 01:00:00','%Y-%m-%d %H:%M:%S'),
|
|
show_label=True,
|
|
show_path=True,
|
|
)
|
|
multiple_sats.append(sat)
|
|
|
|
czml_obj = satellite_czml(satellite_list=multiple_sats)
|
|
multiple_czml_c = czml_obj.get_czml()
|
|
|
|
last_sat_key = list(czml_obj.satellites.keys())[-1]
|
|
last_sat = czml_obj.satellites[last_sat_key]
|
|
|
|
# Change the path to display the orbit path
|
|
last_sat.build_path(rebuild=True,
|
|
show=True,
|
|
color=[255, 255, 0, 127],
|
|
width=3
|
|
)
|
|
|
|
# Change the label look
|
|
last_sat.build_label(rebuild=True,
|
|
show=True,
|
|
font='12pt Arial',
|
|
color=[255, 255, 0, 200],
|
|
outlineColor=[0, 0, 0, 127],
|
|
outlineWidth=3,
|
|
)
|
|
|
|
# Change the marker (billboard)
|
|
last_sat.build_marker(rebuild=True,
|
|
size=18,
|
|
outlineColor=[0, 0, 0, 128],
|
|
)
|
|
|
|
modified_czml = czml_obj.get_czml()
|
|
|
|
|
|
external_css = ['https://cesium.com/downloads/cesiumjs/releases/1.76/Build/Cesium/Widgets/widgets.css']
|
|
|
|
external_scripts = [{'src':'https://cesium.com/downloads/cesiumjs/releases/1.76/Build/Cesium/Cesium.js'}]
|
|
|
|
app = dash.Dash(__name__,
|
|
title='satellite_czml',
|
|
external_scripts=external_scripts,
|
|
external_stylesheets=external_css)
|
|
|
|
app.layout = html.Div(children=[
|
|
dcc.Dropdown(id='choose_czml_dd',
|
|
options=[
|
|
{'label': 'Single CZML', 'value': 'single_czml'},
|
|
{'label': 'Multiple CZML', 'value': 'multiple_czml'},
|
|
{'label': 'Specified Arguments CZML', 'value': 'multiple_czml_p'},
|
|
{'label': 'Create One-by-One CZML', 'value': 'multiple_czml_c'},
|
|
{'label': 'Modified CZML', 'value': 'modified_czml'}
|
|
],
|
|
value='single_czml'
|
|
),
|
|
html.Div(id='cesiumContainer'),
|
|
html.Div(id='czml', style={'display': 'none'}),
|
|
html.Div(id='apikey', style={'display': 'none'}, children=apikey)
|
|
])
|
|
|
|
@app.callback(
|
|
Output('czml', 'children'),
|
|
Input('choose_czml_dd', 'value'))
|
|
def update_satellite_filter(v):
|
|
d = {'single_czml':single_czml,
|
|
'multiple_czml':multiple_czml,
|
|
'multiple_czml_p':multiple_czml_p,
|
|
'multiple_czml_c':multiple_czml_c,
|
|
'modified_czml':modified_czml
|
|
}
|
|
return d[v]
|
|
|
|
app.clientside_callback('''
|
|
function(id, czml, apikey) {
|
|
// Create the Cesium Viewer
|
|
if (!window.viewer) {
|
|
Cesium.Ion.defaultAccessToken = apikey;
|
|
window.viewer = new Cesium.Viewer(id,{
|
|
shouldAnimate: true,
|
|
});
|
|
window.viewer.scene.globe.enableLighting = true;
|
|
}
|
|
|
|
// Update the Cesium Viewer
|
|
if (czml) {
|
|
window.viewer.dataSources.removeAll();
|
|
czmlJson = JSON.parse(czml);
|
|
window.viewer.dataSources.add(
|
|
Cesium.CzmlDataSource.load(czmlJson)
|
|
);
|
|
}
|
|
|
|
return true;
|
|
}''',
|
|
Output('cesiumContainer', 'data-done'),
|
|
Input('cesiumContainer', 'id'),
|
|
Input('czml', 'children'),
|
|
Input('apikey', 'children')
|
|
)
|
|
|
|
if __name__ == '__main__':
|
|
app.run_server(debug=True, use_reloader=False)
|
|
|