satpredictor/satpredict.py

90 lines
2.7 KiB
Python
Raw Normal View History

2017-02-05 05:57:53 +01:00
import predict
import json
import sys
import datetime
2017-02-21 09:37:13 +01:00
#Frequencies that satellites transmit on.
2017-02-05 05:57:53 +01:00
frequencies = {'NOAA-15':'137.620M', 'NOAA-18':'137.9125M', 'NOAA-19':'137.10M', 'METEOR-M2':'137.925M', 'ISS':'145.80M' } #Meteor M2 is also on 137.1M
tle_data = json.load(open('sat_tle.txt'))
2017-02-21 09:37:13 +01:00
default_predictions = 1 #how many predictions do we want to predict in advance
default_min_elevation = 30 #how low the angle of the satellitie pass is allowed to be if we want to record a pass
suppress_low_passes = False #Less console spam if you enable this.
2017-02-05 05:57:53 +01:00
2017-02-21 09:37:13 +01:00
#You can change the default elevation with the first parameter
2017-02-05 05:57:53 +01:00
pass_elevation = default_min_elevation
if( len(sys.argv) > 1 ):
pass_elevation = int(sys.argv[1])
if( pass_elevation == '' ):
pass_elevation = default_min_elevation
2017-02-21 09:37:13 +01:00
#you can change the number of predictions per satellite with the second parameter
2017-02-05 05:57:53 +01:00
predictions = default_predictions
if( len(sys.argv) > 2):
predictions = int(sys.argv[2])
if( predictions == '' ):
predictions = default_predictions
2017-02-21 09:37:13 +01:00
#anything in the third parameter will turn off console spam
2017-02-05 05:57:53 +01:00
if( len(sys.argv) > 3 ):
suppress_low_passes = True
2017-02-21 09:37:13 +01:00
#format a unix timestamp in a time appropriate for the 'at' command
2017-02-05 05:57:53 +01:00
def convert_time( unixtime ):
return datetime.datetime.fromtimestamp(
int(unixtime)
).strftime('%H:%M %Y-%m-%d')
2017-02-21 09:37:13 +01:00
#format the unix timestamp for minutes, used to determine length of recording
2017-02-05 05:57:53 +01:00
def convert_time_short( unixtime ):
return datetime.datetime.fromtimestamp(
int(unixtime)
).strftime('%M')
def get_sat( sat ):
return sat + '\n' + tle_data[sat]
2017-02-21 09:37:13 +01:00
#Where on the earth you are. Change this to your location
2017-02-21 06:49:52 +01:00
qth = (49.5, 123.5, 50) # lat (N), long (W), alt (meters)
2017-02-05 05:57:53 +01:00
data = {}
for sat, freq in frequencies.iteritems():
name = predict.observe(get_sat(sat), qth)['name'].strip()
t = predict.transits(get_sat(sat), qth)
count = 0
while ( count < predictions ):
p = t.next()
p_nw = t_nw.next()
p_se = t_se.next()
2017-02-21 09:37:13 +01:00
#peak check. PEAK CHECK!
2017-02-05 05:57:53 +01:00
while (p.peak()['elevation'] < default_min_elevation):
p = t.next()
p_nw = t_nw.next()
p_se = t_se.next()
if( not suppress_low_passes ):
print name, "pass too low, recalculating"
2017-02-21 09:37:13 +01:00
#this is the data we want to pass on to the rest of the program
2017-02-05 05:57:53 +01:00
data[name] = {}
data[name]['frequency'] = freq
data[name]['start_unix'] = p.start
data[name]['start'] = convert_time(data[name]['start_unix'])
data[name]['duration_seconds'] = int(p.duration())
data[name]['duration_minutes'] = convert_time_short(data[name]['duration_seconds'])
data[name]['elevation'] = p.peak()['elevation']
2017-02-21 09:37:13 +01:00
print name, 'next pass at:', data[name]['start'], 'at', data[name]['elevation'], 'degrees.'
2017-02-05 05:57:53 +01:00
count = count + 1
import json
with open('satpredict.txt', 'w') as fp:
json.dump(data, fp, indent=4)