Commit 5cb09c3d authored by Whitfield, Ross's avatar Whitfield, Ross
Browse files

Allow create a peak with q-sample from IPeaksWorkspace

parent 66fdb835
......@@ -118,6 +118,14 @@ public:
createPeak(const Mantid::Kernel::V3D &position,
const Mantid::Kernel::SpecialCoordinateSystem &frame) const = 0;
//---------------------------------------------------------------------------------------------
/** Create an instance of a Peak
* @param position :: enter of the peak in the sample frame
* @return a pointer to a new Peak object.
*/
virtual std::unique_ptr<Mantid::Geometry::IPeak>
createPeakQSample(const Mantid::Kernel::V3D &position) const = 0;
/**
* Create an instance of a peak using a V3D
* @param HKL V3D
......
......@@ -28,8 +28,8 @@ namespace DataObjects {
//==========================================================================================
/** @class Mantid::DataObjects::LeanElasticPeaksWorkspace
The class LeanElasticPeaksWorkspace stores information about a set of SCD lean
peaks.
The class LeanElasticPeaksWorkspace stores information about a set of SCD
lean peaks.
@author Ruth Mikkelson, SNS ORNL
@date 3/10/2010
......@@ -43,7 +43,8 @@ public:
const std::string id() const override { return "LeanElasticPeaksWorkspace"; }
LeanElasticPeaksWorkspace();
LeanElasticPeaksWorkspace &operator=(const LeanElasticPeaksWorkspace &other) = delete;
LeanElasticPeaksWorkspace &
operator=(const LeanElasticPeaksWorkspace &other) = delete;
/** Get access to shared pointer containing workspace porperties. This
function is there to provide common interface of iTableWorkspace
......@@ -96,6 +97,9 @@ public:
createPeak(const Kernel::V3D &Position,
const Kernel::SpecialCoordinateSystem &frame) const override;
std::unique_ptr<Geometry::IPeak>
createPeakQSample(const Kernel::V3D &position) const override;
std::vector<std::pair<std::string, std::string>>
peakInfo(const Kernel::V3D &qFrame, bool labCoords) const override;
......@@ -185,9 +189,6 @@ private:
void initColumns();
/// Adds a new PeakColumn of the given type
void addPeakColumn(const std::string &name);
/// Create a peak from a QSample position
std::unique_ptr<Geometry::IPeak>
createPeakQSample(const Kernel::V3D &position) const;
// ====================================== ITableWorkspace Methods
// ==================================
......@@ -202,12 +203,14 @@ private:
bool addColumns(const std::string & /*type*/, const std::string & /*name*/,
size_t /*n*/) override {
throw Mantid::Kernel::Exception::NotImplementedError(
"LeanElasticPeaksWorkspace structure is read-only. Cannot add columns.");
"LeanElasticPeaksWorkspace structure is read-only. Cannot add "
"columns.");
}
void removeColumn(const std::string & /*name*/) override {
throw Mantid::Kernel::Exception::NotImplementedError(
"LeanElasticPeaksWorkspace structure is read-only. Cannot remove column.");
"LeanElasticPeaksWorkspace structure is read-only. Cannot remove "
"column.");
}
void setRowCount(size_t /*count*/) override {
......@@ -272,7 +275,8 @@ private:
std::vector<LeanElasticPeak> peaks;
/** Column shared pointers. */
std::vector<std::shared_ptr<Mantid::DataObjects::LeanElasticPeakColumn>> columns;
std::vector<std::shared_ptr<Mantid::DataObjects::LeanElasticPeakColumn>>
columns;
/** Column names */
std::vector<std::string> columnNames;
......@@ -282,9 +286,11 @@ private:
};
/// Typedef for a shared pointer to a peaks workspace.
using LeanElasticPeaksWorkspace_sptr = std::shared_ptr<LeanElasticPeaksWorkspace>;
using LeanElasticPeaksWorkspace_sptr =
std::shared_ptr<LeanElasticPeaksWorkspace>;
/// Typedef for a shared pointer to a const peaks workspace.
using LeanElasticPeaksWorkspace_const_sptr = std::shared_ptr<const LeanElasticPeaksWorkspace>;
using LeanElasticPeaksWorkspace_const_sptr =
std::shared_ptr<const LeanElasticPeaksWorkspace>;
} // namespace DataObjects
} // namespace Mantid
......@@ -95,6 +95,9 @@ public:
createPeak(const Kernel::V3D &Position,
const Kernel::SpecialCoordinateSystem &frame) const override;
std::unique_ptr<Geometry::IPeak>
createPeakQSample(const Kernel::V3D &position) const override;
std::vector<std::pair<std::string, std::string>>
peakInfo(const Kernel::V3D &qFrame, bool labCoords) const override;
......@@ -180,9 +183,6 @@ private:
void initColumns();
/// Adds a new PeakColumn of the given type
void addPeakColumn(const std::string &name);
/// Create a peak from a QSample position
std::unique_ptr<Geometry::IPeak>
createPeakQSample(const Kernel::V3D &position) const;
// ====================================== ITableWorkspace Methods
// ==================================
......
......@@ -39,7 +39,8 @@ LeanElasticPeaksWorkspace::LeanElasticPeaksWorkspace()
: IPeaksWorkspace(), peaks(), columns(), columnNames(),
m_coordSystem(None) {
initColumns();
// LeanElasticPeaksWorkspace does not use the grouping mechanism of ExperimentInfo.
// LeanElasticPeaksWorkspace does not use the grouping mechanism of
// ExperimentInfo.
setNumberOfDetectorGroups(0);
}
......@@ -48,13 +49,15 @@ LeanElasticPeaksWorkspace::LeanElasticPeaksWorkspace()
*
* @param other :: other LeanElasticPeaksWorkspace to copy from
*/
// LeanElasticPeaksWorkspace::LeanElasticPeaksWorkspace(const LeanElasticPeaksWorkspace &other) =
// default;
LeanElasticPeaksWorkspace::LeanElasticPeaksWorkspace(const LeanElasticPeaksWorkspace &other)
// LeanElasticPeaksWorkspace::LeanElasticPeaksWorkspace(const
// LeanElasticPeaksWorkspace &other) = default;
LeanElasticPeaksWorkspace::LeanElasticPeaksWorkspace(
const LeanElasticPeaksWorkspace &other)
: IPeaksWorkspace(other), peaks(other.peaks), columns(), columnNames(),
m_coordSystem(other.m_coordSystem) {
initColumns();
// LeanElasticPeaksWorkspace does not use the grouping mechanism of ExperimentInfo.
// LeanElasticPeaksWorkspace does not use the grouping mechanism of
// ExperimentInfo.
setNumberOfDetectorGroups(0);
}
......@@ -114,7 +117,8 @@ public:
* The peaks are sorted by the first criterion first, then the 2nd if
*equal, etc.
*/
void LeanElasticPeaksWorkspace::sort(std::vector<ColumnAndDirection> &criteria) {
void LeanElasticPeaksWorkspace::sort(
std::vector<ColumnAndDirection> &criteria) {
PeakComparator comparator(criteria);
std::stable_sort(peaks.begin(), peaks.end(), comparator);
}
......@@ -122,12 +126,16 @@ void LeanElasticPeaksWorkspace::sort(std::vector<ColumnAndDirection> &criteria)
//---------------------------------------------------------------------------------------------
/** @return the number of peaks
*/
int LeanElasticPeaksWorkspace::getNumberPeaks() const { return int(peaks.size()); }
int LeanElasticPeaksWorkspace::getNumberPeaks() const {
return int(peaks.size());
}
//---------------------------------------------------------------------------------------------
/** @return the convention
*/
std::string LeanElasticPeaksWorkspace::getConvention() const { return convention; }
std::string LeanElasticPeaksWorkspace::getConvention() const {
return convention;
}
//---------------------------------------------------------------------------------------------
/** Removes the indicated peak
......@@ -149,8 +157,8 @@ void LeanElasticPeaksWorkspace::removePeaks(std::vector<int> badPeaks) {
return;
// if index of peak is in badPeaks remove
int ip = -1;
auto it =
std::remove_if(peaks.begin(), peaks.end(), [&ip, badPeaks](LeanElasticPeak &pk) {
auto it = std::remove_if(
peaks.begin(), peaks.end(), [&ip, badPeaks](LeanElasticPeak &pk) {
(void)pk;
ip++;
return std::any_of(badPeaks.cbegin(), badPeaks.cend(),
......@@ -186,7 +194,9 @@ void LeanElasticPeaksWorkspace::addPeak(const V3D &position,
/** Add a peak to the list
* @param peak :: Peak object to add (move) into this.
*/
void LeanElasticPeaksWorkspace::addPeak(LeanElasticPeak &&peak) { peaks.emplace_back(peak); }
void LeanElasticPeaksWorkspace::addPeak(LeanElasticPeak &&peak) {
peaks.emplace_back(peak);
}
//---------------------------------------------------------------------------------------------
/** Return a reference to the Peak
......@@ -206,7 +216,8 @@ LeanElasticPeak &LeanElasticPeaksWorkspace::getPeak(const int peakNum) {
* @param peakNum :: index of the peak to get.
* @return a reference to a Peak object.
*/
const LeanElasticPeak &LeanElasticPeaksWorkspace::getPeak(const int peakNum) const {
const LeanElasticPeak &
LeanElasticPeaksWorkspace::getPeak(const int peakNum) const {
if (peakNum >= static_cast<int>(peaks.size()) || peakNum < 0) {
throw std::invalid_argument(
"LeanElasticPeaksWorkspace::getPeak(): peakNum is out of range.");
......@@ -222,9 +233,10 @@ const LeanElasticPeak &LeanElasticPeaksWorkspace::getPeak(const int peakNum) con
* @return a pointer to a new Peak object.
*/
std::unique_ptr<Geometry::IPeak>
LeanElasticPeaksWorkspace::createPeak(const Kernel::V3D &QLabFrame,
boost::optional<double> detectorDistance) const {
return createPeakQSample(QLabFrame);
LeanElasticPeaksWorkspace::createPeak(const Kernel::V3D &,
boost::optional<double>) const {
throw Exception::NotImplementedError(
"LeanElasticPeak should be create in q sample frame");
}
//---------------------------------------------------------------------------------------------
......@@ -279,7 +291,7 @@ LeanElasticPeaksWorkspace::createPeakQSample(const V3D &position) const {
* value.
*/
std::vector<std::pair<std::string, std::string>>
LeanElasticPeaksWorkspace::peakInfo(const Kernel::V3D &qFrame, bool labCoords) const {
LeanElasticPeaksWorkspace::peakInfo(const Kernel::V3D &, bool) const {
throw Exception::NotImplementedError("");
}
......@@ -290,7 +302,8 @@ LeanElasticPeaksWorkspace::peakInfo(const Kernel::V3D &qFrame, bool labCoords) c
* @param HKL : reciprocal lattice vector coefficients
* @return Fully formed peak.
*/
std::unique_ptr<IPeak> LeanElasticPeaksWorkspace::createPeakHKL(const V3D &HKL) const {
std::unique_ptr<IPeak>
LeanElasticPeaksWorkspace::createPeakHKL(const V3D &HKL) const {
/*
The following allows us to add peaks where we have a single UB to work from.
*/
......@@ -329,17 +342,19 @@ std::unique_ptr<IPeak> LeanElasticPeaksWorkspace::createPeakHKL(const V3D &HKL)
*form for the corresponding
* value.
*/
int LeanElasticPeaksWorkspace::peakInfoNumber(const Kernel::V3D &qFrame,
bool labCoords) const {
int LeanElasticPeaksWorkspace::peakInfoNumber(const Kernel::V3D &, bool) const {
throw Exception::NotImplementedError("");
}
//---------------------------------------------------------------------------------------------
/** Return a reference to the Peaks vector */
std::vector<LeanElasticPeak> &LeanElasticPeaksWorkspace::getPeaks() { return peaks; }
std::vector<LeanElasticPeak> &LeanElasticPeaksWorkspace::getPeaks() {
return peaks;
}
/** Return a const reference to the Peaks vector */
const std::vector<LeanElasticPeak> &LeanElasticPeaksWorkspace::getPeaks() const {
const std::vector<LeanElasticPeak> &
LeanElasticPeaksWorkspace::getPeaks() const {
return peaks;
}
......@@ -371,7 +386,8 @@ size_t LeanElasticPeaksWorkspace::getMemorySize() const {
* index
* within the LeanElasticPeaksWorkspace of the peak
*/
API::ITableWorkspace_sptr LeanElasticPeaksWorkspace::createDetectorTable() const {
API::ITableWorkspace_sptr
LeanElasticPeaksWorkspace::createDetectorTable() const {
throw Exception::NotImplementedError("");
}
......@@ -416,11 +432,13 @@ void LeanElasticPeaksWorkspace::addPeakColumn(const std::string &name) {
//---------------------------------------------------------------------------------------------
/// @return the index of the column with the given name.
size_t LeanElasticPeaksWorkspace::getColumnIndex(const std::string &name) const {
size_t
LeanElasticPeaksWorkspace::getColumnIndex(const std::string &name) const {
for (size_t i = 0; i < columns.size(); i++)
if (columns[i]->name() == name)
return i;
throw std::invalid_argument("Column named " + name +
throw std::invalid_argument(
"Column named " + name +
" was not found in the LeanElasticPeaksWorkspace.");
}
......@@ -444,7 +462,7 @@ LeanElasticPeaksWorkspace::getColumn(size_t index) const {
return columns[index];
}
void LeanElasticPeaksWorkspace::saveNexus(::NeXus::File *file) const {
void LeanElasticPeaksWorkspace::saveNexus(::NeXus::File *) const {
throw Exception::NotImplementedError("");
}
......@@ -513,7 +531,8 @@ IPropertyManager::getValue<Mantid::DataObjects::LeanElasticPeaksWorkspace_sptr>(
template <>
DLLExport Mantid::DataObjects::LeanElasticPeaksWorkspace_const_sptr
IPropertyManager::getValue<Mantid::DataObjects::LeanElasticPeaksWorkspace_const_sptr>(
IPropertyManager::getValue<
Mantid::DataObjects::LeanElasticPeaksWorkspace_const_sptr>(
const std::string &name) const {
auto *prop = dynamic_cast<
PropertyWithValue<Mantid::DataObjects::LeanElasticPeaksWorkspace_sptr> *>(
......@@ -521,9 +540,9 @@ IPropertyManager::getValue<Mantid::DataObjects::LeanElasticPeaksWorkspace_const_
if (prop) {
return prop->operator()();
} else {
std::string message =
"Attempt to assign property " + name +
" to incorrect type. Expected const shared_ptr<LeanElasticPeaksWorkspace>.";
std::string message = "Attempt to assign property " + name +
" to incorrect type. Expected const "
"shared_ptr<LeanElasticPeaksWorkspace>.";
throw std::runtime_error(message);
}
}
......
......@@ -54,6 +54,15 @@ IPeak *createPeakQLabWithDistance(IPeaksWorkspace &self, const object &data,
// Python will manage the object
return peak.release();
}
/// Create a peak via it's QSample value from a list or numpy array
IPeak *createPeakQSample(IPeaksWorkspace &self, const object &data) {
auto peak = self.createPeakQSample(
Mantid::PythonInterface::Converters::PyObjectToV3D(data)());
// Python will manage it
return peak.release();
}
/// Create a peak via it's QLab value from a list or numpy array
void addPeak(IPeaksWorkspace &self, const IPeak &peak) { self.addPeak(peak); }
......@@ -265,6 +274,10 @@ void export_IPeaksWorkspace() {
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("createPeakQSample", createPeakQSample, (arg("self"), arg("data")),
return_value_policy<manage_new_object>(),
"Create a Peak and return it from its coordinates in the QSample "
"frame")
.def("createPeakHKL", createPeakHKL, (arg("self"), arg("data")),
return_value_policy<manage_new_object>(),
"Create a Peak and return it from its coordinates in the HKL frame")
......
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