Skip to content

Commit

Permalink
Added grouped output, usage example and unit test
Browse files Browse the repository at this point in the history
Refs #10264
  • Loading branch information
DanNixon committed Sep 25, 2014
1 parent 69e51d6 commit 851c793
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 2 deletions.
Expand Up @@ -125,7 +125,7 @@ def PyExec(self):
self._setup()

# CheckXrange(xRange, 'Time')
outWSlist = []
out_ws_list = []

for index, filename in enumerate(self._raw_files):
raw_file = self._read_raw_file(filename)
Expand All @@ -139,7 +139,7 @@ def PyExec(self):
unit = mtd[slice_file].getAxis(0).setUnit("Label")
unit.setLabel("Spectrum Number", "")

outWSlist.append(slice_file)
out_ws_list.append(slice_file)
DeleteWorkspace(raw_file)

if self._save:
Expand All @@ -150,6 +150,10 @@ def PyExec(self):
if self._verbose:
logger.notice('Output file :' + save_path)

if self._out_ws_group is not None:
all_workspaces = ','.join(out_ws_list)
GroupWorkspaces(InputWorkspaces=all_workspaces, OutputWorkspace=self._out_ws_group)

if self._plot:
try:
from IndirectImport import import_mantidplot
Expand Down
Expand Up @@ -39,6 +39,7 @@ set ( TEST_PY_FILES
SuggestTibHYSPECTest.py
UpdatePeakParameterTableValueTest.py
SANSSubtractTest.py
TimeSliceTest.py
ExportSampleLogsToCSVFileTest.py
ExportExperimentLogTest.py
PoldiMergeTest.py
Expand Down
@@ -0,0 +1,47 @@
import unittest
from mantid.simpleapi import *
from mantid.api import *

class TimeSliceTest(unittest.TestCase):

def test_basic(self):
"""
Test to ensure that algorithm completes succesfully.
"""

TimeSlice(InputFiles=['IRS26173.raw'],
SpectraRange=[3, 53],
PeakRange=[62500, 65000],
BackgroundRange=[59000, 61500])

self.assertTrue(mtd.doesExist('irs26173_slice'))

def test_group(self):
"""
Tests to ensure that result workspaces are goruped correctly.
"""

TimeSlice(InputFiles=['IRS26173.raw'],
SpectraRange=[3, 53],
PeakRange=[62500, 65000],
BackgroundRange=[59000, 61500],
OutputWorkspaceGroup='SliceTestOut')

self.assertTrue(mtd.doesExist('SliceTestOut'))
self.assertTrue(mtd.doesExist('irs26173_slice'))

def test_suffix(self):
"""
Tests to ensure that output names have a suffic appended correctly.
"""

TimeSlice(InputFiles=['IRS26173.raw'],
SpectraRange=[3, 53],
PeakRange=[62500, 65000],
BackgroundRange=[59000, 61500],
OutputNameSuffix='_graphite002_slice')

self.assertTrue(mtd.doesExist('irs26173_graphite002_slice'))

if __name__ == '__main__':
unittest.main()
21 changes: 21 additions & 0 deletions Code/Mantid/docs/source/algorithms/TimeSlice-v1.rst
Expand Up @@ -23,4 +23,25 @@ A background range can also be provided which will first calculate
and subtract a flat background from the raw data before the
integration is performed.

Usage
-----

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

**Example - Running TimeSlice**

.. testcode:: ExIndirectTransmissionSimple

TimeSlice(InputFiles=['IRS26173.raw'],
SpectraRange=[3, 53],
PeakRange=[62500, 65000])

print mtd.doesExist('irs26173_slice')

Output:

.. testoutput:: ExIndirectTransmissionSimple

True

.. categories::

0 comments on commit 851c793

Please sign in to comment.