mantidproject / mantid

Main repository for Mantid code
https://www.mantidproject.org
GNU General Public License v3.0
207 stars 122 forks source link

Add option to ignore masked pixels in integration algorithms and improve skew background determination #37596

Open RichardWaiteSTFC opened 1 week ago

RichardWaiteSTFC commented 1 week ago

Description of work

This work comprises 2 improvements to single-crystal integration methods:

  1. When determining background bins by minimising third moment (skew) in IntegratePeaksSkew - ensure loop terminates if skew < 0 (we expect minimum skew of background to be 0 - for low counts it should in fact be positive)
  2. Add option to ignore peaks for which mask (or shoebox etc.) includes a masked detector - this affects
    • IntegratePeaksSkew
    • IntegratePeaksShoeboxTOF
    • IntegratePeaks1DProfile

Purpose of work

Change (1) stops peak mask of IntegratePEaksSkew including too many pixels due to small diffuse scattering - see issue #37105

image

Change (2) allows the user to make a custom mask for edges (or dodgy tube etc.) - whereas NcolsEdge and NRowsEdge are assumed to be the same for all banks. To support this functionality the minimum value for NrowsEdge and NColsEdge has been decreased to 0 - i.e. it is now possible to only define edges using masked detectors on the workspace. Note this is how detector edges are denoted in other integration algorithms such asIntegratePeaksMD.

Fixes #37105

To test:

(1) Run this script

ws = Load(Filename=r'C:\mantid-conda\mantid\build\ExternalData\Testing\Data\DocTest\SXD23767.raw', OutputWorkspace='SXD23767')
# peaks = FindSXPeaksConvolve(InputWorkspace='SXD23767', PeaksWorkspace='peaks_out', ThresholdIoverSigma=4, GetNBinsFromBackToBackParams=True, NFWHM=6, PeakFindingStrategy='VarianceOverMean', ThresholdVarianceOverMean=1.25)

peaks = CreatePeaksWorkspace(InstrumentWorkspace=ws, NumberOfPeaks=0, OutputWorkspace="peaks_out")
pk_pos = [(3169, 1851.59), (752, 2292.94), (1971, 3169.28), (3633, 4623.41), (6469, 1531.5)]
for detid, tof in pk_pos:
    AddPeak(PeaksWorkspace=peaks, RunWorkspace=ws, TOF=tof, DetectorID=detid, EnableLogging=False)

skew_params = {'UseNearestPeak': True, 'IntegrateIfOnEdge': False,
             'NRowsEdge': 1, 'NColsEdge': 1, 
             'LorentzCorrection': True,
             'NVacanciesMax': 2, 'NPixPerVacancyMin': 2, 'NTOFBinsMin': 2,
             'UpdatePeakPosition': False, 'OptimiseMask': True,
             'GetTOFWindowFromBackToBackParams': False, 
              'ScaleThetaWidthByWavelength': True,
             'BackScatteringTOFResolution': 0.035, 'ThetaWidth': 1.5,
             'OptimiseXWindowSize':True, 'ThresholdIoverSigma': 20}
skew_params['OutputFile'] = rf"C:\Users\xhg73778\Desktop\{ws.name()}_peaks_skew_zero_skew.pdf"
peaks_int = IntegratePeaksSkew(InputWorkspace=ws, PeaksWorkspace=peaks, **skew_params)

(2) Open the pdf output and check the mask still covers the peaks (should look like the left hand column in the screenshots above)


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

Functional Tests

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.