Mantid
Loading...
Searching...
No Matches
IMDDimension.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
13#include <memory>
14#include <stdexcept>
15
16#include <boost/python/class.hpp>
17#include <boost/python/copy_const_reference.hpp>
18#include <boost/python/register_ptr_to_python.hpp>
19#include <boost/python/return_internal_reference.hpp>
20
21using namespace Mantid::Geometry;
22using namespace boost::python;
23
25
26GNU_DIAG_OFF("strict-aliasing")
27
28namespace {
33std::string getUnitsAsStr(const IMDDimension &self) { return self.getUnits().ascii(); }
34
40std::shared_ptr<MDFrame> getMDFrame(const IMDDimension &self) {
41 return std::shared_ptr<MDFrame>(self.getMDFrame().clone());
42}
43
51MDHistoDimension &asEditableDimension(IMDDimension &self) {
52 auto *histoDimension = dynamic_cast<MDHistoDimension *>(&self);
53 if (!histoDimension) {
54 throw std::runtime_error("Editing the name or units is only supported for MDHistoWorkspace dimensions.");
55 }
56 return *histoDimension;
57}
58
63void setName(IMDDimension &self, const std::string &name) { asEditableDimension(self).setName(name); }
64
69void setUnits(IMDDimension &self, const std::string &units) {
70 asEditableDimension(self).setUnits(Mantid::Kernel::UnitLabel(units));
71}
72} // namespace
73
74//--------------------------------------------------------------------------------------
75// Deprecated function
76//--------------------------------------------------------------------------------------
81std::string getName(const IMDDimension &self) {
82 PyErr_Warn(PyExc_DeprecationWarning, ".getName() is deprecated. Use .name instead.");
83 return self.getName();
84}
85
87 register_ptr_to_python<std::shared_ptr<IMDDimension>>();
88
89 class_<IMDDimension, boost::noncopyable>("IMDDimension", no_init)
90 .def("getName", &getName, arg("self"),
91 "Return the name of the dimension "
92 "as can be displayed along the "
93 "axis")
94 .add_property("name", &IMDDimension::getName,
95 "Return the name of the dimension as can be displayed "
96 "along the axis")
97 .def("getMaximum", &IMDDimension::getMaximum, arg("self"), "Return the maximum extent of this dimension")
98 .def("getMinimum", &IMDDimension::getMinimum, arg("self"), "Return the maximum extent of this dimension")
99 .def("getNBins", &IMDDimension::getNBins, arg("self"),
100 "Return the number of bins dimension have (an integrated has one). "
101 "A axis directed along dimension would have getNBins+1 axis points.")
102 .def("getNBoundaries", &IMDDimension::getNBoundaries, arg("self"),
103 "Return the number of bins boundaries (axis points) dimension have "
104 "(an integrated has two). "
105 "A axis directed along dimension would have getNBins+1 axis points.")
106 .def("getX", &IMDDimension::getX, (arg("self"), arg("ind")), "Return coordinate of the axis at the given index")
107 .def("getBinWidth", &IMDDimension::getBinWidth, arg("self"), "Return the width of each bin.")
108 .def("getDimensionId", &IMDDimension::getDimensionId, arg("self"), return_value_policy<copy_const_reference>(),
109 "Return a short name which identify the dimension among other "
110 "dimension."
111 "A dimension can be usually find by its ID and various ")
112 .def("getUnits", &getUnitsAsStr, arg("self"), "Return the units associated with this dimension.")
113 .def("getMDFrame", &getMDFrame, arg("self"), "Return the multidimensional frame for this dimension.")
114 .def("setName", &setName, (arg("self"), arg("name")),
115 "Set the name of the dimension as displayed along the axis. Only "
116 "supported for MDHistoWorkspace dimensions.")
117 .def("setUnits", &setUnits, (arg("self"), arg("units")),
118 "Set the units of the dimension. Only supported for MDHistoWorkspace "
119 "dimensions whose frame permits it (HKL and general frames); an HKL "
120 "dimension accepts 'r.l.u.' or an inverse-Angstrom-style label such as "
121 "'in 2.5 A^-1'. Raises for a frame with a fixed unit (e.g. QSample/QLab) "
122 "or a label the frame does not accept.");
123}
std::string name
Definition Run.cpp:60
#define GET_POINTER_SPECIALIZATION(TYPE)
Definition GetPointer.h:17
void export_IMDDimension()
std::string getName(const IMDDimension &self)
#define GNU_DIAG_OFF(x)
This is a collection of macros for turning compiler warnings off in a controlled manner.
The class describes one dimension of multidimensional dataset representing an orthogonal dimension an...
virtual coord_t getMaximum() const =0
virtual coord_t getMinimum() const =0
virtual std::string getName() const =0
virtual const Geometry::MDFrame & getMDFrame() const =0
virtual const Kernel::UnitLabel getUnits() const =0
virtual const std::string & getDimensionId() const =0
short name which identify the dimension among other dimension.
virtual coord_t getBinWidth() const
virtual coord_t getX(size_t ind) const =0
virtual size_t getNBoundaries() const =0
virtual size_t getNBins() const =0
virtual MDFrame * clone() const =0
A base-class for the a class that is able to return unit labels in different representations.
Definition UnitLabel.h:20
const AsciiString & ascii() const
Return an ascii label for unit.