In [1]:
%pylab inline
%load_ext autoreload
%autoreload 2
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)
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
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])
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()
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]:
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)')
In [ ]:
In [ ]: