Functions for fitting and simulating arbitrary dimensional lineshapes commonly found in NMR experiments
This module is imported as nmrglue.linesh and can be called as such
These are the functions the majority of users will use from the linesh module.
Fit a spectrum by region which contain one or more peaks.
Parameters:
spectrum Slicable spectral data.
See fit_NDregion for details.
N-length lists of tuples where each each tuple is the optimiztion starting parameters for a given peak and dimension lineshape.
amps P-length list of amplitudes.
none of the parameters in a given dimension have limits None can be used, otherwise each dimension should have a list/tuple of (min,max) or None for each parameter. min or max may be None when there is no bound in a given direction.
similar to bounds.
centers List of N-tuples indicating peak centers.
region number are fit together).
peak centers to form region around peak to fit.
parameter and amplitude.
supresses all printing.
function.
as params input parameter.
amp_best List of optimal peak amplitudes.
as oarans inout parameter. (Optional)
amp_err Estimated peak amplitude errors.
indicating if the solution was found for a given peak. 1,2,3,4 indicates that a solution was found. Other indicate an error.
Fit a N-dimensional region.
Parameters:
region N-dimensional region to fit.
lineshapes List of lineshapes by label (str) or a lineshape class.
N-length lists of tuples where each each tuple is the optimiztion starting parameters for a given peak and dimension lineshape.
amps P-length list of amplitudes.
none of the parameters in a given dimension have limits None can be used, otherwise each dimension should have a list/tuple of (min,max) or None for each parameter. min or max may be None when there is no bound in a given direction.
similar to bounds.
points in the err calculation, typically a boolean array is used to exclude certain points in the region. Default of None will include all points in the region equally in the error calculation.
parameter and amplitude.
function.
as params input parameter.
amp_best List of optimal peak amplitudes.
as oarans inout parameter. (Optional)
amp_err Estimated peak amplitude errors.
the solution was found. 1,2,3,4 indicates that a solution was found. Otherwise the solution was not found.
Note on the lineshape parameter:
Elements of the lineshape parameter list can be string indicating the lineshape of given dimension or an instance of a lineshape class which provide a sim method which takes two arguments, the first being the length of the lineshape the second being a list of lineshape parameters, and returns a simulated lineshape as well as a nparam method which when given the length of lineshape returns the number of parameters needed to describe the lineshape. Currently the following strings are allowed:
The following are all valid lineshapes parameters for a 2D Gaussian peak:
[‘g’,’g’] [‘gauss’,’gauss’] [ng.analysisbase.gauss1D(),ng.analysisbase.gauss1D()]
An simple example of a lineshape class which simulates the function y=c: XXX
Simulate a arbitrary dimensional region with one or more peaks.
Parameters:
shape tuple of region shape
See fit_NDregion for additional documentation.
N-length lists of tuples where each each tuple is lineshape parameters for a given peak and dimension.
amps P-length of peak amplitudes.
Returns: array containing simulated region
Add (append) multiple columns to a record array
Parameters:
Returns: rec (Records array with columns added)
Pack fitting parameters into table
Parameters:
Return nothing, rec is updated in place.
Unpack initial fitting parameters from a table
Parameters:
rec Records array (table) holding parameters.
See fit_NDregion for format.
amp_column Name of columns in rec holding initial amplitudes.
Returns: params,amps
Estimate scale parameter for peaks in a spectrum
Parameters:
spectrum Slicable spectral data.
centers List of N-tuples indicating peak centers.
peak centers to form region around peak to fit.
scale_axis Axis number to estimate scale parameters for.
These functions are typically not used directly by users. They are called by high level functions. Developers and user who want fine control over lineshape fitting may be interested in these functions.
Fit an arbitrary dimensional regions containing one or more peaks using a contrained Levenberg-Marquard optmization algorithm.
Parameters:
Additional keyword are passed directly to leastsqbound and in turn passed to scipy.optimize.leastsq after variable transformation.
Simulate a arbitrary dimensional region with one or more peaks.
Parameters:
p is modified by this functions, pass a copy if p should be retained.
Simulate a arbitrary dimensional region with a single peak. Called repeatly by s_NDregion to build up a full ND region.
Parameters: * p List (and must be a list) of parameters * shape tuple of region shape * ls_classes List of lineshape classes
Create a list of tuples of given sizes from a list
Parameters: