<jupyter_start><jupyter_text>4 - Displaying Core Data and Deriving a Poro Perm Relationship Created By: <NAME>The following short tutorial illustrates the process of loading in core data from a CSV file, creating poro-perm crossplots, and deriving a poro-perm relationship using numpy.<jupyter_code>import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
core_data = pd.read_csv("Data/15_9-19A-CORE.csv", na_values=' ')
core_data.head()
core_data.describe()<jupyter_output><empty_output><jupyter_text>We can make a quick scatter plot by:<jupyter_code>core_data.plot(kind="scatter", x="CPOR", y="CKHG")<jupyter_output><empty_output><jupyter_text>There is one main problem with previous plot. Poro-perm data is normally presented on semilog scale, where the y-axis is logarithmic and the x-axis set to linear. We can change this by using the yscale('log') method.<jupyter_code>core_data.plot(kind="scatter", x="CPOR", y="CKHG")
plt.yscale('log')
plt.grid(True)<jupyter_output><empty_output><jupyter_text>We can further refine the scatter plot by removing the scientific notation on the y-axis.<jupyter_code>from matplotlib.ticker import FuncFormatter
fig, ax = plt.subplots()

ax.axis([0, 40, 0.01, 100000])
ax.plot(core_data['CPOR'], core_data['CKHG'], 'bo')
ax.set_yscale('log')
ax.grid(True)
ax.set_ylabel('Core Perm (mD)')
ax.set_xlabel('Core Porosity (%)')

#Format the axes so that they show whole numbers
for axis in [ax.yaxis, ax.xaxis]:
    formatter = FuncFormatter(lambda y, _: '{:.16g}'.format(y))
    axis.set_major_formatter(formatter)<jupyter_output><empty_output><jupyter_text>We can derive a linear regression by using the polyfit function from numpy. As we are working with a semi-log plot, we need to calculate log base 10 of the core permeability.<jupyter_code>import statsmodels.api as sm

x = core_data['CPOR']
y = np.log10(core_data['CKHG'])

model = sm.OLS(y, x, missing='drop')
results = model.fit()
results.summary()
x = np.polyfit(core_data['CPOR'], np.log10(core_data['CKHG']), 1)
x<jupyter_output><empty_output><jupyter_text>The result of the regression is: $10^{(0.16911398  * CPOR - 1.61346487)}$ Using the code from the previous plot, we can now add a new line with our x-axis set to porosity and our y-axis set to an equation. Note that we have to use the equation above to reverse the log base 10 function used when deriving the function.<jupyter_code>from matplotlib.ticker import FuncFormatter
fig, ax = plt.subplots()

ax.axis([0, 30, 0.01, 10000])
ax.semilogy(core_data['CPOR'], core_data['CKH'], 'bo')

ax.grid(True)
ax.set_ylabel('Core Perm (mD)')
ax.set_xlabel('Core Porosity (%)')

ax.semilogy(core_data['CPOR'], 10**(x[0] * core_data['CPOR'] + x[1]), 'r-')


#Format the axes so that they show whole numbers
for axis in [ax.yaxis, ax.xaxis]:
    formatter = FuncFormatter(lambda y, _: '{:.16g}'.format(y))
    axis.set_major_formatter(formatter)<jupyter_output><empty_output><jupyter_text>Our next step is to calculate a predicted permeability using our new equation and add it as a new column in the pandas dataframe.<jupyter_code>core_data["PRED_PERM"] = 10**(x[0] * core_data['CPOR'] + x[1])
core_data.describe()<jupyter_output><empty_output><jupyter_text>We can then make a quick plot of our prediction vs the original measurement. To get an idea of how well the prediction did, we can add a 1 to 1 line to aid the visualisation.<jupyter_code>fig, ax = plt.subplots()

ax.axis([0.01, 10000, 0.01, 10000])
ax.loglog(core_data['CKH'], core_data['PRED_PERM'], 'bo')
ax.loglog([0.01, 10000], [0.01, 10000], 'r-')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1281267370761534, 'fraction_numerical': 0.028904947192884937, 'mean_word_length': 6.001945525291829, 'pattern_counts': {'":': 0, '<': 34, '<?xml version=': 0, '>': 34, 'https://': 0, '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': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '142717', 'license': 'MIT', 'n_tokens_mistral': 1346, 'n_tokens_neox': 1228, 'n_words': 380, 'path': '04 - Displaying Core Data and Deriving a Poro Perm Relationship.ipynb', 'repo_name': 'ngocfam/Petrophysics-Python-Series', 'size': '3605'}