scipp / essdiffraction

Diffraction data reduction for the European Spallation Source
https://scipp.github.io/essdiffraction/
BSD 3-Clause "New" or "Revised" License
0 stars 2 forks source link

Filtering unphysical oscillations in PDF transformation #74

Open jokasimr opened 3 months ago

jokasimr commented 3 months ago

The pair distribution function is an integral transform of the intensity distribution over $Q$. See #65 and the related issue #49 for more context.

The transform is computed by approximating the integral. The approximation errors causes the result to contain nonphysical oscillations. Example: pdf_without_extrapolated

In the literature here are some different suggestions about how to handle the oscillations. A common approach is to apply a filter to smooth high frequency oscillations in the result. The issue with that approach is that it doesn't deal with the underlying problem: the approximation error. It removes the symptoms but since it doesn't distinguish between the nonphysical and the physical signal it simultaneously smooths both, therefore it might remove real physical oscillations, and it broadens peaks in the signal. If this is desirable is a question for the IDS, but if my understanding is correct it should be understood that no conclusions like "this peak was removed by the smoothing so it was noise" or "this peak was not removed by the smoothing so it is a real signal" can be drawn from the smoothing procedure.

Step 1:

Step 2:

Alternative: Improve the approximation

An alternative approach is to improve the approximation to remove the nonphysical oscillations without mangling the real signal. One part of the integration error comes from the fact that we are truncating the integral at $Q{max}$ because beyond that we don't have data. In the current implementation what we do is equivalent to assuming that the integrand is $0$ when $Q>Q{max}$. That is a reasonable approximation because the asymptotic value is $0$. But we could probably make some other assumption that better matches reality.

Example / poc

In this example a model is fitted to $S(Q) \quad Q>Q{max}$ to let us integrate beyond $Q{max}$. Doing so removes some oscillations. See comparison below:

This is the $S(Q)$ signal, with a fitted extrapolation: extrapolated_soq

Original result without the extrapolation can be seen in the example figure near the top. The result using the extrapolation method is displayed below. pdf_from_extrapolated

It seems like the nonphysical oscillations are reduced and the peaks are sharper, but evaluating this more requires input from the IDS.

jl-wynen commented 3 months ago

Note in particular comment https://github.com/scipp/essdiffraction/issues/49#issuecomment-2085256019 for links:

Mantid does not actually use an FFT to compute the PDF, see https://docs.mantidproject.org/nightly/algorithms/PDFFourierTransform-v2.html. Instead, it uses an algorithm based on the maths explained in the Manual for Gudrun.