diff --git a/pycreep/gpr.py b/pycreep/gpr.py index 423f2c5..bf35ecf 100644 --- a/pycreep/gpr.py +++ b/pycreep/gpr.py @@ -369,7 +369,8 @@ def predict_log_stress(self, time, temperature): return mean.numpy(), var.numpy() - def predict_stress(self, time, temperature, confidence=None): + # pylint: disable=unused-argument + def predict_stress(self, time, temperature, confidence=None, **kwargs): """ Predict the stress at a given time and temperature diff --git a/pycreep/ttp.py b/pycreep/ttp.py index d40d282..8ae9796 100644 --- a/pycreep/ttp.py +++ b/pycreep/ttp.py @@ -253,7 +253,7 @@ def predict_time(self, stress, temperature, confidence=None): if confidence is None: h = 0.0 else: - h = scipy.stats.norm.interval(confidence)[1] + h = np.sign(confidence) * scipy.stats.norm.interval(np.abs(confidence))[1] return 10.0 ** ( self.time_sign @@ -262,7 +262,9 @@ def predict_time(self, stress, temperature, confidence=None): ) ) - def predict_stress(self, time, temperature, confidence=None, root_bounds=None): + def predict_stress( + self, time, temperature, confidence=None, root_bounds=None, raise_on_error=True + ): """ Predict new values of stress given time and temperature @@ -275,6 +277,7 @@ def predict_stress(self, time, temperature, confidence=None, root_bounds=None): average predictions root_bounds: if not None, lower and upper bounds on which root value to use when inverting the TTP polynomial + raise_on_error: if true throw an error if we can't invert. if not return nan """ # Will want these sorted if root_bounds is not None: @@ -298,7 +301,9 @@ def solve_one(x): pi[-1] -= x rs = np.array(np.roots(pi)) if np.all(np.abs(np.imag(rs)) > 0): - raise ValueError("Inverting relation to predict stress failed") + if raise_on_error: + raise ValueError("Inverting relation to predict stress failed") + return np.nan rs[np.abs(np.imag(rs)) > 0] = 0 rs = np.real(rs) # Need to consider this... @@ -306,7 +311,9 @@ def solve_one(x): return np.max(rs) val = np.logical_and(rs >= root_bounds[0], rs <= root_bounds[1]) if np.all(np.logical_not(val)): - raise ValueError("No root falls within user provided bounds!") + if raise_on_error: + raise ValueError("No root falls within user provided bounds!") + return np.nan return rs[val][0] # Solve each one, one at a time, for now