Skip to content

Commit ead3248

Browse files
committed
test: writting better docstrings and comments
1 parent 2320b82 commit ead3248

File tree

2 files changed

+30
-9
lines changed

2 files changed

+30
-9
lines changed

src/diffpy/morph/morphs/morphsqueeze.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,29 @@ class MorphSqueeze(Morph):
99
1010
Configuration Variables
1111
-----------------------
12-
squeeze
13-
list or array-like
14-
Polynomial coefficients [a0, a1, ..., an] for the squeeze function.
12+
squeeze : list
13+
The polynomial coefficients [a0, a1, ..., an] for the squeeze function
14+
where the polynomial would be of the form a0 + a1*x + a2*x^2 and so
15+
on. The order of the polynomial is determined by the length of the
16+
list.
17+
18+
Example
19+
-------
20+
>>> import numpy as np
21+
>>> from numpy.polynomial import Polynomial
22+
>>> from diffpy.morph.morphs.morphsqueeze import MorphSqueeze
23+
24+
>>> x_morph = np.linspace(0, 10, 101)
25+
>>> x_target = np.linspace(0, 10, 101)
26+
>>> squeeze_coeff = [0.1, -0.01, 0.005]
27+
>>> poly = Polynomial(squeeze_coeff)
28+
>>> y_morph = np.sin(x_morph + poly(x_morph))
29+
>>> y_target = np.sin(x_target)
30+
31+
>>> morph = MorphSqueeze()
32+
>>> morph.squeeze = squeeze_coeff
33+
>>> x_morph_out, y_morph_out, x_target_out, y_target_out = morph(
34+
... x_morph, y_morph, x_target, y_target)
1535
"""
1636

1737
# Define input output types
@@ -23,6 +43,7 @@ class MorphSqueeze(Morph):
2343
parnames = ["squeeze"]
2444

2545
def morph(self, x_morph, y_morph, x_target, y_target):
46+
"""Apply a polynomial to squeeze the morph function"""
2647
Morph.morph(self, x_morph, y_morph, x_target, y_target)
2748

2849
return self.xyallout

tests/test_morphsqueeze.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,17 @@
2525
]
2626
morph_target_grids = [
2727
# UCs from issue 181: https://github.com/diffpy/diffpy.morph/issues/181
28-
# UC2: Same grid
28+
# UC2: Same range and same grid density
2929
(np.linspace(0, 10, 101), np.linspace(0, 10, 101)),
30-
# UC4: Target extends beyond morph
30+
# UC4: Target range wider than morph, same grid density
3131
(np.linspace(0, 10, 101), np.linspace(-2, 20, 221)),
32-
# UC6: Target extends beyond morph; morph coarser
32+
# UC6: Target range wider than morph, finer target grid density
3333
(np.linspace(0, 10, 101), np.linspace(-2, 20, 421)),
34-
# UC8: Target extends beyond morph; target coarser
34+
# UC8: Target range wider than morph, finer morph grid density
3535
(np.linspace(0, 10, 401), np.linspace(-2, 20, 200)),
36-
# UC10: morph starts earlier than target
36+
# UC10: Morph range starts and ends earlier than target, same grid density
3737
(np.linspace(-2, 10, 121), np.linspace(0, 20, 201)),
38-
# UC12: morph extends beyond target
38+
# UC12: Morph range wider than target, same grid density
3939
(np.linspace(-2, 20, 221), np.linspace(0, 10, 101)),
4040
]
4141

0 commit comments

Comments
 (0)