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

38863 Update Engineering Diffraction Calibration region of interest functionality #38870

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

andy-bridger
Copy link
Collaborator

@andy-bridger andy-bridger commented Feb 17, 2025

Description of work

Summary of work

Added support so the Custom File provided to Engineering Diffraction Calibration can be an xml, such as those output by SaveDetectorsGrouping

Fixes #38863 .
Also fixes a bug I found in testing new implementation #38879

Further detail of work

Changed it so the interface now accepts xml files of the grouping. Additionally changed both the user facing and internal reference to this from CalFile (or variations upon this) to GroupingFile and in the UI Crop Calibration to Set Calibration Region of Interest, these provide more accurate names to actual functionality and should make the interface more intuitive to use.
Changed the naming suffix for custom file example_group.xml from _Custom to _Custom_example_group so they don't get overwritten when custom grouping is changed (also more clear to the user what grouping is being used).
Finally changed it so the vanadium normalisation is always rerun for GROUP.CUSTOM and GROUP.CROPPED which fixes the bug #38879

To test:

Open the Engineering Diffraction Interface

Select Create New Calibration

Set the sample as 305738

Select Set Calibration Region of Interest

Set Region of Interest to Custom Grouping File in the drop down

Try setting a custom grouping in xml format (code to create one provided below)

Calibration should be successful

Try using calibration to focus on the next tab

If you use the customs below should get: 2 spectra for "bank", 10 for "module", and 90 for "block"

(Bank should give identical results to Test 1 in the manual testing: https://developer.mantidproject.org/Testing/EngineeringDiffraction/EngineeringDiffractionTestGuide.html)

from mantid.simpleapi import *

def get_detector_grouping_string(ws, group_by):
    info = ws.componentInfo()
    detinfo = ws.detectorInfo()
    dets = detinfo.detectorIDs()
    instr_dets = info.detectorsInSubtree(info.root())

    def get_det_id(comp_ind, dets, instr_dets):
        return dets[np.where(instr_dets == comp_ind)][0]

    nbi = info.indexOfAny("NorthBank")
    sbi = info.indexOfAny("SouthBank")


    nbmi = info.children(nbi)
    sbmi = info.children(sbi)

    nbmbi = [xx for x in [info.children(int(nbm)) for nbm in nbmi] for xx in x]
    sbmbi = [xx for x in [info.children(int(sbm)) for sbm in sbmi] for xx in x]
    if group_by == "bank":
        n_dets = "+".join([str(get_det_id(x, dets, instr_dets)) for x in info.detectorsInSubtree(nbi)])
        s_dets = "+".join([str(get_det_id(x, dets, instr_dets)) for x in info.detectorsInSubtree(sbi)])
        print([d for d in n_dets.split("+") if det_is_monitor(d, detinfo)])
        print([d for d in s_dets.split("+") if det_is_monitor(d, detinfo)])
        return ",".join([n_dets, s_dets])
    if group_by == "module":
        n_mods = ",".join(
            ["+".join([str(get_det_id(x, dets, instr_dets)) for x in info.detectorsInSubtree(int(nbm))]) for nbm in
             nbmi])
        s_mods = ",".join(
            ["+".join([str(get_det_id(x, dets, instr_dets)) for x in info.detectorsInSubtree(int(sbm))]) for sbm in
             sbmi])
        return ",".join([n_mods, s_mods])
    if group_by == "block":
        n_blocks = ",".join(
            ["+".join([str(get_det_id(x, dets, instr_dets)) for x in info.detectorsInSubtree(int(nbm))]) for nbm in
             nbmbi])
        s_blocks = ",".join(
            ["+".join([str(get_det_id(x, dets, instr_dets)) for x in info.detectorsInSubtree(int(sbm))]) for sbm in
             sbmbi])
        return ",".join([n_blocks, s_blocks])
        
ws = LoadNexus(r"C:\Users\kcd17618\Downloads\ENGINX00218189.nxs") #put any enginx run here

group_type = "module" #bank/module/block should all make different custom groupings

CreateGroupingWorkspace(ws,OutputWorkspace ="group_ws", 
                        CustomGroupingString=get_detector_grouping_string(ws, "module"), 
                        ComponentName = "ENGIN-X")
                        
SaveDetectorsGrouping("group_ws", f"custom_{group_type}.xml")

You can also run through the reproduction instructions here: #38879 and check that the bug is no longer there.


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.

@andy-bridger andy-bridger self-assigned this Feb 18, 2025
@andy-bridger andy-bridger changed the title 38863 add xml support to calfile 38863 Update Engineering Diffraction Calibration region of interest functionality Feb 18, 2025
@sf1919 sf1919 removed the request for review from peterfpeterson February 19, 2025 08:27
@andy-bridger andy-bridger force-pushed the 38863-add-xml-support-to-calfile branch from 77549a4 to eaac41a Compare February 25, 2025 13:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant