Commit 5a44cb4c authored by Janik Zikovsky's avatar Janik Zikovsky
Browse files

Fixes #3126: PeaksWorkspace algorithms use the Clone() method in order to give...

Fixes #3126: PeaksWorkspace algorithms use the Clone() method in order to give a different output workspace, if desired. Also added progress reporting to PeakIntegration.
parent 1aa007a9
......@@ -51,6 +51,8 @@ namespace Mantid
declareProperty(new WorkspaceProperty<PeaksWorkspace>("InPeaksWorkspace", "", Direction::Input), "Name of the peaks workspace.");
declareProperty(new WorkspaceProperty<PeaksWorkspace>("OutPeaksWorkspace", "", Direction::Output), "Name of the output peaks workspace with integrated intensities.");
declareProperty("XMin", -7, "Minimum of X (col) Range to integrate for peak");
declareProperty("XMax", 7, "Maximum of X (col) Range to integrate for peak");
declareProperty("YMin", -7, "Minimum of Y (row) Range to integrate for peak");
......@@ -77,9 +79,15 @@ namespace Mantid
Beta0 = 31.9;
Kappa = 46.0;
PeaksWorkspace_sptr peaksW;
peaksW = boost::dynamic_pointer_cast<PeaksWorkspace>(AnalysisDataService::Instance().retrieve(getProperty("InPeaksWorkspace")));
/// Input peaks workspace
PeaksWorkspace_sptr inPeaksW = getProperty("InPeaksWorkspace");
/// Output peaks workspace, create if needed
PeaksWorkspace_sptr peaksW = getProperty("OutPeaksWorkspace");
if (peaksW != inPeaksW)
peaksW = inPeaksW->clone();
Progress prog(this, 0.0, 1.0, peaksW->getNumberPeaks());
int i, XPeak, YPeak;
double col, row, I, sigI;
......@@ -144,7 +152,14 @@ namespace Mantid
//std::cout << peak.getIntensity()<<" " << I << " " << peak.getSigmaIntensity() << " "<< sigI << "\n";
peak.setIntensity(I);
peak.setSigmaIntensity(sigI);
std::ostringstream mess;
mess << "Peak " << peak.getHKL();
prog.report(mess.str());
}
// Save the output
setProperty("OutPeaksWorkspace", peaksW);
}
void PeakIntegration::retrieveProperties()
......
......@@ -173,6 +173,7 @@ public:
alg.setProperty("InputWorkspace", inputW);
alg.setProperty("OutputWorkspace", "tmp");
alg.setProperty("InPeaksWorkspace", "TOPAZ");
alg.setProperty("OutPeaksWorkspace", "TOPAZ");
alg.setProperty("XMin", -2);
alg.setProperty("XMax", 2);
alg.setProperty("YMin", -2);
......
......@@ -72,9 +72,12 @@ namespace MDEvents
declareProperty(new PropertyWithValue<double>("PeakRadius",1.0,Direction::Input),
"Fixed radius around each peak position in which to calculate the centroid.");
declareProperty(new WorkspaceProperty<PeaksWorkspace>("PeaksWorkspace","",Direction::InOut),
"A PeaksWorkspace containing the peaks to integrate. "
"The peaks' coordinates will be updated with the found centroids.");
declareProperty(new WorkspaceProperty<PeaksWorkspace>("PeaksWorkspace","",Direction::Input),
"A PeaksWorkspace containing the peaks to centroid.");
declareProperty(new WorkspaceProperty<PeaksWorkspace>("OutputWorkspace","",Direction::Output),
"The output PeaksWorkspace will be a copy of the input PeaksWorkspace "
"with the peaks' positions modified by the new found centroids.");
}
//----------------------------------------------------------------------------------------------
......@@ -87,8 +90,13 @@ namespace MDEvents
if (nd != 3)
throw std::invalid_argument("For now, we expect the input MDEventWorkspace to have 3 dimensions only.");
/// Peak workspace to integrate
Mantid::DataObjects::PeaksWorkspace_sptr peakWS = getProperty("PeaksWorkspace");
/// Peak workspace to centroid
Mantid::DataObjects::PeaksWorkspace_sptr inPeakWS = getProperty("PeaksWorkspace");
/// Output peaks workspace, create if needed
Mantid::DataObjects::PeaksWorkspace_sptr peakWS = getProperty("OutputWorkspace");
if (peakWS != inPeakWS)
peakWS = inPeakWS->clone();
/// Value of the CoordinatesToUse property.
std::string CoordinatesToUse = getPropertyValue("CoordinatesToUse");
......@@ -162,6 +170,9 @@ namespace MDEvents
}
}
// Save the output
setProperty("OutputWorkspace", peakWS);
}
//----------------------------------------------------------------------------------------------
......
......@@ -73,9 +73,12 @@ namespace MDEvents
"The signal density around the peak (PeakRadius < r < BackgroundRadius) is used to estimate the background under the peak.\n"
"If smaller than PeakRadius, no background measurement is done." );
declareProperty(new WorkspaceProperty<PeaksWorkspace>("PeaksWorkspace","",Direction::InOut),
"A PeaksWorkspace containing the peaks to integrate. The peaks' integrated intensities will be updated"
"with the new values.");
declareProperty(new WorkspaceProperty<PeaksWorkspace>("PeaksWorkspace","",Direction::Input),
"A PeaksWorkspace containing the peaks to integrate.");
declareProperty(new WorkspaceProperty<PeaksWorkspace>("OutputWorkspace","",Direction::Output),
"The output PeaksWorkspace will be a copy of the input PeaksWorkspace "
"with the peaks' integrated intensities.");
}
//----------------------------------------------------------------------------------------------
......@@ -89,7 +92,12 @@ namespace MDEvents
throw std::invalid_argument("For now, we expect the input MDEventWorkspace to have 3 dimensions only.");
/// Peak workspace to integrate
Mantid::DataObjects::PeaksWorkspace_sptr peakWS = getProperty("PeaksWorkspace");
Mantid::DataObjects::PeaksWorkspace_sptr inPeakWS = getProperty("PeaksWorkspace");
/// Output peaks workspace, create if needed
Mantid::DataObjects::PeaksWorkspace_sptr peakWS = getProperty("OutputWorkspace");
if (peakWS != inPeakWS)
peakWS = inPeakWS->clone();
/// Value of the CoordinatesToUse property.
std::string CoordinatesToUse = getPropertyValue("CoordinatesToUse");
......@@ -169,6 +177,9 @@ namespace MDEvents
<< std::endl;
}
// Save the output
setProperty("OutputWorkspace", peakWS);
}
//----------------------------------------------------------------------------------------------
......
......@@ -79,7 +79,8 @@ public:
//-------------------------------------------------------------------------------
/** Run the MDCentroidPeaks with the given peak radius param */
void doRun( V3D startPos, double PeakRadius, V3D expectedResult, std::string message)
void doRun( V3D startPos, double PeakRadius, V3D expectedResult, std::string message,
std::string OutputWorkspace = "MDCentroidPeaksTest_Peaks")
{
// Make a fake instrument - doesn't matter, we won't use it really
IInstrument_sptr inst = ComponentCreationHelper::createTestInstrumentCylindrical(5);
......@@ -105,10 +106,16 @@ public:
TS_ASSERT_THROWS_NOTHING( alg.setPropertyValue("InputWorkspace", "MDCentroidPeaksTest_MDEWS" ) );
TS_ASSERT_THROWS_NOTHING( alg.setPropertyValue("PeaksWorkspace", "MDCentroidPeaksTest_Peaks" ) );
TS_ASSERT_THROWS_NOTHING( alg.setPropertyValue("CoordinatesToUse", CoordinatesToUse ) );
TS_ASSERT_THROWS_NOTHING( alg.setPropertyValue("OutputWorkspace", OutputWorkspace ) );
TS_ASSERT_THROWS_NOTHING( alg.setProperty("PeakRadius", PeakRadius ) );
TS_ASSERT_THROWS_NOTHING( alg.execute() );
TS_ASSERT( alg.isExecuted() );
peakWS = boost::dynamic_pointer_cast<PeaksWorkspace>(
AnalysisDataService::Instance().retrieve(OutputWorkspace));
TS_ASSERT(peakWS);
if (!peakWS) return;
// Compare the result to the expectation
V3D result;
Peak & p = peakWS->getPeak(0);
......@@ -177,6 +184,16 @@ public:
do_test_exec();
}
void test_exec_HKL_NotInPlace()
{
CoordinatesToUse = "HKL";
createMDEW();
addPeak(1000, 0,0.,0., 1.0);
doRun(V3D( 0.,0.,0.), 1.0, V3D( 0.,0.,0.), "Start at the center, get the center",
"MDCentroidPeaksTest_MDEWS_outputCopy");
}
private:
std::string CoordinatesToUse;
......
......@@ -46,16 +46,18 @@ public:
//-------------------------------------------------------------------------------
/** Run the MDEWPeakIntegration with the given peak radius integration param */
static void doRun(double PeakRadius, double BackgroundRadius)
static void doRun(double PeakRadius, double BackgroundRadius,
std::string OutputWorkspace = "MDEWPeakIntegrationTest_peaks")
{
MDEWPeakIntegration alg;
TS_ASSERT_THROWS_NOTHING( alg.initialize() )
TS_ASSERT( alg.isInitialized() )
TS_ASSERT_THROWS_NOTHING( alg.setPropertyValue("InputWorkspace", "MDEWPeakIntegrationTest_MDEWS" ) );
TS_ASSERT_THROWS_NOTHING( alg.setPropertyValue("PeaksWorkspace", "MDEWPeakIntegrationTest_peaks" ) );
TS_ASSERT_THROWS_NOTHING( alg.setPropertyValue("CoordinatesToUse", "HKL" ) );
TS_ASSERT_THROWS_NOTHING( alg.setProperty("PeakRadius", PeakRadius ) );
TS_ASSERT_THROWS_NOTHING( alg.setProperty("BackgroundRadius", BackgroundRadius ) );
TS_ASSERT_THROWS_NOTHING( alg.setPropertyValue("PeaksWorkspace", "MDEWPeakIntegrationTest_peaks" ) );
TS_ASSERT_THROWS_NOTHING( alg.setPropertyValue("OutputWorkspace", OutputWorkspace) );
TS_ASSERT_THROWS_NOTHING( alg.execute() );
TS_ASSERT( alg.isExecuted() );
}
......@@ -182,6 +184,33 @@ public:
//-------------------------------------------------------------------------------
void test_exec_NotInPlace()
{
// --- Fake workspace with 3 peaks ------
createMDEW();
addPeak(1000, 0.,0.,0., 1.0);
// Make a fake instrument - doesn't matter, we won't use it really
IInstrument_sptr inst = ComponentCreationHelper::createTestInstrumentCylindrical(5);
// --- Make a fake PeaksWorkspace ---
PeaksWorkspace_sptr peakWS(new PeaksWorkspace());
peakWS->addPeak( Peak(inst, 1, 1.0, V3D(0., 0., 0.) ) );
AnalysisDataService::Instance().add("MDEWPeakIntegrationTest_peaks",peakWS);
// Integrate and copy to a new peaks workspace
doRun(1.0,0.0, "MDEWPeakIntegrationTest_peaks_out");
// Old workspace is unchanged
TS_ASSERT_EQUALS( peakWS->getPeak(0).getIntensity(), 0.0);
PeaksWorkspace_sptr newPW = boost::dynamic_pointer_cast<PeaksWorkspace>(
AnalysisDataService::Instance().retrieve("MDEWPeakIntegrationTest_peaks_out"));
TS_ASSERT( newPW );
TS_ASSERT_DELTA( newPW->getPeak(0).getIntensity(), 1000.0, 1e-2);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment