From d6b320d43596b5f076bc015e9e6b59516227dcbc Mon Sep 17 00:00:00 2001 From: Yuchen Ethan Xiao Date: Mon, 18 Aug 2025 16:15:52 -0400 Subject: [PATCH 1/2] raise `ValueError` if `x_squeezed` is not strictly increasing --- news/strictly-increasing-squeeze.rst | 23 +++++++++++++++++++++++ src/diffpy/morph/morphs/morphsqueeze.py | 7 +++++++ 2 files changed, 30 insertions(+) create mode 100644 news/strictly-increasing-squeeze.rst diff --git a/news/strictly-increasing-squeeze.rst b/news/strictly-increasing-squeeze.rst new file mode 100644 index 00000000..f14fabf8 --- /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 bc0e4d49..4000423f 100644 --- a/src/diffpy/morph/morphs/morphsqueeze.py +++ b/src/diffpy/morph/morphs/morphsqueeze.py @@ -78,6 +78,13 @@ 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. " + "Please change the input x_morph or the squeeze " + "coefficients." + ) self.y_morph_out = CubicSpline(x_squeezed, self.y_morph_in)( self.x_morph_in ) From add0413994326e2e5493a796aabc8ed8e60afbbf Mon Sep 17 00:00:00 2001 From: Yuchen Ethan Xiao Date: Thu, 11 Sep 2025 15:58:10 -0400 Subject: [PATCH 2/2] chore: update error message --- src/diffpy/morph/morphs/morphsqueeze.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/diffpy/morph/morphs/morphsqueeze.py b/src/diffpy/morph/morphs/morphsqueeze.py index 61260683..a6b0aac1 100644 --- a/src/diffpy/morph/morphs/morphsqueeze.py +++ b/src/diffpy/morph/morphs/morphsqueeze.py @@ -87,7 +87,8 @@ def morph(self, x_morph, y_morph, x_target, y_target): if not strictly_increasing_x: raise ValueError( "Computed squeezed x is not strictly increasing. " - "Please change the input x_morph or the squeeze " + "The squeezed morph is only intended for small polynomial " + "stretches. Please decrease the magnitude of the polynomial " "coefficients." )