import ephem
import datetime
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
sun, moon = ephem.Sun(), ephem.Moon()
sun.compute(gatech)
moon.compute(gatech)
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
print(ephem.separation((sun.az, sun.alt), (moon.az, moon.alt)))
8:26:37.1
print("%.8f %.8f %.11f" % (sun.size, moon.size, sun.size - moon.size))
1951.72009277 1994.17883301 -42.45874023438
gatech.date = ephem.date(gatech.date + 1)
type(gatech.date)
ephem.Date
dates = [start_date + datetime.timedelta(d,0,0) for d in range(1,356)]
a_dec = []
for d in dates:
gatech.date = d
sun.compute(gatech)
a_dec.append(sun.a_dec)
a_dec = np.array(a_dec)
import matplotlib.pyplot as plt
import matplotlib
%matplotlib inline
plt.figure()
plt.plot_date(matplotlib.dates.date2num(dates), np.rad2deg(a_dec), '-')
plt.show()
from sunpy.sun import apparent_declination
sunpy_adec = np.array([apparent_declination(d) for d in dates])
plt.figure()
plt.plot_date(matplotlib.dates.date2num(dates), sunpy_adec, '-')
plt.show()
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()