Skip to content

Commit

Permalink
Port EQSANSQ2DTest to new Python API Refs #7469
Browse files Browse the repository at this point in the history
  • Loading branch information
martyngigg committed Jul 22, 2013
1 parent 3d7ba07 commit 115f315
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 24 deletions.
2 changes: 2 additions & 0 deletions Code/Mantid/Framework/API/src/LogManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,9 @@ Kernel::Logger& LogManager::g_log = Kernel::Logger::get("LogManager");

INSTANTIATE(double);
INSTANTIATE(int);
INSTANTIATE(long);
INSTANTIATE(uint32_t);
INSTANTIATE(uint64_t);
INSTANTIATE(std::string);
INSTANTIATE(bool);

Expand Down
17 changes: 13 additions & 4 deletions Code/Mantid/Framework/WorkflowAlgorithms/src/EQSANSQ2D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,20 @@ void EQSANSQ2D::exec()

// Determine whether we need frame skipping or not by checking the chopper speed
bool frame_skipping = false;
if (inputWS->run().hasProperty("is_frame_skipping"))
const auto & run = inputWS->run();
if (run.hasProperty("is_frame_skipping"))
{
Mantid::Kernel::Property* prop = inputWS->run().getProperty("is_frame_skipping");
Mantid::Kernel::PropertyWithValue<int>* dp = dynamic_cast<Mantid::Kernel::PropertyWithValue<int>* >(prop);
frame_skipping = (*dp==1);
auto prop = run.getProperty("is_frame_skipping");
const auto & typeInfo = *(prop->type_info());
if(typeInfo == typeid(long))
{
frame_skipping = (run.getPropertyValueAsType<long>("is_frame_skipping") == 1);
}
else if(typeInfo == typeid(int))
{
frame_skipping = (run.getPropertyValueAsType<int>("is_frame_skipping") == 1);
}
else g_log.warning() << "Unknown property type for is_frame_skipping\n";
}

// Get run properties necessary to calculate the input parameters to Qxy
Expand Down
42 changes: 22 additions & 20 deletions Code/Mantid/Framework/WorkflowAlgorithms/test/EQSANSQ2DTest.py
Original file line number Diff line number Diff line change
@@ -1,38 +1,40 @@
import unittest
from mantidsimple import *
from mantid.simpleapi import *

class EQSANSQ2DTest(unittest.TestCase):

def setUp(self):

self.test_ws_name = "EQSANS_test_ws"
x = [1.,2.,3.,4.,5.,6.,7.,8.,9.,10.,11.]
y = 491520*[0.1]
y = 491520*[0.1]
CreateWorkspace(OutputWorkspace=self.test_ws_name,DataX=x,DataY=y,DataE=y,NSpec='49152',UnitX='Wavelength')
LoadInstrument(self.test_ws_name, InstrumentName="EQSANS")
mtd[self.test_ws_name].getRun().addProperty_dbl("sample_detector_distance", 4000.0, 'mm', True)
mtd[self.test_ws_name].getRun().addProperty_dbl("beam_center_x", 96, 'pixel', True)
mtd[self.test_ws_name].getRun().addProperty_dbl("beam_center_y", 128, 'pixel', True)
mtd[self.test_ws_name].getRun().addProperty_dbl("wavelength_min", 1, "Angstrom", True)
mtd[self.test_ws_name].getRun().addProperty_dbl("wavelength_max", 11, "Angstrom", True)
mtd[self.test_ws_name].getRun().addProperty_int("is_frame_skipping", 0, True)
mtd[self.test_ws_name].getRun().addProperty_dbl("wavelength_min_frame2", 5, "Angstrom", True)
mtd[self.test_ws_name].getRun().addProperty_dbl("wavelength_max_frame2", 10, "Angstrom", True)
LoadInstrument(Workspace=self.test_ws_name, InstrumentName="EQSANS")

run = mtd[self.test_ws_name].mutableRun()

run.addProperty("sample_detector_distance", 4000.0, 'mm', True)
run.addProperty("beam_center_x", 96.0, 'pixel', True)
run.addProperty("beam_center_y", 128.0, 'pixel', True)
run.addProperty("wavelength_min", 1.0, "Angstrom", True)
run.addProperty("wavelength_max", 11.0, "Angstrom", True)
run.addProperty("is_frame_skipping", 0, True)
run.addProperty("wavelength_min_frame2", 5.0, "Angstrom", True)
run.addProperty("wavelength_max_frame2", 10.0, "Angstrom", True)

def tearDown(self):
if mtd.workspaceExists(self.test_ws_name):
mtd.deleteWorkspace(self.test_ws_name)
if self.test_ws_name in mtd:
DeleteWorkspace(Workspace=self.test_ws_name)

def test_q2d(self):
EQSANSQ2D(self.test_ws_name)
EQSANSQ2D(InputWorkspace=self.test_ws_name)
ReplaceSpecialValues(InputWorkspace=self.test_ws_name+"_Iqxy",OutputWorkspace=self.test_ws_name+"_Iqxy",NaNValue=0,NaNError=0)
Integration(self.test_ws_name+"_Iqxy", "__tmp")
SumSpectra("__tmp", "summed")
self.assertAlmostEquals(mtd["summed"].dataY(0)[0], 7.24077, 6)
Integration(InputWorkspace=self.test_ws_name+"_Iqxy", OutputWorkspace="__tmp")
SumSpectra(InputWorkspace="__tmp", OutputWorkspace="summed")
self.assertAlmostEquals(mtd["summed"].readY(0)[0], 7.24077, 6)
for ws in ["__tmp", "summed"]:
if mtd.workspaceExists(ws):
mtd.deleteWorkspace(ws)

if mtd.doesExist(ws):
DeleteWorkspace(Workspace=ws)

if __name__ == '__main__':
unittest.main()

0 comments on commit 115f315

Please sign in to comment.