Commit 0d10ba2d authored by Owen Arnold's avatar Owen Arnold
Browse files

refs #11056. Setup for new AddPeaksHKL algorithm

parent 1f5c8337
......@@ -103,9 +103,9 @@ namespace
MOCK_METHOD0(findDetector,
bool());
MOCK_METHOD2(setQSampleFrame,
void(Mantid::Kernel::V3D QSampleFrame, double detectorDistance));
void(Mantid::Kernel::V3D QSampleFrame, boost::optional<double> detectorDistance));
MOCK_METHOD2(setQLabFrame,
void(Mantid::Kernel::V3D QLabFrame, double detectorDistance));
void(Mantid::Kernel::V3D QLabFrame, boost::optional<double> detectorDistance));
MOCK_METHOD1(setWavelength,
void(double wavelength));
MOCK_CONST_METHOD0(getWavelength,
......
set ( SRC_FILES
src/AddPeakHKL.cpp
src/AnvredCorrection.cpp
src/CalculatePeaksHKL.cpp
src/CalculateUMatrix.cpp
......@@ -69,6 +70,7 @@ set ( SRC_FILES
set ( SRC_UNITY_IGNORE_FILES )
set ( INC_FILES
inc/MantidCrystal/AddPeakHKL.h
inc/MantidCrystal/AnvredCorrection.h
inc/MantidCrystal/BackgroundStrategy.h
inc/MantidCrystal/CalculatePeaksHKL.h
......@@ -140,6 +142,7 @@ set ( INC_FILES
)
set ( TEST_FILES
AddPeakHKLTest.h
AnvredCorrectionTest.h
CalculatePeaksHKLTest.h
CalculateUMatrixTest.h
......
#ifndef MANTID_CRYSTAL_ADDPEAKHKL_H_
#define MANTID_CRYSTAL_ADDPEAKHKL_H_
#include "MantidKernel/System.h"
#include "MantidAPI/Algorithm.h"
namespace Mantid
{
namespace Crystal
{
/** AddPeakHKL : TODO: DESCRIPTION
Copyright &copy; 2015 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge National Laboratory & European Spallation Source
This file is part of Mantid.
Mantid is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
Mantid is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
File change history is stored at: <https://github.com/mantidproject/mantid>
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
class DLLExport AddPeakHKL : public API::Algorithm
{
public:
AddPeakHKL();
virtual ~AddPeakHKL();
virtual const std::string name() const;
virtual int version() const;
virtual const std::string category() const;
virtual const std::string summary() const;
private:
void init();
void exec();
};
} // namespace Crystal
} // namespace Mantid
#endif /* MANTID_CRYSTAL_ADDPEAKHKL_H_ */
\ No newline at end of file
#include "MantidCrystal/AddPeakHKL.h"
namespace Mantid
{
namespace Crystal
{
using Mantid::Kernel::Direction;
using Mantid::API::WorkspaceProperty;
// Register the algorithm into the AlgorithmFactory
DECLARE_ALGORITHM(AddPeakHKL)
//----------------------------------------------------------------------------------------------
/** Constructor
*/
AddPeakHKL::AddPeakHKL()
{
}
//----------------------------------------------------------------------------------------------
/** Destructor
*/
AddPeakHKL::~AddPeakHKL()
{
}
//----------------------------------------------------------------------------------------------
/// Algorithms name for identification. @see Algorithm::name
const std::string AddPeakHKL::name() const { return "AddPeakHKL"; }
/// Algorithm's version for identification. @see Algorithm::version
int AddPeakHKL::version() const { return 1;};
/// Algorithm's category for identification. @see Algorithm::category
const std::string AddPeakHKL::category() const { return TODO: FILL IN A CATEGORY;}
/// Algorithm's summary for use in the GUI and help. @see Algorithm::summary
const std::string AddPeakHKL::summary() const { return TODO: FILL IN A SUMMARY;};
//----------------------------------------------------------------------------------------------
/** Initialize the algorithm's properties.
*/
void AddPeakHKL::init()
{
declareProperty(new WorkspaceProperty<>("InputWorkspace","",Direction::Input), "An input workspace.");
declareProperty(new WorkspaceProperty<>("OutputWorkspace","",Direction::Output), "An output workspace.");
}
//----------------------------------------------------------------------------------------------
/** Execute the algorithm.
*/
void AddPeakHKL::exec()
{
// TODO Auto-generated execute stub
}
} // namespace Crystal
} // namespace Mantid
\ No newline at end of file
......@@ -145,7 +145,7 @@ void PredictPeaks::doHKL(const double h, const double k, const double l,
PARALLEL_CRITICAL(PredictPeaks_numInRange) { numInRange++; }
// Create the peak using the Q in the lab framewith all its info:
Peak p(inst, q);
Peak p(inst, q, boost::optional<double>());
if (p.findDetector()) {
// Only add peaks that hit the detector
p.setGoniometerMatrix(gonio);
......
#ifndef MANTID_CRYSTAL_ADDPEAKHKLTEST_H_
#define MANTID_CRYSTAL_ADDPEAKHKLTEST_H_
#include <cxxtest/TestSuite.h>
#include "MantidCrystal/AddPeakHKL.h"
using Mantid::Crystal::AddPeakHKL;
using namespace Mantid::API;
class AddPeakHKLTest : public CxxTest::TestSuite
{
public:
// This pair of boilerplate methods prevent the suite being created statically
// This means the constructor isn't called when running other tests
static AddPeakHKLTest *createSuite() { return new AddPeakHKLTest(); }
static void destroySuite( AddPeakHKLTest *suite ) { delete suite; }
void test_Init()
{
AddPeakHKL alg;
TS_ASSERT_THROWS_NOTHING( alg.initialize() )
TS_ASSERT( alg.isInitialized() )
}
void test_exec()
{
// Name of the output workspace.
std::string outWSName("AddPeakHKLTest_OutputWS");
AddPeakHKL alg;
TS_ASSERT_THROWS_NOTHING( alg.initialize() )
TS_ASSERT( alg.isInitialized() )
TS_ASSERT_THROWS_NOTHING( alg.setPropertyValue("REPLACE_PROPERTY_NAME_HERE!!!!", "value") );
TS_ASSERT_THROWS_NOTHING( alg.setPropertyValue("OutputWorkspace", outWSName) );
TS_ASSERT_THROWS_NOTHING( alg.execute(); );
TS_ASSERT( alg.isExecuted() );
// Retrieve the workspace from data service. TODO: Change to your desired type
Workspace_sptr ws;
TS_ASSERT_THROWS_NOTHING( ws = AnalysisDataService::Instance().retrieveWS<Workspace>(outWSName) );
TS_ASSERT(ws);
if (!ws) return;
// TODO: Check the results
// Remove workspace from the data service.
AnalysisDataService::Instance().remove(outWSName);
}
void test_Something()
{
TSM_ASSERT( "You forgot to write a test!", 0);
}
};
#endif /* MANTID_CRYSTAL_ADDPEAKHKLTEST_H_ */
\ No newline at end of file
......@@ -397,6 +397,10 @@ PeaksWorkspace::peakInfo(Kernel::V3D qFrame, bool labCoords) const {
*/
Peak *PeaksWorkspace::createPeakHKL(V3D HKL) const
{
/*
The following allows us to add peaks where we have a single UB to work from.
*/
Geometry::OrientedLattice lattice = this->sample().getOrientedLattice();
Geometry::Goniometer goniometer = this->run().getGoniometer();
......@@ -412,6 +416,9 @@ Peak *PeaksWorkspace::createPeakHKL(V3D HKL) const
// Set the goniometer
peak->setGoniometerMatrix(goniometer.getR());
// Take the run number from this
peak->setRunNumber(this->getRunNumber());
return peak;
}
......
......@@ -50,7 +50,7 @@ void export_IPeak()
.def("setQLabFrame", (void (IPeak::*)(Mantid::Kernel::V3D))&IPeak::setQLabFrame, "Set the peak using the peak's position in reciprocal space, in the lab frame.")
.def("setQLabFrame", setQLabFrame, "Set the peak using the peak's position in reciprocal space, in the lab frame. Detector distance explicitly supplied.") // two argument overload
.def("setQSampleFrame", (void (IPeak::*)(Mantid::Kernel::V3D))&IPeak::setQSampleFrame, "Set the peak using the peak's position in reciprocal space, in the sample frame.")
.def("setQSampleFrame", &IPeak::setQSampleFrame, "Set the peak using the peak's position in reciprocal space, in the sample frame.")
.def("setQSampleFrame", setQSampleFrame, "Set the peak using the peak's position in reciprocal space, in the sample frame.")
.def("setWavelength", &IPeak::setWavelength, "Set the incident wavelength of the neutron. Calculates the energy from this assuming elastic scattering.")
.def("getWavelength", &IPeak::getWavelength, "Return the incident wavelength")
.def("getScattering", &IPeak::getScattering, "Calculate the scattering angle of the peak")
......
......@@ -4,6 +4,8 @@
#include "MantidPythonInterface/kernel/Converters/PyObjectToV3D.h"
#include <boost/python/class.hpp>
#include <boost/python/return_internal_reference.hpp>
#include <boost/optional.hpp>
#include <boost/python/manage_new_object.hpp>
using namespace Mantid::API;
using Mantid::PythonInterface::Registry::DataItemInterface;
......@@ -12,21 +14,21 @@ using namespace boost::python;
namespace {
/// Create a peak via it's HKL value from a list or numpy array
void createPeakHKL(IPeaksWorkspace & self, const object& data)
IPeak* createPeakHKL(IPeaksWorkspace & self, const object& data)
{
self.createPeakHKL(Mantid::PythonInterface::Converters(data));
return self.createPeakHKL(Mantid::PythonInterface::Converters::PyObjectToV3D(data)());
}
/// Create a peak via it's QLab value from a list or numpy array
void createPeakQLab(IPeaksWorkspace & self, const object& data)
IPeak* createPeakQLab(IPeaksWorkspace & self, const object& data)
{
self.createPeak(Mantid::PythonInterface::Converters(data));
return self.createPeak(Mantid::PythonInterface::Converters::PyObjectToV3D(data)(), boost::optional<double>());
}
/// Create a peak via it's QLab value from a list or numpy array
void createPeakQLabWithDistance(IPeaksWorkspace & self, const object& data, double detectorDistance)
IPeak* createPeakQLabWithDistance(IPeaksWorkspace & self, const object& data, double detectorDistance)
{
self.createPeak(Mantid::PythonInterface::Converters(data), distance);
return self.createPeak(Mantid::PythonInterface::Converters::PyObjectToV3D(data)(), detectorDistance);
}
}
......@@ -39,9 +41,9 @@ void export_IPeaksWorkspace()
.def("addPeak", &IPeaksWorkspace::addPeak, "Add a peak to the workspace")
.def("removePeak", &IPeaksWorkspace::removePeak, "Remove a peak from the workspace")
.def("getPeak", &IPeaksWorkspace::getPeakPtr, return_internal_reference<>(), "Returns a peak at the given index" )
.def("createPeak", createPeakQLab, return_internal_reference<>(), "Create a Peak and return it from its coordinates in the QLab frame")
.def("createPeak", createPeakQLabWithDistance, return_internal_reference<>(), "Create a Peak and return it from its coordinates in the QLab frame, detector-sample distance explicitly provided")
.def("createPeakHKL", createPeakHKL, return_internal_reference<>(), "Create a Peak and return it from its coordinates in the HKL frame")
.def("createPeak", createPeakQLab, return_value_policy<manage_new_object>(), "Create a Peak and return it from its coordinates in the QLab frame")
.def("createPeak", createPeakQLabWithDistance, return_value_policy<manage_new_object>(), "Create a Peak and return it from its coordinates in the QLab frame, detector-sample distance explicitly provided")
.def("createPeakHKL", createPeakHKL, return_value_policy<manage_new_object>(), "Create a Peak and return it from its coordinates in the HKL frame")
.def("hasIntegratedPeaks", &IPeaksWorkspace::hasIntegratedPeaks, "Determine if the peaks have been integrated")
.def("getRun", &IPeaksWorkspace::mutableRun, return_internal_reference<>(),
"Return the Run object for this workspace")
......
import unittest
from testhelpers import run_algorithm, WorkspaceCreationHelper
from mantid.kernel import V3D
from mantid.api import IPeaksWorkspace
from mantid.geometry import OrientedLattice
from mantid.api import IPeaksWorkspace, IPeak
class IPeaksWorkspaceTest(unittest.TestCase):
"""
......@@ -38,6 +39,7 @@ class IPeaksWorkspaceTest(unittest.TestCase):
# Create a new peak at some Q in the lab frame
qlab = V3D(1,2,3)
p = pws.createPeak(qlab, 1.54)
p.getQLabFrame()
self.assertAlmostEquals( p.getQLabFrame().X(), 1.0, 3)
# Now try to add the peak back
......@@ -50,7 +52,15 @@ class IPeaksWorkspaceTest(unittest.TestCase):
# Peaks workspace will not be integrated by default.
self.assertTrue(not pws.hasIntegratedPeaks())
def test_createPeakHKL(self):
pws = WorkspaceCreationHelper.createPeaksWorkspace(0)
lattice = pws.mutableSample().getOrientedLattice()
# Simple test that the creational method is exposed
p = pws.createPeakHKL([1,1,1])
self.assertTrue(IPeak != None)
def test_peak_setQLabFrame(self):
pws = WorkspaceCreationHelper.createPeaksWorkspace(1)
p = pws.getPeak(0)
......@@ -64,7 +74,7 @@ class IPeaksWorkspaceTest(unittest.TestCase):
except Exception:
self.fail("Tried setQLabFrame with one V3D argument and a double distance")
def test_peak_setQSampleFrame(self):
def test_peak_setQSampleFrame(self):
pws = WorkspaceCreationHelper.createPeaksWorkspace(1)
p = pws.getPeak(0)
try:
......
......@@ -1193,6 +1193,8 @@ createPeaksWorkspace(const int numPeaks) {
peaksWS->addPeak(peak);
}
Mantid::Geometry::OrientedLattice lattice;
peaksWS->mutableSample().setOrientedLattice(&lattice);
return peaksWS;
}
......
.. algorithm::
.. summary::
.. alias::
.. properties::
Description
-----------
TODO: Enter a full rst-markup description of your algorithm here.
Usage
-----
.. Try not to use files in your examples,
but if you cannot avoid it then the (small) files must be added to
autotestdata\UsageData and the following tag unindented
.. include:: ../usagedata-note.txt
**Example - AddPeakHKL**
.. testcode:: AddPeakHKLExample
# Create a host workspace
ws = CreateWorkspace(DataX=range(0,3), DataY=(0,2))
or
ws = CreateSampleWorkspace()
wsOut = AddPeakHKL()
# Print the result
print "The output workspace has %i spectra" % wsOut.getNumberHistograms()
Output:
.. testoutput:: AddPeakHKLExample
The output workspace has ?? spectra
.. categories::
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