IPeak.cpp 11.8 KB
Newer Older
1
2
3
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4
5
//   NScD Oak Ridge National Laboratory, European Spallation Source,
//   Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6
// SPDX - License - Identifier: GPL - 3.0 +
Owen Arnold's avatar
Owen Arnold committed
7
#include "MantidGeometry/Crystal/IPeak.h"
8
#include "MantidPythonInterface/core/Converters/CloneToNDArray.h"
9
10
11
#include "MantidPythonInterface/core/Converters/PyObjectToMatrix.h"
#include "MantidPythonInterface/core/GetPointer.h"
#include "MantidPythonInterface/core/Policies/MatrixToNumpy.h"
12
#include <boost/optional.hpp>
13
14
#include <boost/python/class.hpp>
#include <boost/python/register_ptr_to_python.hpp>
15

Owen Arnold's avatar
Owen Arnold committed
16
using Mantid::Geometry::IPeak;
17
using namespace Mantid::PythonInterface;
18
19
using namespace boost::python;

20
21
GET_POINTER_SPECIALIZATION(IPeak)

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

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

43
44
45
46
void setQSampleFrame2(IPeak &peak, Mantid::Kernel::V3D qSampleFrame,
                      double distance) {
  // Set the qsample frame. Detector distance specified.
  return peak.setQSampleFrame(qSampleFrame, distance);
47
}
48
49
50
51

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

53
} // namespace
54

55
void export_IPeak() {
56
  // return_value_policy for read-only numpy array
57
  using return_copy_to_numpy = return_value_policy<Policies::MatrixToNumpy>;
Samuel Jackson's avatar
Samuel Jackson committed
58

59
  register_ptr_to_python<IPeak *>();
60
61

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