diffpy.srmise.peaks package
Submodules
diffpy.srmise.peaks.gaussianoverr module
- class diffpy.srmise.peaks.gaussianoverr.GaussianOverR(maxwidth, Cache=None)[source]
Bases:
PeakFunction
Methods for evaluation and parameter estimation of width-limited Gaussian/r.
Allowed formats are internal: [position, parameterized width-squared, area] pwa: [position, full width at half maximum, area] mu_sigma_area: [mu, sigma, area]
The internal parameterization is unconstrained, but are interpreted so that the width is between 0 and a user-provided maximum full width at half maximum, and the area is positive.
Note that all full width at half maximum values are for the corresponding Gaussian.
- estimate_parameters(r, y)[source]
Estimate parameters for single peak from data provided.
- Parameters:
r (array-like) – Data along r from which to estimate
y (array-like) – Data along y from which to estimate
- Returns:
Numpy array of parameters in the default internal format. Raises SrMiseEstimationError if parameters cannot be estimated for any reason.
- Return type:
array-like
- max(pars)[source]
Return position and height of the peak maximum.
- Parameters:
pars (array_like) – The sequence of parameters defining the Gaussian shape.
- Returns:
The sequence of position and height of the peak maximum.
- Return type:
array-like
- scale_at(pars, x, scale)[source]
Change parameters so value(x)->scale*value(x).
Does not change position or height of peak’s maxima. Raises SrMiseScalingError if the parameters cannot be scaled.
- Parameters:
pars (array-like) – Parameters corresponding to a single peak
x (float) – Position of the border
scale (float) – Size of scaling at x. Must be positive.
- Returns:
The sequence of scaled parameters.
- Return type:
array-like
diffpy.srmise.peaks.terminationripples module
- class diffpy.srmise.peaks.terminationripples.TerminationRipples(base, qmax, extension=4.0, supersample=5.0, Cache=None)[source]
Bases:
PeakFunction
Methods for evaluation and parameter estimation of a peak function with termination ripples.
- cut_freq(sequence, delta)[source]
Remove high-frequency components from sequence.
This is equivalent to the discrete convolution of a signal with a sinc function sin(2*pi*r/qmax)/r.
- Parameters:
sequence (array-like) – The sequence to alter.
delta (int) – The spacing between elements in sequence.
- Returns:
The sequence with high-frequency components removed.
- Return type:
array-like
- estimate_parameters(r, y)[source]
Estimate parameters for single peak from data provided.
Uses estimation routine provided by base peak function.
- Parameters:
r (array-like) – Data along r from which to estimate
y (array-like) – Data along y from which to estimate
- Returns:
Numpy array of parameters in the default internal format. Raises SrMiseEstimationError if parameters cannot be estimated for any reason.
- Return type:
array-like
- extend_grid(r, dr)[source]
Return (extended r, slice giving original range).
- Parameters:
r (array-like or float) – The sequence or scalar over which peak is evaluated
dr (array-like or float) – The uncertainties over which peak is evaluated
- Returns:
The extended r, slice giving original range.
- Return type:
tuple
- jacobian(peak, r, rng=None)[source]
Calculate (rippled) jacobian, possibly restricted by range.
- Parameters:
peak (PeakFunction instance) – The Peak to be evaluated
r (array-like) – The sequence or scalar over which peak is evaluated
rng (slice object) – Optional slice object restricts which r-values are evaluated. The output has same length as r, but unevaluated objects have a default value of 0. If caching is enabled these may be previously calculated values instead. Default is None
- Returns:
jac – The Jacobian of base function with termination ripples.
- Return type:
array-like
- scale_at(pars, x, scale)[source]
Change parameters so value(x)->scale*value(x) for the base function.
Does not change position or height of peak’s maxima. Raises SrMiseScalingError if the parameters cannot be scaled.
- Parameters:
pars (array-like) – The parameters corresponding to a single peak
- xfloat
The position of the border
- scalefloat
The size of scaling at x. Must be positive.
- Returns:
The numpy array of scaled parameters.
- Return type:
array-like
- value(peak, r, rng=None)[source]
Calculate (rippled) value of peak, possibly restricted by range.
This function overrides its counterpart in PeakFunction in order to minimize the impact of edge-effects from introducing termination ripples into an existing peak function.
- Parameters:
peak (Peak instance) – The Peak to be evaluated
r (array-like) – The sequence or scalar over which peak is evaluated
rng (slice object) – Optional slice object restricts which r-values are evaluated. The output has same length as r, but unevaluated objects have a default value of 0. If caching is enabled these may be previously calculated values instead. Default is None.
- Returns:
output – The (rippled) value of peak, possibly restricted by range.
- Return type:
array-like
diffpy.srmise.peaks.base module
- class diffpy.srmise.peaks.base.Peak(owner, pars, free=None, removable=True, static_owner=False)[source]
Bases:
ModelPart
Represents a single peak associated with a PeakFunction subclass.
- static factory(peakstr, ownerlist)[source]
Instantiate a Peak from a string.
Parameters: peakstr: string representing peak ownerlist: List of BaseFunctions that owner is in
- scale_at(x, scale)[source]
Change parameters so value(x)->scale*value(x).
Does not change position or height of peak’s maxima. If parameters that are not free would be changed, or violates other constraints, the peak is not adjusted.
Parameters x: (float) Position of the border scale: (float > 0) Amount by which to scale.
Returns True if parameters were scaled, False otherwise.
- class diffpy.srmise.peaks.base.PeakFunction(parameterdict, parformats, default_formats, metadict, base=None, Cache=None)[source]
Bases:
BaseFunction
Base class for functions which represent peaks.
Class members
- parameterdict: A dictionary mapping string keys to their index in the
sequence of parameters. The “position” key is required, while all others are arbitrary. These keys apply only to the default “internal” format.
- parformats: A sequence of strings defining what formats are recognized
by a peak function.
- default_formats: A dictionary which maps the strings “default_input” and
“default_output” to strings also appearing in parformats. “default_input”-> format used internally within the class “default_output”-> Default format to use when converting
parameters for outside use.
Class methods (implemented by inheriting classes)
estimate_parameters() scale_at() _jacobianraw() (optional, but strongly recommended) _transform_derivativesraw() (optional, supports propagation of uncertainty for different paramaterizations) _transform_parametersraw() _valueraw()
Class methods
actualize()
Inherited methods
jacobian() value() transform_derivatives() transform_parameters()
- class diffpy.srmise.peaks.base.Peaks(*args, **kwds)[source]
Bases:
ModelParts
A collection for Peak objects.
- argsort(key='position')[source]
Return sequence of indices which sort peaks in order specified by key.
- match_at(x, y)[source]
Alter peaks so their sum at x is y, preserving each peak’s maximum.
Each peak is scaled equally. Peaks with fixed parameters, a maximum very close to x, or other issues may prevent optimal results. If the peaks cannot be scaled at all they are left unchanged.
Parameters: x: (float) Position at which to match. y: (float) Height to match.
Returns True if one or more peaks was scaled, False otherwise.
diffpy.srmise.peaks.gaussian module
- class diffpy.srmise.peaks.gaussian.Gaussian(maxwidth, Cache=None)[source]
Bases:
PeakFunction
Methods for evaluation and parameter estimation of width-limited Gaussian.
Allowed formats are internal: [position, parameterized width-squared, area] pwa: [position, full width at half maximum, area] mu_sigma_area: [mu, sigma, area]
The internal parameterization is unconstrained, but are interpreted so that the width is between 0 and a user-provided maximum full width at half maximum, and the area is positive.
Note that all full width at half maximum values are for the corresponding Gaussian.
- estimate_parameters(r, y)[source]
Estimate parameters for single peak from data provided.
- Parameters:
r (array-like) – The data along r from which to estimate
y (array-like) – The data along y from which to estimate
- Returns:
Numpy array of parameters in the default internal format. Raises SrMiseEstimationError if parameters cannot be estimated for any reason.
- Return type:
array-like
- max(pars)[source]
Return position and height of the peak maximum. :param pars: A sequence of parameters defining the Gaussian shape. :type pars: array_like
- Returns:
The position and height of the peak maximum.
- Return type:
array_like
- scale_at(pars, x, scale)[source]
Change parameters so value(x)->scale*value(x).
Does not change position or height of peak’s maxima. Raises SrMiseScalingError if the parameters cannot be scaled.
- Parameters:
pars (array-like) – The parameters corresponding to a single peak
x (float) – The position of the border
scale (float) – The size of scaling at x. Must be positive.
- Returns:
mu, area, and sigma that are scaled.
- Return type:
tuple