Spaces:
Sleeping
Sleeping
ibrahim yıldız
commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,130 +3,134 @@ import math
|
|
| 3 |
import plotly.graph_objects as go
|
| 4 |
import streamlit as st
|
| 5 |
|
| 6 |
-
#
|
| 7 |
def spheres(size, clr, dist=0):
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
| 14 |
trace.update(showscale=False)
|
| 15 |
return trace
|
| 16 |
|
| 17 |
-
#
|
| 18 |
def orbits(dist, offset=0, clr='white', wdth=2):
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
|
|
|
|
|
|
| 27 |
return trace
|
| 28 |
|
| 29 |
-
#
|
| 30 |
def annot(xcrd, zcrd, txt, xancr='center'):
|
| 31 |
-
strng
|
|
|
|
|
|
|
| 32 |
return strng
|
| 33 |
|
| 34 |
# The Streamlit app
|
| 35 |
def main():
|
| 36 |
-
|
| 37 |
-
|
| 38 |
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
distance_from_sun = [0, 57.9, 108.2, 149.6, 227.9, 778.6, 1433.5, 2872.5, 4495.1]
|
| 44 |
-
# Eccentricity and inclination values (in degrees) for each planet's orbit
|
| 45 |
-
eccentricities = [0, 0.205, 0.007, 0.017, 0.093, 0.048, 0.056, 0.046, 0.009]
|
| 46 |
-
inclinations = [0, 7.005, 3.394, 0, 1.850, 1.308, 2.488, 0.773, 1.774]
|
| 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 |
-
fig.add_trace(go.Scatter3d(x=[distance_from_sun[3] * 1000000], y=[0], z=[0], mode='markers', marker=dict(size=diameter_km[3] / 2, color='#325bff'))) # Earth
|
| 113 |
-
fig.add_trace(go.Scatter3d(x=[distance_from_sun[4] * 1000000], y=[0], z=[0], mode='markers', marker=dict(size=diameter_km[4] / 2, color='#b20000'))) # Mars
|
| 114 |
-
fig.add_trace(go.Scatter3d(x=[distance_from_sun[5] * 1000000], y=[0], z=[0], mode='markers', marker=dict(size=diameter_km[5] / 2, color='#ebebd2'))) # Jupiter
|
| 115 |
-
fig.add_trace(go.Scatter3d(x=[distance_from_sun[6] * 1000000], y=[0], z=[0], mode='markers', marker=dict(size=diameter_km[6] / 2, color='#ebcd82'))) # Saturn
|
| 116 |
-
fig.add_trace(go.Scatter3d(x=[distance_from_sun[7] * 1000000], y=[0], z=[0], mode='markers', marker=dict(size=diameter_km[7] / 2, color='#37ffda'))) # Uranus
|
| 117 |
-
fig.add_trace(go.Scatter3d(x=[distance_from_sun[8] * 1000000], y=[0], z=[0], mode='markers', marker=dict(size=diameter_km[8] / 2, color='#2500ab'))) # Neptune
|
| 118 |
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
fig.add_trace(trace)
|
| 123 |
|
| 124 |
-
|
| 125 |
-
for trace in traces_rings_saturn:
|
| 126 |
-
trace.line.color = '#827962'
|
| 127 |
-
fig.add_trace(trace)
|
| 128 |
-
|
| 129 |
-
st.plotly_chart(fig)
|
| 130 |
|
| 131 |
if __name__ == "__main__":
|
| 132 |
-
|
|
|
|
| 3 |
import plotly.graph_objects as go
|
| 4 |
import streamlit as st
|
| 5 |
|
| 6 |
+
# THIS FUNCTION CREATES SHPERES
|
| 7 |
def spheres(size, clr, dist=0):
|
| 8 |
+
# Set up 100 points. First, do angles
|
| 9 |
+
theta = np.linspace(0,2*np.pi,100)
|
| 10 |
+
phi = np.linspace(0,np.pi,100)
|
| 11 |
+
# Set up coordinates for points on the sphere
|
| 12 |
+
x0 = dist + size * np.outer(np.cos(theta),np.sin(phi))
|
| 13 |
+
y0 = size * np.outer(np.sin(theta),np.sin(phi))
|
| 14 |
+
z0 = size * np.outer(np.ones(100),np.cos(phi))
|
| 15 |
+
# Set up trace
|
| 16 |
+
trace= go.Surface(x=x0, y=y0, z=z0, colorscale=[[0,clr], [1,clr]])
|
| 17 |
trace.update(showscale=False)
|
| 18 |
return trace
|
| 19 |
|
| 20 |
+
# THIS FUNCTION CREATES ORBITS
|
| 21 |
def orbits(dist, offset=0, clr='white', wdth=2):
|
| 22 |
+
# Initialize empty lists for eac set of coordinates
|
| 23 |
+
xcrd=[]
|
| 24 |
+
ycrd=[]
|
| 25 |
+
zcrd=[]
|
| 26 |
+
# Calculate coordinates
|
| 27 |
+
for i in range(0,361):
|
| 28 |
+
xcrd=xcrd+[(round(np.cos(math.radians(i)),5)) * dist + offset]
|
| 29 |
+
ycrd=ycrd+[(round(np.sin(math.radians(i)),5)) * dist]
|
| 30 |
+
zcrd=zcrd+[0]
|
| 31 |
+
trace = go.Scatter3d(x=xcrd, y=ycrd, z=zcrd, marker=dict(size=0.1), line=dict(color=clr,width=wdth))
|
| 32 |
return trace
|
| 33 |
|
| 34 |
+
# THIS FUNCTION DEFINES ANNOTATIONS
|
| 35 |
def annot(xcrd, zcrd, txt, xancr='center'):
|
| 36 |
+
strng=dict(showarrow=False, x=xcrd,
|
| 37 |
+
y=0, z=zcrd, text=txt,
|
| 38 |
+
xanchor=xancr, font=dict(color='#BEBEBE',size=12), opacity=0.5)
|
| 39 |
return strng
|
| 40 |
|
| 41 |
# The Streamlit app
|
| 42 |
def main():
|
| 43 |
+
st.title('Solar System Visualization')
|
| 44 |
+
st.write('##### Zoom in to realize how small and insignificant you are!')
|
| 45 |
|
| 46 |
+
# VISUALIZE THE SOLAR SYSTEM
|
| 47 |
+
diameter_km = [1391016, 4879, 12104, 12756, 6792, 142984, 120536, 51118, 49528]
|
| 48 |
+
diameter = [((i / 142984) * 20) for i in diameter_km] # Scale diameters
|
| 49 |
+
distance_from_sun = [0, 57.9, 108.2, 149.6, 227.9, 778.6, 1433.5, 2872.5, 4495.1]
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
+
# Set up orbit traces
|
| 52 |
+
traces_orbits = [
|
| 53 |
+
orbits(distance_from_sun[1]), # Mercury
|
| 54 |
+
orbits(distance_from_sun[2]), # Venus
|
| 55 |
+
orbits(distance_from_sun[3]), # Earth
|
| 56 |
+
orbits(distance_from_sun[4]), # Mars
|
| 57 |
+
orbits(distance_from_sun[5]), # Jupiter
|
| 58 |
+
orbits(distance_from_sun[6]), # Saturn
|
| 59 |
+
orbits(distance_from_sun[7]), # Uranus
|
| 60 |
+
orbits(distance_from_sun[8]) # Neptune
|
| 61 |
+
]
|
| 62 |
|
| 63 |
+
# Use the same to draw a few rings for Saturn
|
| 64 |
+
traces_rings_saturn = [
|
| 65 |
+
orbits(60, distance_from_sun[6], '#827962', 3),
|
| 66 |
+
orbits(70, distance_from_sun[6], '#827962', 3),
|
| 67 |
+
orbits(80, distance_from_sun[6], '#827962', 3),
|
| 68 |
+
orbits(90, distance_from_sun[6], '#827962', 3),
|
| 69 |
+
orbits(100, distance_from_sun[6], '#827962', 3),
|
| 70 |
+
orbits(110, distance_from_sun[6], '#827962', 3)
|
| 71 |
+
]
|
| 72 |
|
| 73 |
+
layout=go.Layout(
|
| 74 |
+
title = 'Solar System',
|
| 75 |
+
showlegend=False,
|
| 76 |
+
margin=dict(l=0, r=0, t=0, b=0),
|
| 77 |
+
scene = dict(
|
| 78 |
+
xaxis=dict(title='Distance from the Sun',
|
| 79 |
+
titlefont_color='black',
|
| 80 |
+
range=[-7000,7000],
|
| 81 |
+
backgroundcolor='black',
|
| 82 |
+
color='black',
|
| 83 |
+
gridcolor='black'),
|
| 84 |
+
yaxis=dict(title='Distance from the Sun',
|
| 85 |
+
titlefont_color='black',
|
| 86 |
+
range=[-7000,7000],
|
| 87 |
+
backgroundcolor='black',
|
| 88 |
+
color='black',
|
| 89 |
+
gridcolor='black'
|
| 90 |
+
),
|
| 91 |
+
zaxis=dict(title='',
|
| 92 |
+
range=[-7000,7000],
|
| 93 |
+
backgroundcolor='black',
|
| 94 |
+
color='white',
|
| 95 |
+
gridcolor='black'
|
| 96 |
+
),
|
| 97 |
+
annotations=[
|
| 98 |
+
annot(distance_from_sun[0], 200, 'Sun', xancr='left'),
|
| 99 |
+
annot(distance_from_sun[1], 2, 'Mercury'),
|
| 100 |
+
annot(distance_from_sun[2], 6, 'Venus'),
|
| 101 |
+
annot(distance_from_sun[3], 6, 'Earth'),
|
| 102 |
+
annot(distance_from_sun[4], 3, 'Mars'),
|
| 103 |
+
annot(distance_from_sun[5], 70, 'Jupiter'),
|
| 104 |
+
annot(distance_from_sun[6], 60, 'Saturn'),
|
| 105 |
+
annot(distance_from_sun[7], 25, 'Uranus'),
|
| 106 |
+
annot(distance_from_sun[8], 25, 'Neptune'),
|
| 107 |
+
]
|
| 108 |
+
)
|
| 109 |
+
)
|
| 110 |
|
| 111 |
+
fig = go.Figure(layout=layout)
|
| 112 |
+
|
| 113 |
+
# Add spheres for the Sun and planets
|
| 114 |
+
fig.add_trace(spheres(diameter[0], '#ffff00', distance_from_sun[0])) # Sun
|
| 115 |
+
fig.add_trace(spheres(diameter[1], '#87877d', distance_from_sun[1])) # Mercury
|
| 116 |
+
fig.add_trace(spheres(diameter[2], '#d23100', distance_from_sun[2])) # Venus
|
| 117 |
+
fig.add_trace(spheres(diameter[3], '#325bff', distance_from_sun[3])) # Earth
|
| 118 |
+
fig.add_trace(spheres(diameter[4], '#b20000', distance_from_sun[4])) # Mars
|
| 119 |
+
fig.add_trace(spheres(diameter[5], '#ebebd2', distance_from_sun[5])) # Jupiter
|
| 120 |
+
fig.add_trace(spheres(diameter[6], '#ebcd82', distance_from_sun[6])) # Saturn
|
| 121 |
+
fig.add_trace(spheres(diameter[7], '#37ffda', distance_from_sun[7])) # Uranus
|
| 122 |
+
fig.add_trace(spheres(diameter[8], '#2500ab', distance_from_sun[8])) # Neptune
|
| 123 |
|
| 124 |
+
# Add orbit traces
|
| 125 |
+
for trace in traces_orbits:
|
| 126 |
+
trace.line.color = '#808080'
|
| 127 |
+
fig.add_trace(trace)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 128 |
|
| 129 |
+
# Add rings for Saturn
|
| 130 |
+
for trace in traces_rings_saturn:
|
| 131 |
+
fig.add_trace(trace)
|
|
|
|
| 132 |
|
| 133 |
+
st.plotly_chart(fig)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 134 |
|
| 135 |
if __name__ == "__main__":
|
| 136 |
+
main()
|