In [40]:
import ephem
import datetime

In [41]:
gatech = ephem.Observer()
gatech.lon, gatech.lat = '-84.39733', '33.775867'
start_date = datetime.datetime(2014,1,1,0,0,0)
gatech.date = start_date

In [42]:
sun, moon = ephem.Sun(), ephem.Moon()
sun.compute(gatech)
moon.compute(gatech)

In [43]:
print("%s %s" % (sun.alt, sun.az))
print("%s %s" % (moon.alt, moon.az))


-16:19:43.4 252:52:55.5
-21:16:33.9 260:06:49.6

In [44]:
print(ephem.separation((sun.az, sun.alt), (moon.az, moon.alt)))


8:26:37.1

In [45]:
print("%.8f %.8f %.11f" % (sun.size, moon.size, sun.size - moon.size))


1951.72009277 1994.17883301 -42.45874023438

In [46]:
gatech.date = ephem.date(gatech.date + 1)

In [47]:
type(gatech.date)


Out[47]:
ephem.Date

In [48]:
dates = [start_date + datetime.timedelta(d,0,0) for d in range(1,356)]

In [49]:
a_dec = []
for d in dates:
    gatech.date = d
    sun.compute(gatech)
    a_dec.append(sun.a_dec)

In [63]:
a_dec = np.array(a_dec)

In [64]:
import matplotlib.pyplot as plt
import matplotlib

In [65]:
%matplotlib inline

In [72]:
plt.figure()
plt.plot_date(matplotlib.dates.date2num(dates), np.rad2deg(a_dec), '-')
plt.show()



In [73]:
from sunpy.sun import apparent_declination

In [74]:
sunpy_adec = np.array([apparent_declination(d) for d in dates])

In [75]:
plt.figure()
plt.plot_date(matplotlib.dates.date2num(dates), sunpy_adec, '-')
plt.show()



In [88]:
fig, ax = plt.subplots()
ax.plot_date(matplotlib.dates.date2num(dates), np.rad2deg(a_dec) - sunpy_adec, '-', label = 'pyEphem - sun.py')
ax.xaxis.set_major_locator(matplotlib.dates.MonthLocator())
ax.xaxis.set_major_formatter(matplotlib.dates.DateFormatter('%m'))
plt.title("apparent declination")
plt.grid(True)
fig.autofmt_xdate()
plt.legend()

plt.show()



In [ ]: