Skip to content
Prev Previous commit
Next Next commit
test: modified docstrings
  • Loading branch information
Luiskitsu committed Apr 13, 2025
commit 3538e4db5f414464c35dfe3c27281b024fe6efc3
72 changes: 40 additions & 32 deletions src/diffpy/morph/morphs/morphsqueeze.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,8 @@


class MorphSqueeze(Morph):
"""Squeeze the morph function.

This applies a polynomial to squeeze the morph non-linearly. The morphed
data is returned on the same grid as the unmorphed data.

Configuration Variables
-----------------------
squeeze : list
The polynomial coefficients [a0, a1, ..., an] for the squeeze function
where the polynomial would be of the form a0 + a1*x + a2*x^2 and so
on. The order of the polynomial is determined by the length of the
list.

Example
-------
>>> import numpy as np
>>> from numpy.polynomial import Polynomial
>>> from diffpy.morph.morphs.morphsqueeze import MorphSqueeze

>>> x_target = np.linspace(0, 10, 101)
>>> y_target = np.sin(x_target)
>>> x_morph = np.linspace(0, 10, 101)
>>> squeeze_coeff = [0.1, -0.01, 0.005]
>>> poly = Polynomial(squeeze_coeff)
>>> y_morph = np.sin(x_morph + poly(x_morph))

>>> morph = MorphSqueeze()
>>> morph.squeeze = squeeze_coeff
>>> x_morph_out, y_morph_out, x_target_out, y_target_out = morph(
... x_morph, y_morph, x_target, y_target)
"""
"""Apply a polynomial to squeeze the morph function. The morphed
data is returned on the same grid as the unmorphed data."""

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

def morph(self, x_morph, y_morph, x_target, y_target):
"""Apply a polynomial to squeeze the morph function"""
"""Squeeze the morph function.

This applies a polynomial to squeeze the morph non-linearly.

Configuration Variables
-----------------------
squeeze : list
The polynomial coefficients [a0, a1, ..., an] for the squeeze
function where the polynomial would be of the form
a0 + a1*x + a2*x^2 and so on. The order of the polynomial is
determined by the length of the list.

Returns
-------
A tuple (x_morph_out, y_morph_out, x_target_out, y_target_out)
where the target values remain the same and the morph data
is shifted according to the squeeze. The morphed data is
returned on the same grid as the unmorphed data.

Example
-------
Import the squeeze morph function:
>>> from diffpy.morph.morphs.morphsqueeze import MorphSqueeze
Provide initial guess for squeezing coefficients:
>>> squeeze_coeff = [0.1, -0.01, 0.005]
Run the squeeze morph given input morph array (x_morph, y_morph)
and target array (x_target, y_target):
>>> morph = MorphSqueeze()
>>> morph.squeeze = squeeze_coeff
>>> x_morph_out, y_morph_out, x_target_out, y_target_out = morph(
... x_morph, y_morph, x_target, y_target)
To access parameters from the morph instance:
>>> x_morph_in = morph.x_morph_in
>>> y_morph_in = morph.y_morph_in
>>> x_target_in = morph.x_target_in
>>> y_target_in = morph.y_target_in
>>> squeeze_coeff_out = morph.squeeze
"""
Morph.morph(self, x_morph, y_morph, x_target, y_target)

return self.xyallout