15#include <boost/none.hpp>
16#include <boost/python/class.hpp>
17#include <boost/python/iterator.hpp>
18#include <boost/python/manage_new_object.hpp>
19#include <boost/python/return_internal_reference.hpp>
41 return peak.release();
48 return peak.release();
52IPeak *createPeakQLabWithDistance(
const IPeaksWorkspace &self,
const object &data,
double detectorDistance) {
55 return peak.release();
62 return peak.release();
84void removePeaks(
IPeaksWorkspace &self,
const boost::python::object &peak_nums) {
96class PeakWorkspaceTableAdaptor {
103 explicit PeakWorkspaceTableAdaptor(
IPeaksWorkspace &peaksWorkspace) : m_peaksWorkspace(peaksWorkspace) {
126 void setProperty(
const std::string &columnName,
const int rowIndex,
object value) {
127 auto &peak = m_peaksWorkspace.getPeak(rowIndex);
128 if (m_setterMap.find(columnName) == m_setterMap.end()) {
129 throw std::runtime_error(columnName +
" is a read only column of a peaks workspace");
131 m_setterMap[columnName](peak, std::move(
value));
136 template <
typename T>
using MemberFunc = void (
IPeak::*)(T
value);
138 using MemberFuncV3D = void (
IPeak::*)(const
V3D &
value,
std::optional<double>);
140 using SetterType = std::function<void(
IPeak &peak,
const object)>;
149 template <
typename T> SetterType setterFunction(
const MemberFunc<T> func) {
150 return [func](
IPeak &peak,
const object &
value) {
151 extract<T> extractor{
value};
152 if (!extractor.check()) {
153 throw std::runtime_error(
"Cannot set value. Value was not of the expected type!");
155 (peak.*func)(extractor());
169 SetterType setterFunction(
const MemberFuncV3D func) {
170 return [func](
IPeak &peak,
const object &
value) {
171 extract<const V3D &> extractor{
value};
172 if (!extractor.check()) {
173 throw std::runtime_error(
"Cannot set value. Value was not of the expected type!");
175 (peak.*func)(extractor(), std::nullopt);
182 std::unordered_map<std::string, SetterType> m_setterMap;
197std::pair<
int,
std::
string> getRowAndColumnName(const
IPeaksWorkspace &self, const
object &col_or_row,
198 const
int row_or_col) {
199 extract<std::string> columnNameExtractor{col_or_row};
200 std::string columnName;
203 if (columnNameExtractor.check()) {
204 columnName = columnNameExtractor();
205 rowIndex = row_or_col;
207 rowIndex = extract<int>(col_or_row)();
208 const auto colIndex = row_or_col;
209 const auto columnNames = self.getColumnNames();
210 columnName = columnNames.at(colIndex);
213 return std::make_pair(rowIndex, columnName);
226void setCell(
IPeaksWorkspace &self, const
object &col_or_row, const
int row_or_col, const
object &
value) {
227 std::string columnName;
229 std::tie(rowIndex, columnName) = getRowAndColumnName(self, col_or_row, row_or_col);
231 PeakWorkspaceTableAdaptor tableMap{self};
232 tableMap.setProperty(columnName, rowIndex,
value);
236struct IPeaksWorkspaceIterator {
243 if (m_rowIndex >= m_numPeaks) {
244 objects::stop_iteration_error();
246 return m_workspace->getPeakPtr(m_rowIndex);
251 const int m_numPeaks;
256IPeaksWorkspaceIterator makePyIterator(
IPeaksWorkspace &self) {
return IPeaksWorkspaceIterator(&self); }
261 class_<IPeaksWorkspaceIterator>(
"IPeaksWorkspaceIterator", no_init)
262 .def(
"__next__", &IPeaksWorkspaceIterator::next, return_value_policy<reference_existing_object>())
263 .def(
"__iter__", objects::identity_function());
268 class_<IPeaksWorkspace, bases<ITableWorkspace, ExperimentInfo>, boost::noncopyable>(
"IPeaksWorkspace", no_init)
270 "Returns the number of peaks within the workspace")
271 .def(
"addPeak", addPeak, (arg(
"self"), arg(
"peak")),
"Add a peak to the workspace")
272 .def(
"addPeak", addPeak2, (arg(
"self"), arg(
"data"), arg(
"coord_system")),
"Add a peak to the workspace")
273 .def(
"removePeak", removePeak, (arg(
"self"), arg(
"peak_num")),
"Remove a peak from the workspace")
274 .def(
"removePeaks", removePeaks, (arg(
"self"), arg(
"peak_num")),
"Remove specified peaks from the workspace")
276 "Returns a peak at the given index")
277 .def(
"createPeak", createPeakQLab, (arg(
"self"), arg(
"data")), return_value_policy<manage_new_object>(),
278 "Create a Peak and return it from its coordinates in the QLab frame")
279 .def(
"createPeak", createPeakQLabWithDistance, (arg(
"self"), arg(
"data"), arg(
"detector_distance")),
280 return_value_policy<manage_new_object>(),
281 "Create a Peak and return it from its coordinates in the QLab "
282 "frame, detector-sample distance explicitly provided")
283 .def(
"createPeakQSample", createPeakQSample, (arg(
"self"), arg(
"data")), return_value_policy<manage_new_object>(),
284 "Create a Peak and return it from its coordinates in the QSample "
286 .def(
"createPeakHKL", createPeakHKL, (arg(
"self"), arg(
"data")), return_value_policy<manage_new_object>(),
287 "Create a Peak and return it from its coordinates in the HKL frame")
289 "Determine if the peaks have been integrated")
290 .def(
"getRun", &IPeaksWorkspace::mutableRun, arg(
"self"), return_internal_reference<>(),
291 "Return the Run object for this workspace")
293 "Peak info number at Q vector for this workspace")
294 .def(
"setCell", &setCell, (arg(
"self"), arg(
"row_or_column"), arg(
"column_or_row"), arg(
"value")),
295 "Sets the value of a given cell. If the row_or_column argument is a "
296 "number then it is interpreted as a row otherwise it "
297 "is interpreted as a column name.")
298 .def(
"__iter__", makePyIterator);
double value
The value of the point.
#define GET_POINTER_SPECIALIZATION(TYPE)
IPeaksWorkspace_sptr workspace
void export_IPeaksWorkspaceIterator()
void export_IPeaksWorkspace()
#define GNU_DIAG_OFF(x)
This is a collection of macros for turning compiler warnings off in a controlled manner.
Interface to the class Mantid::DataObjects::PeaksWorkspace.
virtual bool hasIntegratedPeaks() const =0
Determine if the workspace has been integrated using a peaks integration algorithm.
virtual void removePeak(int peakNum)=0
Removes the indicated peak.
virtual void removePeaks(std::vector< int > badPeaks)=0
virtual void addPeak(const Mantid::Geometry::IPeak &ipeak)=0
Add a peak to the list.
virtual int peakInfoNumber(const Kernel::V3D &qLabFrame, bool labCoords) const =0
virtual std::unique_ptr< Geometry::IPeak > createPeakHKL(const Mantid::Kernel::V3D &HKL) const =0
Create an instance of a peak using a V3D.
virtual std::unique_ptr< Geometry::IPeak > createPeak(const Mantid::Kernel::V3D &QLabFrame, std::optional< double > detectorDistance=std::nullopt) const =0
Create an instance of a Peak.
Mantid::Geometry::IPeak * getPeakPtr(size_t const peakNum)
Return a pointer to the Peak.
virtual int getNumberPeaks() const =0
virtual std::unique_ptr< Mantid::Geometry::IPeak > createPeakQSample(const Mantid::Kernel::V3D &position) const =0
Create an instance of a Peak.
void modified()
If the workspace is the AnalysisDataService sends AfterReplaceNotification.
Structure describing a single-crystal peak.
virtual void setIntensity(double m_Intensity)=0
virtual void setK(double m_K)=0
virtual void setBinCount(double m_BinCount)=0
virtual void setQLabFrame(const Mantid::Kernel::V3D &QLabFrame, std::optional< double > detectorDistance)=0
virtual void setH(double m_H)=0
virtual void setPeakNumber(int m_PeakNumber)=0
virtual void setSigmaIntensity(double m_SigmaIntensity)=0
virtual void setL(double m_L)=0
virtual void setRunNumber(int m_RunNumber)=0
virtual void setQSampleFrame(const Mantid::Kernel::V3D &QSampleFrame, std::optional< double > detectorDistance)=0
virtual void setWavelength(double wavelength)=0
std::shared_ptr< Column > Column_sptr
SpecialCoordinateSystem
Special coordinate systems for Q3D.
Takes a Python object and if it supports indexing and is of length 3 then it will attempt to convert ...
Converts a Python sequence type to a C++ std::vector, where the element type is defined by the templa...
Encapsulates the registration required for an interface type T that sits on top of a Kernel::DataItem...