Blog | Tools | Glossary | Search

Support us:
Share:   |  feedback   |  Join us  

Decline Curve Analysis (DCA) with Python

From petrofaq
Jump to navigation Jump to search

About the Author

More By Petro Engineer

PVT and Flow course - Rate Equation (Darcy) Intro
1 vote, 0 comments
Gaslift in simple words
1 vote, 0 comments
Collaborative articles on LinkedIn
1 vote, 0 comments
1

Hello everyone!

In this tutorial, we're going to write a simple Python script to analyze decline curves for oil and gas wells using the Arps method. Here is the DCA theory.
You can find the implementation of the script in Petrofaq Tools: Tools:ArpsDeclineCurveAnalysis

First - let's add the necessary Pyton libraries:

from scipy.optimize import curve_fit
import pandas as pd
import numpy as np

We will import the data from the data.scv file, which must be in the same directory as our Python script. Here is the format of this file:

time,production
0,500
1,300
2,200
3,100

Let's import the file using the Pandas function:

df = pd.read_csv('data.csv')   # import the data

t = df["time"].tolist()        # create the list of timesteps
q = df["production"].tolist()  # create the list of production data

Now let's define Arps' equations:

# exponential decline 
def arps_exp(t, qi, Di):
    return qi * np.exp(-Di * t)

# hyperbolic decline
def arps_hyp(t, qi, Di, b ):
    return qi/((1+b*Di*t)**(1/b))

# harmonic decline
def arps_harmonic(t, qi, Di ):
    return qi/((1+Di*t))

Now, we are ready to find Arps' coefficents using the defined functions and curve_fit function from scipy.optimize:

try:
    popt_hyp, pcov_hyp  = curve_fit(arps_hyp, t, q)                                                # find the coefficients for hyperbolic decline
    popt_harmonic, pcov_harmonic = curve_fit(arps_harmonic, t, q, p0=[popt_hyp[0], popt_hyp[1] ])  # find the coefficients for the harmonic decline, using the results from the hyperbolic decline as an initial guess
    popt_exp, pcov_exp = curve_fit(arps_exp, t, q, p0=[popt_hyp[0], popt_hyp[1] ])                 # find the coefficients for the exponential decline, using the results from the hyperbolic decline as an initial guess.
except:
    print ("no solution")  # if failed, report an error

And finally, print the results:

# Print the estimated parameters for the hyperbolic decline curve
print("Estimated parameters for hyperbolic decline curve:")
print("Initial production ProdRate (qi):", popt_hyp[0])
print("Decline factor (Di):", popt_hyp[1])
print("Arps coefficient (b):", popt_hyp[2])


# Print the estimated parameters for the harmonic decline curve
print("Estimated parameters for harmonic decline curve:")
print("Initial production ProdRate (qi):", popt_harmonic[0])
print("Decline factor (Di):", popt_harmonic[1])


# Print the estimated parameters for the exponential decline curve
print("Estimated parameters for exponential decline curve:")
print("Initial production ProdRate (qi):", popt_exp[0])
print("Decline factor (Di):", popt_exp[1])



Add your comment
petrofaq welcomes all comments. If you do not want to be anonymous, register or log in. It is free.