1+ """Class MorphFuncy -- apply a user-supplied python function to the
2+ y-axis."""
3+
14from diffpy .morph .morphs .morph import LABEL_GR , LABEL_RA , Morph
25
36
47class MorphFuncy (Morph ):
5- """Apply the user-supplied Python function to the y-coordinates of
6- the morph data."""
8+ """Apply a custom function to the y-axis of the morph function.
9+
10+ General morph function that applies a user-supplied function to the
11+ y-coordinates of morph data to make it align with a target.
12+
13+ Configuration Variables
14+ -----------------------
15+ function: callable
16+ The user-supplied function that applies a transformation to the
17+ y-coordinates of the data.
18+
19+ parameters: dict
20+ A dictionary of parameters to pass to the function.
21+
22+ Returns
23+ -------
24+ A tuple (x_morph_out, y_morph_out, x_target_out, y_target_out)
25+ where the target values remain the same and the morph data is
26+ transformed according to the user-specified function and parameters
27+ The morphed data is returned on the same grid as the unmorphed data
28+
29+ Example
30+ -------
31+ Import the funcy morph function:
32+
33+ >>> from diffpy.morph.morphs.morphfuncy import MorphFuncy
34+
35+ Define or import the user-supplied transformation function:
36+
37+ >>> def sine_function(x, y, amplitude, frequency):
38+ >>> return amplitude * np.sin(frequency * x) * y
39+
40+ Provide initial guess for parameters:
41+
42+ >>> parameters = {'amplitude': 2, 'frequency': 2}
43+
44+ Run the funcy morph given input morph array (x_morph, y_morph)and target
45+ array (x_target, y_target):
46+
47+ >>> morph = MorphFuncy()
48+ >>> morph.function = sine_function
49+ >>> morph.funcy = parameters
50+ >>> x_morph_out, y_morph_out, x_target_out, y_target_out =
51+ ... morph.morph(x_morph, y_morph, x_target, y_target)
52+
53+ To access parameters from the morph instance:
54+
55+ >>> x_morph_in = morph.x_morph_in
56+ >>> y_morph_in = morph.y_morph_in
57+ >>> x_target_in = morph.x_target_in
58+ >>> y_target_in = morph.y_target_in
59+ >>> parameters_out = morph.funcy
60+ """
761
862 # Define input output types
963 summary = "Apply a Python function to the y-axis data"
@@ -14,54 +68,8 @@ class MorphFuncy(Morph):
1468 parnames = ["function" , "funcy" ]
1569
1670 def morph (self , x_morph , y_morph , x_target , y_target ):
17- """General morph function that applies a user-supplied function
18- to the y-coordinates of morph data to make it align with a
19- target.
20-
21- Configuration Variables
22- -----------------------
23- function: callable
24- The user-supplied function that applies a transformation to the
25- y-coordinates of the data.
26-
27- parameters: dict
28- A dictionary of parameters to pass to the function.
29- These parameters are unpacked using **kwargs.
30-
31- Returns
32- -------
33- A tuple (x_morph_out, y_morph_out, x_target_out, y_target_out)
34- where the target values remain the same and the morph data is
35- transformed according to the user-specified function and parameters
36- The morphed data is returned on the same grid as the unmorphed data
37-
38- Example
39- -------
40- Import the funcy morph function:
41- >>> from diffpy.morph.morphs.morphfuncy import MorphFuncy
42-
43- Define or import the user-supplied transformation function:
44- >>> def sine_function(x, y, amplitude, frequency):
45- >>> return amplitude * np.sin(frequency * x) * y
46-
47- Provide initial guess for parameters:
48- >>> parameters = {'amplitude': 2, 'frequency': 2}
49-
50- Run the funcy morph given input morph array (x_morph, y_morph)
51- and target array (x_target, y_target):
52- >>> morph = MorphFuncy()
53- >>> morph.function = sine_function
54- >>> morph.funcy = parameters
55- >>> x_morph_out, y_morph_out, x_target_out, y_target_out = morph.morph(
56- ... x_morph, y_morph, x_target, y_target)
57-
58- To access parameters from the morph instance:
59- >>> x_morph_in = morph.x_morph_in
60- >>> y_morph_in = morph.y_morph_in
61- >>> x_target_in = morph.x_target_in
62- >>> y_target_in = morph.y_target_in
63- >>> parameters_out = morph.funcy
64- """
71+ """Apply the user-supplied Python function to the y-coordinates
72+ of the morph data."""
6573 Morph .morph (self , x_morph , y_morph , x_target , y_target )
6674 self .y_morph_out = self .function (
6775 self .x_morph_in , self .y_morph_in , ** self .funcy
0 commit comments