ConvertAxisByFormula v1

../_images/ConvertAxisByFormula-v1_dlg.png

ConvertAxisByFormula dialog.

Summary

Converts the X or Y axis of a MatrixWorkspace via a user defined math formula.

Properties

Name Direction Type Default Description
InputWorkspace Input MatrixWorkspace Mandatory Name of the input workspace
OutputWorkspace Output MatrixWorkspace Mandatory Name of the output workspace
Axis Input string X The axis to modify. Allowed values: [‘X’, ‘Y’]
Formula Input string   The formula to use to convert the values, x or y may be used to refer to the axis values
AxisTitle Input string   The label of he new axis. If not set then the title will not change.
AxisUnits Input string   The units of the new axis. If not set then the unit will not change

Description

This algorithm allows users to adjust the axes of a workspace by a user defined math formula. It will NOT adjust or rearrange the data values (other than in one case the X values) of a workspace. Therefore alterations that will rearrange the order of the axes are not recommended. This only works for MatrixWorkspaces, so will not work on Multi Dimensional Workspaces or Table Workspaces. Like the ConvertSpectrumAxis v2 algorithm the result of this algorithm will have custom units defined for the axis you have altered, and as such may not work in all other algorithms.

The algorithm can operate on the X or Y axis, but cannot alter the values of a spectrum axis (the axis used as the Y axis on newly loaded Raw data). If you wish to alter this axis use the ConvertSpectrumAxis v2 algorithm first.

The formula is defined in a simple math syntax. For example:

  • Squaring - x^2
  • Square root - sqrt(x)
  • Cubing - x^3
  • Basic addition - y + 3
  • Brackets - (y+1)/20
  • Natural Log - ln(x)
  • Log 10 - log(x)
  • Exponent - exp(y)
  • Round to nearest integer - rint(y/10)
  • Absolute value - abs(y-100)

x and y can be used interchangeably to refer to the current axis value.

Refer to the muparser page for a full list of the functions available.

Usage

Example - Squaring the X axis:

# Create sample input workspace
dataX = [1,2,3,4,5]
dataY = [1,1,1,1,1]
input = CreateWorkspace(dataX, dataY)

output = ConvertAxisByFormula(InputWorkspace=input,
                              Axis="X",
                              Formula="x^2",
                              AxisTitle="Squared X",
                              AxisUnits="x^2")

print "New X values:", output.getAxis(0).extractValues()
print "New X units:", output.getAxis(0).getUnit().symbol()
print "New X title:", output.getAxis(0).getUnit().caption()

Output:

New X values: [  1.   4.   9.  16.  25.]
New X units: x^2
New X title: Squared X

Example - Doubling the Y axis:

from mantid.api import NumericAxis

# Create sample input workspace (with 5 spectra)
dataX = [1,2,3,4,5]
dataY = [1,1,1,1,1]
input = CreateWorkspace(dataX, dataY, NSpec=5)

# Create numeric Y axis with values [1..5]
yAxis = NumericAxis.create(5)
for i in range(0,5):
  yAxis.setValue(i, i+1)

# Replace Y axis in the input workspace. This is necessary because CreateWorkspace
# uses TextAxis by default, which are not suitable for conversion.
input.replaceAxis(1, yAxis)

output = ConvertAxisByFormula(InputWorkspace=input,
                              Axis="Y",
                              Formula="y*2",
                              AxisTitle="Doubled Y",
                              AxisUnits="y*2")

print "New Y values:", output.getAxis(1).extractValues()
print "New Y units:", output.getAxis(1).getUnit().symbol()
print "New Y title:", output.getAxis(1).getUnit().caption()

Output:

New Y values: [  2.   4.   6.   8.  10.]
New Y units: y*2
New Y title: Doubled Y

Categories: Algorithms | Transforms | Axes