diff --git a/news/strictly-increasing-squeeze.rst b/news/strictly-increasing-squeeze.rst new file mode 100644 index 0000000..f14fabf --- /dev/null +++ b/news/strictly-increasing-squeeze.rst @@ -0,0 +1,23 @@ +**Added:** + +* Raise ``ValueError`` if ``x_squeezed`` is not strictly increasing. + +**Changed:** + +* + +**Deprecated:** + +* + +**Removed:** + +* + +**Fixed:** + +* + +**Security:** + +* diff --git a/src/diffpy/morph/morphs/morphsqueeze.py b/src/diffpy/morph/morphs/morphsqueeze.py index 401d334..a6b0aac 100644 --- a/src/diffpy/morph/morphs/morphsqueeze.py +++ b/src/diffpy/morph/morphs/morphsqueeze.py @@ -83,6 +83,15 @@ def morph(self, x_morph, y_morph, x_target, y_target): coeffs = [self.squeeze[f"a{i}"] for i in range(len(self.squeeze))] squeeze_polynomial = Polynomial(coeffs) x_squeezed = self.x_morph_in + squeeze_polynomial(self.x_morph_in) + strictly_increasing_x = (np.diff(x_squeezed) > 0).all() + if not strictly_increasing_x: + raise ValueError( + "Computed squeezed x is not strictly increasing. " + "The squeezed morph is only intended for small polynomial " + "stretches. Please decrease the magnitude of the polynomial " + "coefficients." + ) + self.squeeze_cutoff_low = min(x_squeezed) self.squeeze_cutoff_high = max(x_squeezed) self.y_morph_out = CubicSpline(x_squeezed, self.y_morph_in)(