13#include <boost/none.hpp>
14#include <boost/optional.hpp>
15#include <boost/python/class.hpp>
16#include <boost/python/iterator.hpp>
17#include <boost/python/manage_new_object.hpp>
18#include <boost/python/return_internal_reference.hpp>
38 return peak.release();
45 return peak.release();
49IPeak *createPeakQLabWithDistance(
const IPeaksWorkspace &self,
const object &data,
double detectorDistance) {
52 return peak.release();
59 return peak.release();
87class PeakWorkspaceTableAdaptor {
94 explicit PeakWorkspaceTableAdaptor(
IPeaksWorkspace &peaksWorkspace) : m_peaksWorkspace(peaksWorkspace) {
117 void setProperty(
const std::string &columnName,
const int rowIndex,
object value) {
118 auto &peak = m_peaksWorkspace.getPeak(rowIndex);
119 if (m_setterMap.find(columnName) == m_setterMap.end()) {
120 throw std::runtime_error(columnName +
" is a read only column of a peaks workspace");
122 m_setterMap[columnName](peak, std::move(
value));
127 template <
typename T>
using MemberFunc = void (
IPeak::*)(T
value);
129 using MemberFuncV3D = void (
IPeak::*)(
const V3D &
value, boost::optional<double>);
131 using SetterType = std::function<void(
IPeak &peak,
const object)>;
140 template <
typename T> SetterType setterFunction(
const MemberFunc<T> func) {
141 return [func](
IPeak &peak,
const object &
value) {
142 extract<T> extractor{
value};
143 if (!extractor.check()) {
144 throw std::runtime_error(
"Cannot set value. Value was not of the expected type!");
146 (peak.*func)(extractor());
160 SetterType setterFunction(
const MemberFuncV3D func) {
161 return [func](
IPeak &peak,
const object &
value) {
162 extract<const V3D &> extractor{
value};
163 if (!extractor.check()) {
164 throw std::runtime_error(
"Cannot set value. Value was not of the expected type!");
166 (peak.*func)(extractor(), boost::none);
173 std::unordered_map<std::string, SetterType> m_setterMap;
186std::pair<int, std::string> getRowAndColumnName(
const IPeaksWorkspace &self,
const object &col_or_row,
187 const int row_or_col) {
188 extract<std::string> columnNameExtractor{col_or_row};
189 std::string columnName;
192 if (columnNameExtractor.check()) {
193 columnName = columnNameExtractor();
194 rowIndex = row_or_col;
196 rowIndex = extract<int>(col_or_row)();
197 const auto colIndex = row_or_col;
199 columnName = columnNames.at(colIndex);
202 return std::make_pair(rowIndex, columnName);
213void setCell(
IPeaksWorkspace &self,
const object &col_or_row,
const int row_or_col,
const object &
value) {
214 std::string columnName;
216 std::tie(rowIndex, columnName) = getRowAndColumnName(self, col_or_row, row_or_col);
218 PeakWorkspaceTableAdaptor tableMap{self};
219 tableMap.setProperty(columnName, rowIndex,
value);
223struct IPeaksWorkspaceIterator {
230 if (m_rowIndex >= m_numPeaks) {
231 objects::stop_iteration_error();
233 return m_workspace->getPeakPtr(m_rowIndex);
238 const int m_numPeaks;
243IPeaksWorkspaceIterator makePyIterator(
IPeaksWorkspace &self) {
return IPeaksWorkspaceIterator(&self); }
248 class_<IPeaksWorkspaceIterator>(
"IPeaksWorkspaceIterator", no_init)
249 .def(
"__next__", &IPeaksWorkspaceIterator::next, return_value_policy<reference_existing_object>())
250 .def(
"__iter__", objects::identity_function());
255 class_<IPeaksWorkspace, bases<ITableWorkspace, ExperimentInfo>, boost::noncopyable>(
"IPeaksWorkspace", no_init)
257 "Returns the number of peaks within the workspace")
258 .def(
"addPeak", addPeak, (arg(
"self"), arg(
"peak")),
"Add a peak to the workspace")
259 .def(
"addPeak", addPeak2, (arg(
"self"), arg(
"data"), arg(
"coord_system")),
"Add a peak to the workspace")
260 .def(
"removePeak", removePeak, (arg(
"self"), arg(
"peak_num")),
"Remove a peak from the workspace")
262 "Returns a peak at the given index")
263 .def(
"createPeak", createPeakQLab, (arg(
"self"), arg(
"data")), return_value_policy<manage_new_object>(),
264 "Create a Peak and return it from its coordinates in the QLab frame")
265 .def(
"createPeak", createPeakQLabWithDistance, (arg(
"self"), arg(
"data"), arg(
"detector_distance")),
266 return_value_policy<manage_new_object>(),
267 "Create a Peak and return it from its coordinates in the QLab "
268 "frame, detector-sample distance explicitly provided")
269 .def(
"createPeakQSample", createPeakQSample, (arg(
"self"), arg(
"data")), return_value_policy<manage_new_object>(),
270 "Create a Peak and return it from its coordinates in the QSample "
272 .def(
"createPeakHKL", createPeakHKL, (arg(
"self"), arg(
"data")), return_value_policy<manage_new_object>(),
273 "Create a Peak and return it from its coordinates in the HKL frame")
275 "Determine if the peaks have been integrated")
276 .def(
"getRun", &IPeaksWorkspace::mutableRun, arg(
"self"), return_internal_reference<>(),
277 "Return the Run object for this workspace")
279 "Peak info number at Q vector for this workspace")
280 .def(
"setCell", &setCell, (arg(
"self"), arg(
"row_or_column"), arg(
"column_or_row"), arg(
"value")),
281 "Sets the value of a given cell. If the row_or_column argument is a "
282 "number then it is interpreted as a row otherwise it "
283 "is interpreted as a column name.")
284 .def(
"__iter__", makePyIterator);
double value
The value of the point.
#define GET_POINTER_SPECIALIZATION(TYPE)
IPeaksWorkspace_sptr workspace
void export_IPeaksWorkspaceIterator()
void export_IPeaksWorkspace()
Interface to the class Mantid::DataObjects::PeaksWorkspace.
Mantid::Geometry::IPeak * getPeakPtr(const int peakNum)
Return a pointer to the Peak.
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 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 > createPeak(const Mantid::Kernel::V3D &QLabFrame, boost::optional< double > detectorDistance=boost::none) const =0
Create an instance of a Peak.
virtual std::unique_ptr< Geometry::IPeak > createPeakHKL(const Mantid::Kernel::V3D &HKL) const =0
Create an instance of a peak using a V3D.
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.
virtual std::vector< std::string > getColumnNames() const =0
Returns a vector of all column names.
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, boost::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 setQSampleFrame(const Mantid::Kernel::V3D &QSampleFrame, boost::optional< double > detectorDistance)=0
virtual void setRunNumber(int m_RunNumber)=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 ...
Encapsulates the registration required for an interface type T that sits on top of a Kernel::DataItem...