This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def hyperbolic_equation(t, qi, b, di): | |
""" | |
Hyperbolic decline curve equation | |
Arguments: | |
t: Float. Time since the well first came online, | |
can be in various units | |
(days, months, etc) so long as they are consistent. | |
qi: Float. Initial production rate when well first came online. | |
b: Float. Hyperbolic decline constant | |
di: Float. Nominal decline rate at time t=0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def hyperbolic_equation(t, qi, b, di): | |
""" | |
Hyperbolic decline curve equation | |
Arguments: | |
t: Float. Time since the well first came online, can be in various units | |
(days, months, etc) so long as they are consistent. | |
qi: Float. Initial production rate when well first came online. | |
b: Float. Hyperbolic decline constant | |
di: Float. Nominal decline rate at time t=0 | |
Output: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def hyperbolic_equation(t, qi, b, di): | |
""" | |
Hyperbolic decline curve equation | |
Arguments: | |
t: Float. Time since the well first came online, can be in various units | |
(days, months, etc) so long as they are consistent. | |
qi: Float. Initial production rate when well first came online. | |
b: Float. Hyperbolic decline constant | |
di: Float. Nominal decline rate at time t=0 | |
Output: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_max_initial_production(df, number_first_months, variable_column, date_column): | |
""" | |
This function allows you to look at the first X months of production, and selects | |
the highest production month as max initial production | |
Arguments: | |
df: Pandas dataframe. | |
number_first_months: float. Number of months from the point the well comes online | |
to compare to get the max initial production rate qi (this looks at multiple months | |
in case there is a production ramp-up) | |
variable_column: String. Column name for the column where we're attempting to get |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Get the highest value of production in the first three months of production, to use as qi value | |
qi=get_max_initial_production(production_time_series, 3, desired_product_type, 'ReportDate') | |
#Exponential curve fit the data to get best fit equation | |
popt_exp, pcov_exp=curve_fit(exponential_equation, production_time_series['Days_Online'], | |
production_time_series[desired_product_type], | |
bounds=(0, [qi,20])) | |
print('Exponential Fit Curve-fitted Variables: qi='+str(popt_exp[0])+ | |
', di='+str(popt_exp[1])) | |
#Hyperbolic curve fit the data to get best fit equation | |
popt_hyp, pcov_hyp=curve_fit(hyperbolic_equation, production_time_series['Days_Online'], |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def plot_actual_vs_predicted_by_equations(df, x_variable, y_variables, plot_title): | |
""" | |
This function is used to map x- and y-variables against each other | |
Arguments: | |
df: Pandas dataframe. | |
x_variable: String. Name of the column that we want to set as the | |
x-variable in the plot | |
y_variables: string (single), or list of strings (multiple). Name(s) | |
of the column(s) that we want to set as the y-variable in the plot | |
""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Declare the x- and y- variables that we want to plot against each other | |
y_variables=[desired_product_type, "Hyperbolic_Predicted", "Exponential_Predicted"] | |
x_variable='Days_Online' | |
#Create the plot title | |
plot_title=desired_product_type+' Production for Well API '+str(api_number) | |
#Plot the data to visualize the equation fit | |
plot_actual_vs_predicted_by_equations(production_time_series, x_variable, y_variables, plot_title) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
from scipy.optimize import curve_fit | |
import numpy as np | |
import matplotlib.pyplot as plt | |
def read_in_csv(file_path): | |
""" | |
Read in the specified csv as a pandas dataframe | |
Arguments: | |
file_path: String. Path for the csv file that we want to read in |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
This script is used to query data directly from the EPA's Envirofacts API, and land in | |
a pandas data frame. In this script, the GHG data tables are pulled and merged together to | |
create a master dataframe containing all of the GHG data we'd need for analysis: | |
facility location, sector, and subsector, and emissions and emission type by year | |
""" | |
import pandas as pd | |
import io | |
import requests |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Import desired packages | |
import requests | |
import zipfile | |
import io | |
import pandas as pd | |
def pull_zip_file_from_url(url): | |
""" | |
This function pulls a zip file from a URL and generates a ZipFile object | |
Arguments: |
OlderNewer