In [2]:
# Import necessary libraries
import ephem
import math
from datetime import datetime

In [3]:
# Set up location of observer

# In this case, Valparaiso University
#    41.4639 deg (Latitude VU)
#    272.9561 deg (Longitude VU) -87.0439
#    0.245089 km (Alitutde VU)
#    Grid Square = EN61LL
VU = ephem.Observer()
VU.name = "Valparaiso University"
VU.lon = '-87.0439'            #in degrees (+E)
VU.lat = '41.4639'             #in degrees (+N)
#VU.elevation = 245.089         #in meters
VU.date = datetime.utcnow()    #use today's date --> need "from datetime import datetime" in previous cell
#VU.pressure = 0
print("Observation point: %s" % (VU.name))
print("Latitude: %s deg and Longitude: %s deg" % (VU.lat, VU.lon))
print("Current Date: %s" % (VU.date))


Observation point: Valparaiso University
Latitude: 41:27:50.0 deg and Longitude: -87:02:38.0 deg
Current Date: 2017/5/30 14:15:37

In [4]:
# The most recent ISS TLE data from:
# http://spaceflight.nasa.gov/realdata/sightings/SSapplications/Post/JavaSSOP/orbit/ISS/SVPOST.html
tle_line0 = 'ISS'
tle_line1 = '1 25544U 98067A   17144.56334412  .00016717  00000-0  10270-3 0  9002'
tle_line2 = '2 25544  51.6383 156.0737 0005162 190.1606 169.9443 15.53944016 18074'
iss = ephem.readtle(tle_line0, tle_line1,tle_line2)

In [5]:
# body.compute(observer) uses date and epoch of observer
# sets all body attributes and coputes position of body
# For list of attribtutes set: http://rhodesmill.org/pyephem/quick.html
iss.compute(VU)
info = VU.next_pass(iss)
deg_per_radian = 180.0/math.pi
duration = (info[4]-info[0])*60*60*24
minutes, seconds = divmod(duration, 60)
hours, minutes = divmod(minutes, 60)
print("Rise Time: %s, Set Time: %s, Duration: %d:%02d:%02d, Rise Azimuth: %.1f, Set Azimuth: %.1f" % (info[0],info[4],hours,minutes,seconds,info[1]*deg_per_radian,info[5]*deg_per_radian))


Rise Time: 2017/5/30 22:25:57, Set Time: 2017/5/30 22:33:29, Duration: 0:07:31, Rise Azimuth: 169.4, Set Azimuth: 82.1

In [6]:
type(info[0])


Out[6]:
ephem.Date

In [7]:
# Gives the next predicted passes of the ISS
VU.date = datetime.utcnow()
for i in range(20):
    iss.compute(VU)                               # compute all body attributes
    info = VU.next_pass(iss)                      # next pass command yields array with [0]=rise time, [1]=rise azimuth, [2]=max alt time, [3]=max alt, [4]=set time, [5]=set azimuth
    deg_per_radian = 180.0/math.pi                # use to display azimuth in degrees
    duration = (info[4]-info[0])*60*60*24         # (set time - rise time)*s_per_min*min_per_hr*hr_per_day
    minutes, seconds = divmod(duration, 60)       # use to display duration as hr:min:sec
    hours, minutes = divmod(minutes, 60)
    if info[4] > info[0]:                         # only print and update if the set time is greater than the rise time
        print("Rise Time: %s, Set Time: %s, Duration: %d:%02d:%02d, Rise Azimuth: %.1f, Set Azimuth: %.1f" % (info[0],info[4],hours,minutes,seconds,info[1]*deg_per_radian,info[5]*deg_per_radian))
        VU.date = info[-2]                        # new observer date/time = previous set time (negative index means start counting from right, so this is second to last index in array)
    VU.date = VU.date + 0.041667                  # increase time by roughly 1 hour and look for next pass


Rise Time: 2017/5/30 22:25:57, Set Time: 2017/5/30 22:33:29, Duration: 0:07:31, Rise Azimuth: 169.4, Set Azimuth: 82.1
Rise Time: 2017/5/31 00:00:03, Set Time: 2017/5/31 00:11:02, Duration: 0:10:58, Rise Azimuth: 224.0, Set Azimuth: 57.5
Rise Time: 2017/5/31 01:36:57, Set Time: 2017/5/31 01:47:30, Duration: 0:10:32, Rise Azimuth: 265.9, Set Azimuth: 51.1
Rise Time: 2017/5/31 03:14:42, Set Time: 2017/5/31 03:24:26, Duration: 0:09:44, Rise Azimuth: 296.5, Set Azimuth: 60.7
Rise Time: 2017/5/31 04:51:46, Set Time: 2017/5/31 05:02:09, Duration: 0:10:22, Rise Azimuth: 308.6, Set Azimuth: 89.2
Rise Time: 2017/5/31 06:28:15, Set Time: 2017/5/31 06:39:14, Duration: 0:10:59, Rise Azimuth: 304.1, Set Azimuth: 130.1
Rise Time: 2017/5/31 08:05:29, Set Time: 2017/5/31 08:13:52, Duration: 0:08:23, Rise Azimuth: 283.0, Set Azimuth: 182.0
Rise Time: 2017/5/31 21:36:05, Set Time: 2017/5/31 21:39:46, Duration: 0:03:40, Rise Azimuth: 141.5, Set Azimuth: 101.8
Rise Time: 2017/5/31 23:08:12, Set Time: 2017/5/31 23:18:48, Duration: 0:10:35, Rise Azimuth: 209.9, Set Azimuth: 62.2
Rise Time: 2017/6/1 00:44:30, Set Time: 2017/6/1 00:55:21, Duration: 0:10:50, Rise Azimuth: 254.3, Set Azimuth: 51.6
Rise Time: 2017/6/1 02:22:11, Set Time: 2017/6/1 02:32:03, Duration: 0:09:51, Rise Azimuth: 289.1, Set Azimuth: 55.9
Rise Time: 2017/6/1 03:59:33, Set Time: 2017/6/1 04:09:37, Duration: 0:10:04, Rise Azimuth: 307.0, Set Azimuth: 79.1
Rise Time: 2017/6/1 05:36:06, Set Time: 2017/6/1 05:47:05, Duration: 0:10:59, Rise Azimuth: 306.9, Set Azimuth: 117.0
Rise Time: 2017/6/1 07:12:53, Set Time: 2017/6/1 07:22:41, Duration: 0:09:48, Rise Azimuth: 291.8, Set Azimuth: 164.5
Rise Time: 2017/6/1 22:16:38, Set Time: 2017/6/1 22:26:25, Duration: 0:09:47, Rise Azimuth: 194.5, Set Azimuth: 68.6
Rise Time: 2017/6/1 23:52:11, Set Time: 2017/6/2 00:03:13, Duration: 0:11:02, Rise Azimuth: 242.0, Set Azimuth: 53.2
Rise Time: 2017/6/2 01:29:38, Set Time: 2017/6/2 01:39:45, Duration: 0:10:06, Rise Azimuth: 280.2, Set Azimuth: 52.8
Rise Time: 2017/6/2 03:07:13, Set Time: 2017/6/2 03:17:04, Duration: 0:09:50, Rise Azimuth: 303.8, Set Azimuth: 70.2
Rise Time: 2017/6/2 04:43:57, Set Time: 2017/6/2 04:54:45, Duration: 0:10:47, Rise Azimuth: 308.5, Set Azimuth: 104.7
Rise Time: 2017/6/2 06:20:30, Set Time: 2017/6/2 06:31:05, Duration: 0:10:35, Rise Azimuth: 298.2, Set Azimuth: 149.2

In [0]: