Skip to content

Commit 400851b

Browse files
committed
feat: add warning for extrapolation in morphsqueeze
1 parent 3908d63 commit 400851b

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/diffpy/morph/morphs/morphsqueeze.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import numpy as np
55
from numpy.polynomial import Polynomial
66
from scipy.interpolate import CubicSpline
7+
import warnings
78

89
from diffpy.morph.morphs.morph import LABEL_GR, LABEL_RA, Morph
910

@@ -85,4 +86,17 @@ def morph(self, x_morph, y_morph, x_target, y_target):
8586
high_extrap = np.where(self.x_morph_in > x_squeezed[-1])[0]
8687
self.extrap_index_low = low_extrap[-1] if low_extrap.size else None
8788
self.extrap_index_high = high_extrap[0] if high_extrap.size else None
89+
90+
low_extrap_x = x_squeezed[0] - self.x_morph_in[0]
91+
high_extrap_x = self.x_morph_in[-1] - x_squeezed[-1]
92+
if low_extrap_x > 0 or high_extrap_x > 0:
93+
wmsg = "Extrapolating the morphed function: "
94+
if low_extrap_x > 0:
95+
wmsg += f"extrapolating length in the lowe r {low_extrap_x} "
96+
if high_extrap_x > 0:
97+
wmsg += f"extrapolating length in the high r {high_extrap_x} "
98+
warnings.warn(
99+
wmsg,
100+
UserWarning,
101+
)
88102
return self.xyallout

0 commit comments

Comments
 (0)