Skip to content
Snippets Groups Projects
Commit 5a1db129 authored by Owen Arnold's avatar Owen Arnold
Browse files

refs #11304. Add example docs

Also move the test and fix some of the code along the way.
parent 3eb662f8
No related branches found
No related tags found
No related merge requests found
......@@ -79,7 +79,7 @@ class CreateMD(DataProcessorAlgorithm):
def _single_run(self, input_workspace, emode, psi, gl, gs, alatt=None, angdeg=None, u=None, v=None,):
import numpy as np
ub_params = map(any, [alatt, angdeg, u, v])
goniometer_params = map(lambda x : x != None, [psi, gl, gs])
goniometer_params = [psi, gl, gs]
if any(ub_params) and not all(ub_params):
raise ValueError("Either specify all of alatt, angledeg, u, v or none of them")
elif all(ub_params):
......@@ -96,6 +96,7 @@ class CreateMD(DataProcessorAlgorithm):
output_run = self._convert_to_md(workspace=input_workspace, analysis_mode=emode)
return output_run
def category(self):
return 'MDAlgorithms'
......@@ -180,22 +181,22 @@ class CreateMD(DataProcessorAlgorithm):
psi = self.getProperty('Psi').value
gl = self.getProperty('Gl').value
gs = self.getProperty('Gs').value
input_workspaces = self.getProperty("InputWorkspaces").value
ws_entries = len(input_workspaces)
self._validate_inputs()
if not psi:
if len(psi) == 0:
psi = [None] * ws_entries
if not gl:
if len(gl) == 0:
gl = [None] * ws_entries
if not gs:
if len(gs) == 0:
gs = [None] * ws_entries
output_workspace = None
run_md = None
......
......@@ -11,7 +11,6 @@ set ( TEST_PY_FILES
AxisTest.py
CatalogManagerTest.py
CutMDTest.py
CreateMDTest.py
DataProcessorAlgorithmTest.py
DeprecatedAlgorithmCheckerTest.py
ExperimentInfoTest.py
......
......@@ -9,6 +9,7 @@ set ( TEST_PY_FILES
CorrectLogTimesTest.py
CreateLeBailFitInputTest.py
CreateCalibrationWorkspaceTest.py
CreateMDTest.py
CreateWorkspaceTest.py
DakotaChiSquaredTest.py
DensityOfStatesTest.py
......
......@@ -9,26 +9,26 @@
Description
-----------
This workflow algorithm creates MDWorkspaces in the Q3D, HKL frame using `ConvertToMD <http://www.mantidproject.org/ConvertToMD>`__.
This workflow algorithm creates MDWorkspaces in the Q3D, HKL frame using :ref:`algm-ConvertToMD`.
Setting the UB matrix
######################################
*u* and *v* are required. *u* and *v* are both 3-element vectors. These specify how the crystal's axes were oriented relative to the spectrometer in the setup for which you define psi to be zero. *u* specifies the lattice vector that is parallel to the incident neutron beam, whilst *v* is a vector perpendicular to this in the horizontal plane. In UB matrix notation, *u* and *v* provide the U matrix. See `SetUB <http://www.mantidproject.org/SetUB>`__. *Alatt* and *Angdeg* are the lattice parameters in Angstroms and lattice angles in degrees respectively. Both are 3-element vectors. These form the B-matrix.
*u* and *v* are required. *u* and *v* are both 3-element vectors. These specify how the crystal's axes were oriented relative to the spectrometer in the setup for which you define psi to be zero. *u* specifies the lattice vector that is parallel to the incident neutron beam, whilst *v* is a vector perpendicular to this in the horizontal plane. In UB matrix notation, *u* and *v* provide the U matrix. See :ref:`algm-SetUB`. *Alatt* and *Angdeg* are the lattice parameters in Angstroms and lattice angles in degrees respectively. Both are 3-element vectors. These form the B-matrix.
Goniometer Settings
#####################
If goniometer settings have been provided then these will be applied to the input workspace(s). For multiple input workspaces, you will need to provide goniometer settings (*Psi*, *Gl*, *Gs*) as vectors where each element of the vector corresponds to the workspace in the order listed in *InputWorkspaces*. You do not need to provide the goniometer settings at all. If you run `SetGoniometer <http://www.mantidproject.org/SetGoniometer>`__ individually on the input workspace prior to running CreateMD, then those settings will not be overwritten by CreateMD.
If goniometer settings have been provided then these will be applied to the input workspace(s). For multiple input workspaces, you will need to provide goniometer settings (*Psi*, *Gl*, *Gs*) as vectors where each element of the vector corresponds to the workspace in the order listed in *InputWorkspaces*. You do not need to provide the goniometer settings at all. If you run :ref:`algm-SetGoniometer` individually on the input workspace prior to running CreateMD, then those settings will not be overwritten by CreateMD.
Merging Individually Converted Runs
#####################################
If a sequence of input workspaces are provided then these are individually processed as above, and are merged together via `MergeMD <http://www.mantidproject.org/MergeMD>`__. Intermediate workspaces are not kept.
If a sequence of input workspaces are provided then these are individually processed as above, and are merged together via :ref:`algm-MergeMD`. Intermediate workspaces are not kept.
Additional Information
#######################
CreateMD uses `ConvertToMDMinMaxLocal <http://www.mantidproject.org/ConvertToMDMinMaxLocal>`__ to determine the min and max extents prior to running `ConvertToMD <http://www.mantidproject.org/ConvertToMD>`__ on each run.
CreateMD steps use :ref:`algm-ConvertToMDMinMaxGlobal` to determine the min and max possible extents prior to running :ref:`algm-ConvertToMD` on each run.
.. figure:: /images/HoraceOrientation.png
......@@ -37,19 +37,69 @@ CreateMD uses `ConvertToMDMinMaxLocal <http://www.mantidproject.org/ConvertToMDM
`Horace <http://horace.isis.rl.ac.uk/Generating_SQW_files>`__ style orientation used by CreateMD. DSPI and Omega in the image have no meaning in Mantid and are not required by this algorithm.
*Example*
**Single Conversion Example**
##########################################
.. testcode:: CreateMDExample
.. testcode:: SingleConversion
print 'Hello World'
# Create some input data.
current_ws = CreateSimulationWorkspace(Instrument='MAR', BinParams=[-3,1,3], UnitX='DeltaE')
AddSampleLog(Workspace=current_ws,LogName='Ei',LogText='3.0',LogType='Number')
# Execute CreateMD
new_mdew = CreateMD(current_ws, Emode='Direct', Alatt=[1.4165, 1.4165,1.4165], Angdeg=[ 90, 90, 90], u=[1, 0, 0,], v=[0,1,0], Psi=6, Gs=0, Gl=[0])
# Show dimensionality and dimension names
ndims = new_mdew.getNumDims()
for i in range(ndims):
dim = new_mdew.getDimension(i)
print dim.getName()
Output
^^^^^^
.. testoutput:: CreateMDExample
.. testoutput:: SingleConversion
[H,0,0]
[0,K,0]
[0,0,L]
DeltaE
**Multi Conversion Example**
##########################################
.. testcode:: MultiConversion
# Create multiple runs
input_runs = list()
psi = list()
gs = list()
gl = list()
for i in range(1, 5):
current_ws = CreateSimulationWorkspace(Instrument='MAR', BinParams=[-3,1,3], UnitX='DeltaE', OutputWorkspace='input_ws_' + str(i))
input_runs.append(current_ws.name())
AddSampleLog(Workspace=current_ws,LogName='Ei',LogText='3.0',LogType='Number')
psi.append(float(5 * i))
gl.append(0.0)
gs.append(0.0)
# Convert and merge
new_merged = CreateMD(input_runs, Emode='Direct', Alatt=[1.4165, 1.4165,1.4165], Angdeg=[ 90, 90, 90], u=[1, 0, 0,], v=[0,1,0], Psi=psi, Gl=gl, Gs=gs)
# Show dimensionality and dimension names
ndims = new_merged.getNumDims()
for i in range(ndims):
dim = new_merged.getDimension(i)
print dim.getName()
Output
^^^^^^
'Not implemented yet'
.. testoutput:: MultiConversion
[H,0,0]
[0,K,0]
[0,0,L]
DeltaE
.. categories::
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment