diffpy.morph.morphs package

Definition of morphs.

Submodules

diffpy.morph.morphs.morphscale module

Class MorphScale – scale the morph data.

class diffpy.morph.morphs.morphscale.MorphScale(config=None)[source]

Bases: Morph

Scale the morph.

This scales the morph.

Configuration Variables

scale

The scale to apply to y_target_in.

rtype:

No return.

morph(x_morph, y_morph, x_target, y_target)[source]

Apply a scale factor.

parnames = ['scale']
summary = 'Scale morph by specified amount'
xinlabel = 'r (A)'
xoutlabel = 'r (A)'
yinlabel = 'G (1/A^2)'
youtlabel = 'G (1/A^2)'

diffpy.morph.morphs.morphshape module

Class MorphSphere – apply a spherical shape function to the morph class MorphSpheroid – apply a spheroidal shape function to the morph.

class diffpy.morph.morphs.morphshape.MorphSphere(config=None)[source]

Bases: Morph

Apply a spherical characteristic function to the morph.

Configuration Variables

radius

The radius of the sphere.

morph(x_morph, y_morph, x_target, y_target)[source]

Apply a scale factor.

parnames = ['radius']
summary = 'Apply spherical characteristic function to morph'
xinlabel = 'r (A)'
xoutlabel = 'r (A)'
yinlabel = 'G (1/A^2)'
youtlabel = 'G (1/A^2)'
class diffpy.morph.morphs.morphshape.MorphSpheroid(config=None)[source]

Bases: Morph

Apply a spherical characteristic function to the morph.

Configuration Variables

radius

The equatorial radius of the spheroid.

pradius

The polar radius of the spheroid.

morph(x_morph, y_morph, x_target, y_target)[source]

Apply a scale factor.

parnames = ['radius', 'pradius']
summary = 'Apply spheroidal characteristic function to morph'
xinlabel = 'r (A)'
xoutlabel = 'r (A)'
yinlabel = 'G (1/A^2)'
youtlabel = 'G (1/A^2)'

diffpy.morph.morphs.morphshift module

Class MorphShift – shift the morph.

class diffpy.morph.morphs.morphshift.MorphShift(config=None)[source]

Bases: Morph

Shift the morph.

Configuration Variables

vshift

The vertical shift to apply to the morph.

hshift

The horizontal shift to apply to the morph.

Note that a horizontal shift may cause edge effects, since the morph does not know what lies beyond the edge of the signals.

morph(x_morph, y_morph, x_target, y_target)[source]

Apply the shifts.

parnames = ['hshift', 'vshift']
summary = 'Shift morph by specified amount'
xinlabel = 'r (A)'
xoutlabel = 'r (A)'
yinlabel = 'G (1/A^2)'
youtlabel = 'G (1/A^2)'

diffpy.morph.morphs.morphfuncy module

Class MorphFuncy – apply a user-supplied python function to the y-axis.

class diffpy.morph.morphs.morphfuncy.MorphFuncy(config=None)[source]

Bases: Morph

Apply a custom function to the y-axis of the morph function.

General morph function that applies a user-supplied function to the y-coordinates of morph data to make it align with a target.

Configuration Variables

function: callable

The user-supplied function that applies a transformation to the y-coordinates of the data.

parameters: dict

A dictionary of parameters to pass to the function.

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

  • transformed according to the user-specified function and parameters

  • The morphed data is returned on the same grid as the unmorphed data

Example

Import the funcy morph function:

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

Define or import the user-supplied transformation function:

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

Provide initial guess for parameters:

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

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
>>> x_morph_out, y_morph_out, x_target_out, y_target_out =
... morph.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
>>> parameters_out = morph.funcy
morph(x_morph, y_morph, x_target, y_target)[source]

Apply the user-supplied Python function to the y-coordinates of the morph data.

parnames = ['function', 'funcy']
summary = 'Apply a Python function to the y-axis data'
xinlabel = 'r (A)'
xoutlabel = 'r (A)'
yinlabel = 'G (1/A^2)'
youtlabel = 'G (1/A^2)'

diffpy.morph.morphs.morphchain module

MorphChain – Chain of morphs executed in order.

class diffpy.morph.morphs.morphchain.MorphChain(config, *args)[source]

Bases: list

Class for chaining morphs together.

This class is a queue of morphs that get executed in order via the ‘morph’ method. This class derives from the built-in list, and list methods are used to modify the queue.

This derives from list and relies on its methods where possible.

Instance Attributes

config: dict

All configuration variables.

Properties

x_morph_in

Last morph input x data.

y_morph_in

Last morph input y data.

x_morph_out

Last morph result x data.

y_morph_out

Last morph result y data.

x_target_in

Last target input x data.

y_target_in

Last target input y data.

x_target_out

Last target result x data.

y_target_out

Last target result y data.

xy_morph_in

Tuple of (x_morph_in, y_morph_in) from first morph.

xy_morph_out

Tuple of (x_morph_out, y_morph_out) from last morph.

xy_target_in

Tuple of (x_target_in, y_target_in) from first morph.

xy_target_out

Tuple of (x_target_out, y_target_out) from last morph.

xyallout

Tuple of (x_morph_out, y_morph_out, x_target_out, y_target_out) from last morph.

parnames

Names of parameters collected from morphs (Read only).

Notes

The properties return tuples of None if there are no morphs.

morph(x_morph, y_morph, x_target, y_target)[source]

Apply the chain of morphs to the input data.

Parameters:
  • x_morph – Morphed arrays.

  • y_morph – Morphed arrays.

  • x_target – Target arrays.

  • y_target – Target arrays.

Returns:

A tuple of numpy arrays (x_morph_out, y_morph_out, x_target_out, y_target_out).

Return type:

tuple

Notes

Config may be altered by the morphs.

property parnames
property x_morph_in
property x_morph_out
property x_target_in
property x_target_out
property xy_morph_in
property xy_morph_out
property xy_target_in
property xy_target_out
property xyallout
property y_morph_in
property y_morph_out
property y_target_in
property y_target_out

diffpy.morph.morphs.morphresolution module

Class MorphResolutionDamping – apply resolution broadening to the morph.

class diffpy.morph.morphs.morphresolution.MorphResolutionDamping(config=None)[source]

Bases: Morph

Apply resolution damping and broadening to the morph.

Configuration Variables

qdamp

Peak dampening term.

Notes

See the PDFgui manual for how this is used.

morph(x_morph, y_morph, x_target, y_target)[source]

Apply a resolution damping.

parnames = ['qdamp']
summary = 'Apply resolution damping to the morph'
xinlabel = 'r (A)'
xoutlabel = 'r (A)'
yinlabel = 'R (1/A)'
youtlabel = 'R (1/A)'

diffpy.morph.morphs.morphstretch module

Class MorphStretch – stretch the morph.

class diffpy.morph.morphs.morphstretch.MorphStretch(config=None)[source]

Bases: Morph

Smear the morph function.

This stretches (broadens) the morph.

Configuration Variables

stretch

The stretch factor to apply to y_morph_in. This is applied such that a feature at r is moved to r * (1 + stretch).

morph(x_morph, y_morph, x_target, y_target)[source]

Resample arrays onto specified grid.

parnames = ['stretch']
summary = 'Stretch morph by desired amount'
xinlabel = 'r (A)'
xoutlabel = 'r (A)'
yinlabel = 'G (1/A^2)'
youtlabel = 'G (1/A^2)'

diffpy.morph.morphs.morph module

Morph – base class for defining a morph.

class diffpy.morph.morphs.morph.Morph(config=None)[source]

Bases: object

Base class for implementing a morph given a target.

Adapted from diffpy.pdfgetx to include two sets of arrays that get passed through.

Attributes are taken from config when not found locally. The morph may modify the config dictionary. This is the means by which to communicate automatically modified attributes.

Class Attributes

summary

Short description of a morph.

xinlabel

Descriptive label for the x input array.

yinlabel

Descriptive label for the y input array.

xoutlabel

Descriptive label for the x output array.

youtlabel

Descriptive label for the y output array.

parnames: list

Names of configuration variables.

Instance Attributes

config: dict

All configuration variables.

x_morph_in

Last morph input x data.

y_morph_in

Last morph input y data.

x_morph_out

Last morph result x data.

y_morph_out

Last morph result y data.

x_target_in

Last target input x data.

y_target_in

Last target input y data.

x_target_out

Last target result x data.

y_target_out

Last target result y data.

Properties

xy_morph_in

Tuple of (x_morph_in, y_morph_in).

xy_morph_out

Tuple of (x_morph_out, y_morph_out).

xy_target_in

Tuple of (x_target_in, y_target_in).

xy_target_out

Tuple of (x_target_out, y_target_out).

xyallout

Tuple of (x_morph_out, y_morph_out, x_target_out, y_target_out).

applyConfig(config)[source]

Process any configuration data from a dictionary.

Parameters:

config (dict) – Configuration dictionary.

Return type:

No return value.

checkConfig()[source]

Verify data in self.config. No action by default.

To be overridden in a derived class.

morph(x_morph, y_morph, x_target, y_target)[source]

Morph arrays morphed or target.

Identity operation. This method should be overloaded in a derived class.

Parameters:
  • x_morph – Morphed arrays.

  • y_morph – Morphed arrays.

  • x_target – Target arrays.

  • y_target – Target arrays.

Returns:

A tuple of numpy arrays (x_morph_out, y_morph_out, x_target_out, y_target_out)

Return type:

tuple

parnames = []
plotInputs(xylabels=True)[source]

Plot input arrays using matplotlib.pyplot.

Parameters:

xylabels – Flag for updating x and y axes labels.

Returns:

A list of matplotlib line objects.

Return type:

list

plotOutputs(xylabels=True, **plotargs)[source]

Plot output arrays using matplotlib.pyplot.

Parameters:
  • xylabels (bool) – Flag for updating x and y axes labels.

  • plotargs – Arguments passed to the pylab plot function. Note that “label” will be ignored.

Returns:

A list of matplotlib line objects.

Return type:

list

summary = 'identity transformation'
xinlabel = 'x'
xoutlabel = 'x'
property xy_morph_in

Return a tuple of morph input arrays

property xy_morph_out

Return a tuple of morph output arrays

property xy_target_in

Return a tuple of target input arrays

property xy_target_out

Return a tuple of target output arrays

property xyallout

Return a tuple of all output arrays

yinlabel = 'y'
youtlabel = 'y'

diffpy.morph.morphs.morphsqueeze module

Class MorphSqueeze – Apply a polynomial to squeeze the morph function.

class diffpy.morph.morphs.morphsqueeze.MorphSqueeze(config=None)[source]

Bases: Morph

Squeeze the morph function.

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

Configuration Variables

squeezeDictionary

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 dictionary.

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 = {"a0":0.1, "a1":-0.01, "a2":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
extrap_index_high = None
extrap_index_low = None
morph(x_morph, y_morph, x_target, y_target)[source]

Apply a polynomial to squeeze the morph function.

The morphed data is returned on the same grid as the unmorphed data.

parnames = ['squeeze']
summary = 'Squeeze morph by polynomial shift'
xinlabel = 'r (A)'
xoutlabel = 'r (A)'
yinlabel = 'G (1/A^2)'
youtlabel = 'G (1/A^2)'

diffpy.morph.morphs.morphrgrid module

Class MorphRGrid – put morph and target on desired grid.

class diffpy.morph.morphs.morphrgrid.MorphRGrid(config=None)[source]

Bases: Morph

Resample to specified r-grid.

This resamples both the morph and target arrays to be on the specified grid.

Configuration Variables

rmin

The lower-bound on the r-range.

rmax

The upper-bound on the r-range (exclusive within tolerance of 1e-8).

rstep

The r-spacing.

Notes

If any of these is not defined or outside the bounds of the input arrays, then it will be taken to be the most inclusive value from the input arrays. These modified values will be stored as the above attributes.

morph(x_morph, y_morph, x_target, y_target)[source]

Resample arrays onto specified grid.

parnames = ['rmin', 'rmax', 'rstep']
summary = 'Interplolate data onto specified grid'
xinlabel = 'r (A)'
xoutlabel = 'r (A)'
yinlabel = 'G (1/A^2)'
youtlabel = 'G (1/A^2)'

diffpy.morph.morphs.morphishape module

Class MorphISphere – apply inverse spherical shape function class MorphISpheroid – apply inverse spheroidal shape function.

class diffpy.morph.morphs.morphishape.MorphISphere(config=None)[source]

Bases: Morph

Apply inverse spherical characteristic function to the morph.

Configuration Variables

iradius

The radius of the sphere.

morph(x_morph, y_morph, x_target, y_target)[source]

Apply a scale factor.

parnames = ['iradius']
summary = 'Apply inverse spherical characteristic function to morph'
xinlabel = 'r (A)'
xoutlabel = 'r (A)'
yinlabel = 'G (1/A^2)'
youtlabel = 'G (1/A^2)'
class diffpy.morph.morphs.morphishape.MorphISpheroid(config=None)[source]

Bases: Morph

Apply inverse spherical characteristic function to the morph.

Configuration Variables

iradius

The equatorial radius of the spheroid.

ipradius

The polar radius of the spheroid.

morph(x_morph, y_morph, x_target, y_target)[source]

Apply a scale factor.

parnames = ['iradius', 'ipradius']
summary = 'Apply inverse spheroidal characteristic function to morph'
xinlabel = 'r (A)'
xoutlabel = 'r (A)'
yinlabel = 'G (1/A^2)'
youtlabel = 'G (1/A^2)'

diffpy.morph.morphs.morphsmear module

Class MorphSmear – smear the morph.

class diffpy.morph.morphs.morphsmear.MorphSmear(config=None)[source]

Bases: Morph

Smear the morph function.

This smears (broadens) the peaks of the morph. Note that this operates on the RDF. Inputs are not automatically converted to the RDF.

Configuration Variables

smear

The smear factor to apply to y_morph_in.

morph(x_morph, y_morph, x_target, y_target)[source]

Resample arrays onto specified grid.

parnames = ['smear']
summary = 'Smear morph by desired amount'
xinlabel = 'r (A)'
xoutlabel = 'r (A)'
yinlabel = 'R (1/A)'
youtlabel = 'R (1/A)'