In [1]:
from bokeh.plotting import ColumnDataSource, figure, output_notebook, show, GridPlot
from bokeh.models import HoverTool
from datetime import datetime
import pandas as pd
from pandas.tseries.tools import to_datetime
import numpy as np
import ephem
In [2]:
TOOLS="pan,wheel_zoom,box_zoom,reset,hover,previewsave"
output_notebook()
In [3]:
observer = ephem.city('Moscow')
sun = ephem.Sun()
In [4]:
#observer.date = '2014/12/22'
# base_time = str(observer.next_transit(ephem.Sun()))
# base_time = str(observer.next_rising(ephem.Sun()))
# base_time = str(observer.next_setting(ephem.Sun()))
base_time = '2014/12/22 11:00'
base_time
Out[4]:
In [5]:
analemma = pd.DataFrame({'az': pd.Series(), 'alt': pd.Series()},
index=pd.Series(pd.date_range(base_time, periods=365, freq='D')))
In [6]:
for timedate in analemma.index:
observer.date = timedate
sun.compute(observer)
analemma.loc[timedate, 'az'] = np.rad2deg(sun.az)
analemma.loc[timedate, 'alt'] = np.rad2deg(sun.alt)
Details here.
In [7]:
p = figure(plot_width=800,
plot_height=600,
tools=TOOLS)
source = ColumnDataSource(
data=dict(
x=analemma.az,
y=analemma.alt,
date=[str(to_datetime(x)) for x in analemma.index]
)
)
p.circle(analemma.az, analemma.alt, source=source,
fill_color='blue', fill_alpha=0.7,
radius=0.07, line_color=None)
hover = p.select({'type': HoverTool})
hover.tooltips = [
("date", "@date")
]
show(p)
In [8]:
week_based_analemma = analemma.resample('w')
minmax = [analemma.loc[analemma.alt == analemma.alt.min()], analemma.loc[analemma.alt == analemma.alt.max()]]
minmax_df = pd.concat(minmax)
In [9]:
p = figure(plot_width=800,
plot_height=600,
tools=TOOLS)
minmax_dates = [str(to_datetime(x)) for x in minmax_df.index]
p.circle(minmax_df.az, minmax_df.alt,
fill_color='red', fill_alpha=0.6,
radius=0.07, line_color=None)
p.text(minmax_df.az, minmax_df.alt, text=minmax_dates,
text_font_size="10pt",text_baseline="bottom", text_align="center",
alpha=0.8, angle=0)
source = ColumnDataSource(
data=dict(
x=week_based_analemma.az,
y=week_based_analemma.alt,
date=[str(to_datetime(x)) for x in week_based_analemma.index]
)
)
p.circle(week_based_analemma.az, week_based_analemma.alt, source=source,
fill_color='blue', fill_alpha=0.6,
radius=0.07, line_color=None)
hover = p.select({'type': HoverTool})
hover.tooltips = [
("date", "@date")
]
show(p)
In [ ]: