Skip to content

Commit

Permalink
refs #9909 LoadNXSPE and SaveNXSPE usage examples
Browse files Browse the repository at this point in the history
  • Loading branch information
abuts committed Oct 2, 2014
1 parent 9a0cc98 commit f2e84cf
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
5 changes: 5 additions & 0 deletions Code/Mantid/docs/source/algorithms/LoadNXSPE-v1.rst
Expand Up @@ -16,4 +16,9 @@ algorithm.
**NOTE:** In the current implementation, the rendering of the NXSPE
instrument is VERY memory intensive.

Usage
-----

See :ref:`algm-SaveNXSPE` usage examples where Save and Load NXSPE operations are tested together.

.. categories::
28 changes: 22 additions & 6 deletions Code/Mantid/docs/source/algorithms/SaveNXSPE-v1.rst
Expand Up @@ -34,18 +34,31 @@ Usage

import os
import numpy

# Create dummy workspace.
out_ws = CreateSimulationWorkspace(Instrument="IRIS", BinParams="0,500,2000")
out_ws.setY(0, numpy.array([10.0, 50.0, 30.0, 60.0]))

file_path = os.path.join(config["defaultsave.directory"], "NXSPEData.nxsps")

AddSampleLog(out_ws, 'Ei', LogText='321', LogType='Number')

file_path = os.path.join(config["defaultsave.directory"], "NXSPEData.nxspe")

# Do a "roundtrip" of the data.
SaveNXSPE(out_ws, file_path)
SaveNXSPE(out_ws, file_path,Psi=32)

# SaveMXSPE does not store detector's ID-s. LoadNXSPE sets detector's ID-s to defaults.
# To compare loaded and saved workpsaces, one needs to set-up default detector's ID-s to the source workspace
nSpec = out_ws.getNumberHistograms()
for i in xrange(0,nSpec):
sp=out_ws.getSpectrum(i);
sp.setDetectorID(i+1);
in_ws = LoadNXSPE(file_path)


ws_comparison_rez = CheckWorkspacesMatch(out_ws,in_ws,1.e-9,CheckInstrument=False)
print "Contents of the first spectrum = " + str(in_ws.readY(0)) + "."
print "Initial and loaded workspaces comparison is: ",ws_comparison_rez
run = in_ws.getRun();
print "Loaded workspace has attached incident energy Ei={0:5} and rotation angle Psi={1:5}deg".format(run.getLogData('Ei').value,run.getLogData('psi').value)


.. testcleanup:: ExSimpleSavingRoundtrip

Expand All @@ -56,5 +69,8 @@ Output:
.. testoutput:: ExSimpleSavingRoundtrip

Contents of the first spectrum = [ 10. 50. 30. 60.].
Initial and loaded workspaces comparison is: Success!
Loaded workspace has attached incident energy Ei=321.0 and rotation angle Psi= 32.0deg


.. categories::

0 comments on commit f2e84cf

Please sign in to comment.