Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix docstrings for morphfuncx,y
  • Loading branch information
Sparks29032 committed Jul 31, 2025
commit ca0baff623d8bd91fd0eaab3d7335877f2127b8a
33 changes: 20 additions & 13 deletions src/diffpy/morph/morphs/morphfuncx.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@ class MorphFuncx(Morph):
General morph function that applies a user-supplied function to the
x-coordinates of morph data to make it align with a target.

Notice: the morph should maintain the monotonicity of the grid.
Notice: the function provided must preserve the monotonic
increase of the grid.
I.e. the function f applied on the grid x must ensure for all
indices i<j, f(x[i]) < f(x[j]).

Configuration Variables
-----------------------
function: callable
The user-supplied function that applies a transformation to the
y-coordinates of the data.
x-coordinates of the data.

parameters: dict
A dictionary of parameters to pass to the function.
Expand All @@ -29,27 +32,31 @@ class MorphFuncx(Morph):
transformed according to the user-specified function and parameters
The morphed data is returned on the same grid as the unmorphed data

Example (FIX)
-------------
Import the funcy morph function:
Example
-------
Import the funcx morph function:

>>> from diffpy.morph.morphs.morphfuncy import MorphFuncy
>>> from diffpy.morph.morphs.morphfuncx import MorphFuncx

Define or import the user-supplied transformation function:

>>> def sine_function(x, y, amplitude, frequency):
>>> return amplitude * np.sin(frequency * x) * y
>>> import numpy as np
>>> def exp_function(x, y, amplitude, decay):
>>> return abs(amplitude) * (1 - np.exp(-abs(decay) * x))

Note that this transformation is monotonic increasing, so will preserve
the monotonic increasing nature of the provided grid.

Provide initial guess for parameters:

>>> parameters = {'amplitude': 2, 'frequency': 2}
>>> parameters = {'amplitude': 1, 'frequency': 1}

Run the funcy morph given input morph array (x_morph, y_morph)and target
array (x_target, y_target):

>>> morph = MorphFuncy()
>>> morph.function = sine_function
>>> morph.funcy = parameters
>>> morph = MorphFuncx()
>>> morph.funcx_function = exp_function
>>> morph.funcx = parameters
>>> x_morph_out, y_morph_out, x_target_out, y_target_out =
... morph.morph(x_morph, y_morph, x_target, y_target)

Expand All @@ -63,7 +70,7 @@ class MorphFuncx(Morph):
"""

# Define input output types
summary = "Apply a Python function to the y-axis data"
summary = "Apply a Python function to the x-axis data"
xinlabel = LABEL_RA
yinlabel = LABEL_GR
xoutlabel = LABEL_RA
Expand Down
3 changes: 2 additions & 1 deletion src/diffpy/morph/morphs/morphfuncy.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class MorphFuncy(Morph):

Define or import the user-supplied transformation function:

>>> import numpy as np
>>> def sine_function(x, y, amplitude, frequency):
>>> return amplitude * np.sin(frequency * x) * y

Expand All @@ -45,7 +46,7 @@ class MorphFuncy(Morph):
array (x_target, y_target):

>>> morph = MorphFuncy()
>>> morph.function = sine_function
>>> morph.funcy_function = sine_function
>>> morph.funcy = parameters
>>> x_morph_out, y_morph_out, x_target_out, y_target_out =
... morph.morph(x_morph, y_morph, x_target, y_target)
Expand Down