Code
Code
Code
import numpy as np # Import NumPy for advanced numerical operations, including array
manipulations.
import matplotlib.pyplot as plt # Import Matplotlib for crafting static, animated, and interactive
visualizations in Python.
from lmfit import Model # Import the lmfit package to perform nonlinear modeling and data fitting.
import pandas as pd # Import Pandas for efficient data manipulation and analysis purposes...This is
for proccessing excel files
# Inspect the structure and contents of the dataset by displaying its first five rows.
print(data.head())
# The command above reveals the first five rows, offering insight into the dataset's format.
# The 'Date' column spans from January 15, 1981, onwards, indicating the temporal range of the
dataset.
#Production: Shows the production values, starting from 977.0.
#Months: Indicates the time in months, starting from 0.0.
#Predicted_Production: Currently contains NaN values, likely intended for storing future predictions.
#With the data loaded, the next step is to prepare it for analysis.
#This involves checking for any missing values or inconsistencies
#and possibly filtering or transforming the data as needed for the Decline Curve Analysis (DCA).
#It's often helpful to plot the data to understand its trends and characteristics.
#This can inform the choice of the decline model later on.
#The next step is to select a suitable Decline Curve Analysis (DCA) model. Common DCA models
include:
#1:Exponential Decline: Assumes a constant percentage decline over time.
#2:Hyperbolic Decline: Assumes the decline rate decreases over time.
#3:Harmonic Decline: Assumes the decline rate decreases linearly over time.
#The plot above shows the crude oil production over time.
#Based on the trend observed in the plot, we can make an informed decision on which Decline Curve
Analysis (DCA) model to use.
#If the decline appears relatively steady and linear, an exponential decline model could be suitable.
#If the decline rate decreases over time in a more curved manner, a hyperbolic decline model might
be more appropriate.
#Finally, if the decline rate decreases linearly, a harmonic model would be the best choice.
#Given the visual trend from the plot, you might start with an exponential model, which is the
simplest.
#If the fit is not satisfactory, you can explore hyperbolic or harmonic models.
model = Model(exponential_decline)
#You'll need initial guesses for the parameters qi (initial production rate) and d (decline rate).
#Here, we use the first production value as qi and a small fraction for d.
initial_qi = data_cleaned['Production'].iloc[0]
initial_d = 0.1 # This is a guess; you may need to adjust it
result = model.fit(data_cleaned['Production'], t=data_cleaned['Months'], qi=initial_qi, d=initial_d)
print(result.fit_report())
#The report above will give you information about the fitted parameters,
#standard errors, and statistical measures of the fit quality.
plt.figure(figsize=(10, 6))
plt.plot(data_cleaned['Months'], data_cleaned['Production'], 'bo', label='Actual Production')
plt.plot(data_cleaned['Months'], result.best_fit, 'r-', label='Fitted Curve')
plt.xlabel('Months')
plt.ylabel('Production')
plt.legend()
plt.title('DCA Using Exponential Model')
plt.grid(True)
plt.show()
#This plot above will help you visually assess the fit.
#To use the fitted exponential decline model for predicting future production,
#you need to extend your time variable (Months) and use the model to predict production for these
future time points.
#Here's how you can do it:
last_month = data_cleaned['Months'].iloc[-1]
future_months = np.array([last_month + i for i in range(1, 6)])
#Use the fitted model to predict production for these future time points.
#You'll use the parameters from the fitted model.
future_production = result.eval(t=future_months)