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

[Requirement] Normalise by monitor #76

Closed
jl-wynen opened this issue Jul 10, 2024 · 1 comment · Fixed by #93
Closed

[Requirement] Normalise by monitor #76

jl-wynen opened this issue Jul 10, 2024 · 1 comment · Fixed by #93
Assignees

Comments

@jl-wynen
Copy link
Member

Executive summary

Normalise data by monitor counts

Context and background knowledge

This issue is an alternative to #30. In some cases users want to normalise detector data by a monitor. This can be either

  • normalization by a wavelength spectrum of the monitor,
  • normalization by an integrated monitor (single number).

The user needs to be able to pick one or the other.

Inputs

  • Data array for detector counts in wavelength
  • Data array for monitor counts
    • In wavelength if normalising by wavelength spectrum.
    • Arbitrary coordinate when normalising by integrated monitor.

Methodology

Normalisation by wavelength spectrum
Either histogram the monitor into the same bins as the detector data and then divide. Or use sc.lookup to account for different binning. (See old WISH workflow.)

Normalisation by integrated monitor
Divide detector data by sc.sum(monitor).

Outputs

Normalised data array.

We should probably ensure that the data array has the same units regardless of which monitor normalisation was used.

Which interfaces are required?

Integrated into reduction workflow, Python module / function

Test cases

Dummy test data.

Comments

No response

@jl-wynen jl-wynen added this to the Powder Essentials milestone Jul 10, 2024
@jl-wynen jl-wynen moved this from Triage to Selected in Development Board Jul 10, 2024
@jl-wynen jl-wynen self-assigned this Sep 3, 2024
@jl-wynen jl-wynen moved this from Selected to In progress in Development Board Sep 3, 2024
@jl-wynen
Copy link
Member Author

jl-wynen commented Sep 3, 2024

With suitable pre-processing in the workflow, these should work:

def normalize_by_integrated_monitor(
    *, detector: sc.DataArray, monitor: sc.DataArray
) -> sc.DataArray:
    key = monitor.dim
    assert monitor.coords.is_edges(key)

    # Clip `monitor` to the range of `detector`.
    lo = detector.coords[key].min()
    hi = detector.coords[key].max()
    hi.value = np.nextafter(hi.value, np.inf)
    monitor = monitor[key, lo:hi]

    coord = monitor.coords[key]
    norm = sc.sum(monitor.data * (coord[1:] - coord[:-1]))
    return detector / norm


def normalize_by_monitor_histogram(
    *,
    detector: sc.DataArray,
    monitor: sc.DataArray,
) -> sc.DataArray:
    # Requires
    # - `detector` to be binned,
    # - `monitor` to be histogrammed
    return detector.bins / sc.lookup(monitor)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

1 participant