Skip to content

Commit

Permalink
Refs #10026 fix algorithm and add unit and doc tests
Browse files Browse the repository at this point in the history
  • Loading branch information
VickieLynch committed Aug 6, 2014
1 parent ba06bca commit 9140580
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def PyExec(self):
loopIndex = 0
wsOut = mtd[wsOutput]
for norm, spec in sortStat:
wsOut.getAxis(1).setValue(loopIndex, norm)
wsOut.getSpectrum(loopIndex).setSpectrumNo(int(norm*1000))
loopIndex = loopIndex + 1
if len(yUnit) > 0:
wsOut.getAxis(1).setUnit(yUnit)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ set ( TEST_PY_FILES
RetrieveRunInfoTest.py
SANSWideAngleCorrectionTest.py
SavePlot1DTest.py
SortByQVectorsTest.py
SortDetectorsTest.py
SortXAxisTest.py
Stitch1DManyTest.py
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import unittest,os
import mantid


class SortByQVectorsTest(unittest.TestCase):


def test_output(self):
ws = mantid.simpleapi.LoadSassena("outputSassena_1.4.1.h5", TimeUnit=1.0)
mantid.simpleapi.SortByQVectors('ws')
self.assertAlmostEqual(ws[0].getNumberHistograms(),5)
self.assertAlmostEqual(ws[0].dataY(0)[0],0.0)
self.assertAlmostEqual(ws[0].dataY(1)[0],0.00600600591861)
self.assertAlmostEqual(ws[0].dataY(2)[0],0.0120120118372)
self.assertAlmostEqual(ws[0].dataY(3)[0],0.0180180184543)
self.assertAlmostEqual(ws[0].dataY(4)[0],0.0240240236744)
mantid.api.AnalysisDataService.remove("ws")

if __name__=="__main__":
unittest.main()
26 changes: 26 additions & 0 deletions Code/Mantid/docs/source/algorithms/SortByQVectors-v1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,30 @@ This algorithm sorts a group workspace by the qvectors found in the
qvectors file. Workspaces will be tranformed if the qvectors dimension
is in the bins. Used for output from LoadSassena.

Usage
-----

.. include:: ../usagedata-note.txt

.. testcode:: ExSortByQVectors


ws = LoadSassena("outputSassena_1.4.1.h5", TimeUnit=1.0)
print 'workspaces instantiated: ', ', '.join(ws.getNames())
SortByQVectors(InputWorkspace='ws')
ws0 = ws[0]
for i in range(0, ws0.getNumberHistograms()):
print ws0.dataY(i)[0]

Output:

.. testoutput:: ExSortByQVectors

workspaces instantiated: ws_qvectors, ws_fq, ws_fq0, ws_fq2, ws_fqt.Re, ws_fqt.Im
0.0
0.00600600591861
0.0120120118372
0.0180180184543
0.0240240236744

.. categories::

0 comments on commit 9140580

Please sign in to comment.