Skip to content

Commit

Permalink
Removed optional output property 'OutputWorkspace'. Refs #7001.
Browse files Browse the repository at this point in the history
  • Loading branch information
wdzhou committed Jun 18, 2013
1 parent e8e871a commit c4631a0
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 95 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class DLLExport FindPeaks : public API::Algorithm
void fitPeak(const API::MatrixWorkspace_sptr &input, const int spectrum, const double center_guess, const int FWHM_guess);

/// Fit peak
void fitPeak(const API::MatrixWorkspace_sptr &input, const int spectrum, const int i_min, const int i_max, const int i_centre, bool changeflag);
void fitPeak(const API::MatrixWorkspace_sptr &input, const int spectrum, const int i_min, const int i_max, const int i_centre);


int getVectorIndex(const MantidVec &vecX, double x);
Expand Down Expand Up @@ -183,9 +183,6 @@ class DLLExport FindPeaks : public API::Algorithm
double calculateFunctionRwp(API::IFunction_sptr function, API::MatrixWorkspace_sptr dataws,
size_t wsindex, double startx, double endx);

///
API::MatrixWorkspace_sptr createOutputDataWorkspace();

/// Compare 2 fit results and record the better one
void processFitResult(PeakFittingRecord& r1, PeakFittingRecord& r2, API::IPeakFunction_sptr peak, API::IFunction_sptr bkgdfunc, size_t spectrum,
size_t imin, size_t imax, double windowsize);
Expand Down
87 changes: 7 additions & 80 deletions Code/Mantid/Framework/Algorithms/src/FindPeaks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,6 @@ namespace Algorithms
declareProperty(new WorkspaceProperty<>("InputWorkspace", "", Direction::Input),
"Name of the workspace to search");

declareProperty(new WorkspaceProperty<Workspace2D>("OutputWorkspace", "", Direction::Output, PropertyMode::Optional),
"Name of the output workspace containing original data and fitted peaks.");

auto min = boost::make_shared<BoundedValidator<int> >();
min->setLower(1);
// The estimated width of a peak in terms of number of channels
Expand Down Expand Up @@ -322,14 +319,6 @@ namespace Algorithms
<< " peaks found and successfully fitted." << std::endl;
setProperty("PeaksList", m_outPeakTableWS);

std::string outwsname = getPropertyValue("OutputWorkspace");
g_log.information() << "Output workspace name is " << outwsname << " (length = "
<< outwsname.size() << "). " << "\n";
if (outwsname.size() > 0)
{
API::MatrixWorkspace_sptr outWS = createOutputDataWorkspace();
setProperty("OutputWorkspace", outWS);
}
return;
} // END: exec()

Expand Down Expand Up @@ -643,7 +632,7 @@ namespace Algorithms
if (i_max >= wssize)
i_max = wssize - 1;

this->fitPeak(m_dataWS, k, i_min, i_max, i4, true);
this->fitPeak(m_dataWS, k, i_min, i_max, i4);

// reset and go searching for the next peak
i1 = 0, i2 = 0, i3 = 0, i4 = 0, i5 = 0;
Expand Down Expand Up @@ -915,7 +904,7 @@ namespace Algorithms
g_log.debug() << "Background + Peak -- Bounds Fit Range = " << vecX[i_min]
<< ", " << vecX[i_max] << ".\n";

fitPeak(input, spectrum, i_min, i_max, i_centre, true);
fitPeak(input, spectrum, i_min, i_max, i_centre);

return;

Expand Down Expand Up @@ -981,7 +970,7 @@ namespace Algorithms
}

// finally do the actual fit
fitPeak(input, spectrum, i_min, i_max, i_centre, true);
fitPeak(input, spectrum, i_min, i_max, i_centre);

return;
}
Expand All @@ -997,7 +986,7 @@ namespace Algorithms
* @param i4 :: Channel number of peak candidate i4 - the center of the peak
*/
void FindPeaks::fitPeak(const API::MatrixWorkspace_sptr &input, const int spectrum, const int i_min,
const int i_max, const int i_centre, bool changeflag)
const int i_max, const int i_centre)
{
const MantidVec &vecX = input->readX(spectrum);
const MantidVec &vecY = input->readY(spectrum);
Expand Down Expand Up @@ -2584,6 +2573,9 @@ namespace Algorithms
MatrixWorkspace_sptr dataws, size_t wsindex,
double startx, double endx, std::string constraint, double& init_rwp)
{
// FIXME - Constraint is not used for better performance at this moment.
UNUSED_ARG(constraint);

if (!peakbkgdfunc)
throw std::runtime_error("FitPeakBackgroundFunction has a null peak input.");
else
Expand Down Expand Up @@ -2662,71 +2654,6 @@ namespace Algorithms
return final_rwp;
}

//----------------------------------------------------------------------------------------------
/** Create the output data workspace
*/
API::MatrixWorkspace_sptr FindPeaks::createOutputDataWorkspace()
{
// TODO - consider to remove this feature

size_t lenX = m_dataWS->readX(0).size();
size_t lenY = m_dataWS->readY(0).size();

MatrixWorkspace_sptr outws = WorkspaceFactory::Instance().create(m_dataWS, 1, lenX, lenY);

const MantidVec& vecInX = m_dataWS->readX(0);
MantidVec& vecX = outws->dataX(0);
MantidVec& vecY = outws->dataY(0);

// X - axis
for (size_t i = 0; i < vecX.size(); ++i)
{
vecX[i] = vecInX[i];
}
for (size_t i = 0; i < vecY.size(); ++i)
{
vecY[i] = 0.;
}

// Calculation
g_log.information() << "Plot total " << m_fitFunctions.size() << " functions" << ".\n";
FunctionDomain1DVector domain(vecX);
FunctionValues values(domain);

for (size_t fi = 0; fi < m_fitFunctions.size(); ++fi)
{
// calcualte function
IFunction_sptr tfunc = m_fitFunctions[fi];
tfunc->function(domain, values);

// determine range to apply
size_t ileft = m_peakLeftIndexes[fi];
size_t iright = m_peakRightIndexes[fi];
size_t idelta = iright-ileft;
size_t i_left, i_right;
if (ileft > idelta)
i_left = static_cast<size_t>(ileft - idelta);
else
i_left = 0;
if (static_cast<size_t>(iright) < vecY.size() - 2*idelta - 1)
i_right = static_cast<size_t>(iright + 2*idelta);
else
i_right = vecY.size()-1;

for (size_t i = i_left; i <= i_right; ++i)
{
vecY[i] = values[i];
}

g_log.information() << "Peak " << fi << " Range = " << vecX[i_left]
<< ", " << vecX[i_right] << ".\n";

}

return outws;
}



} // namespace Algorithms
} // namespace Mantid
Expand Down
11 changes: 0 additions & 11 deletions Code/Mantid/Framework/Algorithms/test/FindPeaksTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,11 @@ class FindPeaksTest : public CxxTest::TestSuite
Mantid::DataHandling::LoadNexusProcessed loader;
loader.initialize();
loader.setProperty("Filename","focussed.nxs");
loader.setProperty("OutputWorkspace","FindPeaksTest_peaksWS");
loader.execute();

FindPeaks finder;
if ( !finder.isInitialized() ) finder.initialize();

#if 1
MatrixWorkspace_sptr dataws = boost::dynamic_pointer_cast<MatrixWorkspace>(
AnalysisDataService::Instance().retrieve("FindPeaksTest_peaksWS"));
std::ofstream ofile;
ofile.open("spectrum4.dat");
for (size_t i = 0; i < dataws->readY(4).size(); ++i)
ofile << dataws->readX(4)[i] << " \t" << dataws->readY(4)[i] << ".\n";
ofile.close();
#endif

TS_ASSERT_THROWS_NOTHING( finder.setPropertyValue("InputWorkspace","FindPeaksTest_peaksWS") );
TS_ASSERT_THROWS_NOTHING( finder.setPropertyValue("WorkspaceIndex","4") );
// TS_ASSERT_THROWS_NOTHING( finder.setPropertyValue("SmoothedData","smoothed") );
Expand Down

0 comments on commit c4631a0

Please sign in to comment.