Commit faa7ca4b authored by Lynch, Vickie's avatar Lynch, Vickie
Browse files

Refs #16812 get user script working

parent 6609b3d8
......@@ -43,6 +43,7 @@ void CreatePeaksWorkspace::exec() {
Progress progress(this, 0, 1, NumberOfPeaks);
out->setInstrument(instWS->getInstrument());
out->mutableRun().setGoniometer(instWS->run().getGoniometer().getR(), false);
// Create some default peaks
for (int i = 0; i < NumberOfPeaks; i++) {
out->addPeak(Peak(out->getInstrument(),
......
......@@ -192,7 +192,19 @@ const Peak &PeaksWorkspace::getPeak(const int peakNum) const {
Geometry::IPeak *
PeaksWorkspace::createPeak(Kernel::V3D QLabFrame,
boost::optional<double> detectorDistance) const {
return new Peak(this->getInstrument(), QLabFrame, detectorDistance);
Geometry::Goniometer goniometer = this->run().getGoniometer();
// create a peak using the qLab frame
auto peak =
new Peak(this->getInstrument(), QLabFrame, detectorDistance);
// Set the goniometer
peak->setGoniometerMatrix(goniometer.getR());
// Take the run number from this
peak->setRunNumber(this->getRunNumber());
return peak;
}
/**
......
......@@ -2,6 +2,8 @@
#include "MantidGeometry/Crystal/IPeak.h"
#include <boost/python/class.hpp>
#include <boost/python/register_ptr_to_python.hpp>
#include "MantidPythonInterface/kernel/Converters/PyObjectToMatrix.h"
#include <boost/optional.hpp>
using Mantid::Geometry::IPeak;
using namespace boost::python;
......@@ -9,6 +11,7 @@ using namespace boost::python;
GET_POINTER_SPECIALIZATION(IPeak)
namespace {
using namespace Mantid::PythonInterface;
Mantid::Geometry::PeakShape_sptr getPeakShape(IPeak &peak) {
// Use clone to make a copy of the PeakShape.
return Mantid::Geometry::PeakShape_sptr(peak.getPeakShape().clone());
......@@ -33,6 +36,10 @@ void setQSampleFrame2(IPeak &peak, Mantid::Kernel::V3D qSampleFrame,
// Set the qsample frame. Detector distance specified.
return peak.setQSampleFrame(qSampleFrame, distance);
}
void setGoniometerMatrix(IPeak &self, const object &data) {
self.setGoniometerMatrix(Converters::PyObjectToMatrix(data)());
}
}
void export_IPeak() {
......@@ -131,6 +138,9 @@ void export_IPeak() {
"Return the # of counts in the bin at its peak")
.def("setBinCount", &IPeak::setBinCount, (arg("self"), arg("bin_count")),
"Set the # of counts in the bin at its peak")
.def("setGoniometerMatrix", &setGoniometerMatrix,
(arg("self"), arg("goniometerMatrix")),
"Set the goniometer of the peak")
.def("getRow", &IPeak::getRow, arg("self"),
"For RectangularDetectors only, returns "
"the row (y) of the pixel of the "
......
......@@ -70,11 +70,17 @@ class IPeaksWorkspaceTest(unittest.TestCase):
p.setQLabFrame(V3D(1,1,1))
except Exception:
self.fail("Tried setQLabFrame with one V3D argument")
self.assertAlmostEquals( p.getQLabFrame().X(), -1.4976057446828845, places=10)
self.assertAlmostEquals( p.getQLabFrame().Y(), 0.059904229787315376, places=10)
self.assertAlmostEquals( p.getQLabFrame().Z(), 1.4400957702126842, places=10)
try:
p.setQLabFrame(V3D(1,1,1), 1)
except Exception:
self.fail("Tried setQLabFrame with one V3D argument and a double distance")
self.assertAlmostEquals( p.getQLabFrame().X(), 1.0, places=10)
self.assertAlmostEquals( p.getQLabFrame().Y(), 1.0, places=10)
self.assertAlmostEquals( p.getQLabFrame().Z(), 1.0, places=10)
def test_peak_setQSampleFrame(self):
pws = WorkspaceCreationHelper.createPeaksWorkspace(1, True)
......@@ -83,11 +89,17 @@ class IPeaksWorkspaceTest(unittest.TestCase):
p.setQSampleFrame(V3D(1,1,1))
except Exception:
self.fail("Tried setQSampleFrame with one V3D argument")
self.assertAlmostEquals( p.getQSampleFrame().X(), -1.4976057446828845, places=10)
self.assertAlmostEquals( p.getQSampleFrame().Y(), 0.059904229787315376, places=10)
self.assertAlmostEquals( p.getQSampleFrame().Z(), 1.4400957702126842, places=10)
try:
p.setQSampleFrame(V3D(1,1,1), 1)
except Exception:
self.fail("Tried setQSampleFrame with one V3D argument and a double distance")
self.assertAlmostEquals( p.getQSampleFrame().X(), 1.0, places=10)
self.assertAlmostEquals( p.getQSampleFrame().Y(), 1.0, places=10)
self.assertAlmostEquals( p.getQSampleFrame().Z(), 1.0, places=10)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment