In [1]:
%matplotlib inline
In [2]:
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
sns.set_style('whitegrid')
from IPython.display import HTML
In [3]:
flowdata = pd.read_pickle("./data/FlowData")
raindata = pd.read_pickle("./data/RainData")
In [4]:
#Loading the hydropy package
import hydropy as hp
We have a Dataframe with river discharge at different locations in the Maarkebeek basin (Belgium):
In [5]:
HTML('<iframe src=http://biomath.ugent.be/~stvhoey/maarkebeek_data/ width=700 height=350></iframe>')
Out[5]:
Data downloaded from http://www.waterinfo.be/, made available by the Flemish Environmental Agency (VMM).
In [6]:
flowdata.head()
Out[6]:
In [7]:
flowdata.tail()
Out[7]:
In [8]:
print len(flowdata), 'records', 'from', flowdata.index[0], 'till', flowdata.index[-1]
Converting the dataframe to a hydropy time series datatype, provides extra functionalities:
In [9]:
myflowserie = hp.HydroAnalysis(flowdata)
In [10]:
myflowserie.get_year('2009').get_season('summer').plot(figsize=(12,6))
Out[10]:
In [11]:
myflowserie.get_year('2011').get_month("Jun").get_recess().plot(figsize=(12,6))
Out[11]:
In [12]:
fig, ax = plt.subplots(figsize=(13, 6))
myflowserie['LS06_347'].get_year('2010').get_month("Jul").get_highpeaks(150, above_percentile=0.9).plot(style='o', ax=ax)
myflowserie['LS06_347'].get_year('2010').get_month("Jul").plot(ax=ax)
Out[12]:
In [13]:
raindata.columns
Out[13]:
In [14]:
storms = myflowserie.derive_storms(raindata['P05_019'], 'LS06_347',
number_of_storms=3, drywindow=50,
makeplot=True)
In [30]:
storms = myflowserie.derive_storms(raindata['P06_014'], 'LS06_347',
number_of_storms=3, drywindow=96,
makeplot=True)
In [16]:
myflowserie.data.groupby('season').mean()
Out[16]:
Get the code on your computer
git clone https://github.com/yourname/hydropy
Run the python setup script (install as development package):
python setup.py develop
Improve implementation, add functionalities,...
In [ ]:
In [17]:
import hydropy as hp
flowdata = pd.read_pickle("./data/FlowData")
raindata = pd.read_pickle("./data/RainData")
myflowserie = hp.HydroAnalysis(flowdata)
In [18]:
# Data inspection
myflowserie.summary() #head(), tail(),
Out[18]:
In [19]:
# Resampling frequencies
temp1 = myflowserie.frequency_resample('7D', 'mean') # 7 day means
temp1.head()
Out[19]:
In [20]:
temp2 = myflowserie.frequency_resample("M", "max") # Monthly maxima
temp2.head()
Out[20]:
In [21]:
temp3 = myflowserie.frequency_resample("A", 'sum') # Yearly sums
temp3.head(6)
Out[21]:
In [22]:
#slicing of the dataframes
myflowserie['L06_347']['2009'].plot()
Out[22]:
In [23]:
# get_month, get_year, get_season, get_date_range
myflowserie.get_date_range("01/01/2010","03/05/2010").plot(figsize=(13, 6))
Out[23]:
In [24]:
# or combine different statements:
myflowserie.get_year('2010').get_month(6).plot(figsize=(13, 6))
Out[24]:
For the seasons some options are available: Meteorologic (first of the month) or astrologic (21st of the month)
In [25]:
myflowserie.current_season_dates()
Out[25]:
In [26]:
myflowserie.info_season_dates('north', 'astro')
Out[26]:
In [27]:
# Peaks (high or low)
myflowserie['LS06_348'].get_year('2012').get_highpeaks(60, above_percentile=0.8).data.dropna().head()
Out[27]:
In [28]:
# Recessions and climbing periods get_recess, get_climbing
myflowserie.get_year("2012").get_month("april").get_climbing().plot(figsize=(13, 6))
Out[28]:
In [29]:
# above/below certain percentile values
myflowserie["LS06_348"].get_above_percentile(0.6).get_year('2011').get_season('summer').plot()
Out[29]:
Furthermore:
In [ ]:
In [ ]: