<jupyter_start><jupyter_text><jupyter_code># Get DCA utility
!wget https://raw.githubusercontent.com/yohanesnuwara/pyreservoir/master/dca/dca.py
# Import libraries
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
from scipy.optimize import curve_fit

from dca import remove_outlier, arps_fit
# Production data link (same as session 2)
path = "http://bit.ly/piopetro-data1"
# Read data
df = pd.read_csv(path)

df.head()
# Convert date column to pandas datetime format
df["DATEPRD"] = pd.to_datetime(df["DATEPRD"], format="%d-%b-%y")

df.head()
# Select well 15/9-F-14 (Don't forget to reset index)
df = df[df["NPD_WELL_BORE_NAME"]=="15/9-F-14"].reset_index()

# Dataframe only has 2 columns of interest: time and rate
df = df[["DATEPRD", "BORE_OIL_VOL"]]

df.head()
# Plot oil production rate
plt.figure(figsize=(10,5))
plt.step(df["DATEPRD"], df["BORE_OIL_VOL"])
plt.show()
# Removing outliers (window=150, num_stdev=50)
df2 = remove_outlier(df, "BORE_OIL_VOL", 50, 50, trim=True)

df2.head()
# Plot outlier-removed oil production rate, compare w/ original
plt.figure(figsize=(10,5))

plt.step(df["DATEPRD"], df["BORE_OIL_VOL"], color="red", label="Original data")
plt.step(df2["DATEPRD"], df2["BORE_OIL_VOL_rol_Av"], color="blue", label="Outlier removed")
plt.xlabel("Year"); plt.ylabel("Rate [STB/D]")

plt.legend()
plt.show()
# Define time and production rate (from outlier-removed dataframe)
t = df2["DATEPRD"]
q = df2["BORE_OIL_VOL_rol_Av"]
# Decline curve analysis
arps_fit(t, q, plot=True)
# x = np.array([-0.5, -0.25, -1, 0, 1, 0.25, 0.5])

# def f(x, a, b, c):
#   return (a*x**2) + (b*x) + c

# y = f(x, 0.5, 0.8, 10)
# noise = np.random.random(7) * 0.1
# y = np.round((y+noise), 2)

# [a,b,c], pcov = curve_fit(f, x, y)
# print(a, b, c)

# plt.scatter(x,y)
# plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1769394261424017, 'fraction_numerical': 0.030818278427205102, 'mean_word_length': 4.538235294117647, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '59031', 'license': 'MIT', 'n_tokens_mistral': 843, 'n_tokens_neox': 795, 'n_words': 177, 'path': 'PioPetro/piopetro_session4_decline_curve_analysis.ipynb', 'repo_name': 'k1m190r/python-bootcamp-for-geoengineers', 'size': '1882'}