RotateSource v1

../_images/RotateSource-v1_dlg.png

RotateSource dialog.

Summary

Rotates the source by a given angle

Properties

Name Direction Type Default Description
Workspace InOut Workspace Mandatory The name of the workspace for which the new instrument configuration will have an effect. Any other workspaces stored in the analysis data service will be unaffected.
Angle Input number 0 The angle of rotation in degrees (according to the handedness of the coordinate system.

Description

This algorithm corrects the source’s position by rotating it around an axis centered at the sample. The rotation axis is perpendicular to the plane determined by the beam direction and the up direction. The handedness of the coordinate system is considered to determine whether a positive/negative angle corresponds to a clockwise or counterclockwise rotation.

Usage

Example - RotateSource

# Create a workspace with a simple instrument
ws = CreateSampleWorkspace()

# Original positions
samplePos = ws.getInstrument().getSample().getPos()
sourcePos = ws.getInstrument().getSource().getPos()

def pos3D_as_str(pos, digits=1, tolerance=1e-7):
  """
  Produce a string with a human readable version of a V3D position (x, y, z),
  from a V3D object, using a fixed limited number of digits (for robust string
  comparisons).
  """
  def nz(value):
     """ Handles potential issues with +-0 (tiny values) """
     return 0.0 if abs(value) < tolerance else value

  precision = str(digits)
  format_str = '[{0:.'+precision+'f}, {1:.'+precision+'f}, {2:.'+precision+'f}]'
  result = format_str.format(nz(pos.getX()), nz(pos.getY()), nz(pos.getZ()))
  return result

print("Original position of the sample: {0}".format(pos3D_as_str(samplePos)))
print("Original position of the source: {0}".format(pos3D_as_str(sourcePos)))

# Move (rotate) the source around X axis
RotateSource(ws, -90)

# New positions
samplePos = ws.getInstrument().getSample().getPos()
sourcePos = ws.getInstrument().getSource().getPos()
print("New position of the sample: {0}".format(pos3D_as_str(samplePos)))
print("New position of the source: {0}".format(pos3D_as_str(sourcePos)))

Output:

Original position of the sample: [0.0, 0.0, 0.0]
Original position of the source: [0.0, 0.0, -10.0]
New position of the sample: [0.0, 0.0, 0.0]
New position of the source: [0.0, 10.0, 0.0]

Categories: AlgorithmIndex | DataHandling\Instrument

Source

C++ source: RotateSource.cpp (last modified: 2019-06-04)

C++ header: RotateSource.h (last modified: 2018-10-05)