In [1]:
import os, glob
from dateutil import parser
from datetime import datetime
from matplotlib.dates import date2num
from flock.plot import density
from pysurvey.plot import setup, dateticks, hist, embiggen, minmax, legend, icolorbar
In [2]:
%load_ext autoreload
%autoreload 2
In [3]:
hostname = !hostname
assert hostname[0].startswith('axino'), 'This is a computer specific notebook: {}'.format(hostname[0])
In [4]:
names = []
dates = []
for filename in glob.glob('/Users/ajmendez/Pictures/wakeup/*.jpg'):
stats = os.stat(filename)
names.append(os.path.basename(filename))
dates.append(datetime.fromtimestamp(int(stats.st_mtime)))
ndates = date2num(dates)
In [5]:
xr = minmax(ndates)
setup(figsize=(12,6), xr=embiggen(minmax(ndates),[0.05,0.1]))
hist(ndates, np.arange(xr[0], xr[1],10),
filled=True, lw=0, alpha=0.5,
label='Number of pictures per day')
pylab.axvline(date2num(datetime.now()), color='k')
pylab.axvspan(*date2num([datetime(2015,3,6),
datetime(2015,3,16)]),
label='Chile',
color='0.7', alpha=0.5, zorder=-1)
dateticks('%Y-%m-%d')
legend(loc=2)
Out[5]:
In [6]:
print dates[0].weekday() #monday == 0
print np.floor(ndates[0]%7)
In [7]:
days = (ndates%7)
setup(figsize=(6,6),
xr=[0,7], xlabel='Day of the week',
xtickv=np.arange(0,8)+0.5,
xticknames='sun mon tue wed thurs fri sat'.split())
_ = hist(days, np.arange(0,8), filled=True, lw=0, alpha=0.5)
In [8]:
hours = (ndates%1)*24.0
setup(figsize=(6,6),
xr=[0,24], xlabel='Hour of the day',
xtickv=np.arange(0,25,4))
_ = hist(hours, np.arange(0,25), filled=True, lw=0, alpha=0.5)
In [9]:
minutes = (hours%1)*60
setup(figsize=(6,6),
xr=[0,60], xlabel='Minute of the hour',
xtickv=np.arange(0,61,10),
ylabel='Number of pictures per minute interval')
_ = hist(minutes, np.arange(0,61,10), filled=True, lw=0, alpha=0.5)
In [10]:
setup(figsize=(12,6),
xr=[-0.5,7.5], xlabel='day of the week',
xtickv=np.arange(0,7), xticknames='sun mon tue wed thur fri sat'.split(),
ylabel='hour of the day')
pylab.scatter(np.round(days), hours, c=ndates,
marker='s', s=80, alpha=0.5, edgecolor='none')
Out[10]:
In [11]:
def density_week(ndates):
days = (ndates%7)
hours = (ndates%1)*24.0
cmap = pylab.cm.Blues
cmap.set_bad('0.09')
setup(figsize=(12,6),
xr=[0,7], xlabel='day of the week',
yr=[24,0], ylabel='hour of the day')
dn = density(days,hours, extent=[0,7, 0,24], nbins=[7,24], mesh=True, zorder=-10,
cmap=cmap, alpha=0.9, label='Number per day per hour',
maskzeros=True,
# hidezeros=True, maskzeros=True
sqrt=True, colorbar=False)
icolorbar(dn)
density_week(ndates)
In [11]: