Skip to content

Commit

Permalink
new file: LICENSE
Browse files Browse the repository at this point in the history
	new file:   README.md
	new file:   Run_exphydro_distributed_pso.py
	new file:   Run_exphydro_lumped_pso.py
	new file:   SampleData/PET_test.txt
	new file:   SampleData/P_test.txt
	new file:   SampleData/Q_test.txt
	new file:   SampleData/T_test.txt
	new file:   exphydro/__init__.py
	new file:   exphydro/distributed/ExphydroDistrModel.py
	new file:   exphydro/distributed/ExphydroDistrParameters.py
	new file:   exphydro/distributed/__init__.py
	new file:   exphydro/lumped/ExphydroModel.py
	new file:   exphydro/lumped/ExphydroParameters.py
	new file:   exphydro/lumped/__init__.py
	new file:   exphydro/utils/Calibration.py
	new file:   exphydro/utils/ObjectiveFunction.py
	new file:   exphydro/utils/OdeSolver.py
	new file:   exphydro/utils/Parameter.py
	new file:   exphydro/utils/__init__.py
	new file:   setup.py
  • Loading branch information
Sopan Patil committed Jun 1, 2016
1 parent af9284f commit 82a5377
Show file tree
Hide file tree
Showing 21 changed files with 16,960 additions and 0 deletions.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2010-2016 Sopan Patil and Marc Stieglitz

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# EXP-HYDRO Hydrological Model

