#!/usr/bin/env python # coding: utf-8 # In[1]: get_ipython().run_line_magic('matplotlib', 'inline') # In[2]: from __future__ import print_function import numpy as np import pandas as pd 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") # # Hydropy-package # # Go to the [hydropy website](http://stijnvanhoey.github.io/hydropy/) for more information on the package and the code on Github. # 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('') # Data downloaded from http://www.waterinfo.be/, made available by the Flemish Environmental Agency (VMM). # In[6]: flowdata.head() # In[7]: flowdata.tail() # 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) # ### Select the summer of 2009: # In[10]: myflowserie.get_year('2009').get_season('summer').plot(figsize=(12,6)) # ### Select only the recession periods of the discharges (catchment drying) in June 2011: # In[11]: myflowserie.get_year('2011').get_month("Jun").get_recess().plot(figsize=(12,6)) # ### Peak values above the 90th percentile for the station LS06_347 in July 2010: # 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) # ## Select storms and make plot # In[13]: raindata.columns # In[14]: storms = myflowserie.derive_storms(raindata['P05_019'], 'LS06_347', number_of_storms=3, drywindow=50, makeplot=True) # In[15]: storms = myflowserie.derive_storms(raindata['P06_014'], 'LS06_347', number_of_storms=3, drywindow=96, makeplot=True) # ## Season averages (Pandas!) # In[16]: myflowserie.data.groupby('season').mean() # ## Goals # * Use the power of Python **Pandas** # * Provide **domain specific** (hydrological) functionalities # * Provide **intuitive** interface for hydrological time series (main focus on flow series) # * Combine different earlier written loose functionalities in **package** # * Independent, but useful in global **Phd**-developed framework: enables the user to quickly look at different properties of model behaviour # ## Where? # * Code : https://github.com/stijnvanhoey/hydropy --> **Fork** and contribute # * Website : https://stijnvanhoey.github.io/hydropy/ # ### How to start? # 1. Fork the github repo # 2. Get the code on your computer # # git clone https://github.com/yourname/hydropy # 3. Run the python setup script (install as development package): # # python setup.py develop # 4. Improve implementation, add functionalities,... # # * Make a new branch # * Make improvements on this branch # * push the branch towards the repo and perform a pull request # In[ ]: # ## Functionalities extended # In[17]: import hydropy as hp flowdata = pd.read_pickle("./data/FlowData") raindata = pd.read_pickle("./data/RainData") myflowserie = hp.HydroAnalysis(flowdata) # ### Forwarding Pandas functionalities # In[18]: # Data inspection myflowserie.summary() #head(), tail(), # In[19]: # Resampling frequencies temp1 = myflowserie.frequency_resample('7D', 'mean') # 7 day means temp1.head() # In[20]: temp2 = myflowserie.frequency_resample("M", "max") # Monthly maxima temp2.head() # In[21]: temp3 = myflowserie.frequency_resample("A", 'sum') # Yearly sums temp3.head(6) # In[22]: #slicing of the dataframes myflowserie['L06_347']['2009'].plot() # ### Easy period selection # 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)) # In[24]: # or combine different statements: myflowserie.get_year('2010').get_month(6).plot(figsize=(13, 6)) # For the seasons some options are available: Meteorologic (first of the month) or astrologic (21st of the month) # In[25]: myflowserie.current_season_dates() # In[26]: myflowserie.info_season_dates('north', 'astro') # ### 'Hydrological' selections # In[27]: # Peaks (high or low) myflowserie['LS06_348'].get_year('2012').get_highpeaks(60, above_percentile=0.8).data.dropna().head() # In[28]: # Recessions and climbing periods get_recess, get_climbing myflowserie.get_year("2012").get_month("april").get_climbing().plot(figsize=(13, 6)) # In[29]: # above/below certain percentile values myflowserie["LS06_347"].get_above_percentile(0.6).get_year('2011').get_season('summer').plot() # Furthermore: # # * get_storms_per_year (in combination with rain-data) # * get_above_baseflow (in combination with baseflow-data) => next on the list # * ... # In[ ]: # In[ ]: