Skip to content
Snippets Groups Projects
Unverified Commit 57389530 authored by Gigg, Martyn Anthony's avatar Gigg, Martyn Anthony Committed by GitHub
Browse files

Merge pull request #30982 from mantidproject/SCD265_DefaultCreatePeaksWorkspaceToPeaksWorkspace

Change default output type of CreatePeaksworkspace back to standard Peaksworkspace
parents 3bc85772 ba765cb4
No related branches found
No related tags found
No related merge requests found
......@@ -11,6 +11,7 @@
#include "MantidDataObjects/LeanElasticPeaksWorkspace.h"
#include "MantidDataObjects/PeaksWorkspace.h"
#include "MantidGeometry/Instrument/Goniometer.h"
#include "MantidKernel/ListValidator.h"
#include "MantidKernel/System.h"
namespace Mantid {
......@@ -36,12 +37,22 @@ void CreatePeaksWorkspace::init() {
declareProperty(std::make_unique<WorkspaceProperty<IPeaksWorkspace>>(
"OutputWorkspace", "", Direction::Output),
"An output workspace.");
// explicit control of output peak workspace tyep
// Full: standar peak workspace
// Lean: LeanElasticPeakWorkspace
const std::vector<std::string> peakworkspaceTypes{"Peak", "LeanElasticPeak"};
declareProperty(
"OutputType", "Peak",
std::make_shared<StringListValidator>(peakworkspaceTypes),
"Output peak workspace type, default to full peak workspace.");
}
/** Execute the algorithm.
*/
void CreatePeaksWorkspace::exec() {
Workspace_sptr instWS = this->getProperty("InstrumentWorkspace");
Workspace_sptr instWS = getProperty("InstrumentWorkspace");
const std::string outputType = getProperty("OutputType");
int NumberOfPeaks = getProperty("NumberOfPeaks");
MultipleExperimentInfos_sptr instMDWS =
std::dynamic_pointer_cast<MultipleExperimentInfos>(instWS);
......@@ -49,45 +60,53 @@ void CreatePeaksWorkspace::exec() {
ExperimentInfo_sptr ei;
IPeaksWorkspace_sptr out;
if (instWS)
// By default, we generate a PeakWorkspace unless user explicitly
// requires a LeanElasticPeakWorkspace
if (outputType == "Peak") {
out = std::make_shared<PeaksWorkspace>();
else
out = std::make_shared<LeanElasticPeaksWorkspace>();
setProperty("OutputWorkspace", out);
int NumberOfPeaks = getProperty("NumberOfPeaks");
setProperty("OutputWorkspace", out);
if (instMDWS != nullptr) {
if (instMDWS->getNumExperimentInfo() > 0) {
out->setInstrument(instMDWS->getExperimentInfo(0)->getInstrument());
out->mutableRun().setGoniometer(
instMDWS->getExperimentInfo(0)->run().getGoniometer().getR(), false);
if (instMDWS != nullptr) {
if (instMDWS->getNumExperimentInfo() > 0) {
out->setInstrument(instMDWS->getExperimentInfo(0)->getInstrument());
out->mutableRun().setGoniometer(
instMDWS->getExperimentInfo(0)->run().getGoniometer().getR(),
false);
} else {
throw std::invalid_argument(
"InstrumentWorkspace has no ExperimentInfo");
}
} else {
throw std::invalid_argument("InstrumentWorkspace has no ExperimentInfo");
ei = std::dynamic_pointer_cast<ExperimentInfo>(instWS);
if (ei) {
out->setInstrument(ei->getInstrument());
out->mutableRun().setGoniometer(ei->run().getGoniometer().getR(),
false);
}
}
} else {
ei = std::dynamic_pointer_cast<ExperimentInfo>(instWS);
if (ei) {
out->setInstrument(ei->getInstrument());
out->mutableRun().setGoniometer(ei->run().getGoniometer().getR(), false);
if (instMDWS || ei) {
Progress progress(this, 0.0, 1.0, NumberOfPeaks);
// Create some default Peaks
for (int i = 0; i < NumberOfPeaks; i++) {
out->addPeak(Peak(out->getInstrument(),
out->getInstrument()->getDetectorIDs(true)[0], 1.0));
progress.report();
}
}
}
Progress progress(this, 0.0, 1.0, NumberOfPeaks);
} else if (outputType == "LeanElasticPeak") {
// use LeanElasticPeakWorkspace, which means no instrument related info
out = std::make_shared<LeanElasticPeaksWorkspace>();
setProperty("OutputWorkspace", out);
if (instMDWS || ei) {
// Create some default Peaks
for (int i = 0; i < NumberOfPeaks; i++) {
out->addPeak(Peak(out->getInstrument(),
out->getInstrument()->getDetectorIDs(true)[0], 1.0));
progress.report();
}
} else {
// Create some default LeanElasticPeaks
Progress progress(this, 0.0, 1.0, NumberOfPeaks);
for (int i = 0; i < NumberOfPeaks; i++) {
out->addPeak(LeanElasticPeak());
progress.report();
}
} else {
throw std::invalid_argument("OutputType MUST be either Full or Lean!");
}
// ALG END
}
} // namespace Algorithms
......
......@@ -63,7 +63,7 @@ public:
AnalysisDataService::Instance().remove(outWSName);
}
void test_exec_no_instr() {
void test_exec_leanElasticPeakWorkspace() {
// Name of the output workspace.
std::string outWSName("CreatePeaksWorkspaceTest_OutputWS2");
......@@ -73,6 +73,7 @@ public:
TS_ASSERT_THROWS_NOTHING(
alg.setPropertyValue("OutputWorkspace", outWSName));
TS_ASSERT_THROWS_NOTHING(alg.setProperty("NumberOfPeaks", 13));
TS_ASSERT_THROWS_NOTHING(alg.setProperty("OutputType", "LeanElasticPeak"));
TS_ASSERT_THROWS_NOTHING(alg.execute();)
TS_ASSERT(alg.isExecuted());
......
......@@ -9,8 +9,12 @@
Description
-----------
Create an empty :ref:`PeaksWorkspace <PeaksWorkspace>`. Use
:ref:`algm-LoadIsawPeaks` or :ref:`algm-FindPeaksMD` to
This algorithm can be used to create a:
- :ref:`PeaksWorkspace <PeaksWorkspace>` (Default, or when `OutputType` is set to `Peak`.)
- :ref:`LeanElasticPeaksWorkspace <LeanElasticPeaksWorkspace>` (when `OutputType` is set to `LeanElasticPeak`)
Use :ref:`algm-LoadIsawPeaks` or :ref:`algm-FindPeaksMD` to
create a peaks workspace with peaks.
This workspace can serve as a starting point for modifying the
......@@ -20,23 +24,32 @@ for example.
If the input workspace is a MDWorkspace then the instrument from the
first experiment info is used.
If the `InstrumentWorkspace` is not provided then a
:ref:`LeanElasticPeaksWorkspace <LeanElasticPeaksWorkspace>` is
created instead of a :ref:`PeaksWorkspace <PeaksWorkspace>`
Usage
-----
**Example: An empty table, not tied to an instrument**
.. testcode:: ExEmptyPeaksworkspaceTable
ws = CreatePeaksWorkspace()
print("Created a {} with {} rows".format(ws.id(), ws.rowCount()))
Output:
.. testoutput:: ExEmptyPeaksworkspaceTable
Created a PeaksWorkspace with 0 rows
**Example: Create an empty LeanElasticPeaksWorkspace, not tied to an instrument**
.. testcode:: ExEmptyTable
.. testcode:: ExEmptyLeanElasticPeaksworkspaceTable
ws = CreatePeaksWorkspace(NumberOfPeaks=0)
ws = CreatePeaksWorkspace(NumberOfPeaks=0, OutputType="LeanElasticPeak")
print("Created a {} with {} rows".format(ws.id(), ws.rowCount()))
Output:
.. testoutput:: ExEmptyTable
.. testoutput:: ExEmptyLeanElasticPeaksworkspaceTable
Created a LeanElasticPeaksWorkspace with 0 rows
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment