ThresholdMD v1#
Summary#
Threshold an MDHistoWorkspace.
See Also#
Properties#
Name |
Direction |
Type |
Default |
Description |
|---|---|---|---|---|
InputWorkspace |
Input |
IMDHistoWorkspace |
Mandatory |
An input workspace. |
Condition |
Input |
string |
Less Than |
Selected threshold condition. Any value which does meet this condition with respect to the ReferenceValue will be overwritten. Allowed values: [‘Less Than’, ‘Greater Than’] |
ReferenceValue |
Input |
number |
0 |
Comparator value used by the Condition. |
OverwriteWithZero |
Input |
boolean |
True |
Flag for enabling overwriting with a custom value. Defaults to overwrite signals with zeros. |
CustomOverwriteValue |
Input |
number |
0 |
Custom overwrite value for the signal. Defaults to zero. |
OutputWorkspace |
Output |
IMDHistoWorkspace |
Mandatory |
Output thresholded workspace. |
Description#
This algorithm applies a simple linear transformation to a MDWorkspace or MDHistoWorkspace. This could be used, for example, to scale the Energy dimension to different units.
Each coordinate is transformed so that \(x'_d = (x_d * s_d) + o_d\) where:
d : index of the dimension, from 0 to the number of dimensions
s : value of the Scaling parameter
o : value of the Offset parameter.
You can specify either a single value for Scaling and Offset, in which case the same m_scaling or m_offset are applied to each dimension; or you can specify a list with one entry for each dimension.
Notes#
The relationship between the workspace and the original MDWorkspace, for example when the MDHistoWorkspace is the result of BinMD v1, is lost. This means that you cannot re-bin a transformed MDHistoWorkspace.
No units are not modified by this algorithm.
Performance Notes#
Performing the operation in-place (input=output) is always faster because the first step of the algorithm if NOT in-place is to clone the original workspace.
For MDHistoWorkspaces done in-place, TransformMD is very quick (no data is modified, just the coordinates).
For MDWorkspaces, every event’s coordinates gets modified, so this may take a while for large workspaces.
For file-backed MDWorkspaces, you will find much better performance if you perform the change in-place (input=output), because the data gets written out to disk twice otherwise.
Usage#
Example - Threshold a small workspace:
# Create input workspace
CreateMDWorkspace(Dimensions=3, Extents='-10,10,-10,10,-10,10', Names='A,B,C', Units='U,U,U', OutputWorkspace='demo')
FakeMDEventData(InputWorkspace='demo', PeakParams='32,0,0,0,1')
threshold_input = BinMD(InputWorkspace='demo', AlignedDim0='A,-2,2,4', AlignedDim1='B,-2,2,4', AlignedDim2='C,-2,2,4')
# Run the algorithm to set all values greater than 4 to zero
threshold_output = ThresholdMD(InputWorkspace='threshold_input', Condition='Greater Than', ReferenceValue=4)
# Print selection before and after
print("selected bins before threshold greater than 4 {}".format(threshold_input.getSignalArray()[1,1]))
print("same bins after threshold greater than 4 {}".format(threshold_output.getSignalArray()[1,1]))
Output:
selected bins before threshold greater than 4 [0. 5. 4. 0.]
same bins after threshold greater than 4 [0. 0. 4. 0.]
Categories: AlgorithmIndex | MDAlgorithms\Transforms
Source#
C++ header: ThresholdMD.h
C++ source: ThresholdMD.cpp