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

Add signal to sigma post fitting check #37826

Merged
merged 4 commits into from
Sep 12, 2024

Conversation

MohamedAlmaki
Copy link
Contributor

@MohamedAlmaki MohamedAlmaki commented Aug 19, 2024

Description of work

This pull request introduces a new property to FitPeaks and PDCalibration: the option to set a minimum signal-to-sigma ratio for post-fitting. When this property is provided, peaks with a signal-to-sigma ratio below the specified minimum will be rejected. The signal-to-sigma ratio is calculated as the integrated fitted peak minus the integrated background, divided by the sigma, which is calculated using the quadrature sum of the errors.

Fixes #35224.

To test:

1- Run the following script:

from mantid.simpleapi import *

ws = CreateSampleWorkspace(Function="User Defined",
                           UserDefinedFunction="name=LinearBackground, A0=0.3;name=Gaussian, PeakCentre=5, Height=10, Sigma=0.7",
                           NumBanks=1, BankPixelWidth=1, XMin=0, XMax=10, BinWidth=0.1)

FitPeaks(InputWorkspace='ws', PeakCenters='5.1', FitWindowBoundaryList='0,10', OutputPeakParametersWorkspace='fitted_params',
         BackgroundType='Linear', FittedPeaksWorkspace='fitted', OutputWorkspace='peakpositions', MinimumSignalToSigmaRatio='200')

2- Check the fitted data and params, you will notice the peak has been rejected.
3- Rerun the same script but with MinimumSignalToSigmaRatio='150', then you will see the expected fitted peak.


Reviewer

Please comment on the points listed below (full description).
Your comments will be used as part of the gatekeeper process, so please comment clearly on what you have checked during your review. If changes are made to the PR during the review process then your final comment will be the most important for gatekeepers. In this comment you should make it clear why any earlier review is still valid, or confirm that all requested changes have been addressed.

Code Review

  • Is the code of an acceptable quality?
  • Does the code conform to the coding standards?
  • Are the unit tests small and test the class in isolation?
  • If there is GUI work does it follow the GUI standards?
  • If there are changes in the release notes then do they describe the changes appropriately?
  • Do the release notes conform to the release notes guide?

Functional Tests

  • Do changes function as described? Add comments below that describe the tests performed?
  • Do the changes handle unexpected situations, e.g. bad input?
  • Has the relevant (user and developer) documentation been added/updated?

Does everything look good? Mark the review as Approve. A member of @mantidproject/gatekeepers will take care of it.

Gatekeeper

If you need to request changes to a PR then please add a comment and set the review status to "Request changes". This will stop the PR from showing up in the list for other gatekeepers.

@MohamedAlmaki MohamedAlmaki changed the title add signal to sigma post fitting check Add signal to sigma post fitting check Aug 20, 2024
@MohamedAlmaki MohamedAlmaki added Diffraction Issues and pull requests related to diffraction ISIS Team: Diffraction Issue and pull requests managed by the Diffraction subteam at ISIS labels Aug 22, 2024
@MohamedAlmaki MohamedAlmaki added this to the Release 6.11 milestone Aug 22, 2024
@MohamedAlmaki MohamedAlmaki marked this pull request as ready for review August 22, 2024 15:20
Copy link
Contributor

@RichardWaiteSTFC RichardWaiteSTFC left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this, the calculation of I/sigma looks good.
Just some suggested changes and would it be possible to add a test and release notes for this .
Sorry I haven't been able to test this yet due to boost update requiring a new build, but I will do manual testing once comments addressed. Thanks!

Framework/Algorithms/src/FitPeaks.cpp Outdated Show resolved Hide resolved
Framework/Algorithms/src/FitPeaks.cpp Show resolved Hide resolved
Framework/Algorithms/src/FitPeaks.cpp Outdated Show resolved Hide resolved
Copy link
Contributor

@RichardWaiteSTFC RichardWaiteSTFC left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks good - but I think there may be something wrong with the I/sigma calculation.
It looks to me like the I/sigma of the peak in your test code should ~12

intens = np.sum(ws.readY(0) - ws.readY(0)[0])
sigma = np.sqrt(np.sum(ws.readE(0)**2))
print(intens/sigma)  # 12.24

It looks to me though that FitPeaks only rejects the peak around ~100
Can you see what's going on?

@sf1919
Copy link
Contributor

sf1919 commented Sep 12, 2024

@MohamedAlmaki This looks like genuine test failures.

@MohamedAlmaki
Copy link
Contributor Author

Yes, I am working on fixing it

@jclarkeSTFC jclarkeSTFC changed the base branch from main to release-next September 12, 2024 15:16
Copy link
Contributor

@RichardWaiteSTFC RichardWaiteSTFC left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this - looks good. Now in test script the chi-squared of the peak gets set to DBL_MAX around I/sigma ~ 12

@robertapplin robertapplin self-assigned this Sep 12, 2024
@robertapplin robertapplin merged commit c36a1c9 into release-next Sep 12, 2024
9 of 10 checks passed
@robertapplin robertapplin deleted the 35224_add_post_fitting branch September 12, 2024 16:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Diffraction Issues and pull requests related to diffraction ISIS Team: Diffraction Issue and pull requests managed by the Diffraction subteam at ISIS
Projects
Status: Merged
Status: Done
Development

Successfully merging this pull request may close these issues.

Provide a post-fitting check in PDCalibration/FitPeaks for I/Sigma ratio.
4 participants