Skip to content

Commit 3538e4d

Browse files
committed
test: modified docstrings
1 parent 924872e commit 3538e4d

File tree

1 file changed

+40
-32
lines changed

1 file changed

+40
-32
lines changed

src/diffpy/morph/morphs/morphsqueeze.py

Lines changed: 40 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,8 @@
22

33

44
class MorphSqueeze(Morph):
5-
"""Squeeze the morph function.
6-
7-
This applies a polynomial to squeeze the morph non-linearly. The morphed
8-
data is returned on the same grid as the unmorphed data.
9-
10-
Configuration Variables
11-
-----------------------
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_target = np.linspace(0, 10, 101)
25-
>>> y_target = np.sin(x_target)
26-
>>> x_morph = np.linspace(0, 10, 101)
27-
>>> squeeze_coeff = [0.1, -0.01, 0.005]
28-
>>> poly = Polynomial(squeeze_coeff)
29-
>>> y_morph = np.sin(x_morph + poly(x_morph))
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)
35-
"""
5+
"""Apply a polynomial to squeeze the morph function. The morphed
6+
data is returned on the same grid as the unmorphed data."""
367

378
# Define input output types
389
summary = "Squeeze morph by polynomial shift"
@@ -43,7 +14,44 @@ class MorphSqueeze(Morph):
4314
parnames = ["squeeze"]
4415

4516
def morph(self, x_morph, y_morph, x_target, y_target):
46-
"""Apply a polynomial to squeeze the morph function"""
17+
"""Squeeze the morph function.
18+
19+
This applies a polynomial to squeeze the morph non-linearly.
20+
21+
Configuration Variables
22+
-----------------------
23+
squeeze : list
24+
The polynomial coefficients [a0, a1, ..., an] for the squeeze
25+
function where the polynomial would be of the form
26+
a0 + a1*x + a2*x^2 and so on. The order of the polynomial is
27+
determined by the length of the list.
28+
29+
Returns
30+
-------
31+
A tuple (x_morph_out, y_morph_out, x_target_out, y_target_out)
32+
where the target values remain the same and the morph data
33+
is shifted according to the squeeze. The morphed data is
34+
returned on the same grid as the unmorphed data.
35+
36+
Example
37+
-------
38+
Import the squeeze morph function:
39+
>>> from diffpy.morph.morphs.morphsqueeze import MorphSqueeze
40+
Provide initial guess for squeezing coefficients:
41+
>>> squeeze_coeff = [0.1, -0.01, 0.005]
42+
Run the squeeze morph given input morph array (x_morph, y_morph)
43+
and target array (x_target, y_target):
44+
>>> morph = MorphSqueeze()
45+
>>> morph.squeeze = squeeze_coeff
46+
>>> x_morph_out, y_morph_out, x_target_out, y_target_out = morph(
47+
... x_morph, y_morph, x_target, y_target)
48+
To access parameters from the morph instance:
49+
>>> x_morph_in = morph.x_morph_in
50+
>>> y_morph_in = morph.y_morph_in
51+
>>> x_target_in = morph.x_target_in
52+
>>> y_target_in = morph.y_target_in
53+
>>> squeeze_coeff_out = morph.squeeze
54+
"""
4755
Morph.morph(self, x_morph, y_morph, x_target, y_target)
4856

4957
return self.xyallout

0 commit comments

Comments
 (0)