-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstarlinkPassPredictor.py
125 lines (81 loc) · 3.29 KB
/
starlinkPassPredictor.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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
113
114
115
116
117
118
119
120
# starlinkPassPredictor.py
#
# Pull the latest Starlink TLEs from Celestrak and find observable passes
#
# Harry Krantz
# Steward Observatory
# University of Arizona
# Copyright May 2020
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
import os
from findPass import *
from satFunctions import *
from loadFile import *
# Find all starlink passes for a given date range and location
# Args: start = datetime, stop = datetime, loc = skyfield Topos, path = string
# Returns: array of dict
def starlinkPassPredictor(start, stop, loc, params = [False, None, False, 0], path=None, filename="observablePasses"):
sunUp, moonUp, eclipsed, minAlt = params
#Load the list of TLEs from a file
print("Downloading TLE data from Celestrak...")
url = "https://celestrak.com/NORAD/elements/supplemental/starlink.txt"
tleList = loadFileURL(url)
saveFile(tleList, os.path.join(path, "starlinkTLE.txt"))
print("Downloaded " + str(len(tleList)) + " valid TLEs")
print("Date Range: " + start.strftime('%Y-%m-%d %H:%M:%S') + " to " + stop.strftime('%Y-%m-%d %H:%M:%S'))
print("Looking for observable satellites...\n")
#Find all passes and filter them per paramters
allPasses = []
for tle in tleList:
#Compute passes
passes = findPass(tle, loc, start, stop)
#Filter them for observable passes
passes = filterPasses(passes, sunUp, moonUp, eclipsed, minAlt)
allPasses += passes
#Check that valid passes were found before continuing
if len(allPasses) <= 0:
print("Found " + str(len(allPasses)) + " observable passes" )
exit()
#Sort by time
allPasses.sort(key=lambda p: p["maxTime"])
print("\nFound " + str(len(allPasses)) + " observable passes" )
print()
printPassList(allPasses)
print()
if path != None:
#Save list of observable passes to csv file
saveCSV( os.path.join(path, filename + ".csv"), makePassArray(allPasses), allPasses[0].keys())
return allPasses
# select Starlink passes with time allowance inbetween
# Args: passes = array of dict, timePer = num, path = string
# Returns: array of dict
def selectStarlinkPasses(passes, timePer, path=None, filename="selectedPasses"):
#Sort by time
passes.sort(key=lambda p: p["maxTime"])
#Select passes for observation
print("Selecting passes for observation...")
selectPasses = [passes[0]]
for p in passes:
#if too soon since last observation skip this one
if (p["maxTime"] - selectPasses[-1]["maxTime"]) < timePer:
continue
else:
selectPasses.append(p)
print("Selected " + str(len(selectPasses)) + " for observation")
print()
printPassList(selectPasses)
print()
if path != None:
#Save list of selected passes to csv file
saveCSV( os.path.join(path, filename + ".csv"), makePassArray(selectPasses), selectPasses[0].keys())
return selectPasses