def fit_unloading(self): well_names = [] for idx in range(self.well_listWidget.count()): item = self.well_listWidget.item(idx) if item.checkState() == Qt.Checked: well_names.append(str(item.text())) vel_name = str(self.velocity_comboBox.currentText()) obp_name = str(self.obp_comboBox.currentText()) vel = list() obp = list() pres = list() for well_name in well_names: well = ppp.Well(str(CONF.well_dir / ".{}".format(well_name))) obp_log = well.get_log(obp_name) vel_log = well.get_log(vel_name) # get data for pres_name in ["unloading"]: if pres_name not in well.params.keys(): continue if pres_name == "MP": pres_log = well.get_pressure_normal() else: pres_log = well._get_pressure(pres_name) depth = np.array(vel_log.depth) for dp, val in zip(pres_log.depth, pres_log.data): idx = np.searchsorted(depth, dp) vel.append(vel_log.data[idx]) obp.append(obp_log.data[idx]) pres.append(val) vel, obp, pres = \ np.array(vel), np.array(obp), np.array(pres) es = obp - pres # fit v_max = float(self.vmax_lineEdit.text()) A = float(self.a_lineEdit.text()) B = float(self.b_lineEdit.text()) sigma_max = ((v_max - 1524)/A)**(1/B) temp_dict = {"A": A, "B": B, "sigma_max": sigma_max} def unloading_curve(sigma, u): independent = temp_dict["sigma_max"]*(sigma/temp_dict["sigma_max"])**(1/u) return 1524 + temp_dict['A'] * independent**temp_dict['B'] popt, pcov = curve_fit(unloading_curve, es, vel) U, = popt self.u_lineEdit.setText("{}".format(U)) RRMSE = ppp.rmse(vel, ppp.unloading_curve(es, A, B, U, v_max)) R_squared = r2_score(vel, ppp.unloading_curve(es, A, B, U, v_max)) string_output = 'RRMSE={}\n'.format(RRMSE) + \ "R-squared={}".format(R_squared) self.unloading_textEdit.setText(string_output) self.draw_unloading_line()
def fit_loading(self): well_names = [] for idx in range(self.well_listWidget.count()): item = self.well_listWidget.item(idx) if item.checkState() == Qt.Checked: well_names.append(str(item.text())) vel_name = str(self.velocity_comboBox.currentText()) obp_name = str(self.obp_comboBox.currentText()) vel = list() obp = list() pres = list() for well_name in well_names: well = ppp.Well(str(CONF.well_dir / ".{}".format(well_name))) obp_log = well.get_log(obp_name) vel_log = well.get_log(vel_name) # get data for pres_name in ["MP", "loading"]: if pres_name not in well.params.keys(): continue if pres_name == "MP": pres_log = well.get_pressure_normal() else: pres_log = well._get_pressure(pres_name) depth = np.array(vel_log.depth) for dp, val in zip(pres_log.depth, pres_log.data): idx = np.searchsorted(depth, dp) vel.append(vel_log.data[idx]) obp.append(obp_log.data[idx]) pres.append(val) vel, obp, pres = \ np.array(vel), np.array(obp), np.array(pres) es = obp - pres # fit popt, pcov = curve_fit(ppp.virgin_curve, es, vel) a, b = popt self.a_lineEdit.setText("{}".format(a)) self.b_lineEdit.setText("{}".format(b)) # RRMSE = rrmse(vel, ppp.virgin_curve(es, a, b)) RRMSE = ppp.rmse(vel, ppp.virgin_curve(es, a, b)) # print('RRMSE={}'.format()) # print('R-squared={}'.format()) R_squared = r2_score(vel, ppp.virgin_curve(es, a, b)) string_output = 'RRMSE={}\n'.format(RRMSE) + \ "R-squared={}".format(R_squared) self.loading_textEdit.setText(string_output) self.line_loading.append(self.plot_with_a_b(a, b)) self.matplotlib_widget.fig.canvas.draw()
def predict(self): # get log well_name = self.well_comboBox.currentText() well = ppp.Well(str(CONF.well_dir / ".{}".format(well_name))) obp_log = well.get_log(str(self.obp_comboBox.currentText())) vel_log = well.get_log(str(self.velocity_comboBox.currentText())) pres_log = well.get_pressure_measured() nct = well.params[str(self.nct_comboBox.currentText())] a, b = nct['a'], nct['b'] # calculate normal velocity and normal stress vnormal = ppp.normal(np.array(vel_log.depth), a, b) hydrostatic = ppp.hydrostatic_pressure( np.array(obp_log.depth), kelly_bushing=well.kelly_bushing, depth_w=well.water_depth, rho_f=1.01) pressure = ppp.eaton( np.array(vel_log.data), vnormal, hydrostatic, np.array(obp_log.data), float(self.n_lineEdit.text())) pp = [] depth = np.array(vel_log.depth) for dp in pres_log.depth: idx = np.searchsorted(depth, dp) pp.append(pressure[idx]) mp = np.array(pres_log.data) pp = np.array(pp) RRMSE = ppp.rmse(mp, pp) self.ax.cla() # self.ax.invert_yaxis() self.ax.plot(pressure, obp_log.depth, color='blue') self.ax.plot(obp_log.data, obp_log.depth, color='green') self.ax.scatter(pres_log.data, pres_log.depth, color='red') self.ax.plot(hydrostatic, obp_log.depth, 'g--') self.ax.set_title('{}'.format(obp_log.name.upper().replace('_', '-')[4:])) self.ax.set_ylabel("Depth(m)") self.ax.set_xlabel("Pressure(mPa)") self.ax.set_xlim(xmin=0) self.ax.set_ylim(ymax=0) self.matplotlib_widget.fig.canvas.draw()
def test__rmse(array_for_test): assert ppp.rmse(array_for_test, array_for_test) == 0