Plotting the brightest 200 stars

Grabbing our libraries

import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
plt.style.use('seaborn-v0_8-darkgrid')

Solar System

Generating our data, wherein all the density is in the initial bin (the Sun)

aus = np.arange(0.1, 5, 0.1)
m_sun = 2E30
d_init = m_sun / (4/3 * np.pi * 0.1**3)
dens = np.zeros(shape=aus.shape)
dens[0] = d_init

ss_data = pd.DataFrame({'R_au': aus, 'density': dens})
ss_data.head()

ss_data.to_csv('L19_solar.csv', index=False)

Plotting it up:

plt.bar(ss_data.R_au, ss_data.density, width=-0.1, align='edge')
plt.show()

Computing the mass and then cumulative mass:

ss_data['mass'] = 4/3 * np.pi * ss_data.R_au**3 * ss_data.density
ss_data['cmass'] = ss_data.mass.cumsum()
ss_data.head()
R_au density mass cmass
0 0.1 4.774648e+32 2.000000e+30 2.000000e+30
1 0.2 0.000000e+00 0.000000e+00 2.000000e+30
2 0.3 0.000000e+00 0.000000e+00 2.000000e+30
3 0.4 0.000000e+00 0.000000e+00 2.000000e+30
4 0.5 0.000000e+00 0.000000e+00 2.000000e+30

Computing the velocity:

G = 6.602E-11
au = 1.496E11
ss_data['vel'] = np.sqrt(G * ss_data['cmass'] / (ss_data.R_au * au))
ss_data.head()
R_au density mass cmass vel
0 0.1 4.774648e+32 2.000000e+30 2.000000e+30 93947.874955
1 0.2 0.000000e+00 0.000000e+00 2.000000e+30 66431.179459
2 0.3 0.000000e+00 0.000000e+00 2.000000e+30 54240.830895
3 0.4 0.000000e+00 0.000000e+00 2.000000e+30 46973.937477
4 0.5 0.000000e+00 0.000000e+00 2.000000e+30 42014.766948

Graphing it up:

plt.plot(ss_data.R_au, ss_data.vel, 'o')
plt.xlabel('Distance away (AU)')
plt.ylabel('Velocity (m/s)')
plt.show()

Sanity check: how long for Earth to go around?

dist = 2*np.pi * 1 * au
time = dist / ss_data[ss_data.R_au == 1].vel
time / 86400
9    366.193607
Name: vel, dtype: float64

Galaxy

Generating our data, where the bulge will have a constant density that will then drop off

rs = np.arange(10,20000,10) # lyrs
dens_init = 4E30 / (4/3 * np.pi * 10**3)
dens = dens_init/(1+np.exp((rs - 3000)/500))

gal_data = pd.DataFrame({'R_ly': rs, 'density': dens})
gal_data.head()
gal_data.to_csv('L19_galaxy.csv', index=False)

Plotting it up?

plt.bar(gal_data.R_ly, gal_data.density, width=-10, align='edge')
plt.show()

Computing the mass and then cumulative mass:

gal_data['mass'] = 4/3 * np.pi * gal_data.R_ly**3 * gal_data.density
gal_data['cmass'] = gal_data.mass.cumsum()
gal_data.head()
R_ly density mass cmass
0 10 9.525209e+26 3.989910e+30 3.989910e+30
1 20 9.524724e+26 3.191766e+31 3.590757e+31
2 30 9.524229e+26 1.077165e+32 1.436241e+32
3 40 9.523723e+26 2.553144e+32 3.989385e+32
4 50 9.523208e+26 4.986340e+32 8.975725e+32

Computing the velocity:

G = 6.602E-11
ly = 9.461E15
gal_data['vel'] = np.sqrt(G * gal_data['cmass'] / (gal_data.R_ly * ly))
gal_data.head()
R_ly density mass cmass vel
0 10 9.525209e+26 3.989910e+30 3.989910e+30 52.765590
1 20 9.524724e+26 3.191766e+31 3.590757e+31 111.930185
2 30 9.524229e+26 1.077165e+32 1.436241e+32 182.777276
3 40 9.523723e+26 2.553144e+32 3.989385e+32 263.810580
4 50 9.523208e+26 4.986340e+32 8.975725e+32 353.931328

Graphing it up:

plt.plot(gal_data.R_ly, gal_data.vel, 'o')
plt.xlabel('Distance away (lyrs)')
plt.ylabel('Velocity (m/s)')
plt.show()