forked from diffpy/diffpy.morph
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmorphsqueeze.py
40 lines (32 loc) · 1.26 KB
/
morphsqueeze.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from numpy.polynomial import Polynomial
from scipy.interpolate import interp1d
from diffpy.morph.morphs.morph import LABEL_GR, LABEL_RA, Morph
class MorphSqueeze(Morph):
"""Squeeze the morph function.
This applies a polynomial to squeeze the morph non-linearly.
Configuration Variables
-----------------------
squeeze
list or array-like
Polynomial coefficients [a0, a1, ..., an] for the squeeze function.
"""
# Define input output types
summary = "Squeeze morph by polynomial shift"
xinlabel = LABEL_RA
yinlabel = LABEL_GR
xoutlabel = LABEL_RA
youtlabel = LABEL_GR
parnames = ["squeeze"]
def morph(self, x_morph, y_morph, x_target, y_target):
Morph.morph(self, x_morph, y_morph, x_target, y_target)
if self.squeeze is None:
self.x_morph_out = self.x_morph_in
self.y_morph_out = self.y_morph_in
return self.xyallout
squeeze_polynomial = Polynomial(self.squeeze)
x_squeezed = self.x_morph_in + squeeze_polynomial(self.x_morph_in)
self.y_morph_out = interp1d(
x_squeezed, self.y_morph_in, kind="cubic", bounds_error=False
)(self.x_morph_in)
self.x_morph_out = self.x_morph_in
return self.xyallout