2022-05-11 16:25:39 -06:00
|
|
|
#!/usr/bin/python3
|
|
|
|
|
|
|
|
import random
|
|
|
|
import urllib.request
|
|
|
|
import dash
|
2022-05-11 17:04:54 -06:00
|
|
|
from dash import html
|
|
|
|
from dash import dcc
|
2022-05-11 16:25:39 -06:00
|
|
|
from dash.dependencies import Input, Output
|
|
|
|
from datetime import datetime, timedelta
|
|
|
|
from satellite_czml import satellite_czml
|
|
|
|
from satellite_czml import satellite
|
|
|
|
|
2022-05-11 17:04:54 -06:00
|
|
|
url = 'https://celestrak.com/NORAD/elements/gnss.txt'
|
2022-05-11 16:25:39 -06:00
|
|
|
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]
|
|
|
|
|
2022-05-11 17:04:54 -06:00
|
|
|
multiple_czml = satellite_czml(tle_list=tle_list).get_czml()
|
2022-05-11 16:25:39 -06:00
|
|
|
|
2022-05-11 17:04:54 -06:00
|
|
|
name_list = [t[0] for t in tle_list]
|
|
|
|
description_list = ['Station: ' + t[0] for t in tle_list]
|
|
|
|
color_list = [[random.randrange(256) for x in range(3)] for x in range(len(tle_list))]
|
|
|
|
size_list = [7] * len(tle_list)
|
2022-05-11 16:25:39 -06:00
|
|
|
|
2022-05-11 17:04:54 -06:00
|
|
|
czml_obj = satellite_czml(tle_list=tle_list, name_list=name_list, description_list=description_list,
|
2022-05-11 16:25:39 -06:00
|
|
|
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=[]
|
2022-05-11 17:04:54 -06:00
|
|
|
for tle in tle_list:
|
2022-05-11 16:25:39 -06:00
|
|
|
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__,
|
2022-05-11 17:04:54 -06:00
|
|
|
title='Spacecruft GNSS Earth',
|
2022-05-11 16:25:39 -06:00
|
|
|
external_scripts=external_scripts,
|
|
|
|
external_stylesheets=external_css)
|
|
|
|
|
|
|
|
app.layout = html.Div(children=[
|
|
|
|
dcc.Dropdown(id='choose_czml_dd',
|
|
|
|
options=[
|
2022-05-11 17:04:54 -06:00
|
|
|
{'label': 'Multiple CZML', 'value': 'multiple_czml'}
|
2022-05-11 16:25:39 -06:00
|
|
|
],
|
2022-05-11 17:04:54 -06:00
|
|
|
value='multiple_czml'
|
2022-05-11 16:25:39 -06:00
|
|
|
),
|
|
|
|
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):
|
2022-05-11 17:04:54 -06:00
|
|
|
d = {'multiple_czml':multiple_czml
|
2022-05-11 16:25:39 -06:00
|
|
|
}
|
|
|
|
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,{
|
2022-05-11 17:04:54 -06:00
|
|
|
shouldAnimate: false,
|
2022-05-11 16:25:39 -06:00
|
|
|
});
|
|
|
|
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)
|
|
|
|
|