IPeak.cpp 10 KB
Newer Older
Owen Arnold's avatar
Owen Arnold committed
1
#include "MantidGeometry/Crystal/IPeak.h"
2
#include "MantidPythonInterface/kernel/Converters/CloneToNumpy.h"
3
#include "MantidPythonInterface/kernel/Converters/PyObjectToMatrix.h"
4
#include "MantidPythonInterface/kernel/GetPointer.h"
Samuel Jackson's avatar
Samuel Jackson committed
5
#include "MantidPythonInterface/kernel/Policies/MatrixToNumpy.h"
6
#include <boost/optional.hpp>
7
8
#include <boost/python/class.hpp>
#include <boost/python/register_ptr_to_python.hpp>
9

Owen Arnold's avatar
Owen Arnold committed
10
using Mantid::Geometry::IPeak;
11
using namespace Mantid::PythonInterface;
12
13
using namespace boost::python;

14
15
GET_POINTER_SPECIALIZATION(IPeak)

16
namespace {
17
using namespace Mantid::PythonInterface;
18
19
20
21
Mantid::Geometry::PeakShape_sptr getPeakShape(IPeak &peak) {
  // Use clone to make a copy of the PeakShape.
  return Mantid::Geometry::PeakShape_sptr(peak.getPeakShape().clone());
}
22
void setQLabFrame1(IPeak &peak, Mantid::Kernel::V3D qLabFrame) {
Owen Arnold's avatar
Owen Arnold committed
23
  // Set the q lab frame. No explicit detector distance.
Hahn, Steven's avatar
Hahn, Steven committed
24
  return peak.setQLabFrame(qLabFrame, boost::none);
25
}
26
27
void setQLabFrame2(IPeak &peak, Mantid::Kernel::V3D qLabFrame,
                   double distance) {
Owen Arnold's avatar
Owen Arnold committed
28
  // Set the q lab frame. Detector distance specified.
29
  return peak.setQLabFrame(qLabFrame, distance);
30
}
31
32

void setQSampleFrame1(IPeak &peak, Mantid::Kernel::V3D qSampleFrame) {
33
  // Set the qsample frame. No explicit detector distance.
Hahn, Steven's avatar
Hahn, Steven committed
34
  return peak.setQSampleFrame(qSampleFrame, boost::none);
35
36
}

37
38
39
40
void setQSampleFrame2(IPeak &peak, Mantid::Kernel::V3D qSampleFrame,
                      double distance) {
  // Set the qsample frame. Detector distance specified.
  return peak.setQSampleFrame(qSampleFrame, distance);
41
}
42
43
44
45

void setGoniometerMatrix(IPeak &self, const object &data) {
  self.setGoniometerMatrix(Converters::PyObjectToMatrix(data)());
}
46

47
} // namespace
48

49
void export_IPeak() {
50
  // return_value_policy for read-only numpy array
51
  using return_copy_to_numpy = return_value_policy<Policies::MatrixToNumpy>;
Samuel Jackson's avatar
Samuel Jackson committed
52

53
  register_ptr_to_python<IPeak *>();
54
55

  class_<IPeak, boost::noncopyable>("IPeak", no_init)
56
      .def("getDetectorID", &IPeak::getDetectorID, arg("self"),
Samuel Jackson's avatar
Samuel Jackson committed
57
58
           "Get the ID of the :class:`~mantid.geometry.Detector` at the center "
           "of the peak")
59
      .def("setDetectorID", &IPeak::setDetectorID, (arg("self"), arg("det_id")),
Samuel Jackson's avatar
Samuel Jackson committed
60
61
           "Set the :class:`~mantid.geometry.Detector` ID and look up and "
           "cache values related to it.")
62
      .def("getRunNumber", &IPeak::getRunNumber, arg("self"),
63
           "Return the run number this peak was measured at")
64
65
66
67
      .def("getPeakNumber", &IPeak::getPeakNumber, arg("self"),
           "Return the peak number for this peak")
      .def("getBankName", &IPeak::getBankName, arg("self"),
           "Return the bank name for this peak")
68
      .def("setRunNumber", &IPeak::setRunNumber,
69
           (arg("self"), arg("run_number")),
70
           "Set the run number that measured this peak")
71
72
73
      .def("setPeakNumber", &IPeak::setPeakNumber,
           (arg("self"), arg("peak_number")),
           "Set the peak number for this peak")
74
      .def("getMonitorCount", &IPeak::getMonitorCount, arg("self"),
75
76
           "Get the monitor count set for this peak")
      .def("setMonitorCount", &IPeak::setMonitorCount,
77
           (arg("self"), arg("monitor_count")),
78
           "Set the monitor count for this peak")
79
80
81
      .def("getH", &IPeak::getH, arg("self"), "Get the H index of the peak")
      .def("getK", &IPeak::getK, arg("self"), "Get the K index of the peak")
      .def("getL", &IPeak::getL, arg("self"), "Get the L index of the peak")
Samuel Jackson's avatar
Samuel Jackson committed
82
83
      .def("getHKL", &IPeak::getHKL, arg("self"),
           "Get HKL as a :class:`~mantid.kernel.V3D` object")
84
      .def("setHKL", (void (IPeak::*)(double, double, double)) & IPeak::setHKL,
85
           (arg("self"), arg("h"), arg("k"), arg("l")),
86
           "Set the HKL values of this peak")
87
      .def("setH", &IPeak::setH, (arg("self"), arg("h")),
88
           "Get the H index of the peak")
89
      .def("setK", &IPeak::setK, (arg("self"), arg("k")),
90
           "Get the K index of the peak")
91
      .def("setL", &IPeak::setL, (arg("self"), arg("l")),
92
           "Get the L index of the peak")
93
      .def("getQLabFrame", &IPeak::getQLabFrame, arg("self"),
94
           "Return the Q change (of the lattice, k_i - k_f) for this peak.\n"
Samuel Jackson's avatar
Samuel Jackson committed
95
96
           "The Q is in the Lab frame: the "
           ":class:`~mantid.geometry.Goniometer` rotation was NOT taken "
97
98
           "out.\n"
           "Note: There is no 2*pi factor used, so \\|Q| = 1/wavelength.")
99
100
      .def("findDetector", (bool (IPeak::*)()) & IPeak::findDetector,
           arg("self"),
Samuel Jackson's avatar
Samuel Jackson committed
101
102
103
           "Using the :class:`~mantid.geometry.Instrument` set in the peak, "
           "perform ray tracing to find "
           "the exact :class:`~mantid.geometry.Detector`.")
104
      .def("getQSampleFrame", &IPeak::getQSampleFrame, arg("self"),
105
           "Return the Q change (of the lattice, k_i - k_f) for this peak."
Samuel Jackson's avatar
Samuel Jackson committed
106
107
           "The Q is in the Sample frame: the "
           ":class:`~mantid.geometry.Goniometer` rotation WAS taken "
108
           "out. ")
109
      .def("setQLabFrame", setQLabFrame1, (arg("self"), arg("qlab_frame")),
110
           "Set the peak using the peak's "
111
112
           "position in reciprocal space, in "
           "the lab frame.")
113
      .def("setQLabFrame", setQLabFrame2,
114
           (arg("self"), arg("qlab_frame"), arg("distance")),
115
           "Set the peak using the peak's position in reciprocal space, in the "
Samuel Jackson's avatar
Samuel Jackson committed
116
117
118
           "lab frame. :class:`~mantid.geometry.Detector` distance explicitly "
           "supplied.") // two argument
                        // overload
119
      .def("setQSampleFrame", setQSampleFrame1,
Samuel Jackson's avatar
Samuel Jackson committed
120
121
122
           (arg("self"), arg("qsample_frame")), "Set the peak using the peak's "
                                                "position in reciprocal space, "
                                                "in the sample frame.")
123
      .def("setQSampleFrame", setQSampleFrame2,
124
           (arg("self"), arg("qsample_frame"), arg("distance")),
125
           "Set the peak using the peak's position in reciprocal space, in the "
Samuel Jackson's avatar
Samuel Jackson committed
126
127
           "sample frame. :class:`~mantid.geometry.Detector` distance "
           "explicitly supplied.")
128
      .def("setWavelength", &IPeak::setWavelength,
129
           (arg("self"), arg("wave_length")),
130
131
           "Set the incident wavelength of the neutron. Calculates the energy "
           "from this assuming elastic scattering.")
132
      .def("getWavelength", &IPeak::getWavelength, arg("self"),
133
           "Return the incident wavelength")
134
      .def("getScattering", &IPeak::getScattering, arg("self"),
135
           "Calculate the scattering angle of the peak")
136
137
      .def("getAzimuthal", &IPeak::getAzimuthal, arg("self"),
           "Calculate the azimuthal angle of the peak")
138
      .def("getDSpacing", &IPeak::getDSpacing, arg("self"),
139
           "Calculate the d-spacing of the peak, in 1/Angstroms")
140
      .def("getTOF", &IPeak::getTOF, arg("self"),
141
142
143
           "Calculate the time of flight (in "
           "microseconds) of the neutrons for this "
           "peak")
144
      .def("getInitialEnergy", &IPeak::getInitialEnergy, arg("self"),
Samuel Jackson's avatar
Samuel Jackson committed
145
           "Get the initial (incident) neutron energy in meV.")
146
      .def("getFinalEnergy", &IPeak::getFinalEnergy, arg("self"),
Samuel Jackson's avatar
Samuel Jackson committed
147
           "Get the final neutron energy in meV.")
148
      .def("getEnergyTransfer", &IPeak::getEnergyTransfer, arg("self"),
Samuel Jackson's avatar
Samuel Jackson committed
149
150
           "Get the initial neutron energy minus the final neutron energy in "
           "meV."
151
           "\n\n.. versionadded:: 3.12.0")
152
      .def("setInitialEnergy", &IPeak::setInitialEnergy,
153
           (arg("self"), arg("initial_energy")),
Samuel Jackson's avatar
Samuel Jackson committed
154
           "Set the initial (incident) neutron energy in meV.")
155
      .def("setFinalEnergy", &IPeak::setFinalEnergy,
Samuel Jackson's avatar
Samuel Jackson committed
156
157
           (arg("self"), arg("final_energy")),
           "Set the final neutron energy in meV.")
158
      .def("getIntensity", &IPeak::getIntensity, arg("self"),
159
           "Return the integrated peak intensity")
160
      .def("getSigmaIntensity", &IPeak::getSigmaIntensity, arg("self"),
161
           "Return the error on the integrated peak intensity")
162
163
      .def("getIntensityOverSigma", &IPeak::getIntensityOverSigma, arg("self"),
           "Return the error on the integrated peak intensity divided by the "
164
           "error in intensity.\n\n.. versionadded:: 3.12.0")
165
      .def("setIntensity", &IPeak::setIntensity,
166
           (arg("self"), arg("intensity")), "Set the integrated peak intensity")
167
      .def("setSigmaIntensity", &IPeak::setSigmaIntensity,
168
           (arg("self"), arg("sigma_intensity")),
169
           "Set the error on the integrated peak intensity")
170
      .def("getBinCount", &IPeak::getBinCount, arg("self"),
171
           "Return the # of counts in the bin at its peak")
172
      .def("setBinCount", &IPeak::setBinCount, (arg("self"), arg("bin_count")),
173
           "Set the # of counts in the bin at its peak")
Samuel Jackson's avatar
Samuel Jackson committed
174
175
176
177
      .def("getGoniometerMatrix", &IPeak::getGoniometerMatrix, arg("self"),
           return_copy_to_numpy(),
           "Get the :class:`~mantid.geometry.Goniometer` rotation matrix of "
           "this peak."
178
           "\n\n.. versionadded:: 3.12.0")
179
180
      .def("setGoniometerMatrix", &setGoniometerMatrix,
           (arg("self"), arg("goniometerMatrix")),
Samuel Jackson's avatar
Samuel Jackson committed
181
182
           "Set the :class:`~mantid.geometry.Goniometer` rotation matrix of "
           "this peak.")
183
      .def("getRow", &IPeak::getRow, arg("self"),
Samuel Jackson's avatar
Samuel Jackson committed
184
           "For :class:`~mantid.geometry.RectangularDetector` s only, returns "
185
186
           "the row (y) of the pixel of the "
           "detector.")
187
      .def("getCol", &IPeak::getCol, arg("self"),
Samuel Jackson's avatar
Samuel Jackson committed
188
           "For :class:`~mantid.geometry.RectangularDetector` s only, returns "
189
           "the column (x) of the pixel of the "
Samuel Jackson's avatar
Samuel Jackson committed
190
           ":class:`~mantid.geometry.Detector`.")
191
      .def("getDetPos", &IPeak::getDetPos, arg("self"),
Samuel Jackson's avatar
Samuel Jackson committed
192
           "Return the :class:`~mantid.geometry.Detector` position vector")
193
      .def("getL1", &IPeak::getL1, arg("self"),
Samuel Jackson's avatar
Samuel Jackson committed
194
195
           "Return the L1 flight path length (source to "
           ":class:`~mantid.api.Sample`), in meters. ")
196
      .def("getL2", &IPeak::getL2, arg("self"),
Samuel Jackson's avatar
Samuel Jackson committed
197
198
           "Return the L2 flight path length (:class:`~mantid.api.Sample` to "
           ":class:`~mantid.geometry.Detector`), in meters.")
199
      .def("getPeakShape", getPeakShape, arg("self"), "Get the peak shape");
200
}