Table of Contents
Replaces instances of NaN and infinity in the workspace with user defined numbers. If a replacement value is not provided the check will not occur. This algorithm can also be used to replace numbers whose absolute value is larger than a user-defined threshold.
Name | Direction | Type | Default | Description |
---|---|---|---|---|
InputWorkspace | Input | MatrixWorkspace | Mandatory | The name of the input workspace |
OutputWorkspace | Output | MatrixWorkspace | Mandatory | The name to use for the output workspace (can be the same as the input one). |
NaNValue | Input | number | Optional | The value used to replace occurrences of NaN (default: do not check). |
NaNError | Input | number | 0 | The error value used when replacing a value of NaN |
InfinityValue | Input | number | Optional | The value used to replace occurrences of positive or negative infinity (default: do not check). |
InfinityError | Input | number | 0 | The error value used when replacing a value of infinity |
BigNumberThreshold | Input | number | Optional | The threshold above which a number (positive or negative) should be replaced. (default: do not check) |
BigNumberValue | Input | number | 0 | The value with which to replace occurrences of ‘big’ numbers. |
BigNumberError | Input | number | 0 | The error value used when replacing a ‘big’ number |
SmallNumberThreshold | Input | number | Optional | The threshold below which a number (positive or negative) should be replaced. (default: do not check) |
SmallNumberValue | Input | number | 0 | The value with which to replace occurrences of ‘small’ numbers. |
SmallNumberError | Input | number | 0 | The error value used when replacing a ‘small’ number |
The algorithm searches over all of the values in a workspace and if it finds a value set to NaN (not a number), infinity, larger or smaller than the ‘big’/’small’ threshold given then that value and the associated error is replaced by the user provided values.
If no value is provided for either NaNValue, InfinityValue, BigValueThreshold or SmallValueThreshold then the algorithm will exit with an error, as in this case it would not be checking anything.
The algorithm can also handle event workspaces.
Example
import numpy as np
ws = CreateSampleWorkspace(BankPixelWidth=1)
yArray = np.array(ws.readY(0))
yArray[0] = 8e80
yArray[1] = float("inf")
yArray[2] = float("-inf")
yArray[3] = float("NaN")
yArray[4] = 8e-7
ws.setY(0,yArray)
ws = ReplaceSpecialValues(ws,NaNValue=0,InfinityValue=1000,
BigNumberThreshold=1000, BigNumberValue=1000,
SmallNumberThreshold=1e-6, SmallNumberValue=200)
print "i\tBefore\tAfter"
print "-\t------\t-----"
for i in range(5):
print "%i\t%s\t%s" % (i, yArray[i],ws.readY(0)[i])
Output:
i Before After
- ------ -----
0 8e+80 1000.0
1 inf 1000.0
2 -inf 1000.0
3 nan 0.0
4 8e-07 200.0
import numpy as np
ws = CreateSampleWorkspace(BankPixelWidth=1)
value1 = 1.00000004
value2 = 1.00000003
valueDiff = value1 - value2
wsYArray = np.array(ws.readY(0))
wsYArray[0] = valueDiff
ws.setY(0, wsYArray)
ws = ReplaceSpecialValues(ws, SmallNumberThreshold=1e-6)
print("Before\t\t After")
print("{0}\t{1}".format(wsYArray[0], ws.readY(0)[0]))
Output:
Before After
9.99999993923e-09 0.0
Categories: Algorithms | CorrectionFunctions\SpecialCorrections