Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Code

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

# Make sure all the package below are installed before running the code (i.

e pip install numpy


matplotlib lmfit pandas)

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

# Load the dataset from an Excel file for analysis.


data = pd.read_excel('cleaned_dta.xlsx')

# A quick inspection of the data is essential to confirm correct loading.


# Display the initial rows of the dataset using the head() function for a preliminary overview:

# 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.

plt.plot(data['Months'], data['Production'], 'o')


plt.xlabel('Months')
plt.ylabel('Production')
plt.title('Production Over Time')
plt.show()

#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.

#Define the Exponential Decline Model

def exponential_decline(t, qi, d):


return qi * np.exp(-d * t)

model = Model(exponential_decline)

#Handling Missing Values in the data!!!!!!!!!!!!!!!!!!!!!!!


#Since there are only a few missing values, you might consider dropping these rows,
#especially if they are not consecutive or critical for the decline curve analysis.

data_cleaned = data.dropna(subset=['Production', 'Months'])

#Fit the Model

#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)

#Analyze the Results


#Check the fit report to understand how well the model fits the data:

print(result.fit_report())

#The report above will give you information about the fitted parameters,
#standard errors, and statistical measures of the fit quality.

#Plot the Results

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.

#Use the Model for Prediction:


#Once you're satisfied with the fit, you can use the model to make predictions about future
production.

#HOW TO MAKE PREDICTIONS?

#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:

#Extend the Time Variable


#First, create an array of future time points.
#For example, if you want to predict the next five months and your last month in the data is n,
#you would create an array [n+1, n+2, n+3, n+4, n+5].

last_month = data_cleaned['Months'].iloc[-1]
future_months = np.array([last_month + i for i in range(1, 6)])

#Use the Model to Predict Future Production

#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)

#Display the Predictions

for month in future_months:


print(f'Month: {month}')

for production in future_production:


print(f'Production: {production}')

You might also like