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

Use uncertainties in plots and fits #22

Closed
2 tasks done
Tom-Willemsen opened this issue Aug 21, 2024 · 1 comment · Fixed by #52
Closed
2 tasks done

Use uncertainties in plots and fits #22

Tom-Willemsen opened this issue Aug 21, 2024 · 1 comment · Fixed by #52
Assignees
Labels

Comments

@Tom-Willemsen
Copy link
Contributor

Tom-Willemsen commented Aug 21, 2024

As a user, if uncertainties have been published by the underlying device, I would like plots & fits to use them.

This issue depends on all of:

Which must be completed first.

Acceptance criteria:

  • Uncertainties, if available, are plotted as error bars on plots.
    • We probably want a LivePlotWithUncertainty wrapper on top of LivePlot for this.
    • matplotlib can already handle plots with error bars, so this is largely "pass data through to matplotlib in the right places".
  • Uncertainties, if available, are used in fits.
    • lmfit takes weights for each point which can be used to implement this - so this is largely "pass data through to lmfit in the right places".
@KathrynBaker KathrynBaker moved this to Backlog in PI_2024_08 Oct 4, 2024
@Tom-Willemsen
Copy link
Contributor Author

Tom-Willemsen commented Oct 15, 2024

When doing fitting, the weights of each point are 1/uncertainty. Obviously this is problematic in the case where counts = uncertainty = 0.

I discussed this with the scientists in the scans meeting 2024/10/15 and agreed that when initially generating the uncertainties (in read_spectrum_dataarray), the uncertainties should be sqrt(N + 0.5) rather than sqrt(N) as per poisson counting statistics. This was agreed with CK, RD, JL present. The actual data should be unchanged, the +0.5 is only for uncertainty calculation.

The above approach is both "smooth" and converges towards sqrt(N) in the limit with high counts, and should also mean that we never get an uncertainty of zero in the fitting side.

When doing this ticket make sure we document the above approach (e.g. write an ADR for it)

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

Successfully merging a pull request may close this issue.

5 participants