Skip to content

Commit 097190e

Browse files
committed
Fix docstrings for morphfuncx,y
1 parent 0e810cc commit 097190e

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

src/diffpy/morph/morphs/morphfuncx.py

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,16 @@ class MorphFuncx(Morph):
1111
General morph function that applies a user-supplied function to the
1212
x-coordinates of morph data to make it align with a target.
1313
14-
Notice: the morph should maintain the monotonicity of the grid.
14+
Notice: the function provided must preserve the monotonic
15+
increase of the grid.
16+
I.e. the function f applied on the grid x must ensure for all
17+
indices i<j, f(x[i]) < f(x[j]).
1518
1619
Configuration Variables
1720
-----------------------
1821
function: callable
1922
The user-supplied function that applies a transformation to the
20-
y-coordinates of the data.
23+
x-coordinates of the data.
2124
2225
parameters: dict
2326
A dictionary of parameters to pass to the function.
@@ -29,27 +32,31 @@ class MorphFuncx(Morph):
2932
transformed according to the user-specified function and parameters
3033
The morphed data is returned on the same grid as the unmorphed data
3134
32-
Example (FIX)
33-
-------------
34-
Import the funcy morph function:
35+
Example
36+
-------
37+
Import the funcx morph function:
3538
36-
>>> from diffpy.morph.morphs.morphfuncy import MorphFuncy
39+
>>> from diffpy.morph.morphs.morphfuncx import MorphFuncx
3740
3841
Define or import the user-supplied transformation function:
3942
40-
>>> def sine_function(x, y, amplitude, frequency):
41-
>>> return amplitude * np.sin(frequency * x) * y
43+
>>> import numpy as np
44+
>>> def exp_function(x, y, amplitude, decay):
45+
>>> return abs(amplitude) * (1 - np.exp(-abs(decay) * x))
46+
47+
Note that this transformation is monotonic increasing, so will preserve
48+
the monotonic increasing nature of the provided grid.
4249
4350
Provide initial guess for parameters:
4451
45-
>>> parameters = {'amplitude': 2, 'frequency': 2}
52+
>>> parameters = {'amplitude': 1, 'frequency': 1}
4653
4754
Run the funcy morph given input morph array (x_morph, y_morph)and target
4855
array (x_target, y_target):
4956
50-
>>> morph = MorphFuncy()
51-
>>> morph.function = sine_function
52-
>>> morph.funcy = parameters
57+
>>> morph = MorphFuncx()
58+
>>> morph.funcx_function = exp_function
59+
>>> morph.funcx = parameters
5360
>>> x_morph_out, y_morph_out, x_target_out, y_target_out =
5461
... morph.morph(x_morph, y_morph, x_target, y_target)
5562
@@ -63,7 +70,7 @@ class MorphFuncx(Morph):
6370
"""
6471

6572
# Define input output types
66-
summary = "Apply a Python function to the y-axis data"
73+
summary = "Apply a Python function to the x-axis data"
6774
xinlabel = LABEL_RA
6875
yinlabel = LABEL_GR
6976
xoutlabel = LABEL_RA

src/diffpy/morph/morphs/morphfuncy.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class MorphFuncy(Morph):
3434
3535
Define or import the user-supplied transformation function:
3636
37+
>>> import numpy as np
3738
>>> def sine_function(x, y, amplitude, frequency):
3839
>>> return amplitude * np.sin(frequency * x) * y
3940
@@ -45,7 +46,7 @@ class MorphFuncy(Morph):
4546
array (x_target, y_target):
4647
4748
>>> morph = MorphFuncy()
48-
>>> morph.function = sine_function
49+
>>> morph.funcy_function = sine_function
4950
>>> morph.funcy = parameters
5051
>>> x_morph_out, y_morph_out, x_target_out, y_target_out =
5152
... morph.morph(x_morph, y_morph, x_target, y_target)

0 commit comments

Comments
 (0)