Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Magic numbers" in resolution calculation #131

Open
henrikjacobsenfys opened this issue Apr 5, 2024 · 1 comment
Open

"Magic numbers" in resolution calculation #131

henrikjacobsenfys opened this issue Apr 5, 2024 · 1 comment

Comments

@henrikjacobsenfys
Copy link
Member

As part of the resolution calculations, EasyReflectometry/calculators/refl1d/wrapper.py, the following is calculated

        q.calc_Qo = np.linspace(
            q_array[argmin] - 3.5 * dq_vector_normalized_to_refnx[argmin],
            q_array[argmax] + 3.5 * dq_vector_normalized_to_refnx[argmax],
            21 * len(q_array),

The numbers 3.5 and 21 seem arbitrary. We should look into if these are the optimal values.

The 21 * len(q_array) indicates that the resolution calculation will assume that calc_Qo consists of many close-lying points (perhaps the calculation relies on Fast Fourier Transforms?). This is probably always the case in the typical use case when q_array is a set of data points, but might not be true in general, e.g. if a model value is calculated only at a few points.

We should check if the calculation is consistent if q_array is, say, only a few points in a wide q-range vs. hundreds of points in the same q-range. If it is not consistent, we should implement a check to make sure the results of the calculation are reliable, and warn the user if they are not.

Furthermore, if the calculations are time-consuming, the numbers 3.5 and 21 can possibly be tweaked to optimize performance.

@andyfaff
Copy link

I can advise on these numbers for refnx if required (issue seems to be about refl1d though). The point-wise resolution smearing of refnx uses a highly optimised gaussian quadrature. The abscissa are at Gauss Legendre points, not linearly spaced. The current default in refnx is to use an oversampling of 17, not 21. You need to choose that oversampling number depending on how thick your films are. For thicker films that number might need to be higher. W.r.t the +/- 3.5 that's to ensure the entirety of the gaussian is probed. It may be possible to bring that in slightly, but the main thing in calculation speed is the oversampling factor.

I've spent a lot of time looking into all aspects of resolution smearing, including a lot of benchmarking.
e.g.
https://gist.github.com/andyfaff/6abc5ca58796f4e74cad213028b76e96
https://gist.github.com/andyfaff/d71531e4e8c9549a3049621c32697d7a
https://gist.github.com/andyfaff/03cc009e987c10178ec7174aedaca278
https://gist.github.com/andyfaff/056d516c1eb101e6951cf657152e3475

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants