-
Notifications
You must be signed in to change notification settings - Fork 2
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
Transfer PV-logs during load of grouping and mask workspaces #539
base: next
Are you sure you want to change the base?
Conversation
This is a supporting PR for the reduction live-data work. The changes here allow all loaded workspaces, with the exception of the input data workspace itself, to be reused from reduction cycle to reduction cycle. During development work, it was found that although Mantid's `LoadDiffCal` allows an instrument to be specified, it does not additionally transfer the relevant instrument PV-logs from the donor workspace. The result of this is that any mask or grouping workspace loaded by SNAPRed would not have a defined stateID-SHA. During the reduction process, pixel-mask compatibility is checked using the combination of the stateID-SHA, and the lite-mode state -- ADS-resident pixel-mask workspaces with no stateID-SHA will be skipped as incompatible. Also found during development work, when the detector positions are compared between workspaces written using `SaveNexus` and read back using `LoadNexus`, they fail to match to the Mantid position and rotation target accuracy. For positions, this accuracy is `1.0e-9`m, and for rotations, it is `1.0e-9`m at `1000.0`m, which corresponds to `1.0e-12` radians. The reason for this readback mismatch has to do with the lack of a precision specification when writing the locations to the _legacy_ 'instrument_parameter_map' (in the NeXus file). Unfortunately, this same legacy system is used to initialize the instrument parameters during reload. This write-precision defect has been separately fixed in another Mantid PR. This current PR adds a temporary work around for this issue. This commit includes the following changes: * `LoadCalibrationWorkspaces` and `LoadGroupingDefinition` algorithms, both of which use Mantid's `LoadDiffCal` algorithm, now transfer the relevent instrument PV-logs to their output workspaces; * Any `FetchGroceriesAlgorithm` loader which goes through the `LoadNexus` pathway, now additionally calls `populateInstrumentParameters` for the output workspace. This bypasses the inaccuracy of the legacy 'instrument_parameter_map', and directly utilizes the PV-log values, which are stored in their binary representation as double-precision values; * General utilities `transferInstrumentPVLogs` and `populateInstrumentParameters` are provided in `snapred.backend.data.util.PV_logs_util`. The `populateInstrumentParameters` utility is a temporary work around, as `ExperimentInfo.populateInstrumentParameters` has now been exposed to the Python API in another Mantid PR.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## next #539 +/- ##
==========================================
- Coverage 95.98% 95.91% -0.07%
==========================================
Files 68 69 +1
Lines 5152 5163 +11
==========================================
+ Hits 4945 4952 +7
- Misses 207 211 +4 ☔ View full report in Codecov by Sentry. |
0517849
to
4e92b71
Compare
for more information, see https://pre-commit.ci
from mantid.simpleapi import AddSampleLog, mtd | ||
|
||
|
||
def transferInstrumentPVLogs(dest: Run, src: Run, keys: Iterable): |
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.
Should this require the Run
objects, or would it be more idiomatic to pass the workspace string names?
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.
If Run
, could some kind of parameter validation be added?
CreateSampleWorkspace( | ||
OutputWorkspace=wsName, | ||
# WorkspaceType="Histogram", | ||
Function="User Defined", | ||
UserDefinedFunction="name=Gaussian,Height=10,PeakCentre=1.2,Sigma=0.2", | ||
Xmin=0, | ||
Xmax=5, | ||
BinWidth=0.001, | ||
XUnit="dSpacing", | ||
NumBanks=4, # must produce same number of pixels as fake instrument | ||
BankPixelWidth=2, # each bank has 4 pixels, 4 banks, 16 total | ||
) | ||
LoadInstrument( | ||
Workspace=wsName, | ||
Filename=Resource.getPath("inputs/testInstrument/fakeSNAP_Definition.xml"), | ||
RewriteSpectraMap=True, | ||
) |
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.
Isn't there a helper for this?
Description of work
This is a supporting PR for the reduction live-data work. The changes here allow all loaded workspaces, with the exception of the input data workspace itself, to be reused from reduction cycle to reduction cycle.
During development work, it was found that although Mantid's
LoadDiffCal
allows an instrument to be specified, it does not additionally transfer the relevant instrument PV-logs from the donor workspace. The result of this is that any mask or grouping workspace loaded by SNAPRed would not have a defined stateID-SHA. During the reduction process, pixel-mask compatibility is checked using the combination of the stateID-SHA, and the lite-mode state -- ADS-resident pixel-mask workspaces with no stateID-SHA will be skipped as incompatible.Also found during development work, when the detector positions are compared between workspaces written using
SaveNexus
and read back usingLoadNexus
, they fail to match to the Mantid position and rotation target accuracy. For positions, this accuracy is1.0e-9
m, and for rotations, it is1.0e-9
m at1000.0
m, which corresponds to1.0e-12
radians. The reason for this readback mismatch has to do with the lack of a precision specification when writing the locations to the legacy 'instrument_parameter_map' (in the NeXus file). Unfortunately, this same legacy system is used to initialize the instrument parameters during reload. This write-precision defect has been separately fixed in another Mantid PR. This current PR adds a temporary work around for this issue.Explanation of work
This commit includes the following changes:
LoadCalibrationWorkspaces
andLoadGroupingDefinition
algorithms, both of which use Mantid'sLoadDiffCal
algorithm, now transfer the relevent instrument PV-logs to their output workspaces;Any
FetchGroceriesAlgorithm
loader which goes through theLoadNexus
pathway, now additionally callspopulateInstrumentParameters
for the output workspace. This bypasses the inaccuracy of the legacy 'instrument_parameter_map', and directly utilizes the PV-log values, which are stored in their binary representation as double-precision values;General utilities
transferInstrumentPVLogs
andpopulateInstrumentParameters
are provided insnapred.backend.data.util.PV_logs_util
. ThepopulateInstrumentParameters
utility is a temporary work around, asExperimentInfo.populateInstrumentParameters
has now been exposed to the Python API in another Mantid PR.To test
Additional unit tests have been added to test the new
PV_logs_util
.Current unit tests have also been adjusted to cover this work. Mostly these adjustments involved adding a more-complete instrument to initialization to the workspaces used in the
GroceryService
tests.CIS testing
This is a SNAPRed internal item. It can be evaluated as part of the reduction live-data work.
Link to EWM item
Note that there is NO EWM item for this PR specifically. These defects were fixed in support of the reduction live-data work.
EWM#7437