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