EXP-HYDRO is a catchment scale hydrological model that operates at a daily time-step. It takes as inputs the daily values of precipitation, air temperature, and potential evapotranspiration, and simulates daily streamflow at the catchment outlet. This model was originally developed by Dr Sopan Patil in 2010 as part of his PhD research. Our research group (http://sopanpatil.weebly.com) continues its active development in both spatially lumped and spatially distributed configurations.

The source code provided is written in Python programming language and has been tested using Python 2.7.

The following data from a sample catchment in Wales are provided (in SampleData folder) to test the model code: P_test.txt (Precipitation data), T_test.txt (Air temperature data), PET_test.txt (Potential evapotranspiration data), Q_test.txt (catchment streamflow data).

Following are the execution files for running EXP-HYDRO:
(1) Run_exphydro_lumped_pso.py: Performs a calibration and validation run of the lumped EXP-HYDRO model using Particle Swarm Optimisation (PSO) algorithm.
(2) Run_exphydro_distributed_pso.py: Performs a calibration and validation run of the distributed EXP-HYDRO model using PSO algorithm.

System Requirements: Please make sure that the following Python packages are installed on your computer before running any of the above execution files:
(1) NumPy (http://www.numpy.org/)
(2) SciPy (http://www.scipy.org/)
(3) matplotlib (http://matplotlib.org/)

Please cite as: Patil, S. and M. Stieglitz (2014) Modelling daily streamflow at ungauged catchments: What information is necessary?, Hydrological Processes, 28(3), 1159-1169, doi:10.1002/hyp.9660.
67 changes: 67 additions & 0 deletions Run_exphydro_distributed_pso.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/usr/bin/env python

# Programmer(s): Sopan Patil.

""" MAIN PROGRAM FILE
Run this file to optimise the EXP-HYDRO model parameters
using Particle Swarm Optimisation (PSO) algorithm.
"""

import numpy
import os
import matplotlib.pyplot as plt
from exphydro.distributed import ExphydroDistrModel, ExphydroDistrParameters
from exphydro.utils import Calibration, ObjectiveFunction

######################################################################
# SET WORKING DIRECTORY

# Getting current directory, i.e., directory containing this file
dir1 = os.path.dirname(os.path.abspath('__file__'))

# Setting to current directory
os.chdir(dir1)

######################################################################
# MAIN PROGRAM

# Load meteorological and observed flow data
P = numpy.genfromtxt('SampleData/P_test.txt') # Observed rainfall (mm/day)
T = numpy.genfromtxt('SampleData/T_test.txt') # Observed air temperature (deg C)
PET = numpy.genfromtxt('SampleData/PET_test.txt') # Potential evapotranspiration (mm/day)
Qobs = numpy.genfromtxt('SampleData/Q_test.txt') # Observed streamflow (mm/day)

# Specify the no. of parameter sets (particles) in a PSO swarm
npart = 10

# Specify the number of pixels in the catchment
npixels = 5

# Generate 'npart' initial EXP-HYDRO model parameters
params = [ExphydroDistrParameters(npixels) for j in range(npart)]

# Initialise the model by loading its climate inputs
model = ExphydroDistrModel(P, PET, T, npixels)

# Specify the start and end day numbers of the calibration period.
# This is done separately for the observed and simulated data
# because they might not be of the same length in some cases.
calperiods_obs = [365, 2557]
calperiods_sim = [365, 2557]

# Calibrate the model to identify optimal parameter set
paramsmax = Calibration.pso_maximise(model, params, Qobs, ObjectiveFunction.klinggupta, calperiods_obs, calperiods_sim)
print 'Calibration run KGE value = ', paramsmax.objval

# Run the optimised model for validation period
Qsim = model.simulate(paramsmax)
kge = ObjectiveFunction.klinggupta(Qobs[calperiods_obs[1]:], Qsim[calperiods_sim[1]:])
print 'Independent run KGE value = ', kge

# Plot the observed and simulated hydrographs
plt.plot(Qobs[calperiods_obs[0]:],'b-')
plt.hold(True)
plt.plot(Qsim[calperiods_sim[0]:],'r-')
plt.show()

######################################################################
64 changes: 64 additions & 0 deletions Run_exphydro_lumped_pso.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/usr/bin/env python

# Programmer(s): Sopan Patil.

""" MAIN PROGRAM FILE
Run this file to optimise the EXP-HYDRO model parameters
using Particle Swarm Optimisation (PSO) algorithm.
"""

import numpy
import os
import matplotlib.pyplot as plt
from exphydro.lumped import ExphydroModel, ExphydroParameters
from exphydro.utils import Calibration, ObjectiveFunction

######################################################################
# SET WORKING DIRECTORY

# Getting current directory, i.e., directory containing this file
dir1 = os.path.dirname(os.path.abspath('__file__'))

# Setting to current directory
os.chdir(dir1)

######################################################################
# MAIN PROGRAM

# Load meteorological and observed flow data
P = numpy.genfromtxt('SampleData/P_test.txt') # Observed rainfall (mm/day)
T = numpy.genfromtxt('SampleData/T_test.txt') # Observed air temperature (deg C)
PET = numpy.genfromtxt('SampleData/PET_test.txt') # Potential evapotranspiration (mm/day)
Qobs = numpy.genfromtxt('SampleData/Q_test.txt') # Observed streamflow (mm/day)

# Specify the no. of parameter sets (particles) in a PSO swarm
npart = 10

# Generate 'npart' initial EXP-HYDRO model parameters
params = [ExphydroParameters() for j in range(npart)]

# Initialise the model by loading its climate inputs
model = ExphydroModel(P, PET, T)

# Specify the start and end day numbers of the calibration period.
# This is done separately for the observed and simulated data
# because they might not be of the same length in some cases.
calperiods_obs = [365, 2557]
calperiods_sim = [365, 2557]

# Calibrate the model to identify optimal parameter set
paramsmax = Calibration.pso_maximise(model, params, Qobs, ObjectiveFunction.klinggupta, calperiods_obs, calperiods_sim)
print 'Calibration run KGE value = ', paramsmax.objval

# Run the optimised model for validation period
Qsim = model.simulate(paramsmax)
kge = ObjectiveFunction.klinggupta(Qobs[calperiods_obs[1]:], Qsim[calperiods_sim[1]:])
print 'Independent run KGE value = ', kge

# Plot the observed and simulated hydrographs
plt.plot(Qobs[calperiods_obs[0]:],'b-')
plt.hold(True)
plt.plot(Qsim[calperiods_sim[0]:],'r-')
plt.show()

######################################################################
Loading

0 comments on commit 82a5377

Please sign in to comment.