mantid icon indicating copy to clipboard operation
mantid copied to clipboard

Use mantid fitting in IntegratePeaks1DProfile (instead of scipy as was too slow)

Open RichardWaiteSTFC opened this issue 7 months ago • 0 comments

Description of work

Use mantid fitting in IntegratePeaks1DProfile for speed. Previously scipy fitting used, but the only minimizer that worked robustly was a simplex/Nelder-Mead method which was very slow (slow to converge, lots of function evaluations per iteration). The original issue was to add mantid fitting as an option, but the mantid fitting with the relatively new option StepSizeMethod="Sqrt epsilon" seems more robust than scipy fitting and orders of magnitude quicker. So in order to reduce duplication the scipy fitting has been completely replaced by mantid Fit algorithm.

In order to do this have also exposed a couple of IPEakFunction methods to python

  • getWidthParameterName
  • getCentreParameterName

Which are used to construct function parameter constraints.

Fixes #37526

Report to: Nick Funnell (LMX/PEARL)

To test:

(1) Run this script

# import mantid algorithms, numpy and matplotlib
from mantid.simpleapi import *
import matplotlib.pyplot as plt
import numpy as np

ws  =Load(Filename=r'C:/Users/xhg73778/Desktop/SXD34361.nxs', OutputWorkspace='SXD34361')
peaks = FindSXPeaksConvolve(InputWorkspace=ws, PeakFindingStrategy="IOverSigma", NCols=7, NRows=7, NFWHM=6, ThresholdIoverSigma=5)

profile_kwargs = {"GetNBinsFromBackToBackParams": True, "NFWHM": 6,
                "CostFunction": "Poisson", "FixPeakParameters": "A",
                "FractionalChangeDSpacing": 0.05,
                "IntegrateIfOnEdge": False,
                "LorentzCorrection": True,
                "IOverSigmaThreshold": 2.5,
                'BackgroundFunction': 'FlatBackground',         
                "OutputFile": "SXD34361_profile_testpdf"}

peaks_int = IntegratePeaks1DProfile(ws, peaks_small, **profile_kwargs)

(2) Check the pdf file, peaks should be integrated well, with peak shape in TOF spectrum a good fit and most intense pixels included in peak mask


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.

RichardWaiteSTFC avatar Jul 10 '24 09:07 RichardWaiteSTFC