Skip to content

Commit

Permalink
refs #11304. Add example docs
Browse files Browse the repository at this point in the history
Also move the test and fix some of the code along the way.
  • Loading branch information
OwenArnold committed Apr 1, 2015
1 parent 3eb662f commit 5a1db12
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 17 deletions.
Expand Up @@ -79,7 +79,7 @@ def _merge_runs(self, to_merge):
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):
Expand All @@ -96,6 +96,7 @@ def _single_run(self, input_workspace, emode, psi, gl, gs, alatt=None, angdeg=N

output_run = self._convert_to_md(workspace=input_workspace, analysis_mode=emode)
return output_run


def category(self):
return 'MDAlgorithms'
Expand Down Expand Up @@ -180,22 +181,22 @@ def PyExec(self):
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

Expand Down
Expand Up @@ -11,7 +11,6 @@ set ( TEST_PY_FILES
AxisTest.py
CatalogManagerTest.py
CutMDTest.py
CreateMDTest.py
DataProcessorAlgorithmTest.py
DeprecatedAlgorithmCheckerTest.py
ExperimentInfoTest.py
Expand Down
Expand Up @@ -9,6 +9,7 @@ set ( TEST_PY_FILES
CorrectLogTimesTest.py
CreateLeBailFitInputTest.py
CreateCalibrationWorkspaceTest.py
CreateMDTest.py
CreateWorkspaceTest.py
DakotaChiSquaredTest.py
DensityOfStatesTest.py
Expand Down
70 changes: 60 additions & 10 deletions Code/Mantid/docs/source/algorithms/CreateMD-v1.rst
Expand Up @@ -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
Expand All @@ -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 comments on commit 5a1db12

Please sign in to comment.