diffpy.srmise package
Peak extraction and peak fitting tool for atomic pair distribution functions.
Subpackages
Submodules
diffpy.srmise.multimodelselection module
- class diffpy.srmise.multimodelselection.MultimodelSelection[source]
Bases:
PeakStability
Quick and dirty multimodel selection using AIC and its offspring.
- animate_classprobs(step=False, duration=0.0, **kwds)[source]
Show animation of extracted peaks from first to last.
- Parameters:
step (bool) – Require keypress to show next plot, default is False.
duration (float) – Minimum time in seconds to complete animation. Default is 0.
pyplot.plot() (Keywords passed to)
- animate_probs(step=False, duration=0.0, **kwds)[source]
Show animation of extracted peaks from first to last.
- Parameters:
step (bool) – Require keypress to show next plot, default is False.
duration (float) – Minimum time in seconds to complete animation. Default is 0.
pyplot.plot() (Keywords passed to)
- bestclasses(dgs=None)[source]
Return the best classes for all models.
- Parameters:
dgs (array-like, optional) – The uncertainties of the models, by default None
- Returns:
The best classes for all models.
- Return type:
array-like
- bestmodels(dgs=None)[source]
Return the best models for all models.
- Parameters:
dgs (array-like, optional) – The uncertainties of the models, by default None
- Returns:
Sequence of best model
- Return type:
array-like
- classbestdgs(cls, dgs=None)[source]
Return the best uncertainties for the models.
- Parameters:
cls (ModelEvaluator Class) – Override corder with a specific class index, or None to ignore classes entirely.
dgs (array-like, optional) – The uncertainties of the models, by default None
- Returns:
Sequence of best uncertainties for the models.
- Return type:
array-like
- classify(r, tolerance=0.05)[source]
Find classes of models that are essentially the same.
Same is defined as having peaks and baselines which all match (to within the specified tolerance). This is calculated as the fraction of the difference between the squared values to the squared values of the peak (or baseline) itself. The method is agnostic about free and fixed parameters.
This will fail in the following cases: 1) The corresponding peaks are in the wrong order, even if just by a little 2) The exemplar (first model) of each class isn’t the best representative 3) The parameters vary so smoothly there aren’t actually definite classes
- Parameters:
r (array-like) – The r values over which to evaluate the models
tolerance (float) – The fraction below which models are considered the same
- Return type:
None
- dg_key(dg_in)[source]
Return the dg value usable as a key nearest to dg_in.
- Parameters:
dg_in (The uncertainties of the model)
- Returns:
The dg value usable as a key nearest to dg_in.
- Return type:
float
- get(dG, *args, **kwds)[source]
Return tuple of values corresponding to string arguments for best model of best class at given dG.
- Parameters:
dG (array-like) – The uncertainty used to calculate probabilities
arguments (Permissible)
value) (("dG" simply returns the provided dG)
Keywords
--------
default). (morder - Which model to get based on AIC. Ordered from best to worst from 0 (the)
default). – Returns a model from a class, or from the collection of all models if classes are ignored.
index (cls - Override corder with a specific class)
entirely. (or None to ignore classes)
- Returns:
The values corresponding to string arguments for best model of best class at given dG.
- Return type:
tuple
- get_aic(dG, **kwds)[source]
Return number of free parameters of best model of best class at given dG.
- Parameters:
dG (array-like) – The uncertainty used to calculate probabilities
Keywords
--------
default). (morder - Which model to get based on AIC. Ordered from best to worst from 0 (the)
default). – Returns a model from a class, or from the collection of all models if classes are ignored.
index (cls - Override corder with a specific class)
entirely. (or None to ignore classes)
- Returns:
Number of free parameters of best model of best class at given dG.
- Return type:
int
- get_class(dG, **kwds)[source]
Return index of best class at given dG.
- Parameters:
dG (array-like) – The uncertainty used to calculate probabilities
Keywords
--------
default). (corder - Which class to get based on AIC. Ordered from best to worst from 0 (the)
- Returns:
Index of best model of best class at given dG.
- Return type:
int
- get_model(dG, **kwds)[source]
Return index of best model of best class at given dG.
- Parameters:
dG (array-like) – The uncertainty used to calculate probabilities
Keywords
--------
default). (morder - Which model to get based on AIC. Ordered from best to worst from 0 (the)
default). – Returns a model from a class, or from the collection of all models if classes are ignored.
index (cls - Override corder with a specific class)
entirely. (or None to ignore classes)
- Returns:
Index of best model of best class at given dG.
- Return type:
int
- get_nfree(dG, **kwds)[source]
Return number of free parameters of best model of best class at given dG.
- Parameters:
dG (array-like) – The uncertainty used to calculate probabilities
Keywords
--------
default). (morder - Which model to get based on AIC. Ordered from best to worst from 0 (the)
default). – Returns a model from a class, or from the collection of all models if classes are ignored.
index (cls - Override corder with a specific class)
entirely. (or None to ignore classes)
- Returns:
Number of free parameters of best model of best class at given dG.
- Return type:
int
- get_prob(dG, **kwds)[source]
Return Akaike probability of best model of best class at given dG.
- Parameters:
dG (array-like) – The uncertainty used to calculate probabilities
Keywords
--------
default). (morder - Which model to get based on AIC. Ordered from best to worst from 0 (the)
default). – Returns a model from a class, or from the collection of all models if classes are ignored.
index (cls - Override corder with a specific class)
entirely. (or None to ignore classes)
- Returns:
The sequence of Akaike probability of best model of best class at given dG.
- Return type:
array-like
- loadaics(filename)[source]
Load file containing results of the testall method.
- Parameters:
filename (str) – Filename to load.
- Return type:
None
- makeaics(dgs, dr, filename=None)[source]
Test quality of each model for all possible uncertainties.
- Parameters:
dgs (array-like) – The array of uncertainties over which to test each model.
dr (float) – The sampling rate to use. This determines the actual data to use for testing, since sometimes the actual result is different than the nominal value.
filename (str) – Optional file to save pickled results
- Return type:
None
- maxprobdG_byclass(model)[source]
Return the post-hoc dG for which the given model’s Akaike probability is maximized.
Each model is mapped to its class’ best member.
- Parameters:
model (array-like) – The model to get the post-hoc dG.
- Returns:
The post-hoc dG for the given model where the given model’s Akaike probability is maximized.
- Return type:
array-like
- maxprobdG_bymodel(model)[source]
Return the post-hoc dG for which the given model’s Akaike probability is maximized. Classes are not considered.
- Parameters:
model (array-like) – The model to get the post-hoc dG.
- Returns:
The post-hoc dG by the given model’s Akaike probability is maximize
- Return type:
array-like
- maxprobmodel_byclass(dG)[source]
Calculate the model which maximizes probability at given dG.
The best class is mapped to its best model.
- Parameters:
dG (array-like) – The uncertainty used to calculate probabilities
- Returns:
The model mapped by class which maximizes probability at given dG.
- Return type:
float
- maxprobmodel_bymodel(dG)[source]
Return the model which maximizes probability at given dG. Classes are not considered.
- Parameters:
dG (array-like) – The uncertainty used to calculate probabilities
- Returns:
model – The model which maximizes probability at given dG.
- Return type:
array-like
- modelbestdgs(model, dgs=None)[source]
Return uncertainties where given model has greatest Akaike probability.
- Parameters:
model (ModelEvaluator Class) – The model evaluator class to use
dgs (array-like, optional) – The uncertainties of the models, by default None
- Returns:
The uncertainties where given model has greatest Akaike probability
- Return type:
array-like
- plot3dclassprobs(**kwds)[source]
Return 3D plot of class probabilities.
Keywords
dGs - Sequence of dG values to plot. Default is all values. highlight - Sequence of dG values to highlight on plot. Default is []. classes - Sequence of indices of classes to plot. Default is all classes. probfilter - [float1, float2]. Only show classes with maximum probability in given range.
Default is [0., 1.]
class_size - Report the size of each class as a “number” or “fraction”. Default is “number”. norm - A colors normalization for displaying number/fraction of models in class. Default is “auto”.
If equal to “full” determined by the total number of models. If equal to “auto” determined by the number of models in displayed classes.
- cmap - A colormap or registered colormap name. Default is cm.jet.
If class_size is “number” and norm is either “auto” or “full” the map is converted to an indexed colormap.
highlight_cmap - A colormap or registered colormap name for coloring highlights. Default is cm.gray. title - True, False, or a string. Defaults to True, which displays some basic information about the graph. p_alpha - Probability graph alpha. (Colorbar remains opaque). Default is 0.7. figure - A matplotlib.figure.Figure instance. Default is the current figure. subplot - Specify a subplot. Default is 111. cbpos - Explicit position for colorbar given as (l,b,w,h) in axes coordinates.
Does not resize other elements. Note that this overrides all colorbar keywords except orientation.
scale - Scales the dG shown on the graph.
All other keywords are passed to the colorbar.
- returns:
a dictionary containing the following figure elements
“fig” - The figure
“axis” - The image axis
“cbaxis” - The colorbar axis, if it exists.
“cb” - The colorbar, if it exists.
diffpy.srmise.srmiselog module
Controls the logging and plotting options of diffpy.srmise.
By default messages are logged to stdout, but logging to a file is also supported. SrMiseLog defines five levels of message importance, and all messages at least as important as the set level are displayed and/or written to the appropriate file. Levels are specified as non-negative integers or equivalent strings, and are identical to those found in the Python logging package.
‘debug’ -> 10 ‘info’ -> 20 (default) ‘warning’ -> 30 ‘error’ -> 40 ‘critical’ -> 50
Liveplotting plots the value of a model each time it is fit, showing results for before and after fitting. User input is optionally required to procede after fitting.
Functions
addfilelog: Send logging information to a file. liveplotting: Set whether to use liveplotting, and whether to wait after each liveplot setfilelevel: Set logging level for the file logger. setlevel: Set logging level of default logger. gettracer: Get a TracePeaks instance for tracing peak extraction.
- class diffpy.srmise.srmiselog.TracePeaks(**kwds)[source]
Bases:
object
Output trace information during peak extraction.
- emit(*args, **kwds)[source]
Write current trace to file.
Parameters Any number of ModelCluster instances
- property filter
- maketrace(*args, **kwds)[source]
Return dictionary of trace properties.
Keywords model - Use specified model (Peaks instance) instead of those in args.
- read(filename)[source]
Read tracer ModelCluster from file.
Parameters filename - file from which to read
Returns dictionary with keys “clusters” - List of cluster regions [[r0,r1],[r2,r3],…] “counter” - The count when object was created “mc” - A ModelCluster instance “recursion” - The recursion level of mc
- readstr(datastring)[source]
Read tracer ModelCluster from string.
Parameters datastring - The string representation of a trace
Returns dictionary with keys “clusters” - List of cluster regions [[r0,r1],[r2,r3],…] “counter” - The count when object was created “mc” - A ModelCluster instance “recursion” - The recursion level of mc
- diffpy.srmise.srmiselog.addfilelog(filename, level=20, format='%(message)s')[source]
Log output from diffpy.srmise in specified file.
Parameters filename: Name of file to receiving output level: The logging level format: A string defining format of output messages conforming to logging package.
- diffpy.srmise.srmiselog.liveplotting(lp, w=False)[source]
Set whether or not to use live plotting.
When using liveplotting, a plot will be shown and updated as extraction progresses.
Parameters lp: Use live plotting (True) or not (False). w: (False) Whether to wait for user after plotting.
- diffpy.srmise.srmiselog.setfilelevel(level)[source]
Set level of file logger.
Parameters level: The logging level.
diffpy.srmise.modelparts module
Module for representing instances of mathematical functions.
Classes
ModelPart: Superclass of Peak and Baseline ModelParts: Collection (list) of ModelPart instances.
- class diffpy.srmise.modelparts.ModelPart(owner, pars, free=None, removable=True, static_owner=False)[source]
Bases:
object
Represents a single part (instance of some function) of a model.
- pars
The array containing the parameters of this model part
- Type:
array-like
- free
The array containing boolean values defining whether the corresponding parameter is free or not.
- Type:
array-like
- removable
The boolean determining whether or not this model part can be removed during extraction.
- Type:
bool
- static_owner
The boolean determines if owner can be changed with changeowner()
- Type:
bool
- getfree(index=None, keyword=None)[source]
Retrieve a free parameter by index or keyword defined by the owner.
- setfree(index=None, value=None, keyword=None, new_value=None)[source]
Set a free parameter by index or keyword defined by the owner.
- changeowner(owner)[source]
Change the owner of this part.
Does not change the parameters associated with this model part. Raises SrMiseStaticOwnerError if this peak has been declared to have a static owner, or if the number of parameters is incompatible.
- Parameters:
owner (BaseFunction subclass) – The instance of a BaseFunction subclass
- Return type:
None
- compress()[source]
Return part parameters with non-free values removed.
- Returns:
pars – The compressed parameters of the model part.
- Return type:
array-like
- copy()[source]
Return a deep copy of this ModelPart.
The original and the copy are completely independent, except they both reference the same owner.
- Returns:
A deep copy of this ModelPart.
- Return type:
- getfree(key_or_idx)[source]
Return value of free corresponding with key_or_idx.
- Parameters:
key_or_idx (Optional[int, slice object, key]) – The integer index, slice, or key from owner’s parameter dictionary.
- Returns:
freepars – The value of the free corresponding to key_or_idx.
- Return type:
array-like
- jacobian(r, range=None)[source]
Return jacobian of this part over r.
- Parameters:
r (array-like) – The input domain
range (slice object) – The slice object specifying region of r and y over which to fit. All the data by default.
- Returns:
jacobian – The jacobian of the model part.
- Return type:
array-like
- npars(count_fixed=True)[source]
Return total number of parameters in all parts.
- Parameters:
count_fixed (bool) – The boolean which determines if fixed parameters are included in the count.
- Returns:
The number of parameters in all parts.
- Return type:
int
- owner()[source]
Return the BaseFunction subclass instance which owns this part.
- Returns:
The BaseFunction subclass which owns this part.
- Return type:
BaseFunction subclass
- setfree(key_or_idx, value)[source]
Set value of free corresponding with key_or_idx.
- Parameters:
key_or_idx (Optional[int, slice object, key]) – The integer index, slice, or key from owner’s parameter dictionary.
value (bool) – The boolean to set in free corresponding to key_or_idx.
- Return type:
None
- update(freepars)[source]
Sequentially update free parameters from freepars.
- Parameters:
freepars (array-like) – The sequence of new parameter values. May contain more parameters than can actually be updated.
- Returns:
number of parameters updated from freepars.
- Return type:
numfree
- class diffpy.srmise.modelparts.ModelParts(*args, **kwds)[source]
Bases:
list
A collection of ModelPart instances.
- copy: Return deep copy
- fit: Fit to given data
- npars: Return total number of parameters
- pack_freepars: Update free parameters with values in given sequence
- residual: Return residual of model
- residual_jacobian: Return jacobian of residual of model
- transform: Change format of parameters.
- value: Return value of model
- unpack_freepars: Return sequence containing value of all free parameters
- copy()[source]
Return deep copy of this ModelParts.
The original and the copy are completely independent, except each ModelPart and its copy still reference the same owner.
- Returns:
The deep copy of this ModelParts.
- Return type:
- covariance(format='internal', **kwds)[source]
Return estimated covariance matrix of the model.
The covariance matrix may be given in terms of any parameterization defined by the formats for each individual ModelPart.
- Parameters:
format (str) – The format (“internal” by default) to use for all ModelParts. This may be overridden for specific peaks as shown below.
Keywords
--------
f0 (str) – The format of the 0th ModelPart
f1 (str) – The format of the 1st ModelPart
etc.
- Returns:
cov – The estimated covariance matrix.
- Return type:
ndarray
- fit(r, y, y_error, range=None, ntrials=0, cov=None, cov_format='default_output')[source]
Chi-square fit of all free parameters to given data.
There must be at least as many free parameters as data points. Fitting is performed with the MINPACK leastsq() routine exposed by scipy.
- Parameters:
r (array-like) – The sequence of r values over which to fit
y (array-like) – The sequence of y values over which to fit
y_error (array-like) – The sequence of uncertainties in y
range (slice object) – The slice object specifying region of r and y over which to fit. Fits over all the data by default.
ntrials (int) – The maximum number of function evaluations while fitting.
cov (ModelCovariance instance) – The Optional ModelCovariance object preserves covariance information.
cov_format (str) – The parameterization to use in cov.
- Return type:
None
- npars(count_fixed=True)[source]
Return total number of parameters in all parts.
- Parameters:
count_fixed (bool) – The boolean which determines if fixed parameters are included in the count.
- Returns:
n – The total number of parameters.
- Return type:
int
- pack_freepars(freepars)[source]
Update parameters with values from sequence of freepars.
- Parameters:
freepars (array-like) – The sequence of free parameters.
- Return type:
None
- residual(freepars, r, y_expected, y_error, range=None)[source]
Calculate residual of all parameters.
- Parameters:
freepars (array-like) – The sequence of free parameters
r (array-like) – The input domain
y_expected (array-like) – The sequence of expected values
y_error (array-like) – The sequence of uncertainties in y-variable
range (slice object) – The slice object specifying region of r and y over which to fit. All the data by default.
- Returns:
The residual of all parameters.
- Return type:
array-like
- residual_jacobian(freepars, r, y_expected, y_error, range=None)[source]
Calculate the Jacobian of freepars.
Parameters freepars : array-like
The sequence of free parameters
- rarray-like
The input domain
- y_expectedarray-like
The sequence of expected values
- y_errorarray-like
The sequence of uncertainties in y-variable
- rangeslice object
The slice object specifying region of r and y over which to fit. All the data by default.
- Returns:
The Jacobian of all parameters.
- Return type:
ndarray
- transform(in_format='internal', out_format='internal')[source]
Transforms format of parameters in this modelpart.
Parameters in_format : str
The format the parameters are already in.
- out_formatstr
The format the parameters are transformed to.
- value(r, range=None)[source]
Calculate total value of all parts over range.
- Parameters:
r (array-like) – The input domain
range (slice object) – The slice object specifying region of r and y over which to fit. All the data by default.
- Returns:
total – The total value of all slice region of r.
- Return type:
float
diffpy.srmise.peakstability module
- class diffpy.srmise.peakstability.PeakStability[source]
Bases:
object
Utility to test robustness of peaks.
results: [error scalar, model, bl, dr] ppe: a PDFPeakExtraction instance
- animate(results=None, step=False, **kwds)[source]
Show animation of extracted peaks from first to last.
Keywords passed to pyplot.plot()
- Parameters:
step (bool) – Require keypress to show next plot
array-like (results) – The indices of results to show
- run(err, savecovs=False)[source]
Running the uncertainty for the results.
- Parameters:
err (array-like) – The sequence of uncertainties to run at.
savecovs (bool) – boolean to determine to save covariance matrix. Default is False. If savecovs is True, return the covariance matrix for each final fit.
diffpy.srmise.basefunction module
Defines BaseFunction, the base class for mathematical functions in srmise.
- class diffpy.srmise.basefunction.BaseFunction(parameterdict, parformats, default_formats, metadict, base=None, Cache=None)[source]
Bases:
object
Base class for mathematical functions which model numeric sequences.
- parameterdict
The dictionary mapping string keys to their index in the sequence of parameters. These keys apply only to the default “internal” format.
- Type:
dict
- parformats
The sequence of strings defining what formats are recognized by a function.
- Type:
array-like
- default_formats
The 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.
- Type:
dict
- metadict
The Dictionary mapping string keys to tuple (v, m) where v is an additional argument required by function, and m is a method whose string output recreates v when passed to eval().
- Type:
dict
- base
The basefunction subclass instance which this one decorates with additional functionality.
- Type:
BaseFunction subclass
- Class methods (implemented by inheriting classes)
- -------------------------------------------------
- _transform_derivatives() (optional, supports propagation of uncertainty for different paramaterizations)
- Class methods
- -------------
- actualize(*args, **kwds)[source]
Create ModelPart instance of self with given parameters. (“Virtual” method)
- estimate_parameters(*args, **kwds)[source]
Estimate BaseFunction parameters from supplied data. (“Virtual” method)
- static factory(functionstr, baselist)[source]
Instantiate a BaseFunction (or any subclass) from a string.
References to other BaseFunction instances in functionstr use the corresponding index of that instance in baselist.
- Parameters:
functionstr (str) – The string representation of the BaseFunction instance
baselist (array-like) – The list of BaseFunction (or subclass) instances.
Returns
instance (Basefunction) – The BaseFunction instance based on the parameter strings
- jacobian(p, r, rng=None)[source]
Calculate jacobian of p, possibly restricted by range.
- Parameters:
p (ModelPart instance) – The ModelPart to be evaluated
:array-like (r) – sequence or scalar over which function 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.
- pgradient(p, format)[source]
Return gradient matrix of parameterization in specified format wrt “internal” format at p.
Consider the “internal” parameterization given by (i0, i1, …, in). Each parameter in a different format, say (o0, o1, …, om), is a function of the internal parameters.
The gradient matrix is [[do0/di0 do0/di1 … do0/din]
[do1/di0 do1/di1 … do1/din] … [dom/di0 dom/di1 … dom/din]]
In the trivial case where format=”internal”, returns an identity matrix.
- Parameters:
p (ModelPart instance) – The ModelPart instance to be evaluated for gradient calculation.
format (str) – The format of the parameters
- Returns:
A 2D array containing the partial derivatives.
- Return type:
array-like
- static safefunction(f, fsafe)[source]
Append BaseFunction instance f to fsafe, but adding dependent functions first.
Does not handle circular dependencies.
- Parameters:
f (BaseFunction instance) – The BaseFunction instance
fsafe (array-like) – The list of BaseFunction instances being built.
- Return type:
None
- static safefunctionlist(fs)[source]
Return list of BaseFunction instances where any dependencies occur earlier in list.
Any functions with hidden dependent functions (i.e. those not in fs) are included in the returned list. This list provides an order that is guaranteed to be safe for saving/reinstantiating peak functions.
Parameters fs: List of BaseFunction instances.
- transform_derivatives(pars, in_format=None, out_format=None)[source]
Return gradient matrix for pars converted from in_format to out_format.
- Parameters:
pars (array-like) – The sequence of parameters
in_format (str) – The format defined for this class
out_format (str) – The format defined for this class
- Returns:
The gradient matrix for pars converted from in_format to out_format.
- Return type:
array-like
- transform_parameters(pars, in_format=None, out_format=None)[source]
Return new sequence with pars converted from in_format to out_format.
Also restores parameters to a preferred range if it permits multiple values that correspond to the same physical result.
- Parameters:
pars (array-like) – The sequence of parameters
str (in_format :) – The format defined for this class
out_format (str) – The format defined for this class
- Returns:
The new sequence of parameters with out_format.
- Return type:
array-like
- value(p, r, rng=None)[source]
Calculate value of ModelPart over r, possibly restricted by range.
- Parameters:
p (ModelPart instance) – The ModelPart to be evaluated
r (array-like or float) – The sequence or scalar over which function 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.
- Returns:
The value of ModelPart over r, possibly restricted by range.
- Return type:
array-like
diffpy.srmise.pdfpeakextraction module
- class diffpy.srmise.pdfpeakextraction.PDFPeakExtraction[source]
Bases:
PeakExtraction
PDFPeakExtraction extends the PeakExtraction class to specialize in extracting peaks from PDF (Probability Density Function) data.
- Parameters:
filename (str) – The source PDF file path.
nyquist (bool, optional) – Specifies whether to fit the final model at the Nyquist sampling rate. Defaults to False.
qmax (float, optional) – The maximum q value to use during peak extraction. Use 0 to denote infinity. Defaults to 0.
qmax_reportedbypdf (float) – The qmax value read directly from the PDF file.
qmax_fromdata (float) – The qmax value determined directly from the PDF data.
scale (bool, optional) – Determines whether to use increased uncertainties during supersampling. This can expedite extraction by minimizing the detection of minuscule peaks, albeit risking the overlook of minor features. When Nyquist is True, uncertainties are scaled to maintain a similar chi-square error pre- and post-resampling. Defaults to False if Nyquist is True.
supersample (int, optional) – Ensures the data is supersampled by at least this factor above the Nyquist rate before initiating peak extraction. Defaults to 1.
- clear()[source]
Clear all members.
The purpose of the method is to ensure the object is in a clean state.
- defaultvars(*args)[source]
Set default values.
- Parameters:
*args (argparse.Namespace) – Arguments passed to PeakExtraction.setdata().
- errorscale(dr)[source]
Return proper scale of uncertainties.
Always returns 1 unless qmax > 0, Nyquist sampling is enabled, and scale is True.
- Parameters:
dr (float) – The sampling interval
- Returns:
The uncertainties scaled.
- Return type:
float
- extract(**kwds)[source]
Extract peaks from the PDF. Returns ModelCovariance instance summarizing results.
- Parameters:
**kwds (dict) – Additional keyword arguments that might influence the extraction process. These could include parameters like qmax, supersample, nyquist, etc., which affect resampling and model refinement strategies.
- Returns:
An instance of ModelCovariance summarizing the covariance of the extracted model parameters.
- Return type:
- fit(**kwds)[source]
Fit peaks in the PDF. Returns ModelCovariance instance summarizing results.
- Parameters:
**kwds (dict) – Keyword arguments passed to ModelCovariance instance. Different keywords could have different strategies to fit. See ModelCovariance class for more information.
- Returns:
The fitted ModelCovariance instance.
- Return type:
ModelCovariance instance
- loadpdf(pdf)[source]
Load dataset.
- Parameters:
pdf (PDFDataSet instance or str) – The PDFDataSet instance or a PDF file name.
- readmetadata(metastr)[source]
Read metadata from string.
- Parameters:
metastr (str) – Metadata string to read.
- Return type:
None
- resampledata(dr, **kwds)[source]
Return (x, y, error in x, effective error in y) resampled by interval dr.
Uses values of self.x, self.y, self.dx, self.effective_dy. The range is constrained by self.rng.
The effective error may be scaled if class member scale is True.
The method for ‘resampling’ the uncertainties is interpolation, since insufficient information exists in a PDFPeakExtraction object to propogate them correctly on the new grid.
- Parameters:
dr (float) – The sampling interval for resampling the data.
**kwds (dict, optional) –
Additional keyword arguments.
- epsfloat, default=1e-6
Suppresses the information lost warning when the difference between dr and the Nyquist interval dr_nyquist is less than eps.
- Returns:
A tuple containing the resampled (x, y, error in x, effective error in y).
- Return type:
tuple of ndarray
- setdata(x, y, dx=None, dy=None)[source]
Set data.
- Parameters:
x (array-like) – The x-coordinates of the data.
y (array-like) – The y-coordinates of the data.
- setvars(quiet=False, **kwds)[source]
Set one or more extraction variables.
- Parameters:
quiet (bool, optional) – Log changes quietly. Default is False.
**kwds (keyword arguments) – Additional variables to set. Possible keywords include:
cres (-) – The clustering resolution, must be greater than or equal to 0.
effective_dy (-) – The uncertainties actually used during extraction. Aliased as ‘dg’.
pf (-) – Sequence of peak function base subclass instances.
baseline (-) – Baseline instance or BaselineFunction instance for built-in estimation.
error_method (-) – Error evaluator subclass instance used to compare models. Default is AIC.
initial_peaks (-) – Peaks instance representing the peaks present at the start of extraction.
rng (-) – Specifies the least and greatest x-values over which to extract peaks.
qmax (-) – The qmax value for the probability density function (pdf). If set to “automatic”, it will be estimated from the data.
nyquist (-) – Whether to use nyquist sampling or not.
supersample (-) – Degree of supersampling above the Nyquist rate to use.
scale (-) – Scale uncertainties on recursion when nyquist is True.
- diffpy.srmise.pdfpeakextraction.find_qmax(r, y, showgraphs=False)[source]
Determine approximate qmax from PDF.
- Parameters:
r (array-like) – The r values of the PDF.
y (array-like) – The corresponding y values of the PDF.
showgraphs (bool) – If True, the graphs are shown.
- Returns:
The qmax of the PDF and its corresponding uncertainties.
- Return type:
tuple
- diffpy.srmise.pdfpeakextraction.resample(orig_r, orig_y, new_r)[source]
Resample sequence with Whittaker-Shannon interpolation formula.
- Parameters:
orig_r (array-like) – The r grid of the original sample.
orig_y (array-like) – The data to resample.
new_r (array-like) – The resampled r grid.
- Returns:
new_y – The sequence of same type as new_r with the resampled values.
- Return type:
array-like
- diffpy.srmise.pdfpeakextraction.stdratio(data)[source]
Calculate ratio of standard deviation for runs of equal length in data.
Uses a numerically-stable online algorithm for calculating the standard deviation.
- Parameters:
data (array-like) – The sequence of data values
- Returns:
an array of length floor(len(data)/2)-1. The ith element is equivalent to std(data[:i+2])/std(data[i+2:2i+4]).
- Return type:
array-like
diffpy.srmise.modelcluster module
Defines ModelCluster class.
Classes
ModelCluster: Associate a region of data to a model that describes it. ModelCovariance: Helper class for model covariance.
- class diffpy.srmise.modelcluster.ModelCluster(model, *args, **kwds)[source]
Bases:
object
Associate a contiguous cluster of data with an appropriate model.
A ModelCluster instance is the basic unit of diffpy.srmise, combining data and a model with the basic tools for controlling their interaction.
- addexternalpeaks: Add peaks to model, and their value to the data.
- augment: Add peaks to model, only keeping those which improve model quality.
- change_slice: Change the range of the data considered within cluster.
- cleanfit: Remove extremely poor or non-contributing peaks from model.
- contingent_fit: Fit model to data if size of cluster has significantly increased
since previous fit.
- factory: Static method to recreate a ModelCluster from a string.
- join_adjacent: Static method to combine two ModelClusters.
- npars: Return total number of parameters in model.
- replacepeaks: Add and/or delete peaks in model
- deletepeak: Delete a single peak in model.
- estimatepeak: Add single peak to model with no peaks.
- fit: Fit the model to the data
- plottable: Return list of arguments for convenient plotting with matplotlib
- plottable_residual: Return list of argument for convenient plotting of residual
with matplotlib.
- prune: Remove peaks from model which maximize quality.
- reduce_to: If value(x)>y, change model to so that value(x)=y
- quality: Return ModelEvaluator instance that calculates quality of model to data.
- value: Return value of the model plus baseline
- valuebl: Return value of the baseline
- writestr: Return string representation of self.
- addexternalpeaks(peaks)[source]
Add peaks (and their value) to self.
- Parameters:
peaks (A Peaks object) – The peaks to be added
- Return type:
None
- augment(source)[source]
Add peaks from another ModelCluster that improve this one’s quality.
- Parameters:
source (ModelCluster instance) – The ModelCluster instance to augment the model’s quality.
- Return type:
None
- change_slice(new_slice)[source]
Change the slice which represents the extent of a cluster.
- Parameters:
new_slice (slice object) – The new slice to change.
- Return type:
None
- contingent_fit(minpoints, growth_threshold)[source]
Fit cluster if it has grown sufficiently large since its last fit.
- Parameters:
minpoints (int) – The minimum number of points an empty cluster requires to fit.
growth_threshold (float) – Fit non-empty model if (currentsize/oldsize) >= this value.
- Returns:
Return ModelEvaluator instance if fit changed, otherwise None.
- Return type:
ModelEvaluator or None
- deletepeak(idx)[source]
Delete the peak at the given index.
- Parameters:
idx (int) – Index of peak to delete.
- Return type:
None
- estimatepeak()[source]
Attempt to add single peak to empty cluster. Return True if successful.
- Returns:
True if successful, False otherwise.
- Return type:
bool
- static factory(mcstr, **kwds)[source]
Create ModelCluster from string.
Keywords
pfbaselist : List of peak function bases blfbaselist : List of baseline function bases
- fit(justify=False, ntrials=0, fitbaseline=False, estimate=True, cov=None, cov_format='default_output')[source]
Perform a chi-square fit of the model to data in cluster.
- Parameters:
justify (bool) – Revert to initial model (if one exists) if new model has only a single peak and the quality of the fit suggests additional peaks are present. Default is False.
ntrials (int) – The maximum number of function evaluations. ‘0’ indicates the fitting algorithm’s default.
fitbaseline (bool) – Whether to fit baseline along with peaks. Default is False.
estimate (bool) – Estimate a single peak from data if model is empty. Default is True.
cov (ModelCovariance or None) – Optional ModelCovariance object preserves covariance information.
cov_format (str) – Parameterization to use in cov.
- Returns:
ModelEvaluator or None
If fitting changes a model, return ModelEvaluator instance. Otherwise
return None.
- static join_adjacent(m1, m2)[source]
Create new ModelCluster from two adjacent ones.
Suspected duplicate peaks are removed, and peaks may be adjusted if their sum where the clusters meet exceeds the data. m1 and m2 are unchanged.
- Parameters:
m1 (ModelCluster instance) – The first ModelCluster instance.
m2 (ModelCluster instance) – The second ModelCluster instance.
- Returns:
The new ModelCluster instance between m1 and m2.
- Return type:
ModelCluster instance
- npars(count_baseline=True, count_fixed=True)[source]
Return number of parameters in model and baseline.
- Parameters:
count_baseline (bool) – The boolean determines whether to count parameters from baseline. Default is True.
count_fixed (bool)
True. (The boolean determines whether to include non-free parameters. Default is)
- Returns:
n – The number of parameters in model and baseline.
- Return type:
int
- plottable(joined=False)[source]
Return sequence suitable for plotting cluster model+baseline with matplotlib.
- Parameters:
joined (bool) – Return sum of all peaks if joined is True, or each one individually if False.
- Returns:
A sequence of plottable objects.
- Return type:
array-like
- plottable_residual()[source]
Return sequence suitable for plotting cluster residual with matplotlib.
- Returns:
A sequence of plottable clusters and residuals.
- Return type:
array-like
- prune()[source]
Remove peaks until model quality no longer improves.
Peaks are removed in a greedy fashion, and the best possible model is by no means guaranteed.
Due to the somewhat exploratory nature of prune many non-convergent fits will generally be performed, but it severely restricts the number of function evaluations permitted during fitting, and so fits that do not converge rapidly are abandoned. Nevertheless, occasionally this method will take an unusually long time to complete.
- quality(evaluator=None, **kwds)[source]
Return ModelEvaluator instance containing calculated quality of the model.
ModelEvaluator objects may be compared as though they were numerical quantities. Its raw value is given by the ‘stat’ member. For more details see ModelEvaluator documentation.
- Parameters:
evaluator (ModelEvaluator class or None) – The ModelEvaluator class to use. Default is None.
Keywords
--------
method. (kwds - Keyword arguments passed the the ModelEvaluator's evaluate())
- Returns:
The ModelEvaluator instance with quality calculated
- Return type:
ModelEvaluator instance
- reduce_to(x, y)[source]
Reduce model(x)>y to model(x)=y if hidden peaks are unlikely.
This serves as an initial parameter estimate more likely to match with peaks on the other side of x. Peaks with fixed parameters or a maximum very close to x may prevent optimal results.
- Parameters:
x (array-like) – The position at which to match
y (array-like) – The height to match.
- Returns:
Return ModelEvaluator instance if fit changed, otherwise None.
- Return type:
ModelEvaluator or None
- replacepeaks(newpeaks, delslice=slice(0, 0, None))[source]
Replace peaks given by delslice by those in newpeaks.
- Parameters:
newpeaks (Peak instance) – The peak that id added to each existing peak to cluster.
delslice (Peak instance) – The existing peaks given by slice object are deleted.
- Return type:
None
- value(r=None)[source]
Return value of baseline+model over cluster.
- Parameters:
r (array-like, optional) – value(s) over which to calculate the baseline’s value. The default is over the entire cluster.
- Returns:
The value of baseline+model over cluster.
- Return type:
float
- class diffpy.srmise.modelcluster.ModelCovariance(*args, **kwds)[source]
Bases:
object
Helper class preserves uncertainty info (full covariance matrix) for a fit model.
This object preserves a light-weight “frozen” version of a model which can be used to interrogate the model about the uncertainties of its parameters.
Note that all parameters defined by a model, including fixed ones, are included in the covariance matrix. Fixed parameters are defined to have 0 uncertainty.
- correlationwarning(threshold=0.8)[source]
Report distinct variables with magnitude of correlation greater than threshold.
Returns a list of tuples (i, j, c), where i and j are tuples indicating the modelpart and parameter indices of the correlated variables, and c is their correlation.
- Parameters:
threshold (float) – A real number between 0 and 1.
- Returns:
tuple (i, j, c)
Indices of the modelpart and their correlations.
- get(i)[source]
Return (value, uncertainty) tuple for parameter i.
The variable may be specified as an integer, or as a two-component tuple of integers (l, m) which indicate the mth parameter of modelpart l.
- Parameters:
i (int) – The index of variable in peak mapping
- Returns:
The value and uncertainty of variable at index i.
- Return type:
(float, float)
- getcorrelation(i, j)[source]
Return the correlation between variables i and j, Corr_ij=Cov_ij/(sigma_i sigma_j)
The variables may be specified as integers, or as a two-component tuple of integers (l, m) which indicate the mth parameter in peak l.
The standard deviation of fixed parameters is 0, in which case the correlation is undefined, but return 0 for simplicity.
- Parameters:
i (int) – The index of variable in peak mapping
j (int) – The index of variable in peak mapping
- Returns:
The correlation between variables i and j
- Return type:
float
- getcovariance(i, j)[source]
Return the covariance between variables i and j.
The variables may be specified as integers, or as a two-component tuple of integers (l, m) which indicate the mth parameter of modelpart l.
- Parameters:
i (int) – The index of variable in peak mapping
j (int) – The index of variable in peak mapping
- Returns:
The covariance between variables at indeex i and j.
- Return type:
float
- getuncertainty(i)[source]
Return uncertainty of parameter i.
The variable may be specified as an integer, or as a two-component tuple of integers (l, m) which indicate the mth parameter of modelpart l.
- Parameters:
i (int) – The index of variable in peak mapping
- Returns:
The uncertainty of variable at index i.
- Return type:
float
- getvalue(i)[source]
Return value of parameter i.
The variable may be specified as an integer, or as a two-component tuple of integers (l, m) which indicate the mth parameter of modelpart l.
- prettypar(i)[source]
Return string ‘value (uncertainty)’ for parameter i.
The variable may be specified as an integer, or as a two-component tuple of integers (l, m) which indicate the mth parameter of modelpart l.
- Parameters:
i (int) – The index of variable in peak mapping
- Returns:
str
’value (uncertainty)’ for variable at index i.
- setcovariance(model, cov)[source]
Set model and covariance.
Automatically initializes covariance matrix to full set of parameters in model, even those listed as “fixed.”
- Parameters:
model (ModelParts) – The ModelParts instance
cov (ndarray) – The nxn covariance matrix for n model parameters. If the parameterization includes “fixed” parameters not included in the covariance matrix, the matrix is expanded to include these parameters with 0 uncertainty.
- transform(in_format, out_format, **kwds)[source]
Transform parameters and covariance matrix under specified change of variables.
By default this change applies to all parameters of the model. If the specified transformation is invalid for a given ModelPart the original parameterization is maintained for that part.
This function assumes that the derivative of every variable under this change depends only on the other parameters in its own part. Essentially, each model part has it own non-zero gradient matrix for any change of variables, but the gradient matrix between different parts is 0.
Note that transformed parameters may mix previously fixed and free parameters, and consequently the number of each kind is not necessarily preserved. The user is cautioned to interpret a transformed covariance matrix carefully. For example, the apparent degrees of freedom in the transformed covariance matrix may not coincide with the degrees of freedom during model fitting.
- Parameters:
in_format (str) – The current format of parameters
out_format (str) – The new format for parameters
Keywords
--------
part (parts - Specify which model) – “peaks” to transform all but the last part, and “baseline” to convert only the last part.
index (by) – “peaks” to transform all but the last part, and “baseline” to convert only the last part.
Alternately (to transform. Defaults to all parts.) – “peaks” to transform all but the last part, and “baseline” to convert only the last part.
:param : “peaks” to transform all but the last part, and “baseline” to convert only the last part.
diffpy.srmise.dataclusters module
Defines class to partition sequences representing the x and y axis into peak-like clusters.
- class diffpy.srmise.dataclusters.DataClusters(x, y, res)[source]
Bases:
object
Find clusters corresponding to peaks in the PDF (y-array)
DataClusters determines which points in inter-atomic distane, r, correspond to peaks in the PDF. The division between clusters is contiguous, with borders between clusters likely near relative minima in the data.
Clusters are iteratively formed around points with the largest PDF values. New clusters are added only when the unclustered data point under consideration is greater than a given distance (the ‘resolution’) from the nearest existing cluster.
Data members
- xarray
The array of r values.
- ysequence of y values
The array of PDF values, G(r)
- resfloat
The clustering resolution, i.e., the number of distance another point has to be away from the center of an existing cluster to before a new cluster is formed. A value of zero allows every point to be a cluster.
- data_orderarray
The array of x, y indices ordered by decreasing y
- clustersndarray
The array of cluster ranges
- current_idxint
The index of data_order currently considered
- cluster_is_full(cluster_idx)[source]
Return whether the given cluster can grow.
A cluster is full if no unclustered points remain adjacent to its boundaries.
- Parameters:
cluster_idx (array-like) – The index of the cluster to test
- Returns:
True if the cluster is full, False otherwise
- Return type:
bools
- combine_clusters(combine)[source]
Combine clusters specified by each subarray of cluster indices.
Clusters to combine must be contiguous, increasing, and have no unclustered points between them.
- Parameters:
combine (ndarray) – [[leftmost_idx1, …, rightmost_idx1], …]
- Return type:
None
- cut(idx)[source]
Return slice(s) for data given cluster index (or indices).
Parameters idx - Cluster index (or sequence of indices).
- find_adjacent_clusters()[source]
Return all cluster indices with no unclustered points between them.
Return array([[leftmost_idx1,…,rightmost_idx1],…]) such that there are no unclustered points between each element in subarray of clusters (inclusive). If no such clusters exist, returns an empty array.
- find_nearest_cluster(idx)[source]
Return [cluster index, distance] for cluster nearest to x[idx].
The distance is positive/negative if the point is right/left of the nearest cluster. If the point is within an existing cluster then distance = 0.
- Parameters:
idx (array-like) – index of point in self.x of interest.
- Returns:
The array of cluster index and the distacne to the nearest cluster. None if no clusters exist.
- Return type:
array-like
- find_nearest_cluster2(x)[source]
Return [cluster index, distance] for cluster nearest to x.
- Parameters:
x (ndarray) – Coordinate of point of interest
the (The distance is positive/negative if the point is right/left of)
then (nearest cluster. If the point is within an existing cluster)
0. (distance =)
- Returns:
The index of the nearest cluster, and the distance for cluster nearest to x. None if no cluster
- Return type:
array-like
diffpy.srmise.srmiseerrors module
Defines all custom exceptions used by diffpy.srmise.
Classes
SrMiseError: Subclass of Exception, and superclass of all diffpy.srmise exceptions. SrMiseDataFormatError: Error in format of diffpy.srmise data. SrMiseEstimationError: Parameter estimation error. SrMiseFileError: Error while reading/writing files. SrMiseFitError: Error while fitting. SrMiseLogError: Error while logging. SrMiseModelEvaluatorError: Error while computing or comparing model quality. SrMisePDFKeyError: Error in key referencing component of PDF dataset. SrMiseQmaxError: Error in value of Qmax. SrMiseScalingError: Error while scaling a peak function. SrMiseStaticOwnerError: Error when changing ModelPart instance owner.
- exception diffpy.srmise.srmiseerrors.SrMiseDataFormatError(info)[source]
Bases:
SrMiseError
diffpy.srmise exception class. Error in formatted data.
- exception diffpy.srmise.srmiseerrors.SrMiseError(info)[source]
Bases:
Exception
Superclass of all diffpy.srmise exceptions.
- exception diffpy.srmise.srmiseerrors.SrMiseEstimationError(info)[source]
Bases:
SrMiseError
diffpy.srmise.modelevaluator exception class. Parameter estimation error.
- exception diffpy.srmise.srmiseerrors.SrMiseFileError(info)[source]
Bases:
SrMiseError
diffpy.srmise exception class. Error while reading/writing files.
- exception diffpy.srmise.srmiseerrors.SrMiseFitError(info)[source]
Bases:
SrMiseError
diffpy.srmise exception class. Error occurred during fitting.
- exception diffpy.srmise.srmiseerrors.SrMiseLogError(info)[source]
Bases:
SrMiseError
diffpy.srmise exception class. Error while handling logging capabilities.
- exception diffpy.srmise.srmiseerrors.SrMiseModelEvaluatorError(info)[source]
Bases:
SrMiseError
diffpy.srmise.modelevaluator exception class. Error when comparing models.
- exception diffpy.srmise.srmiseerrors.SrMisePDFKeyError(info)[source]
Bases:
SrMiseError
diffpy.srmise exception class. Requested PDF key can’t be found.
- exception diffpy.srmise.srmiseerrors.SrMiseQmaxError(info)[source]
Bases:
SrMiseError
diffpy.srmise.modelevaluator exception class. Error when setting qmax.
- exception diffpy.srmise.srmiseerrors.SrMiseScalingError(info)[source]
Bases:
SrMiseError
diffpy.srmise.peaks exception class. Error when scaling a peak function.
- exception diffpy.srmise.srmiseerrors.SrMiseStaticOwnerError(info)[source]
Bases:
SrMiseError
diffpy.srmise exception class. Attempt to change owner of static model part.
- exception diffpy.srmise.srmiseerrors.SrMiseTransformationError(info)[source]
Bases:
SrMiseError
diffpy.srmise exception class. Error transforming model/covariance parameters.
- exception diffpy.srmise.srmiseerrors.SrMiseUndefinedCovarianceError(info)[source]
Bases:
SrMiseError
diffpy.srmise exception class. Attempted to perform on undefined covariance.
diffpy.srmise.peakextraction module
- class diffpy.srmise.peakextraction.PeakExtraction(newvars=[])[source]
Bases:
object
Class for peak extraction.
- Parameters:
x (array-like) – The x coordinates of the data
y (array-like) – The y coordinates of the data
dx (array-like) – The uncertainties in the x coordinates (not used)
dy (array-like) – The uncertainties in the y coordinates
effective_dy (array-like) – The uncertainties in the y coordinates actually used during extraction
rng (list) – The [xmin, xmax] Range of x coordinates over which to extract peaks
pf (array-like) – The sequence of peak functions that can be extracted
initial_peaks (Peaks object) – The peaks present at start of extraction
baseline (Baseline object) – The baseline for data
cres (float) – The resolution of clustering
error_method (ErrorEvaluator class) – The Evaluation class used to compare models
members (Calculated)
------------------
extracted (ModelCluster object) – The ModelCluster object after extraction
extraction_type (Type of extraction)
- add_peaks(peaks)[source]
Add peaks to extracted peaks, or initial_peaks if no extracted peaks exist.
- Parameters:
peaks (Peaks object) – The peaks instance
- clear()[source]
Clear all members.
The purpose of the method is to ensure the object is in initialized state.
- defaultvars(*args)[source]
Set unset(=None) extraction variables to default values.
Certain variables may be partially set for convenience, and are transformed appropriately. See ‘Default values assigned’ below.
- Parameters:
*args (str) – The variable argument list where each string corresponds to an extraction variable name.
assigned (Default values)
cres (-)
effective_dy (-) – otherwise, it’s 5% of the range (max(y) - min(y)). If effective_dy is a positive scalar, an array of that value with a length matching y is used.
pf (-) – spanning the entire x range (x[-1] - x[0]).
baseline (-)
error_method (-)
initial_peaks (-)
rng (-) – If a range is partially defined, e.g., [None, 100.], the None value is replaced with the respective boundary of the x data.
uncertainty (Note that the default values of very important parameters like the)
best. (and clustering resolution are crude guesses at)
- estimate_peak(x, add=True)[source]
Return new estimated peak near x.
Peaks already extracted, if any, are taken into account. If none exist, use those specified by initial_peaks instead.
- Parameters:
x (array-like) – The oordinate of the point of interest
add (bool) – Automatically add peak to extracted peaks or initial_peaks. Default is True.
- Return type:
The Peak object, or None if estimation fails.
- extract_single(recursion_depth=1)[source]
Find ModelCluster with peaks extracted from data. Return ModelCovariance instance at top level.
Every extracted peak is one of the peak functions supplied. All comparisons of different peak models are performed with the class specified by error_method.
Parameters recursion_depth: (1) Tracks recursion with extract_single.
- fit_single()[source]
Fit peaks in initial_peaks with baseline. Return ModelCovariance instance summarizing results.
- plot(**kwds)[source]
Convenience function to plot data and extracted peaks with matplotlib.
Uses initial peaks instead if no peaks have been extracted.
Takes same keywords as ModelCluster.plottable()
- Parameters:
**kwds (args) – The keyword arguments to pass to matplotlib.
- read(filename)[source]
load PeakExtraction object from file
- Parameters:
filename (str) – The file from which to read
- Return type:
self
- readstr(datastring)[source]
Initialize members from string.
- Parameters:
datastring (array-like) – The raw data to read
- setvars(quiet=False, **kwds)[source]
Set one or more extraction variables.
- Parameters:
quiet (bool) – The log changes quietly. Default is False.
cres (float) – The clustering resolution, must be > 0.
effective_dy (array-like) – The uncertainties actually used during extraction
pf (list) – The sequence of PeakFunctionBase subclass instances.
baseline (Baseline instance or BaselineFunction instance) – The Baseline instance or BaselineFunction instance that use built-in estimation
error_method (ErrorEvaluator subclass instance) – The ErrorEvaluator subclass instance used to compare models. Default is AIC.
initial_peaks (Peaks instance) – These peaks are present at the start of extraction.
rng (array-like) – The sequence specifying the least and greatest x-values over which to extract peaks.
- write(filename)[source]
Write string representation of PeakExtraction instance to file.
- Parameters:
filename (str) – The name of the file to write
diffpy.srmise.pdfdataset module
class PDFDataSet for experimental PDF data.
- exception diffpy.srmise.pdfdataset.PDFDataFormatError[source]
Bases:
Exception
Exception class marking failure to proccess PDF data string.
- class diffpy.srmise.pdfdataset.PDFDataSet(name)[source]
Bases:
PDFComponent
PDFDataSet is a class for experimental PDF data.
- robs
The list of observed r points.
- Type:
list
- Gobs
The list of observed G values.
- Type:
list
- drobs
The list of standard deviations of robs.
- Type:
list
- dGobs
The list of standard deviations of Gobs.
- Type:
list
- stype
The scattering type, either ‘X’ or ‘N’.
- Type:
str
- qmax
The maximum value of Q in inverse Angstroms. Termination ripples are neglected for qmax=0.
- Type:
float
- qdamp
Specifies width of Gaussian damping factor in pdf_obs due to imperfect Q resolution.
- Type:
float
- qbroad
The quadratic peak broadening factor related to the dataset.
- Type:
float
- spdiameter
The particle diameter for shape damping function. Note: This attribute was moved to PDFStructure. It is retained here for backward compatibility when reading PDFgui project files.
- Type:
float
- dscale
The scale factor of this dataset.
- Type:
float
- rmin
The same as robs[0].
- Type:
float
- rmax
The same as robs[-1].
- Type:
float
- filename
Set to the absolute path after reading from a file.
- Type:
str
- metadata
The dictionary for other experimental conditions, such as temperature or doping.
- Type:
dict
- Class Members
- -------------
- persistentItems
The list of attributes saved in the project file.
- Type:
list
- refinableVars
The set (or dict-like) of refinable variable names.
- Type:
set
- clear()[source]
reset all data members to initial empty values
The purpose of this method is to set the PDF dataset to initial empty values.
- copy(other=None)[source]
copy self to other. if other is None, create new instance
- Parameters:
other (PDFDataSet instance) – ref to other object
- Returns:
reference to copied object
- Return type:
PDFDataSet instance
- getvar(var)[source]
Obtain value corresponding to PdfFit dataset variable. Used by findParameters().
- Parameters:
var (str) – string representation of dataset PdfFit variable. Possible values: qdamp, qbroad, dscale
- Returns:
value of var
- Return type:
float
- persistentItems = ['robs', 'Gobs', 'drobs', 'dGobs', 'stype', 'qmax', 'qdamp', 'qbroad', 'dscale', 'rmin', 'rmax', 'metadata']
- read(filename)[source]
load data from PDFGetX2 or PDFGetN gr file
- filenamestr
file to read from
- Return type:
self
- readStr(datastring)[source]
read experimental PDF data from a string
Parameter
- datastringstr
string of raw data
Returns self
- refinableVars = {'dscale': None, 'qbroad': None, 'qdamp': None}
- setvar(var, value)[source]
Assign a data member using PdfFit-style variable notation. This method is typically utilized by the applyParameters() function.
- Parameters:
var (str) – String representation of the dataset PdfFit variable. Possible values include: ‘qdamp’, ‘qbroad’, ‘dscale’.
value (float) – The new value to which the variable var will be set.
- Return type:
None