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 methods to find consistent UBs and optimise goniometer axes and angles in ISIS single-crystal classes #37599

Merged

Conversation

RichardWaiteSTFC
Copy link
Contributor

@RichardWaiteSTFC RichardWaiteSTFC commented Jun 24, 2024

Description of work

This PR adds 2 features:

  • Add method to find consistent UBs given a reference workspace
  • Add method to optimise the goniometer axes and angles given a sequence of workspaces at different goniometer angle with consistent UBs

Fixes #35713 - albeit with different solution (doesn't change FindGoniometerFromUB algorithm)
Fixes #36907

Further detail of work

To test:

(1) To test making a set of consistent UBs

from mantid.simpleapi import *
import numpy as np
from Diffraction.single_crystal.sxd import SXD

sxd = SXD(detcal_path="SXD34330_peaks_detcal.xml")

omega = [-45.0, 10.0, 10.0]
chi = [-38.0, -38.0, 0.0]
runs = list(range(34363,34366))

pk_ws_list = []
for irun, run in enumerate(runs):
    ws = sxd.load_run(run)
    SetGoniometer(Workspace=ws, Axis0=str(omega[irun])+',0,1,0,1',Axis1=str(chi[irun]) + ',1,0,0,-1')
    peaks_ws = sxd.find_sx_peaks(ws, PeakFindingStrategy="IOverSigma", NCols=7, NRows=7, NFWHM=6, ThresholdIoverSigma=15)
    sxd.remove_peaks_on_detector_edge(peaks_ws, 1)
    # set goniometer on peaks workspace for later use
    SetGoniometer(Workspace=peaks_ws, Axis0=str(omega[irun])+',0,1,0,1',Axis1=str(chi[irun]) + ',1,0,0,-1')
    pk_ws_list.append(peaks_ws)              
                  
# optimise set of consistent UBs independently (could also use FindGlobalBMatrix)
iref = len(omega) - 1 # use last workspace
FindUBUsingFFT(PeaksWorkspace=pk_ws_list[iref], MinD=1, MaxD=20, DegreesPerStep=0.5)
for irun, peaks in enumerate(pk_ws_list):
    sxd.find_consistent_ub(pk_ws_list[iref], peaks, hkl_tol=0.15)
    predicted_peaks = PredictPeaks(InputWorkspace=peaks, WavelengthMin=0.3, MinDSpacing=1, ReflectionCondition='Primitive', 
                                   OutputWorkspace=peaks + '_indep_predicted', EnableLogging=False)
    print("ub of ", peaks)
    print(np.round(predicted_peaks.sample().getOrientedLattice().getUB(),3))  # should be very similar but not quite the same
    

The UBs should be very similar but maybe the 2nd or 3rd decimal point will be different.

(2) Optimise the goniometer axis and angles

axes, angles = SXD.optimize_goniometer_axis(pk_ws_list, iaxis=1, euler_axes="yz", fix_angles=False)

print("axes = ", np.round(axes,2))
# axes =  [[ 0.    1.    0.  ]
#          [-1.    0.   -0.04]]

print("angles = ", np.round(angles,2))
# angles =  [[-45.   -40.41]
#            [ 10.   -40.56]
#            [ 10.     0.76]]

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 RichardWaiteSTFC added Diffraction Issues and pull requests related to diffraction Single Crystal Issues and pull requests related to single crystal ISIS Team: Diffraction Issue and pull requests managed by the Diffraction subteam at ISIS labels Jun 24, 2024
@RichardWaiteSTFC RichardWaiteSTFC added this to the Release 6.11 milestone Jun 24, 2024
@RichardWaiteSTFC RichardWaiteSTFC marked this pull request as draft June 24, 2024 16:33
@RichardWaiteSTFC RichardWaiteSTFC marked this pull request as ready for review June 25, 2024 10:22
@github-actions github-actions bot added the Has Conflicts Used by the bot to label pull requests that have conflicts label Jul 4, 2024
Copy link

github-actions bot commented Jul 4, 2024

👋 Hi, @RichardWaiteSTFC,

Conflicts have been detected against the base branch. Please rebase your branch against the base branch.

Copy link
Contributor

@MohamedAlmaki MohamedAlmaki left a comment

Choose a reason for hiding this comment

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

LGTM, I tried the script and it works as expected. Also, the good looks code to me.

Could you just resolve the merge conflict and then I will approve

@github-actions github-actions bot removed the Has Conflicts Used by the bot to label pull requests that have conflicts label Jul 10, 2024
Copy link
Contributor

@MohamedAlmaki MohamedAlmaki left a comment

Choose a reason for hiding this comment

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

LGTM

@robertapplin robertapplin self-assigned this Jul 15, 2024
@robertapplin robertapplin merged commit 840f705 into main Jul 15, 2024
10 checks passed
@robertapplin robertapplin deleted the 36907_find_consistent_UBs_and_optimise_goniometer_axes branch July 15, 2024 13:51
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 Single Crystal Issues and pull requests related to single crystal
Projects
Status: Merged
Status: Done
3 participants