ADR Suggestion ResolutionHandler
#2
Replies: 3 comments 3 replies
-
|
Two problems need to be carefully addressed:
For now, I will stick with numerical convolutions, and be mindful of the instabilities. They can to some extent be overcome with the |
Beta Was this translation helpful? Give feedback.
-
|
I would propose some slight changes to this structure. Instead of a Now for the |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.




Uh oh!
There was an error while loading. Please reload this page.
-
General
The instrument resolution must be included when fitting QENS data, and often also for INS. We shall here only consider fitting 1d cuts of the data, with intensity as function of energy. The fit function is then the convolution of the model with the resolution, plus a background. The model is most commonly a sum of one or more Lorentzian functions, but can also include Gaussians, damped harmonic oscillators (DHO), and many other functions.
The resolution function is determined using measurements of either vanadium or the sample itself at low temperature. Either way, there are two common ways to determine it, and both must be supported. The first way (a) is to simply use the measurement directly, after cleaning it up a bit (detailed below). The convolution is then calculated numerically using, e.g.,
scipy.signal.fftconvolve. This leads to some potential errors when the model function is sharply peaked or if the data is not linearly spaced.The second way is to fit the resolution to an analytical model. Unless the resolution is particularly ugly (which we do not expect it to be), this can be done using a sum of Gaussians and Lorentzians. In general, the convolution with the model can then be calculated numerically as above, with the same potential errors. However, the convolution of a Gaussian with a Gaussian is another Gaussian, the convolution of a Lorentzian with another Lorentzian is another Lorentzian, and the convolution of a Gaussian with a Lorentzian is a Voigt profile, which is also available, e.g., in
scipy.special.voigt_profile. This can be used to improve accuracy and make the calculations faster.Current implementation
Nothing is implemented yet
Proposed implementation
I propose a class,
ResolutionHandlerto handle this. It takes aSampleModelandResolutionModeland produces the convolution of the two. TheAnalysisclass can use this for the fitting, together with aBackgroundModel(to be defined elsewhere). Let's talk about theSampleModelandResolutionModelSampleModelThis holds the model, which consists of
components, which can beGaussian,Lorentzian,DHO, etc., or user defined. (Care must be taken to also allow 2d models often used in QENS, such asJumpDiffusion. This will probably be handled by a separate class, which can then generate aSampleModelfor each probed Q).It has methods to create and remove components.
ResolutionModelIn case (a), this holds the measured resolution. It will have methods to clean the data, such as smoothing and background subtraction.
In case (b), this will be a
SampleModelthat holds the fitted resolution.It has methods to create and remove components.
ResolutionHandlerThis will loop over the components in
SampleModeland calculate their convolution with theResolutionModel, using the analytical method where possible, and numerical methods otherwise. (If the analytical method is not possible, the calculation can be sped up by summing theSampleModelcomponents first. Let's not worry about this unless the fitting is slow).It will take
xas input, i.e. the points where the convoluted model will be evaluated, as well as aSampleModelandResolutionModel.Optionally, it can take
upsampling: how many more points to evaluate on compared to the input (default: probably around 4) (perhaps also anum_pointsto let the user choose how many points instead)It will need some methods in addition to the
convolutemethod to combat numerical instabilities:interpolate: If the data is not evenly spaced, the fft convolution method produces incorrect results. The model must therefore be evaluated at evenly spaced points and interpolated onto the input.It will also need to check if the input is symmetric, and handle it properly.
Beta Was this translation helpful? Give feedback.
All reactions