Example #1
0
def plot_production_history_with_fit_and_predict():
    df = pd.read_csv(predict_file)
    starting_index = producer_starting_indicies[1]
    producer = producers[1][starting_index:]
    injectors_tmp = [injector[starting_index:] for injector in injectors]
    X, y = production_rate_dataset(producer, *injectors_tmp)
    X_train, X_test, y_train, y_test = train_test_split(X,
                                                        y,
                                                        test_size=0.5,
                                                        shuffle=False)
    crmp = CRMP().fit(X_train, y_train)
    for i in range(len(producer_names)):
        producer_df = producer_rows_from_df(df, i + 1)
        starting_index = producer_starting_indicies[i]
        producer = producers[i][starting_index:]
        injectors_tmp = [injector[starting_index:] for injector in injectors]
        X, y = production_rate_dataset(producer, *injectors_tmp)
        X_train, X_test, y_train, y_test = train_test_split(X,
                                                            y,
                                                            test_size=0.5,
                                                            shuffle=False)
        producer_length = len(producer)
        t = np.linspace(1, producer_length, producer_length)
        train_length = len(y_train)
        train_time = t[:train_length]
        test_time = t[train_length:][1:]

        empty = []
        plt.plot(empty, empty, c='r', label='Fit')
        plt.plot(empty, empty, c='g', label='Predict')
        plt.plot(t, producer, c='k')

        for index, row in producer_df.iterrows():
            tau = row['tau_final']
            f1 = row['f1_final']
            f2 = row['f2_final']
            f3 = row['f3_final']
            f4 = row['f4_final']
            crmp.tau_ = tau
            crmp.gains_ = [f1, f2, f3, f4]

            # Fitting
            y_hat = crmp.predict(X_train)
            plt.plot(train_time, y_hat, '--', alpha=0.02, c='r', linewidth=2)

            # Prediction
            y_hat = crmp.predict(X_test)
            plt.plot(test_time, y_hat, ':', alpha=0.02, c='g', linewidth=2)

        plt.vlines(test_time[0],
                   0,
                   1.1 * max(producer),
                   linewidth=2,
                   alpha=0.8)
        plot_helper(FIG_DIR,
                    title=producer_names[i],
                    xlabel='Time [days]',
                    ylabel='Production Rate [bbls/day]',
                    legend=True,
                    save=True)
def objective_function_contour_plot():
    for i in range(number_of_producers):
        producer = i + 1
        producer_df = producer_rows_from_df(objective_function_df, producer)
        x, y, z = contour_params(producer_df,
                                 x_column='f1',
                                 y_column='tau',
                                 z_column='MSE')
        plt.contourf(x, y, z, 15, alpha=1.0)
        plt.colorbar()
        title = 'CRMP: Producer {} Objective Function'.format(producer)
        x_true, y_true = true_params[producer]
        actual = plt.scatter(x_true,
                             y_true,
                             s=100,
                             c='r',
                             label='True Value',
                             alpha=0.4)
        plt.legend(handles=[actual], loc='upper left')
        plt.tight_layout()
        plt.ylim(0, 100)
        plot_helper(FIG_DIR,
                    title=title,
                    xlabel=xlabel,
                    ylabel=ylabel,
                    save=True)
Example #3
0
def smallest_error_by_well():
    objective_function_file = INPUTS['crmp']['crmp']['predict'][
        'objective_function']
    objective_function_df = pd.read_csv(objective_function_file)
    for i in range(number_of_producers):
        producer = i + 1
        producer_rows_df = producer_rows_from_df(objective_function_df,
                                                 producer)
        min_mse = producer_rows_df['MSE'].min()
        print(min_mse)
        print(np.log(min_mse))
        print()
        print()
        print()
def parameter_convergence():
    for i in range(len(producers)):
        plt.figure(figsize=[7, 4.8])
        producer = i + 1
        producer_rows_df = producer_rows_from_df(
            fitting_sensitivity_analysis_df, producer)
        x, y = initial_and_final_params_from_df(producer_rows_df)
        x_true, y_true = true_params[producer]
        for j in range(len(x)):
            initial = plt.scatter(x[j][0],
                                  y[j][0],
                                  s=40,
                                  c='g',
                                  marker='o',
                                  label='Initial')
            final = plt.scatter(x[j][1],
                                y[j][1],
                                s=40,
                                c='r',
                                marker='x',
                                label='Final')
            plt.plot(x[j], y[j], c='k', alpha=0.15)
        actual = plt.scatter(x_true,
                             y_true,
                             s=200,
                             c='b',
                             marker='X',
                             label='True Value')
        # actual = plt.scatter(
        #     x_true, y_true, s=100, c='r', label='Actual', alpha=0.5
        # )
        title = 'CRMP: Producer {} Initial Parameter Values with Convergence'.format(
            producer)
        plt.legend(handles=[actual, initial, final],
                   bbox_to_anchor=(1.04, 1),
                   loc="upper left")
        plt.xlim(0, 1)
        plt.ylim(0, 100)
        plt.tight_layout()
        plot_helper(FIG_DIR,
                    title=title,
                    xlabel=xlabel,
                    ylabel=ylabel,
                    save=True)
def gradient_across_parameter_space_prediction_data():
    for i in range(number_of_producers):
        producer = i + 1
        producer_df = producer_rows_from_df(objective_function_df, producer)
        x, y, z = contour_params(producer_df,
                                 x_column='f1',
                                 y_column='tau',
                                 z_column='MSE')
        dz = np.gradient(z)[0]
        plt.contourf(x, y, dz, 15, alpha=1.0)
        plt.colorbar()
        title = 'CRMP: Producer {} ln(Gradient) Across Parameter Space for MSEs from Prediction'.format(
            producer)
        plt.tight_layout()
        plt.ylim(0, 100)
        plot_helper(FIG_DIR,
                    title=title,
                    xlabel=xlabel,
                    ylabel=ylabel,
                    save=True)
def fitted_params_and_mean_squared_error_fitting():
    for i in range(len(producers)):
        producer = i + 1
        producer_rows_df = producer_rows_from_df(
            fitting_sensitivity_analysis_df, producer)
        x, y, z = contour_params(producer_rows_df,
                                 x_column='f1_initial',
                                 y_column='tau_initial',
                                 z_column='MSE')
        plt.contourf(x, y, z)
        plt.colorbar()
        x, y = true_params[producer]
        actual = plt.scatter(x, y, c='red', label='Actual')
        plt.legend(handles=[actual])
        title = 'CRMP Producer {}: Fitted Parameter Values with ln(MSE) from Fitting'.format(
            producer)
        plot_helper(FIG_DIR,
                    title=title,
                    xlabel=xlabel,
                    ylabel=ylabel,
                    save=True)
Example #7
0
def constraint_analysis():
    df = pd.read_csv(predict_output_file)
    length = len(p0s)
    print(length)
    print()
    for i in range(len(producer_names)):
        print(producer_names[i])
        constraint_violation_counter = 0
        sum_of_gains = 0
        producer_df = producer_rows_from_df(df, i + 1)
        for index, row in producer_df.iterrows():
            f1 = row['f1_final']
            f2 = row['f2_final']
            f3 = row['f3_final']
            f4 = row['f4_final']
            gains = f1 + f2 + f3 + f4
            sum_of_gains += gains
            if gains > 1.01:
                constraint_violation_counter += 1
        print('Constraint Violations: ', constraint_violation_counter)
        print('Average Gains Sum: ', (sum_of_gains / length))
        print()
Example #8
0
def converged_parameter_statistics():
    df = pd.read_csv(predict_output_file)
    for i in range(len(producer_names)):
        producer_df = producer_rows_from_df(df, i + 1)
        print(producer_names[i])
        print('tau: ', producer_df['tau_final'].mean())
        print('tau std: ', producer_df['tau_final'].std())
        print('f1: ', producer_df['f1_final'].mean())
        print('f1 std: ', producer_df['f1_final'].std())
        print('f2: ', producer_df['f2_final'].mean())
        print('f2 std: ', producer_df['f2_final'].std())
        print('f3: ', producer_df['f3_final'].mean())
        print('f3 std: ', producer_df['f3_final'].std())
        print('f4: ', producer_df['f4_final'].mean())
        print('f4 std: ', producer_df['f4_final'].std())
        print('MSE: ', producer_df['MSE'].mean())
        print('MSE std: ', producer_df['MSE'].std())
        print()
        print()
        print()
        print()
        print()
        print()