Skip to content

"Magic numbers" in resolution calculation #131

Open

Description

@henrikjacobsenfys

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.

Activity

  1. andyfaff commented on May 11, 2024

    @andyfaff

    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

  2. added
    [scope] maintenance
    [priority] low
    on Oct 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    [priority] low[scope] maintenance

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions