Skip to content

Conversation

KyleQianliMa
Copy link
Contributor

@KyleQianliMa KyleQianliMa commented Aug 16, 2024

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

  • 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.

@KyleQianliMa KyleQianliMa added Framework Issues and pull requests related to components in the Framework ORNL Team Issues and pull requests managed by the ORNL development team labels Aug 16, 2024
@KyleQianliMa KyleQianliMa added this to the Release 6.11 milestone Aug 16, 2024
@KyleQianliMa KyleQianliMa self-assigned this Aug 16, 2024
@KyleQianliMa KyleQianliMa requested a review from jmborr August 16, 2024 18:20
Copy link
Member

@jmborr jmborr left a 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?

@KyleQianliMa
Copy link
Contributor Author

in the pull request description, can you write a manual test I can run in the workbench?
I wrote that in the wrong place and it got commented out. Should I also write something that can be directly exectued from commandline of workbench?

@jmborr
Copy link
Member

jmborr commented Aug 16, 2024

in the pull request description, can you write a manual test I can run in the workbench?
I wrote that in the wrong place and it got commented out. Should I also write something that can be directly exectued from commandline of workbench?

Yes, a few python statements that I could execute in the workbench would be best

@KyleQianliMa
Copy link
Contributor Author

KyleQianliMa commented Aug 19, 2024

I've updated the test instructions

Copy link
Member

@jmborr jmborr left a 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?

@KyleQianliMa
Copy link
Contributor Author

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
https://builds.mantidproject.org/job/pull_requests-conda-windows/7015/console

Parsing console log (workspace: '/jenkins_workdir/workspace/pull_requests-conda-windows')
12:35:17 [MSBuild] -> found 1 issue (skipped 0 duplicates)

jmborr
jmborr previously approved these changes Aug 21, 2024
@KyleQianliMa KyleQianliMa mentioned this pull request Aug 21, 2024
@KyleQianliMa
Copy link
Contributor Author

@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.

@peterfpeterson peterfpeterson merged commit 77428f9 into main Aug 22, 2024
11 checks passed
@peterfpeterson peterfpeterson deleted the FilterByTime branch August 22, 2024 14:05
@KyleQianliMa KyleQianliMa restored the FilterByTime branch August 22, 2024 15:16
@KyleQianliMa KyleQianliMa mentioned this pull request Aug 22, 2024
@KyleQianliMa KyleQianliMa deleted the FilterByTime branch August 23, 2024 13:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Framework Issues and pull requests related to components in the Framework ORNL Team Issues and pull requests managed by the ORNL development team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants