Skip to content

Commit

Permalink
Refs #9584 Add fix broken usage examples.
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuel Jackson committed Jun 9, 2014
1 parent 76db215 commit aa38056
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 32 deletions.
41 changes: 29 additions & 12 deletions Code/Mantid/docs/source/algorithms/GeneratePythonScript-v1.rst
Expand Up @@ -26,7 +26,7 @@ Usage
ws = RenameWorkspace(ws, OutputWorkspace="MyTestWorkspace")

script_text = GeneratePythonScript(ws)
print script_text
print script_text.strip()

Output:

Expand All @@ -40,10 +40,23 @@ Output:
Power(InputWorkspace='ws',OutputWorkspace='ws',Exponent='1.5')
RenameWorkspace(InputWorkspace='ws',OutputWorkspace='MyTestWorkspace')

.. testcleanup:: ExGeneratePythonScriptSimple

import os
def removeFiles(files):
for ws in files:
try:
path = os.path.join(config['defaultsave.directory'], ws)
os.remove(path)
except:
pass

removeFiles(['myscript.py'])


**Example - generate a python script and save it to file:**

.. testcode:: ExGeneratePythonScriptSimple
.. testcode:: ExGeneratePythonScriptFile

#create a workspace and run some operations on it
ws = CreateSampleWorkspace()
Expand All @@ -54,18 +67,11 @@ Output:
GeneratePythonScript(ws, Filename='myscript.py')

with open ('myscript.py', 'r') as script:
print script.read()

.. testcleanup:: ExGeneratePythonScriptSimple
import os
try:
os.remove('myscript.py')
except:
pass
print script.read().strip()

Output:

.. testoutput:: ExGeneratePythonScriptSimple
.. testoutput:: ExGeneratePythonScriptFile

######################################################################
#Python Script Generated by GeneratePythonScript Algorithm
Expand All @@ -75,6 +81,17 @@ Output:
Power(InputWorkspace='ws',OutputWorkspace='ws',Exponent='1.5')
RenameWorkspace(InputWorkspace='ws',OutputWorkspace='MyTestWorkspace')


.. testcleanup:: ExGeneratePythonScriptFile

import os
def removeFiles(files):
for ws in files:
try:
path = os.path.join(config['defaultsave.directory'], ws)
os.remove(path)
except:
pass

removeFiles(['myscript.py'])

.. categories::
9 changes: 4 additions & 5 deletions Code/Mantid/docs/source/algorithms/SaveFocusedXYE-v1.rst
Expand Up @@ -39,13 +39,12 @@ Usage
ws = CreateSampleWorkspace()
ws = ExtractSingleSpectrum(ws, 0)

file_name = "myworkspace"
file_name = "myworkspace.ascii"
SaveFocusedXYE(ws, file_name)

path = os.path.join(config['defaultsave.directory'], file_name + "-0.ascii")
path = os.path.join(config['defaultsave.directory'], "myworkspace-0.ascii")
print os.path.isfile(path)


Output:

.. testoutput:: ExSaveFocusedXYESimple
Expand All @@ -63,7 +62,7 @@ Output:
except:
pass

removeFiles(file_name + "-0.ascii")
removeFiles(["myworkspace-0.ascii"])

**Example - an example using SaveFocusedXYE with additional options.**

Expand Down Expand Up @@ -98,6 +97,6 @@ Output:
except:
pass

removeFiles(file_name)
removeFiles([file_name])

.. categories::
12 changes: 6 additions & 6 deletions Code/Mantid/docs/source/algorithms/SaveGSS-v1.rst
Expand Up @@ -41,7 +41,7 @@ Usage
-----
**Example - a basic example using SaveGSS.**

.. testcode:: ExSaveGSSimple
.. testcode:: ExSaveGSSSimple

import os

Expand All @@ -50,17 +50,17 @@ Usage
file_name = "myworkspace.ascii"
SaveGSS(ws, file_name)

path = os.path.join(config['defaultsave.directory'], file_name)
path = os.path.join(config['defaultsave.directory'], "myworkspace-0.ascii")
print os.path.isfile(path)


Output:

.. testoutput:: ExSaveGSSimple
.. testoutput:: ExSaveGSSSimple

True

.. testcleanup:: ExSaveGSSimple
.. testcleanup:: ExSaveGSSSimple

import os
def removeFiles(files):
Expand All @@ -71,7 +71,7 @@ Output:
except:
pass

removeFiles(file_name)
removeFiles(["myworkspace-0.ascii"])

**Example - an example using SaveGSS with additonal options.**

Expand Down Expand Up @@ -105,7 +105,7 @@ Output:
except:
pass

removeFiles(file_name)
removeFiles([file_name])


.. categories::
42 changes: 39 additions & 3 deletions Code/Mantid/docs/source/algorithms/SaveNexusProcessed-v1.rst
Expand Up @@ -77,7 +77,7 @@ Output:
except:
pass

removeFiles(file_name)
removeFiles([file_name])


**Example - an example using SaveNexusProcessed with additonal options.**
Expand All @@ -95,7 +95,7 @@ Output:

ws = Load(file_name)
print "Saved workspace has %d spectra" % ws.getNumberHistograms()

Output:

.. testoutput:: ExSaveNexusProcessedOptions
Expand All @@ -114,7 +114,43 @@ Output:
except:
pass

removeFiles(file_name)
removeFiles([file_name])

**Example - an example using SaveNexusProcessed to save an Event workspace.**

.. testcode:: ExSaveNexusProcessedEvent

import os

ws = CreateSampleWorkspace("Event")
file_name = "myworkspace.nxs"
SaveNexusProcessed(ws, file_name, CompressNexus=True, PreserveEvents=True)

path = os.path.join(config['defaultsave.directory'], file_name)
print os.path.isfile(path)

ws = Load(file_name)
print "Saved workspace has %d spectra" % ws.getNumberHistograms()

Output:

.. testoutput:: ExSaveNexusProcessedEvent

True
Saved workspace has 200 spectra

.. testcleanup:: ExSaveNexusProcessedEvent

import os
def removeFiles(files):
for ws in files:
try:
path = os.path.join(config['defaultsave.directory'], ws)
os.remove(path)
except:
pass

removeFiles([file_name])


.. categories::
10 changes: 4 additions & 6 deletions Code/Mantid/docs/source/algorithms/SortPeaksWorkspace-v1.rst
Expand Up @@ -26,19 +26,17 @@ Usage

#sort the table by column k
peaks_ws = SortPeaksWorkspace(peaks_ws, ColumnNameToSortBy='k')
print "Column k in ascending order: \n" + str(peaks_ws.column('k'))
print "Column k in ascending order: " + str(peaks_ws.column('k'))

#the algorithm can also sort in descending order
peaks_ws = SortPeaksWorkspace(peaks_ws, ColumnNameToSortBy='k', SortAscending=False)
print "Column k in descending order: \n" + str(peaks_ws.column('k'))
print "Column k in descending order: " + str(peaks_ws.column('k'))

Output:

.. testoutput:: ExSortPeaksWorkspaceSimple

Column k in ascending order:
[-3.0, -2.0, -2.0, -2.0, -2.0, -2.0, -2.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -0.0, -0.0, -0.0, 0.0, -0.0, -0.0, 0.0, -0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 2.0, 4.0, 5.0, 5.0]
Column k in descending order:
[5.0, 5.0, 4.0, 2.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, -0.0, -0.0, -0.0, 0.0, -0.0, -0.0, 0.0, -0.0, 0.0, 0.0, 0.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -2.0, -2.0, -2.0, -2.0, -2.0, -2.0, -3.0]
Column k in ascending order: [-3.0, -2.0, -2.0, -2.0, -2.0, -2.0, -2.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -0.0, -0.0, -0.0, 0.0, -0.0, -0.0, 0.0, -0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 2.0, 4.0, 5.0, 5.0]
Column k in descending order: [5.0, 5.0, 4.0, 2.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, -0.0, -0.0, -0.0, 0.0, -0.0, -0.0, 0.0, -0.0, 0.0, 0.0, 0.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -2.0, -2.0, -2.0, -2.0, -2.0, -2.0, -3.0]

.. categories::

0 comments on commit aa38056

Please sign in to comment.