In [25]:
%matplotlib inline

In [26]:
import os, glob
import pylab
import numpy as np
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 [27]:
%load_ext autoreload
%autoreload 2


The autoreload extension is already loaded. To reload it, use:
  %reload_ext autoreload

In [28]:
hostname = !hostname
assert hostname[0].startswith('axino'), 'This is a computer specific notebook: {}'.format(hostname[0])

In [29]:
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 [30]:
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[30]:
<matplotlib.legend.Legend at 0x113e52350>

In [31]:
print dates[0].weekday() #monday == 0
print np.floor(ndates[0]%7)


0
1.0

In [32]:
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 [33]:
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 [34]:
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 [35]:
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[35]:
<matplotlib.collections.PathCollection at 0x1139b15d0>

In [36]:
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 [36]: