<jupyter_start><jupyter_text>Space plots ! This notebook comes with a blog post, go check it out : https://alelouis.github.io/blog/space-things<jupyter_code>%matplotlib inline
import math
import ephem
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd<jupyter_output><empty_output><jupyter_text>Load up the stars locations and satellites TLEs<jupyter_code>stars = np.genfromtxt('stardata.csv', delimiter=',')
satellites = open('satellites.txt').read().splitlines()<jupyter_output><empty_output><jupyter_text>Next create an observer, specifying it position in Latitude / Longitude<jupyter_code>toulouse = ephem.Observer()
toulouse.lat, toulouse.lon = '43.598', '1.4447'<jupyter_output><empty_output><jupyter_text>Next we can create one function that returns the azimuth and altitude of the traces of all TLEs specified in satellites.txt<jupyter_code>def make_satellites(satellites, observer):
    ite = 50
    satellites_iter = 0
    orbit_tracer = observer.copy()
    for satellites_iter in range(0, len(satellites)/3):
        az  = np.empty((ite, len(satellites)/3))
        alt = np.empty((ite, len(satellites)/3))
        satellite_temp = ephem.readtle(satellites[satellites_iter*3], satellites[satellites_iter*3+1], satellites[satellites_iter*3+2])
        for i in range(0,ite):
            orbit_tracer.date += 10*ephem.second
            satellite_temp.compute(orbit_tracer)
            az[i, satellites_iter] = satellite_temp.az
            alt[i, satellites_iter] = 90 - math.degrees(satellite_temp.alt)
    return az, alt<jupyter_output><empty_output><jupyter_text>We also make a function that return the azimuth and altitude of the stars for a given observer.We put a condition an magnitude to avoid displaying every star.<jupyter_code>def make_stars(stars, observer):
    temp_star =  ephem.FixedBody()
    star_number = 0
    stars_az  = np.empty(stars.shape[0])
    stars_alt = np.empty(stars.shape[0])
    stars_mag = np.empty(stars.shape[0])
    for star in stars:
        if star[2] > 9:
            temp_star._ra = star[0]
            temp_star._dec = np.radians(star[1])
            temp_star.compute(observer)
            stars_az[star_number] =  temp_star.az
            stars_alt[star_number] = 90 - math.degrees(temp_star.alt)
            stars_mag[star_number] = (star[2]-9)/3
        else:
            stars_mag[star_number] = 0
        star_number += 1
    return stars_az, stars_alt, stars_mag<jupyter_output><empty_output><jupyter_text>We then choose a date of observation and set it to the observer.<jupyter_code>init_date = '2018/2/28 05:11:00'
toulouse.date = init_date<jupyter_output><empty_output><jupyter_text>We compute the positions of stars and satellites for the observer<jupyter_code>az_stars, alt_stars, mag_stars = make_stars(stars, toulouse)
az_sat, alt_sat = make_satellites(satellites, toulouse)<jupyter_output><empty_output><jupyter_text>And finaly plot it using Matplotlib. We define a polar plot and customize it.<jupyter_code>fig = plt.figure(figsize=(4,4), dpi = 150)
ax = fig.add_subplot(111, projection = 'polar')
ax.set_rlim(0,90)
ax.set_xticks(np.arange(0,2*np.pi,np.pi/2))
ax.set_theta_zero_location("N")
ax.set_theta_direction(1)
ax.axes.get_xaxis().set_visible(False)
ax.axes.get_yaxis().set_visible(False)
ax.set_facecolor('#000d21')
scat = ax.scatter(az_stars, alt_stars, s = mag_stars, c = 'white', edgecolors='none')
orbits = list()
for i in range(0, len(satellites)/3):
    if alt_sat[:,i].any() > 0:
        orbits.append(ax.scatter(az_sat[:,i], alt_sat[:,i], s = 5, edgecolors='none', c = 'red'))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11800554016620499, 'fraction_numerical': 0.02188365650969529, 'mean_word_length': 4.572530864197531, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 35, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '394464', 'license': 'MIT', 'n_tokens_mistral': 1336, 'n_tokens_neox': 1261, 'n_words': 269, 'path': 'demo.ipynb', 'repo_name': 'alelouis/moving-stars', 'size': '3610'}