IPeak.cpp 9.54 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
Samuel Jackson's avatar
Samuel Jackson committed
51
52
  typedef return_value_policy<Policies::MatrixToNumpy> return_copy_to_numpy;

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