Temperatures à la grange !

Ce notebook permet de visualisé la température à la grange


In [1]:
%pylab inline
%load_ext autoreload
%autoreload 2


Populating the interactive namespace from numpy and matplotlib

In [2]:
import pandas as pd
import numpy as np
from matplotlib import pylab as plt

import time
from datetime import datetime

from source_emoncms import EmoncmsSource

Creation de 'emonsrc' interface avec les systeme de stockage des data de la grange.

Completer le fichier config


In [3]:
with open("emonsrc_config.txt") as emoncfg:
    url = emoncfg.readline().strip()
    key = emoncfg.readline().strip()
    emonsrc = EmoncmsSource(url=url, apikey=key)

 Time selection


In [101]:
#nb_day = 30*2 - 5
#end_time = time.time() # now

end_time = datetime( 2014, 10, 30, 0, 0, 0 )  
end_time = time.mktime( end_time.timetuple() )

start_time = datetime( 2014, 9, 10, 0, 0, 0 )  
start_time = time.mktime( start_time.timetuple() )

# compute date params
#start_ts = end_time - nb_day*24*60*60
start = datetime.fromtimestamp(start_time)
print "Start at: %s" % start

delta_sec = 5*60 # measure each *  in seconds
nb_data = (end_time - start_time)/delta_sec
print "delta (s): ", delta_sec, "        nbr points theo: ", nb_data


Start at: 2014-09-10 00:00:00
delta (s):  300         nbr points theo:  14412.0

Feeds selection


In [102]:
feed_id = {}
feed_id['T_grange'] = 40
feed_id['T_ext'] = 34
feed_id['T_atelier'] = 42

In [104]:
# Download data #

data = {}
for k, f_id in feed_id.iteritems():
    data[ k ] = emonsrc.get_data( f_id , start, delta_sec, nb_data=nb_data)
    print "%s \t Count:%s  \t Start: %s \t End: %s" % (k, len(  data[ k ] ), data[k].index[0], data[k].index[-1])


T_atelier 	 Count:14343  	 Start: 2014-09-10 02:30:00 	 End: 2014-10-30 00:55:00
T_grange 	 Count:14343  	 Start: 2014-09-10 02:30:00 	 End: 2014-10-30 00:55:00
T_ext 	 Count:8528  	 Start: 2014-09-10 02:28:00 	 End: 2014-10-09 15:33:00

Affichage des données brutes et resamplées


In [115]:
nPlots = len( data )
i = 1
for k, d in data.iteritems():
    plt.subplot(nPlots, 1, i)
    i = i + 1
    
    T_15min = d.resample("15Min", how="mean")
    T_day = d.resample("D", how="mean")
    
    T_15min.plot(style="r", figsize=(14, 10))
    T_day.plot()


Calcul et affichage de la pluie en mm/jour


In [12]:
last_day_rain = rain_accu_day.tshift(1)
rain_by_day = rain_accu_day - last_day_rain
rain_by_day.name = "rain_by_day"

In [ ]:
#print "## end of the day"
#print rain_accu_day[1:]
#print "## end of the LAST last day"
#print last_day_rain
#print "## rain by day"
#print rain_by_day[1:-1]

In [13]:
rain_by_day["2014-11-2"]


Out[13]:
0.0

In [14]:
all_data = pd.concat([rain_accu_day[1:], rain_by_day[1:-1]], axis=1)

In [21]:
plt.figure(figsize=(13,5))

ax = all_data['rain_by_day'].plot(
    style="cd-",
    label="mm/day"
)
#ax2 = all_data['ext_rain'].plot(
#    kind="-",
#    color="m", alpha=0.1,
#    ax=ax
#)
ax.set_ylabel('mm/day')
ax.right_ax.set_ylabel('mm (total)')


---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-21-e2c7c289ec21> in <module>()
     11 #)
     12 ax.set_ylabel('mm/day')
---> 13 ax.right_ax.set_ylabel('mm (total)')

AttributeError: 'AxesSubplot' object has no attribute 'right_ax'

In [ ]:


In [ ]: