11"""Class MorphSqueeze -- Apply a polynomial to squeeze the morph
22function."""
33
4- import warnings
5-
64import numpy as np
75from numpy .polynomial import Polynomial
86from scipy .interpolate import CubicSpline
97
108from diffpy .morph .morphs .morph import LABEL_GR , LABEL_RA , Morph
119
1210
13- def custom_formatwarning (msg , * args , ** kwargs ):
14- return f"{ msg } \n "
15-
16-
17- warnings .formatwarning = custom_formatwarning
18-
19-
2011class MorphSqueeze (Morph ):
2112 """Squeeze the morph function.
2213
@@ -75,6 +66,11 @@ class MorphSqueeze(Morph):
7566 # extrap_index_high: first index after interpolation region
7667 extrap_index_low = None
7768 extrap_index_high = None
69+ squeeze_cutoff_low = None
70+ squeeze_cutoff_high = None
71+
72+ def __init__ (self , config = None ):
73+ super ().__init__ (config )
7874
7975 def morph (self , x_morph , y_morph , x_target , y_target ):
8076 """Apply a polynomial to squeeze the morph function.
@@ -87,34 +83,14 @@ def morph(self, x_morph, y_morph, x_target, y_target):
8783 coeffs = [self .squeeze [f"a{ i } " ] for i in range (len (self .squeeze ))]
8884 squeeze_polynomial = Polynomial (coeffs )
8985 x_squeezed = self .x_morph_in + squeeze_polynomial (self .x_morph_in )
86+ self .squeeze_cutoff_low = min (x_squeezed )
87+ self .squeeze_cutoff_high = max (x_squeezed )
9088 self .y_morph_out = CubicSpline (x_squeezed , self .y_morph_in )(
9189 self .x_morph_in
9290 )
93- low_extrap = np .where (self .x_morph_in < x_squeezed [ 0 ] )[0 ]
94- high_extrap = np .where (self .x_morph_in > x_squeezed [ - 1 ] )[0 ]
91+ low_extrap = np .where (self .x_morph_in < self . squeeze_cutoff_low )[0 ]
92+ high_extrap = np .where (self .x_morph_in > self . squeeze_cutoff_high )[0 ]
9593 self .extrap_index_low = low_extrap [- 1 ] if low_extrap .size else None
9694 self .extrap_index_high = high_extrap [0 ] if high_extrap .size else None
97- below_extrap = min (x_morph ) < min (x_squeezed )
98- above_extrap = max (x_morph ) > max (x_squeezed )
99- if below_extrap or above_extrap :
100- if not above_extrap :
101- wmsg = (
102- "Warning: points with grid value below "
103- f"{ min (x_squeezed )} will be extrapolated."
104- )
105- elif not below_extrap :
106- wmsg = (
107- "Warning: points with grid value above "
108- f"{ max (x_squeezed )} will be extrapolated."
109- )
110- else :
111- wmsg = (
112- "Warning: points with grid value below "
113- f"{ min (x_squeezed )} and above { max (x_squeezed )} will be "
114- "extrapolated."
115- )
116- warnings .warn (
117- wmsg ,
118- UserWarning ,
119- )
95+
12096 return self .xyallout
0 commit comments