<jupyter_start><jupyter_text>Rainfall<jupyter_code>%matplotlib inline
from datetime import timedelta
import pandas as pd
from collections import namedtuple
from rdii.rain import find_rain_periods
import matplotlib.pyplot as plt
from pylab import rcParams
rcParams['figure.figsize'] = 14, 6<jupyter_output><empty_output><jupyter_text>Load and clean data<jupyter_code>df = pd.read_csv('../testdata/rainfall1.csv.gz', index_col='time', parse_dates=['time'])
rainfall = df['rainfall'].fillna(0).resample('1H').sum()
print(rainfall.head())
print(rainfall.describe())
rains = find_rain_periods(rainfall)
print('Found {} rain events'.format(len(rains)))
%timeit find_rain_periods(rainfall)
sorted_rains = rains.sort_values('intensity', ascending=False)
sorted_rains.head(10)
def plot_rain(ds, start_date, end_date):
    ds2 = ds[start:end]
    plt.bar(ds2.index, ds2, 0.01, edgecolor='lightblue', color='lightblue')
    plt.show()
    
index = 7
start = sorted_rains.iloc[index]['start_date'].date()
end = sorted_rains.iloc[index]['end_date'].date() + timedelta(days=1)
plot_rain(rainfall, start, end)<jupyter_output><empty_output>