-
Notifications
You must be signed in to change notification settings - Fork 128
add FilterByTime functionality #37816
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in the pull request description, can you write a manual test I can run in the workbench?
|
Yes, a few python statements that I could execute in the workbench would be best |
I've updated the test instructions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This script pass
from mantid.simpleapi import HFIRSANS2Wavelength, LoadEventAsWorkspace2D, LoadEventNexus
filename="/HFIR/CG3/IPTS-23782/nexus/CG3_4829.nxs.h5"
LoadEventNexus(
Filename=filename,
OutputWorkspace="CG3_4829_1",
FilterByTimeStart=60,
FilterByTimeStop=120
)
HFIRSANS2Wavelength(InputWorkspace="CG3_4829_1", OutputWorkspace="CG3_4829_1")
LoadEventAsWorkspace2D(
Filename=filename,
OutputWorkspace="CG3_4829_2",
FilterByTimeStart=60,
FilterByTimeStop=120
)
# Accept if workspaces differ by one count, but no more
CompareWorkspaces(Workspace1="CG3_4829_1", Workspace2="CG3_4829_2", Tolerance=1)
The rest looks 👌
@KyleQianliMa You still need to fix the conda build. Have you already tried?
I'm not sure why it failed windows testing. The console output says all test passed. I can't seem to understand where it failed. Here is a link to the console log Parsing console log (workspace: '/jenkins_workdir/workspace/pull_requests-conda-windows') |
@jmborr Could you re-run the tests using CG3_4829.nxs.h5 file? It seems like all the check passed somehow. Previously some tests mysteriously failed, so I rebased the repo and pushed again. That caused some problem while I resolve merge conflict. I believe now everything should be ok. |
Description of work
This PR adds the function of "FilterbyTime to the LoadEventAsWorkspace2D function by introducing two optional input fields: "FilterByTimeStart" and "FilterByTimeStop". If both are left empty, it will by default not apply any filter. If either start or stop is entered, it will filter from start time till end or start till end time.
The functionality is implemented by introducing "BankPulseTime" and "PulseIndexer". Once "FilterByTimeStart" and/or "FilterByTimeStop" are introduced, a TimeROI is created from BankPulseTime, then this TimeROI is used to extract event_index using PulseIndexer, then a for loop is used to loop through the filtered event_index to generate "Y" of workspace.
Related to story 6294
Summary of work
Add FilterByTime functionality similar to the workflow of LoadEventNexus(FilterByTime) + Integeration.
Fixes #xxxx.
Further detail of work
To test:
Run python scripts as below:
ws1 = LoadEventAsWorkspace2D(Filename = "BSS_11841_event.nxs", OutputWorkspace = "outputWS",
FilterByTimeStart = 0.0, FilterByTimeStop = 5.0,
XCenter = 1.54, XWidth = 0.1,
Units = "Wavelength"
)
ws2 = LoadEventNexus(Filename = "BSS_11841_event.nxs", OutputWorkspace ="outputWS2",
FilterByTimeStart = "0.0", FilterByTimeStop = "5.0")
ws3 = Integration(InputWorkspace = "outputWS2", RangeLower = 0.0, OutputWorkspace = "outputWS3")
ws3.getAxis(0).setUnit("Wavelength")
xBins = [1.463, 1.617]
for i in range(ws3.getNumberHistograms()):
ws3.setX(i, xBins)
CompareWorkspaces(ws1,ws3)
Alternatively:
In Mantid, open LoadEventAsWorkspace2D, load mantid/build/ExternalData/Testing/Data/UnitTest/BSS_11841_event.nxs. Set FilteByTimeStart and FilterByTimeStop to specific values(i.e. 0 and 5), set XCenter to 1.54, XWidth to 0.1, units = Wavelength and generate workspace.
Then open LoadEventNexus, load same .nxs file, set FilterByTimeStart/FilterByTimeStop to same values as before and create another workspace. Then use Integration to integrate this workspace, set RangeLower = 0 and generate workspace. Compare the Y values of the workspace. This can be done by plotting the data or look at the data specifically.
Another wayt to test is follow the LoadEventAsWorkspace2DTest.h to directly call LoadEventAsWorkspace2D, LoadEventNexus, Integrate from command line.
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.