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

Owen Arnold's avatar
Owen Arnold committed
8
using Mantid::Geometry::IPeak;
9
10
using namespace boost::python;

11
12
GET_POINTER_SPECIALIZATION(IPeak)

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

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

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

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

45
46
void export_IPeak() {
  register_ptr_to_python<IPeak *>();
47
48

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