Python GUI for surface hydrology: Calculate Recession Constant online [Example solution to Fetter Hydrogeology]

Today I am going to show you another computer application in hydrogeology, more specifically – in surface hydrogeology. In many projects, it is crucial to monitor flow. Flow generally varies over time and respond to rainfall events. It also varies depending on the season. For many engineering applications, it is important to establish the base flow at a station of interest. If a dedicated rainfall-station not available at the project area, we use freely available weather station data for the closest nationally established station.

For some application, we need to determine recession constant after a rainfall event has occurred. 

There are some great papers and lab work that you can use to review the concept of recession constant. In short, the decline is similar to exponential decay of a radioactive atom.

  1. Hydrograph recession constants are required in rainfall-runoff models: http://engineering.tufts.edu/cee/people/vogel/documents/estimationBaseflow.pdf
  2. Obtain the groundwater recession constant using the following data: http://www.engr.colostate.edu/~ramirez/ce_old/classes/cive322-Ramirez/CE322_Web/Example_RecessionConstant.htm

The best selling book, Applied Hydrogeology by C.W. Fetter has an in-depth coverage of the base flow and recession constant in chapter two. Today, I will make your job simple by presenting a web based GUI application that you can use to calculate the recession constant online. The application that I have developed in coded in Python and you are free to use and distribute the program to anyone you like.

Let me first present the link to run the program online: http://www.codeskulptor.org/#user22_wPyL02hegL_2.py

Here is how the program would look when you hit the RUN button:

Recession Constant Calculator GUI in Python

Recession Constant Calculator GUI in Python

note: photo says to enter the “base flow”. I have edited it later. It should be PEAKFLOW.

 

If you are having trouble finding the run button here it is:

run

The GUI screen I have presented  actually used input parameters from a problem from Fetter Hydro Book on chapter 2. (Problem 9). He stated that the river has a flow at the start of a baseflow recession as 712 cubic meter/s; after 60 days, the flow reduced to 523 cubic meter/s. What is the recession constant? 

Using our tool, we determine that the recession constant is 5.14 E-3 /day.

For advanced users: Debug the code for yourself!

#Template for calculating recession constant
#can be used to solve hydrogeology problems from various text books.
# Programmed by Ankan Basu, CPG
# Contact: admin@coalgeology.com
# website: www.coalgeology.com
# Coded in Python, Version 1.9
# Date: 10/28/2013

import simplegui, math
peakflow, flow_at_t, t=0,0,0
recession_constant=1

flow_at_time_t_text=''
peakflow_text=''
time_at_t_text=''
print_recession_constant=''

def reset():
    global peakflow, flow_at_t, t,flow_at_time_t_text,time_at_t_text,print_recession_constant,recession_constant
    peakflow, flow_at_t, t=0,0,0
    recession_constant=1

    flow_at_time_t_text=''
    peakflow_text=''
    time_at_t_text=''
    print_recession_constant=''

    print1()
    print2()
    print3()
    print4()

def get_flow_at_t(f):
    global flow_at_time_t_text,flow_at_t
    flow_at_t=float(f)
    print1()

def print1():
    global flow_at_time_t_text
    flow_at_time_t_text='Flow at time t in cubic meters/s is '+str(flow_at_t)       

def get_peakflow(f):
    global peakflow_text,peakflow
    peakflow=float(f)
    print2()

def print2():
    global peakflow_text, peakflow
    peakflow_text='peakflow in Cubic meters/s is '+str(peakflow)       

def get_time(time):
    global t, time_at_t_text
    t=float(time)
    print3()

def print3():
    global time_at_t_text, t
    time_at_t_text='Time in dass at flow at time t is '+str(t) 

def calculate_recession_constant():
    global recession_constant, print_recession_constant,peakflow, flow_at_t, t
    recession_constant=-(math.log(flow_at_t/peakflow))/(t*math.log(math.e))  
    #print_recession_constant='recession_constant is '+"%.2e" %recession_constant
    print4() 

def print4(): 
    global print_recession_constant, recession_constant
    print_recession_constant='Calculated recession constant is '+"%.2e" %recession_constant

# define draw handler
def draw(canvas):
    frame.set_canvas_background('Green')
    canvas.draw_text('Tools for Surface Hydrogeology', [20,42], 22, "Orange")    
    canvas.draw_text('Calculate Recession constant in [1/day] unit', [20,62], 20, "White")
    canvas.draw_text('Enter parameters to the left', [55,82], 18, "Black")    
    canvas.draw_text(peakflow_text, [55,102], 16, "White")
    canvas.draw_text(flow_at_time_t_text, [55,122], 16, "white")
    canvas.draw_text(time_at_t_text, [55,142], 16, "White")    
    canvas.draw_text(print_recession_constant, [55,172], 18, "Yellow")
    canvas.draw_text('Coded by Ankan Basu, P.G, 10/28/13', [35,230], 15, "White")
    canvas.draw_text('Website: WWW.COALGEOLOGY.COM', [35,250], 15, "White")
    canvas.draw_text('contact: admin@coalgeology.com', [35,270], 15, "White")

# create frame
frame = simplegui.create_frame("Calculate recession_constant", 400, 320,300,)
frame.add_label('Enter NUMBERS only')
inp1 = frame.add_input('1.Enter peakflow in cubic meters/s, hit ENTER', get_peakflow, 150)
inp2 = frame.add_input('2.Enter flow at time t in cubic meters/s, hit ENTER', get_flow_at_t, 150)
inp3 = frame.add_input('3.Enter time in days for the flow at time t: , hit ENTER', get_time, 150)

#frame.add_button("Start", start,100)
frame.add_button("Calculate Recession Constant", calculate_recession_constant,250)
frame.add_button("Reset", reset,250)
frame.set_draw_handler(draw)

# start frame
frame.start()

Leave a Comment

Your email address will not be published. Required fields are marked *