Skip to content

Commit c2e49a0

Browse files
committed
funct/test: fixing squeeze function and test
1 parent b9d73d5 commit c2e49a0

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

news/morphsqueeze.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
**Changed:**
66

77
* Added cubic and quadratic terms, as well as
8-
* squeeze_1 and squeeze_2 parameters
8+
* squeeze_1 and squeeze_2 parameters.
9+
* I was not keeping the y-axis constant and
10+
* corrected for it
911

1012
**Deprecated:**
1113

@@ -17,7 +19,7 @@
1719

1820
**Fixed:**
1921

20-
* <news item>
22+
* I was not keeping the y-values constant, fixed now
2123

2224
**Security:**
2325

src/diffpy/morph/morphs/morphsqueeze.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
"""class MorphSqueeze -- apply a non-linear squeeze to the morph.
22
This morph non-linearly adjusts the x-coordinates.
3-
The y-values are then recomputed by interpolating the original data.
3+
The y-values are the same as initial, just on a new grid.
44
"""
55

6-
import numpy as np
7-
86
from diffpy.morph.morphs.morph import LABEL_GR, LABEL_RA, Morph
97

108

@@ -48,8 +46,8 @@ def morph(self, x_morph, y_morph, x_target, y_target):
4846

4947
self.x_morph_out = new_x
5048

51-
# Interpolate the y-values at the new x positions.
52-
self.y_morph_out = np.interp(new_x, self.x_morph_in, self.y_morph_in)
49+
# The y-axis should be the same
50+
self.y_morph_out = self.y_morph_in
5351

5452
return self.xyallout
5553

tests/test_morphsqueeze.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,12 @@ def test_morph_with_squeeze(self, setup):
5353
+ morph.squeeze_1 * self.x_morph**2
5454
+ morph.squeeze_2 * self.x_morph**3
5555
)
56-
expected_y = np.interp(expected_x, self.x_morph, self.y_morph)
56+
expected_y = np.sin(self.x_morph)
5757

58-
# Allow for some tolerance because of numerical interpolation if used
5958
res = sum(np.fabs(expected_y - y_new))
60-
assert res < 1
59+
res2 = sum(np.fabs(expected_x - x_new))
60+
assert res < 0.1
61+
assert res2 < 0.1
6162

6263

6364
if __name__ == "__main__":

0 commit comments

Comments
 (0)