Mantid
Loading...
Searching...
No Matches
MatrixWorkspace.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
8
9#include "MantidAPI/Axis.h"
10#include "MantidAPI/Run.h"
13#include "MantidHistogramData/HistogramY.h"
14#include "MantidIndexing/IndexInfo.h"
16
25
26#include <boost/python/class.hpp>
27#include <boost/python/copy_const_reference.hpp>
28#include <boost/python/dict.hpp>
29#include <boost/python/implicit.hpp>
30#include <boost/python/list.hpp>
31#include <boost/python/overloads.hpp>
32#include <boost/python/register_ptr_to_python.hpp>
33#include <boost/python/suite/indexing/map_indexing_suite.hpp>
34#include <boost/python/tuple.hpp>
35
36#define PY_ARRAY_UNIQUE_SYMBOL API_ARRAY_API
37#define NO_IMPORT_ARRAY
38#include <numpy/arrayobject.h>
39
40using namespace Mantid::API;
41using namespace Mantid::Geometry;
42using namespace Mantid::Kernel;
43using namespace Mantid::PythonInterface;
47using namespace boost::python;
48
50
51namespace {
53using data_modifier = Mantid::MantidVec &(MatrixWorkspace::*)(const std::size_t);
54
56using return_readonly_numpy = return_value_policy<VectorRefToNumpy<WrapReadOnly>>;
58using return_readwrite_numpy = return_value_policy<VectorRefToNumpy<WrapReadWrite>>;
59
60//------------------------------- Overload macros ---------------------------
61GNU_DIAG_OFF("unused-local-typedef")
62// Ignore -Wconversion warnings coming from boost::python
63// Seen with GCC 7.1.1 and Boost 1.63.0
64GNU_DIAG_OFF("conversion")
65// Overloads for yIndexOfX function which has 2 optional argument
66// cppcheck-suppress unknownMacro
67BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(MatrixWorkspace_yIndexOfXOverloads, MatrixWorkspace::yIndexOfX, 1, 3)
68// Overloads for YUnitLabel which has 1 optional argument
69BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(MatrixWorkspace_YUnitLabelOverloads, YUnitLabel, 0, 2)
70GNU_DIAG_ON("conversion")
71GNU_DIAG_ON("unused-local-typedef")
72
73
82void setSpectrumFromPyObject(MatrixWorkspace &self, data_modifier accessor, const size_t wsIndex,
83 const boost::python::object &values) {
84 if (NDArray::check(values)) {
85 NDArrayToVector<double> converter(values);
86 converter.copyTo((self.*accessor)(wsIndex));
87 } else {
88 PySequenceToVector<double> converter(values);
89 converter.copyTo((self.*accessor)(wsIndex));
90 }
91}
92
99void setMonitorWorkspace(MatrixWorkspace &self, const boost::python::object &value) {
101 std::dynamic_pointer_cast<MatrixWorkspace>(Mantid::PythonInterface::ExtractSharedPtr<Workspace>(value)());
102 self.setMonitorWorkspace(monWS);
103}
109std::weak_ptr<Workspace> getMonitorWorkspace(MatrixWorkspace &self) {
110 return std::weak_ptr<Workspace>(self.monitorWorkspace());
111}
117void clearMonitorWorkspace(MatrixWorkspace &self) {
119 self.setMonitorWorkspace(monWS);
120}
121
127list getSpectrumNumbers(const MatrixWorkspace &self) {
128 const auto &spectrumNums = self.indexInfo().spectrumNumbers();
129 list spectra;
130
131 for (const auto &index : spectrumNums) {
132 spectra.append(static_cast<int32_t>(index));
133 }
134
135 return spectra;
136}
137
144void setXFromPyObject(MatrixWorkspace &self, const size_t wsIndex, const boost::python::object &values) {
145 setSpectrumFromPyObject(self, &MatrixWorkspace::dataX, wsIndex, values);
146}
147
154void setYFromPyObject(MatrixWorkspace &self, const size_t wsIndex, const boost::python::object &values) {
155 setSpectrumFromPyObject(self, &MatrixWorkspace::dataY, wsIndex, values);
156}
157
164void setEFromPyObject(MatrixWorkspace &self, const size_t wsIndex, const boost::python::object &values) {
165 setSpectrumFromPyObject(self, &MatrixWorkspace::dataE, wsIndex, values);
166}
167
174void setDxFromPyObject(MatrixWorkspace &self, const size_t wsIndex, const boost::python::object &values) {
175 setSpectrumFromPyObject(self, &MatrixWorkspace::dataDx, wsIndex, values);
176}
177
178std::vector<double> getIntegratedCountsForWorkspaceIndices(MatrixWorkspace &self,
179 const boost::python::object &workspaceIndices,
180 const size_t numberOfWorkspaces, const double minX,
181 const double maxX, const bool entireRange) {
182
183 std::vector<size_t> sWorkspaceIndices(numberOfWorkspaces);
184 if (NDArray::check(workspaceIndices)) {
185 NDArrayToVector<size_t> converter(workspaceIndices);
186 converter.copyTo(sWorkspaceIndices);
187 } else {
188 PySequenceToVector<size_t> converter(workspaceIndices);
189 converter.copyTo(sWorkspaceIndices);
190 }
191
192 return self.getIntegratedCountsForWorkspaceIndices(sWorkspaceIndices, minX, maxX, entireRange);
193}
194
201Mantid::API::Run &getSampleDetailsDeprecated(MatrixWorkspace &self) {
202 PyErr_Warn(PyExc_DeprecationWarning, "``getSampleDetails`` is deprecated, use ``getRun`` instead.");
203 return self.mutableRun();
204}
205
212std::size_t getNumberBinsDeprecated(MatrixWorkspace &self) {
213 PyErr_Warn(PyExc_DeprecationWarning, "``getNumberBins`` is deprecated, use ``blocksize`` instead.");
214 return self.blocksize();
215}
216
227std::size_t binIndexOfDeprecated(MatrixWorkspace &self, const double xValue, const std::size_t index = 0) {
228 PyErr_Warn(PyExc_DeprecationWarning, "``binIndexOf`` is deprecated, use ``yIndexOfX`` instead.");
229 return self.yIndexOfX(xValue, index);
230}
231
232GNU_DIAG_OFF("unused-local-typedef")
233// Ignore -Wconversion warnings coming from boost::python
234// Seen with GCC 7.1.1 and Boost 1.63.0
235GNU_DIAG_OFF("conversion")
236// Overloads for binIndexOfDeprecated function which has 1 optional argument
237BOOST_PYTHON_FUNCTION_OVERLOADS(binIndexOfDeprecatedOverloads, binIndexOfDeprecated, 2, 3)
238GNU_DIAG_ON("conversion")
239GNU_DIAG_ON("unused-local-typedef")
240
241
248std::vector<size_t> maskedBinsIndices(MatrixWorkspace &self, const int i) { return self.maskedBinsIndices(i); }
249
257void pythonReplaceAxis(MatrixWorkspace &self, const std::size_t &axisIndex, Axis *newAxis) {
258 self.replaceAxis(axisIndex, std::unique_ptr<Axis>(newAxis->clone(&self)));
259}
260
268object getSignalAtCoord(MatrixWorkspace &self, const NDArray &npCoords,
269 const Mantid::API::MDNormalization &normalization) {
270 if (npCoords.get_shape()[1] != 2) {
271 throw std::invalid_argument("MatrixWorkspace::getSignalAtCoord - Input "
272 "array must have shape (n, 2)");
273 }
274 // Create our output array
275 Py_intptr_t length = len(npCoords);
276 auto *signalValues = new Mantid::signal_t[length];
277
278 // Convert coords to a vector
279 std::vector<Mantid::coord_t> coords = NDArrayToVector<Mantid::coord_t>(npCoords)();
280
281 // Fill output array
282 for (int i = 0; i < length; ++i) {
283 std::array<Mantid::coord_t, 2> coord = {{coords[2 * i], coords[2 * i + 1]}};
284 signalValues[i] = self.getSignalAtCoord(coord.data(), normalization);
285 }
286 PyObject *npSignalArray =
287 Impl::wrapWithNDArray(signalValues, 1, &length, NumpyWrapMode::ReadOnly, OwnershipMode::Python);
288 return object(handle<>(npSignalArray));
289}
290
291boost::python::tuple findY(MatrixWorkspace &self, double value, tuple start) {
292 int64_t first = extract<int64_t>(start[0]);
293 int64_t second = extract<int64_t>(start[1]);
294 auto idx = self.findY(value, std::make_pair(first, second));
295 return make_tuple(idx.first, idx.second);
296}
297
306void applyBinEdgesFromAnotherWorkspace(MatrixWorkspace &self, const MatrixWorkspace &ws, const size_t getIndex,
307 const size_t setIndex) {
308 self.setBinEdges(setIndex, ws.binEdges(getIndex));
309}
310
319void applyPointsFromAnotherWorkspace(MatrixWorkspace &self, const MatrixWorkspace &ws, const size_t getIndex,
320 const size_t setIndex) {
321 self.setPoints(setIndex, ws.points(getIndex));
322}
323
324std::vector<size_t> getIndicesFromDetectorIDs(MatrixWorkspace &self, const boost::python::list &detIDs) {
326}
327
328boost::python::dict getDetectorIDToWorkspaceIndexMap(MatrixWorkspace &self, bool throwIfMultipleDets,
329 bool ignoreIfNoValidDets) {
330 const auto unorderedMap = self.getDetectorIDToWorkspaceIndexMap(throwIfMultipleDets, ignoreIfNoValidDets);
331 boost::python::dict pythonDict;
332 for (const auto &[key, value] : unorderedMap) {
333 pythonDict[key] = value;
334 }
335
336 return pythonDict;
337}
338
339} // namespace
340
345
346 class_<MatrixWorkspace, boost::python::bases<ExperimentInfo, IMDWorkspace>, boost::noncopyable>("MatrixWorkspace",
347 no_init)
348 //--------------------------------------- Meta information
349 //-----------------------------------------------------------------------
350 .def("isRaggedWorkspace", &MatrixWorkspace::isRaggedWorkspace, arg("self"),
351 "Returns true if the workspace is ragged (has differently sized "
352 "spectra).")
353 .def("blocksize", &MatrixWorkspace::blocksize, arg("self"), "Returns size of the Y data array")
354 .def("getNumberBins", &MatrixWorkspace::getNumberBins, (arg("self"), arg("index")),
355 "Returns the number of bins for a given histogram index.")
356 .def("getNumberBins", &getNumberBinsDeprecated, arg("self"),
357 "Returns size of the Y data array (deprecated, use "
358 ":class:`~mantid.api.MatrixWorkspace.blocksize` "
359 "instead)")
360 .def("getMaxNumberBins", &MatrixWorkspace::getMaxNumberBins, arg("self"),
361 "Returns the maximum number of bins in a workspace (works on ragged "
362 "data).")
363 .def("getNumberHistograms", &MatrixWorkspace::getNumberHistograms, arg("self"),
364 "Returns the number of spectra in the workspace")
365 .def("getPlotType", &MatrixWorkspace::getPlotType, arg("self"), "Returns the plot type of the workspace")
366 .def("getMarkerStyle", &MatrixWorkspace::getMarkerStyle, arg("self"), "Return the marker style for the workspace")
367 .def("getMarkerSize", &MatrixWorkspace::getMarkerSize, arg("self"), "Returns the marker size for the workspace")
368 .def("getSpectrumNumbers", &getSpectrumNumbers, arg("self"),
369 "Returns a list of all spectrum numbers in the workspace")
370 .def("yIndexOfX", &MatrixWorkspace::yIndexOfX,
371 MatrixWorkspace_yIndexOfXOverloads((arg("self"), arg("xvalue"), arg("workspaceIndex"), arg("tolerance")),
372 "Returns the y index which corresponds to the X Value provided. "
373 "The workspace_index [default=0] and tolerance [default=0.0] is "
374 "optional."))
375 .def("detectorTwoTheta", &MatrixWorkspace::detectorTwoTheta, (arg("self"), arg("det")),
376 "Returns the two theta value for a given detector")
377 .def("detectorSignedTwoTheta", &MatrixWorkspace::detectorSignedTwoTheta, (arg("self"), arg("det")),
378 "Returns the signed two theta value for given detector")
379 .def("getSpectrum", (ISpectrum & (MatrixWorkspace::*)(const size_t)) & MatrixWorkspace::getSpectrum,
380 (arg("self"), arg("workspaceIndex")), return_internal_reference<>(),
381 "Return the spectra at the given workspace index.")
382 .def("getIndexFromSpectrumNumber", &MatrixWorkspace::getIndexFromSpectrumNumber, (arg("self"), arg("spec_no")),
383 "Returns workspace index correspondent to the given spectrum "
384 "number. Throws if no such spectrum is present in the workspace")
385 .def("getIndicesFromDetectorIDs", &getIndicesFromDetectorIDs, (arg("self"), arg("detID_list")),
386 "Returns a list of workspace indices from the corrresponding "
387 "detector IDs.")
388 .def("getDetectorIDToWorkspaceIndexMap", &getDetectorIDToWorkspaceIndexMap,
389 (arg("self"), arg("throwIfMultipleDets"), arg("ignoreIfNoValidDets")),
390 " Return a map where the key is detector ID (pixel ID), and the value at that index = the corresponding "
391 "workspace index")
392 .def("getDetector", &MatrixWorkspace::getDetector, return_value_policy<RemoveConstSharedPtr>(),
393 (arg("self"), arg("workspaceIndex")),
394 "Return the :class:`~mantid.geometry.Detector` or "
395 ":class:`~mantid.geometry.DetectorGroup` that is linked to "
396 "the given workspace index")
397 .def("getRun", &MatrixWorkspace::mutableRun, arg("self"), return_internal_reference<>(),
398 "Return the :class:`~mantid.api.Run` object for this workspace")
399 .def("axes", &MatrixWorkspace::axes, arg("self"), "Returns the number of axes attached to the workspace")
400 .def("getAxis", &MatrixWorkspace::getAxis, (arg("self"), arg("axis_index")), return_internal_reference<>(),
401 "Get a pointer to a workspace axis")
402 .def("isHistogramData", &MatrixWorkspace::isHistogramData, arg("self"),
403 "Returns ``True`` if this is considered to be binned data.")
404 .def("isDistribution", (bool (MatrixWorkspace::*)() const) & MatrixWorkspace::isDistribution, arg("self"),
405 "Returns the status of the distribution flag")
406 .def("YUnit", &MatrixWorkspace::YUnit, arg("self"), return_value_policy<copy_const_reference>(),
407 "Returns the current Y unit for the data (Y axis) in the workspace")
408 .def("YUnitLabel", &MatrixWorkspace::YUnitLabel,
409 MatrixWorkspace_YUnitLabelOverloads((arg("self"), arg("useLatex"), arg("plotAsDistribution")),
410 "Returns the caption for the Y axis"))
411 .def("hasAnyMaskedBins", &MatrixWorkspace::hasAnyMaskedBins, (arg("self")),
412 "Returns true if any of the bins in this workspace are masked.")
413 .def("hasMaskedBins", &MatrixWorkspace::hasMaskedBins, (arg("self"), arg("workspaceIndex")),
414 "Returns true if this spectrum contains any masked bins")
415 .def("maskedBinsIndices", &maskedBinsIndices, (arg("self"), arg("workspaceIndex")),
416 "Returns all the masked bins' indices at the workspace index. "
417 ":class:`~mantid.api.MatrixWorkspace.hasMaskedBins` MUST be called "
418 "first to check if any bins are "
419 "masked, otherwise an exception will be thrown")
420 .def("findY", &findY, (arg("self"), arg("value"), arg("start") = make_tuple(0, 0)),
421 "Find first index in Y equal to value. Start may be specified to "
422 "begin at a specifc index. Returns tuple with the "
423 "histogram and bin indices.")
424 .def("getSampleDetails", &getSampleDetailsDeprecated, arg("self"), return_internal_reference<>(),
425 "Return the Run object for this workspace (deprecated, use "
426 ":class:`~mantid.api.MatrixWorkspace.getRun` "
427 "instead)")
428 .def("binIndexOf", &binIndexOfDeprecated,
429 binIndexOfDeprecatedOverloads((arg("self"), arg("xvalue"), arg("workspaceIndex")),
430 "Returns the index of the bin containing the given xvalue "
431 "(deprecated, use "
432 ":class:`~mantid.api.MatrixWorkspace.yIndexOfX` instead)"))
433
434 //--------------------------------------- Setters
435 //------------------------------------
436 .def("setPlotType", &MatrixWorkspace::setPlotType, (arg("self"), arg("newType")),
437 "Sets a new plot type for the workspace")
438 .def("setMarkerStyle", &MatrixWorkspace::setMarkerStyle, (arg("self"), arg("markerType")),
439 "Sets the marker type for the workspace")
440 .def("setMarkerSize", &MatrixWorkspace::setMarkerSize, (arg("self"), arg("markerSize")),
441 "Sets the size of the marker for the workspace")
442 .def("setYUnitLabel", &MatrixWorkspace::setYUnitLabel, (arg("self"), arg("newLabel")),
443 "Sets a new caption for the data (Y axis) in the workspace")
444 .def("setYUnit", &MatrixWorkspace::setYUnit, (arg("self"), arg("newUnit")),
445 "Sets a new unit for the data (Y axis) in the workspace")
446 .def("setDistribution", &MatrixWorkspace::setDistribution, (arg("self"), arg("newVal")),
447 "Set distribution flag. If True the workspace has been divided by "
448 "the bin-width.")
449 .def("replaceAxis", &pythonReplaceAxis, (arg("self"), arg("axisIndex"), arg("newAxis")),
450 "Replaces one of the workspace's axes with the new one provided. "
451 "The axis is cloned.")
452 .def("applyBinEdgesFromAnotherWorkspace", &applyBinEdgesFromAnotherWorkspace,
453 (arg("self"), arg("ws"), arg("getIndex"), arg("setIndex")),
454 "Sets the bin edges at setIndex to be the bin edges of ws at "
455 "getIndex.")
456 .def("applyPointsFromAnotherWorkspace", &applyPointsFromAnotherWorkspace,
457 (arg("self"), arg("ws"), arg("getIndex"), arg("setIndex")),
458 "Sets the points at setIndex to be the points of ws at getIndex.")
459
460 //--------------------------------------- Read spectrum data
461 //-------------------------
462 .def("readX", &MatrixWorkspace::readX, (arg("self"), arg("workspaceIndex")), return_readonly_numpy(),
463 "Creates a read-only numpy wrapper "
464 "around the original X data at the "
465 "given index")
466 .def("readY", &MatrixWorkspace::readY, return_readonly_numpy(), args("self", "workspaceIndex"),
467 "Creates a read-only numpy wrapper "
468 "around the original Y data at the "
469 "given index")
470 .def("readE", &MatrixWorkspace::readE, return_readonly_numpy(), args("self", "workspaceIndex"),
471 "Creates a read-only numpy wrapper "
472 "around the original E data at the "
473 "given index")
474 .def("readDx", &MatrixWorkspace::readDx, return_readonly_numpy(), args("self", "workspaceIndex"),
475 "Creates a read-only numpy wrapper "
476 "around the original Dx data at the "
477 "given index")
478 .def("hasDx", &MatrixWorkspace::hasDx, args("self", "workspaceIndex"),
479 "Returns True if the spectrum uses the DX (X Error) array, else "
480 "False.")
481 //--------------------------------------- Write spectrum data
482 //------------------------
483 .def("dataX", (data_modifier)&MatrixWorkspace::dataX, return_readwrite_numpy(), args("self", "workspaceIndex"),
484 "Creates a writable numpy wrapper around the original X data at the "
485 "given index")
486 .def("dataY", (data_modifier)&MatrixWorkspace::dataY, return_readwrite_numpy(), args("self", "workspaceIndex"),
487 "Creates a writable numpy wrapper around the original Y data at the "
488 "given index")
489 .def("dataE", (data_modifier)&MatrixWorkspace::dataE, return_readwrite_numpy(), args("self", "workspaceIndex"),
490 "Creates a writable numpy wrapper around the original E data at the "
491 "given index")
492 .def("dataDx", (data_modifier)&MatrixWorkspace::dataDx, return_readwrite_numpy(), args("self", "workspaceIndex"),
493 "Creates a writable numpy wrapper around the original Dx data at "
494 "the given index")
495 .def("setX", &setXFromPyObject, args("self", "workspaceIndex", "x"),
496 "Set X values from a python list or numpy array. It performs a "
497 "simple copy into the array.")
498 .def("setY", &setYFromPyObject, args("self", "workspaceIndex", "y"),
499 "Set Y values from a python list or numpy array. It performs a "
500 "simple copy into the array.")
501 .def("setE", &setEFromPyObject, args("self", "workspaceIndex", "e"),
502 "Set E values from a python list or numpy array. It performs a "
503 "simple copy into the array.")
504 .def("setDx", &setDxFromPyObject, args("self", "workspaceIndex", "dX"),
505 "Set Dx values from a python list or numpy array. It performs a "
506 "simple copy into the array.")
507
508 // --------------------------------------- Extract data
509 // ------------------------------
510 .def("extractX", Mantid::PythonInterface::cloneX, args("self"),
511 "Extracts (copies) the X data from the workspace into a 2D numpy "
512 "array. "
513 "Note: This can fail for large workspaces as numpy will require a "
514 "block "
515 "of memory free that will fit all of the data.")
516 .def("extractY", Mantid::PythonInterface::cloneY, args("self"),
517 "Extracts (copies) the Y data from the workspace into a 2D numpy "
518 "array. "
519 "Note: This can fail for large workspaces as numpy will require a "
520 "block "
521 "of memory free that will fit all of the data.")
522 .def("extractE", Mantid::PythonInterface::cloneE, args("self"),
523 "Extracts (copies) the E data from the workspace into a 2D numpy "
524 "array. "
525 "Note: This can fail for large workspaces as numpy will require a "
526 "block "
527 "of memory free that will fit all of the data.")
528 .def("extractDx", Mantid::PythonInterface::cloneDx, args("self"),
529 "Extracts (copies) the E data from the workspace into a 2D numpy "
530 "array. "
531 "Note: This can fail for large workspaces as numpy will require a "
532 "block "
533 "of memory free that will fit all of the data.")
534 .def("getSignalAtCoord", &getSignalAtCoord, args("self", "coords", "normalization"),
535 "Return signal for array of coordinates")
536 .def("getIntegratedCountsForWorkspaceIndices", &getIntegratedCountsForWorkspaceIndices,
537 args("self", "workspaceIndices", "numberOfWorkspaces", "minX", "maxX", "entireRange"),
538 "Return a vector with the integrated counts within the given range for the given workspace indices")
539 //-------------------------------------- Operators
540 //-----------------------------------
541 .def("equals", &Mantid::API::equals, args("self", "other", "tolerance"),
542 "Performs a comparison operation on two workspaces, using the "
543 "CompareWorkspaces algorithm")
544 //--------- monitor workspace --------------------------------------
545 .def("getMonitorWorkspace", &getMonitorWorkspace, args("self"),
546 "Return internal monitor workspace bound to current workspace.")
547 .def("setMonitorWorkspace", &setMonitorWorkspace, args("self", "MonitorWS"),
548 "Set specified workspace as monitor workspace for"
549 "current workspace. "
550 "Note: The workspace does not have to contain monitors though "
551 "some subsequent algorithms may expect it to be "
552 "monitor workspace later.")
553 .def("clearMonitorWorkspace", &clearMonitorWorkspace, args("self"),
554 "Forget about monitor workspace, attached to the current workspace")
555 .def("isCommonBins", &MatrixWorkspace::isCommonBins, "Returns true if the workspace has common X bins.")
556 .def("isCommonLogBins", &MatrixWorkspace::isCommonLogBins,
557 "Returns true if the workspace has common X bins with log spacing.");
558
560}
double value
The value of the point.
Definition FitMW.cpp:51
#define GET_POINTER_SPECIALIZATION(TYPE)
Definition GetPointer.h:17
std::map< DeltaEMode::Type, std::string > index
void export_MatrixWorkspace()
Python exports of the Mantid::API::MatrixWorkspace class.
#define GNU_DIAG_ON(x)
#define GNU_DIAG_OFF(x)
This is a collection of macros for turning compiler warnings off in a controlled manner.
Class to represent the axis of a workspace.
Definition Axis.h:30
virtual Axis * clone(const MatrixWorkspace *const parentWorkspace)=0
Virtual constructor.
Run & mutableRun()
Writable version of the run object.
A "spectrum" is an object that holds the data for a particular spectrum, in particular:
Definition ISpectrum.h:38
Base MatrixWorkspace Abstract Class.
std::string YUnitLabel(bool useLatex=false, bool plotAsDistribution=false) const
Returns a caption for the units of the data in the workspace.
virtual std::pair< int64_t, int64_t > findY(double value, const std::pair< int64_t, int64_t > &idx={0, 0}) const
Find first index in Y equal to value.
void setMarkerStyle(const std::string &markerType)
Set the marker style for plotting.
const MantidVec & readE(std::size_t const index) const
Deprecated, use e() instead.
virtual ISpectrum & getSpectrum(const size_t index)=0
Return the underlying ISpectrum ptr at the given workspace index.
double detectorSignedTwoTheta(const Geometry::IDetector &det) const
Returns the signed 2Theta scattering angle for a detector.
const MantidVec & readDx(size_t const index) const
Deprecated, use dx() instead.
bool hasAnyMaskedBins() const
Does this workspace contain any masked bins.
virtual MantidVec & dataDx(const std::size_t index)
Deprecated, use mutableDx() instead. Returns the x error data.
virtual bool isCommonLogBins() const
Returns true if the workspace contains common X bins with log spacing.
HistogramData::BinEdges binEdges(const size_t index) const
void setPoints(const size_t index, T &&...data) &
HistogramData::Points points(const size_t index) const
double detectorTwoTheta(const Geometry::IDetector &det) const
Returns the 2Theta scattering angle for a detector.
virtual std::size_t blocksize() const =0
Returns the size of each block of data returned by the dataY accessors.
signal_t getSignalAtCoord(const coord_t *coords, const Mantid::API::MDNormalization &normalization) const override
Get the signal at a coordinate in the workspace.
virtual MantidVec & dataX(const std::size_t index)
Deprecated, use mutableX() instead. Returns the x data.
virtual void setMonitorWorkspace(const std::shared_ptr< MatrixWorkspace > &monitorWS)
Sets the internal monitor workspace to the provided workspace.
virtual std::size_t getNumberHistograms() const =0
Returns the number of histograms in the workspace.
bool hasMaskedBins(const size_t &workspaceIndex) const
Does this spectrum contain any masked bins.
std::size_t yIndexOfX(const double xValue, const std::size_t &index=0, const double tolerance=0.0) const
Returns the y index which corresponds to the X Value provided.
virtual MantidVec & dataE(const std::size_t index)
Deprecated, use mutableE() instead. Returns the error data.
bool isDistribution() const
Are the Y-values dimensioned?
std::string getMarkerStyle() const
Get the marker style for plotting.
std::shared_ptr< MatrixWorkspace > monitorWorkspace() const
Returns a pointer to the internal monitor workspace.
virtual bool isRaggedWorkspace() const =0
Returns true if the workspace is ragged (has differently sized spectra).
std::vector< size_t > maskedBinsIndices(const size_t &workspaceIndex) const
std::vector< size_t > getIndicesFromDetectorIDs(const std::vector< detid_t > &detIdList) const
Converts a list of detector IDs to the corresponding workspace indices.
void setDistribution(bool newValue)
Set the flag for whether the Y-values are dimensioned.
const Indexing::IndexInfo & indexInfo() const
Returns a const reference to the IndexInfo object of the workspace.
float getMarkerSize() const
Get the size of the marker for plotting.
virtual bool hasDx(const std::size_t index) const
Probes if DX (X Error) values were set on a particular spectrum.
virtual std::size_t getMaxNumberBins() const =0
Returns the maximum number of bins in a workspace (works on ragged data).
const std::string & YUnit() const
std::string getPlotType() const
Gets MatrixWorkspace plot_type.
const MantidVec & readY(std::size_t const index) const
Deprecated, use y() instead.
detid2index_map getDetectorIDToWorkspaceIndexMap(bool throwIfMultipleDets=false, bool ignoreIfNoValidDets=false) const
Return a map where: KEY is the DetectorID (pixel ID) VALUE is the Workspace Index.
virtual Axis * getAxis(const std::size_t &axisIndex) const
Get a non owning pointer to a workspace axis.
void setPlotType(const std::string &)
Sets MatrixWorkspace plot_type.
std::vector< double > getIntegratedCountsForWorkspaceIndices(const std::vector< size_t > &workspaceIndices, const double minX, const double maxX, const bool entireRange) const
virtual std::size_t getNumberBins(const std::size_t &index) const =0
Returns the number of bins for a given histogram index.
const MantidVec & readX(std::size_t const index) const
Deprecated, use x() instead.
size_t getIndexFromSpectrumNumber(const specnum_t specNo) const
Given a spectrum number, find the corresponding workspace index.
void replaceAxis(const std::size_t &axisIndex, std::unique_ptr< Axis > newAxis)
Replaces one of the workspace's axes with the new one provided.
virtual MantidVec & dataY(const std::size_t index)
Deprecated, use mutableY() instead. Returns the y data.
void setYUnitLabel(const std::string &newLabel)
Sets a new caption for the data (Y axis) in the workspace.
void setMarkerSize(const float markerSize)
Set the size of the marker for plotting.
virtual bool isCommonBins() const
Returns true if the workspace contains common X bins.
std::shared_ptr< const Geometry::IDetector > getDetector(const size_t workspaceIndex) const
Get the effective detector for the given spectrum.
void setYUnit(const std::string &newUnit)
Sets a new unit for the data (Y axis) in the workspace.
virtual bool isHistogramData() const
Returns true if the workspace contains data in histogram form (as opposed to point-like)
void setBinEdges(const size_t index, T &&...data) &
This class stores information regarding an experimental run as a series of log entries.
Definition Run.h:35
Thin object wrapper around a numpy array.
Definition NDArray.h:31
static bool check(const boost::python::object &obj)
Check if a python object points to an array type object.
Definition NDArray.cpp:49
Py_intptr_t const * get_shape() const
Definition NDArray.cpp:61
bool MANTID_API_DLL equals(const MatrixWorkspace_sptr &lhs, const MatrixWorkspace_sptr &rhs, double tolerance=0.0)
Performs a comparison operation on two workspaces, using the CompareWorkspaces algorithm.
MDNormalization
Enum describing different ways to normalize the signal in a MDWorkspace.
Definition IMDIterator.h:25
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
PyObject * wrapWithNDArray(const ElementType *, const int ndims, Py_intptr_t *dims, const NumpyWrapMode mode, const OwnershipMode oMode=OwnershipMode::Cpp)
Defines the wrapWithNDArray specialization for C array types.
PyObject * cloneE(const API::MatrixWorkspace &self)
Create a numpy array from the E values of the given workspace reference.
PyObject * cloneY(const API::MatrixWorkspace &self)
Create a numpy array from the Y values of the given workspace reference.
PyObject * cloneDx(const API::MatrixWorkspace &self)
Create a numpy array from the E values of the given workspace reference.
PyObject * cloneX(const API::MatrixWorkspace &self)
double signal_t
Typedef for the signal recorded in a MDBox, etc.
Definition MDTypes.h:36
std::vector< double > MantidVec
typedef for the data storage used in Mantid matrix workspaces
Definition cow_ptr.h:172
Converter taking an input numpy array and converting it to a std::vector.
void copyTo(TypedVector &dest) const
Fill the container with data from the array.
Converts a Python sequence type to a C++ std::vector, where the element type is defined by the templa...
void copyTo(TypedVector &dest)
Fill the container with data from the array.
Encapsulates the registration required for an interface type T that sits on top of a Kernel::DataItem...