from IPython.core.display import HTML with open('creative_commons.txt', 'r') as f: html = f.read() name = '2013-10-28-ephem-ison' html = """
This post was written as an IPython notebook. It is available for download or as a static html.
%s """ % (name, name, html) %matplotlib inline from matplotlib import style style.use('ggplot') import ephem import numpy as np import matplotlib.pyplot as plt ISON = "C/2012 S1 (ISON),h,11/28.7744/2013,62.3994,295.6528,345.5644,1.000002,0.012444,2000,7.5,3.2" comet = ephem.readdb(ISON) print(comet) from pandas import DataFrame, date_range days = date_range(start='2013/10/28', end='2013/12/31', freq='D') earth_d, sun_d = [], [] for day in days: comet.compute(day) earth_d.append(comet.earth_distance) sun_d.append(comet.sun_distance) df = DataFrame(np.c_[earth_d, sun_d], index=days, columns=['Earth', 'Sun']) from scipy import constants conversion = constants.au * 1e-3 df['Sun km'] = df['Sun'] * conversion df['Earth km'] = df['Earth'] * conversion df.head(5) kw = dict(markeredgecolor='k', marker='o', linestyle='none') arrowprops = dict(arrowstyle="->", connectionstyle="arc3,rad=.2", color='k') fig, ax = plt.subplots(figsize=(8, 4)) sx, sy, sm = df['Sun'].argmin(), df['Sun'].min(), df['Sun km'].min() ex, ey, em = df['Earth'].argmin(), df['Earth'].min(), df['Earth km'].min() ax.plot(ex, ey, markerfacecolor='#339933', **kw) ax.plot(sx, sy, markerfacecolor='#ff3333', **kw) ax.annotate('Closest to Earth is\n%s km' % em, xy=(ex, ey), xycoords='data', xytext=(-20, 30), textcoords='offset points', arrowprops=arrowprops) ax.annotate('Closest to the Sun is\n%s km' % sm, xy=(sx, sy), xycoords='data', xytext=(-180, 30), textcoords='offset points', arrowprops=arrowprops) ax = df[['Earth', 'Sun']].plot(ax=ax, zorder=0, color=['#339933', '#ff3333'], linewidth=2) _ = ax.set_ylabel('Distance [AU]') obs = ephem.Observer() obs.lon = np.deg2rad(-46.665) obs.lat = np.deg2rad(-23.473) obs.date = ex comet.compute(obs) print("Date: %s\nRight ascension: %s\nDeclination: %s\nMagnitude: %s" % (obs.date, comet.ra, comet.dec, comet.mag)) from IPython.display import YouTubeVideo YouTubeVideo("A1yH_DuC88M", autoplay=0, theme="light", color="red") HTML(html)