Skip to content

Commit

Permalink
Refs #9584 Add examples for GeneratePythonScript.
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuel Jackson committed Jun 5, 2014
1 parent a88f6fd commit f2c8427
Showing 1 changed file with 57 additions and 16 deletions.
73 changes: 57 additions & 16 deletions Code/Mantid/docs/source/algorithms/GeneratePythonScript-v1.rst
Expand Up @@ -12,28 +12,69 @@ Description
Retrieves the algorithm history of the workspace and saves it to a
Python script file or Python variable.

Example usage:
##############
Usage
-----

.. code-block:: python
**Example - generate a python script for a workspace:**

# Optional: Store the contents of the workspace to a file to your desktop.
GeneratePythonScript("MUSR00022725", "/home/userName/Desktop/MUSR00022725.py")
.. testcode:: ExGeneratePythonScriptSimple

# Store the contents of the workspace history into the hist variable
wsHistory = GeneratePythonScript("MUSR00022725")
#create a workspace and run some operations on it
ws = CreateSampleWorkspace()
ws = CropWorkspace(ws, XMin=7828.162291, XMax=11980.906921)
ws = Power(ws, Exponent=1.5)
ws = RenameWorkspace(ws, OutputWorkspace="MyTestWorkspace")

# Output the contents of the hist variable.
print wsHistory
script_text = GeneratePythonScript(ws)
print script_text

######################################################################
#Python Script Generated by GeneratePythonScript Algorithm
######################################################################
Load(Filename=r'/home/userName/workspace/mantid/Test/AutoTestData/MUSR00022725.nxs',OutputWorkspace='MUSR00022725')
RenameWorkspace(InputWorkspace='MUSR00022725',OutputWorkspace='test')
Output:

.. testoutput:: ExGeneratePythonScriptSimple

######################################################################
#Python Script Generated by GeneratePythonScript Algorithm
######################################################################
CreateSampleWorkspace(OutputWorkspace='ws')
CropWorkspace(InputWorkspace='ws',OutputWorkspace='ws',XMin='7828.1622909999996',XMax='11980.906921')
Power(InputWorkspace='ws',OutputWorkspace='ws',Exponent='1.5')
RenameWorkspace(InputWorkspace='ws',OutputWorkspace='MyTestWorkspace')


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

.. testcode:: ExGeneratePythonScriptSimple

#create a workspace and run some operations on it
ws = CreateSampleWorkspace()
ws = CropWorkspace(ws, XMin=7828.162291, XMax=11980.906921)
ws = Power(ws, Exponent=1.5)
ws = RenameWorkspace(ws, OutputWorkspace="MyTestWorkspace")

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

Output:

.. testoutput:: ExGeneratePythonScriptSimple

######################################################################
#Python Script Generated by GeneratePythonScript Algorithm
######################################################################
CreateSampleWorkspace(OutputWorkspace='ws')
CropWorkspace(InputWorkspace='ws',OutputWorkspace='ws',XMin='7828.1622909999996',XMax='11980.906921')
Power(InputWorkspace='ws',OutputWorkspace='ws',Exponent='1.5')
RenameWorkspace(InputWorkspace='ws',OutputWorkspace='MyTestWorkspace')

.. raw:: mediawiki

{{AlgorithmLinks|GeneratePythonScript}}

.. categories::

0 comments on commit f2c8427

Please sign in to comment.