In [4]:
%pylab inline
%load_ext autoreload
%autoreload 2
In [ ]:
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.
In [ ]:
with open("emonsrc_config.txt") as emoncfg:
url = emoncfg.readline().strip()
key = emoncfg.readline().strip()
emonsrc = EmoncmsSource(url=url, apikey=key)
In [ ]:
rain_feed = 45
nb_day = 30*5
now = time.time()
# compute date params
start_ts = now - nb_day*24*60*60
start = datetime.fromtimestamp(start_ts)
print "Start at: %s" % start
delta_sec = 60*60 # measure each hour
nb_data = (nb_day*60*60*24)/delta_sec
print delta_sec, nb_data
In [ ]:
# get data
rain_accu = emonsrc.get_data(rain_feed, start, delta_sec, nb_data=nb_data)
print "first %s" % rain_accu.index[0]
print "last %s" % rain_accu.index[-1]
In [ ]:
rain_accu_day = rain_accu.resample("D", how="last")
nbnan = np.count_nonzero(np.isnan(rain_accu_day))
print("Got %s missing values (on %s)" % (nbnan, len(rain_accu_day) ))
rain_accu_day = rain_accu_day.fillna(method="pad").fillna(method="bfill")
print rain_accu_day
In [ ]:
ax = rain_accu.plot()
rain_accu_day.plot(style="r", figsize=(14, 6))
In [ ]:
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 [ ]:
rain_by_day["2014-11-2"]
In [ ]:
all_data = pd.concat([rain_accu_day[1:], rain_by_day[1:-1]], axis=1)
In [ ]:
plt.figure(figsize=(13,5))
ax = all_data['rain_by_day'].plot(
style="cd-",
label="mm/day",
)
ax2 = all_data['ext_rain'].plot(
kind="area",
color="m", alpha=0.1,
ax=ax,
secondary_y=True,
)
ax.set_ylabel('mm/day')
ax.right_ax.set_ylabel('mm (total)')
In [ ]:
In [ ]: