Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/feature/9567_rst_doc'
Browse files Browse the repository at this point in the history
  • Loading branch information
mantid-roman committed Jun 24, 2014
2 parents 16917ab + f47ef9f commit 040e360
Show file tree
Hide file tree
Showing 20 changed files with 3,324 additions and 0 deletions.
55 changes: 55 additions & 0 deletions Code/Mantid/docs/source/algorithms/ApplyCalibration-v1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,59 @@ to the Detector ID and the enties of the *Detector Position* are
`V3Ds <V3D>`__ referring to the position of the detector whose ID is in
same row.

This algorithm is not appropriate for rectangular detectors and won't move them.

Usage
-----
**Example - move three detectors to specified positions that would be got from calibration**

.. testcode:: ExApplyCalibSimple

from mantid.kernel import V3D
# Create Workspace with instrument
# We use HRP workspace, which has detectors that are not rectangular.
ws = Load("HRP39180.RAW")

spectra = [0, 1, 3] # Spectra of detectors to be moved

# Show positions before calibration
for i in spectra:
det = ws.getDetector(i)
print "Position of Detector ID=%i before ApplyCalibration: %.0f,%.0f,%.0f" % (det.getID(),
det.getPos().X(), det.getPos().Y(), det.getPos().Z())


# Create PositionTable - This would be done by the calibration functions
calibTable = CreateEmptyTableWorkspace(OutputWorkspace="CalibTable")
# Add required columns
calibTable.addColumn(type="int",name="Detector ID")
calibTable.addColumn(type="V3D",name="Detector Position")
# Populate the columns for three detectors
detIDList = [ ws.getDetector(spectra[0]).getID(), ws.getDetector(spectra[1]).getID(), ws.getDetector(spectra[2]).getID() ]
detPosList = [ V3D(9.0,0.0,0.0), V3D(10.0,3.0,0.0), V3D(12.0,3.0,6.0)]
for j in range(len(detIDList)):
nextRow = {'Detector ID': detIDList[j], 'Detector Position': detPosList[j] }
calibTable.addRow ( nextRow )


# Apply Calibration to Workspace
ApplyCalibration ( Workspace=ws, PositionTable=calibTable)

# Show positions after calibration
for i in spectra:
det = ws.getDetector(i)
print "Position of Detector ID=%i after ApplyCalibration: %.0f,%.0f,%.0f" % (det.getID(),
det.getPos().X(), det.getPos().Y(), det.getPos().Z())

Output:

.. testoutput:: ExApplyCalibSimple

Position of Detector ID=1100 before ApplyCalibration: 0,0,-1
Position of Detector ID=1101 before ApplyCalibration: 0,0,-1
Position of Detector ID=1103 before ApplyCalibration: 0,0,-1
Position of Detector ID=1100 after ApplyCalibration: 9,0,0
Position of Detector ID=1101 after ApplyCalibration: 10,3,0
Position of Detector ID=1103 after ApplyCalibration: 12,3,6

.. categories::
22 changes: 22 additions & 0 deletions Code/Mantid/docs/source/algorithms/ApplyDetailedBalance-v1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,26 @@ vol 1
[2] I. A. Zaliznyak and S. H. Lee - Magnetic Neutron Scattering in
"Modern techniques for characterizing magnetic materials"

Usage
-----

**Example - Run LoadprofResolution for both TableWorkspace and workspace with XX Instrument**

.. testcode:: ExApplyDetailedBalanceSimple

ws = CreateWorkspace(DataX='-5,-4,-3,-2,-1,0,1,2,3,4,5',DataY='2,2,2,2,2,2,2,2,2,2',DataE='1,1,1,1,1,1,1,1,1,1',UnitX='DeltaE')
ows = ApplyDetailedBalance(InputWorkspace='ws',OutputWorkspace='ows',Temperature='100')

print "The Y values in the Output Workspace are"
print str(ows.readY(0)[0:5])
print str(ows.readY(0)[5:10])

Output:

.. testoutput:: ExApplyDetailedBalanceSimple

The Y values in the Output Workspace are
[-4.30861792 -3.14812682 -2.11478496 -1.19466121 -0.37535083]
[ 0.35419179 1.00380206 1.58223777 2.09729717 2.55592407]

.. categories::
53 changes: 53 additions & 0 deletions Code/Mantid/docs/source/algorithms/CopyInstrumentParameters-v1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,57 @@ workspace.
Does not work on workspaces with grouped detectors if some of the
detectors were calibrated.

Usage
-----
**Example - Copy parameters that contain the movement of 3 detectors**

.. testcode:: ExCopyInstrumentParametersSimple

# We load two workspaces with same instument
# the first of which has had come detectors moved by calibration.
# The run CopyInstrumentParameters and show that the same detectors have been moved.
#
# We use HRPD workspaces, which have detectors that are not rectangular.
ws1 = Load("HRP38094Calib.nxs")
ws2 = Load("HRP39180.RAW")

spectra = [0, 1, 3] # Sprectra of detectors moved

# Show positions in 1st workspace
for i in spectra:
det = ws1.getDetector(i)
print "Position of Detector ID=%i in 1st workspace: %.0f,%.0f,%.0f" % (det.getID(),
det.getPos().X(), det.getPos().Y(), det.getPos().Z())

# Show positions in 2nd workspace before CopyInstrumrentParameters
for i in spectra:
det = ws2.getDetector(i)
print "Position of Detector ID=%i in 2nd workspace before CopyInstrumentParameters: %.0f,%.0f,%.0f" % (det.getID(),
det.getPos().X(), det.getPos().Y(), det.getPos().Z())


# Copy paremeters from 1st workspace to 2nd workspace
CopyInstrumentParameters( ws1, ws2 )


# Show positions in 2nd workspace after CopyInstrumrentParameters
for i in spectra:
det = ws2.getDetector(i)
print "Position of Detector ID=%i in 2nd workspace after CopyInstrumentParameters: %.0f,%.0f,%.0f" % (det.getID(),
det.getPos().X(), det.getPos().Y(), det.getPos().Z())

Output:

.. testoutput:: ExCopyInstrumentParametersSimple

Position of Detector ID=1100 in 1st workspace: 9,0,0
Position of Detector ID=1101 in 1st workspace: 10,3,0
Position of Detector ID=1103 in 1st workspace: 12,3,6
Position of Detector ID=1100 in 2nd workspace before CopyInstrumentParameters: 0,0,-1
Position of Detector ID=1101 in 2nd workspace before CopyInstrumentParameters: 0,0,-1
Position of Detector ID=1103 in 2nd workspace before CopyInstrumentParameters: 0,0,-1
Position of Detector ID=1100 in 2nd workspace after CopyInstrumentParameters: 9,0,0
Position of Detector ID=1101 in 2nd workspace after CopyInstrumentParameters: 10,3,0
Position of Detector ID=1103 in 2nd workspace after CopyInstrumentParameters: 12,3,6

.. categories::
33 changes: 33 additions & 0 deletions Code/Mantid/docs/source/algorithms/CreateCalFileByNames-v1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,37 @@ both assembly names are given in the GroupNames, they will get assigned
different grouping numbers. This allows to isolate a particular
sub-assembly of a particular leaf of the tree.

Usage
-----
**Example - create cal file from GEM instrument**

.. testcode:: ExCreateCalFileByNamesSimple

import os

# Prepare output file
newFile = os.path.join(os.path.expanduser("~"), "output.cal")

# Create test workspace. Normally just use reduced one
GEM = LoadEmptyInstrument(Filename="GEM_Definition.xml")

# Run the algorithm
CreateCalFileByNames("GEM",newFile,"bank1,bank2,module1")


# Check the output file
print "File Exists:", os.path.exists(newFile)

Output:

.. testoutput:: ExCreateCalFileByNamesSimple

File Exists: True

.. testcleanup:: ExCreateCalFileByNamesSimple

os.remove( newFile )



.. categories::
47 changes: 47 additions & 0 deletions Code/Mantid/docs/source/algorithms/CreateDummyCalFile-v1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,51 @@ specified.
Detectors will be assigned to group one when using AlignDetector or
DiffractionFocussing algorithms.

Usage
-----
**Example - CreateDummyCalFile for MUSR**

.. testcode:: ExCreateDummyCalFileSimple

import os

result = Load("MUSR00015189")
group = result[0]
ws_1 = group[0]
ws_2 = group[1]

newFile = os.path.join(os.path.expanduser("~"), "dummy.cal")

# Run the Algorithm
CreateDummyCalFile(ws_1,newFile)

# Check the output file
print "File Exists:", os.path.exists(newFile)

f = open( newFile, 'r' )
file = f.read().split('\n')
f.close()

for line in file[0:6]:
# print the line truncating before system dependent line break can take effect
# also stripping off any trailing spaces
print line[0:89].rstrip()

Output:

.. testoutput:: ExCreateDummyCalFileSimple

File Exists: True
# Diffraction focusing calibration file created by Mantid
# Detectors have been grouped using assembly names:MUSR
# No template file, all offsets set to 0.0 and select to 1
# Number UDET offset select group
0 33 0.0000000 1 1
1 34 0.0000000 1 1

.. testcleanup:: ExCreateDummyCalFileSimple

os.remove( newFile )


.. categories::
63 changes: 63 additions & 0 deletions Code/Mantid/docs/source/algorithms/CreateGroupingWorkspace-v1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,67 @@ If the GroupNames parameter is given, the names of banks matching the
comma-separated strings in the parameter will be used to sequentially
number the groups in the output.

Usage
-----
**Example - CreateGoupingWorkspace for MUSR Instrument**

.. testcode:: ExCreateGroupingWorkspaceSimple

# Run algorithm with instrument specified
result = CreateGroupingWorkspace(InstrumentName="MUSR")

# Confirm instrument in grouping workspace.
grouping = result[0]
inst1 = grouping.getInstrument()
comp1 = inst1.getComponentByName("MUSR")
print "Instrument name =", comp1.getName()

Output:

.. testoutput:: ExCreateGroupingWorkspaceSimple

Instrument name = MUSR

**Example - CreateGoupingWorkspace from MUSR workspace**

.. testcode:: ExCreateGroupingWorkspaceFromWorkspace

# Create Workspace
load_result = Load("MUSR00015189")
group = load_result[0]
ws_1 = group[0]

# Run algorithm with workspace
result = CreateGroupingWorkspace(InputWorkspace=ws_1)

# Confirm instrument in grouping workspace.
grouping = result[0]
inst1 = grouping.getInstrument()
comp1 = inst1.getComponentByName("MUSR")
print "Instrument name =", comp1.getName()

Output:

.. testoutput:: ExCreateGroupingWorkspaceFromWorkspace

Instrument name = MUSR
**Example - CreateGoupingWorkspace from GEM Instrument Definition**

.. testcode:: ExCreateGroupingWorkspaceFromIDF

# Run algorithm with Instrument Definition File
result = CreateGroupingWorkspace(InstrumentFilename="GEM_Definition.xml")

# Confirm instrument in grouping workspace.
grouping = result[0]
inst1 = grouping.getInstrument()
comp1 = inst1.getComponentByName("GEM")
print "Instrument name =", comp1.getName()

Output:

.. testoutput:: ExCreateGroupingWorkspaceFromIDF

Instrument name = GEM

.. categories::
28 changes: 28 additions & 0 deletions Code/Mantid/docs/source/algorithms/LoadFullprofResolution-v1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,32 @@ limitted to Fullprof:
Note for NPROF=9 the translation is currently ignoring the Lorentzian
part of the pseudo-Voigt.

Usage
-----

**Example - Run LoadprofResolution for both TableWorkspace and workspace with MUSR Instrument**

.. testcode:: ExLoadFullprofResolutionSimple

# We run LoadFullprof Resolution with both the OutputTable workspace
# and an appropriate output workspace (group of 2)
# selecting 2 banks from the IRF file
ws = Load("MUSR00015189")

tws = LoadFullprofResolution("MUSR_01.irf",Banks="3,5", Workspace="ws")

#Print first four rows
for i in [0,1,2,3]:
row = tws.row(i)
print "{'Name': '%s', 'Value_3': %.2f, 'Value_5': %.2f}" % ( row["Name"], row["Value_3"], row["Value_5"] )

Output:

.. testoutput:: ExLoadFullprofResolutionSimple

{'Name': 'BANK', 'Value_3': 3.00, 'Value_5': 5.00}
{'Name': 'Alph0', 'Value_3': 1.60, 'Value_5': 1.61}
{'Name': 'Alph1', 'Value_3': 1.50, 'Value_5': 1.30}
{'Name': 'Beta0', 'Value_3': 33.57, 'Value_5': 37.57}

.. categories::
27 changes: 27 additions & 0 deletions Code/Mantid/docs/source/algorithms/LoadGSASInstrumentFile-v1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,31 @@ pseudo-Voigt translated into `IkedaCarpenterPV <IkedaCarpenterPV>`__ or
back-to-back-exponential pseudo-Voigt translated into
`BackToBackExponential <BackToBackExponential>`__.


Usage
-----

**Example - Run LoadGSASInstrumentFile for both TableWorkspace and workspace with Instrument**

.. testcode:: ExLoadGSASInstrumentFileSimple

# We load a GSAS Instrument file with 2 Banks
# which will suit MUSR00015189 at a later stage of devolpment

tws = LoadGSASInstrumentFile("GSAS_2bank.prm")

#Print first four rows
for i in [0,1,2,3]:
row = tws.row(i)
print "{'Name': '%s','Value_1': %.2f, 'Value_2': %.2f}" % ( row["Name"], row["Value_1"], row["Value_2"] )

Output:

.. testoutput:: ExLoadGSASInstrumentFileSimple

{'Name': 'BANK','Value_1': 1.00, 'Value_2': 2.00}
{'Name': 'Alph0','Value_1': 0.00, 'Value_2': 0.00}
{'Name': 'Alph1','Value_1': 0.21, 'Value_2': 0.22}
{'Name': 'Beta0','Value_1': 31.79, 'Value_2': 31.79}

.. categories::
Loading

0 comments on commit 040e360

Please sign in to comment.