Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AverageLogData, test is just a placeholder. Refs #460
- Loading branch information
1 parent
05bb6e2
commit 4d150d5
Showing
4 changed files
with
262 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/AverageLogData.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#ifndef MANTID_ALGORITHMS_AVERAGELOGDATA_H_ | ||
#define MANTID_ALGORITHMS_AVERAGELOGDATA_H_ | ||
|
||
#include "MantidKernel/System.h" | ||
#include "MantidAPI/Algorithm.h" | ||
|
||
namespace Mantid | ||
{ | ||
namespace Algorithms | ||
{ | ||
|
||
/** AverageLogData : TODO: DESCRIPTION | ||
Copyright © 2012 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory | ||
This file is part of Mantid. | ||
Mantid is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation; either version 3 of the License, or | ||
(at your option) any later version. | ||
Mantid is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
File change history is stored at: <https://github.com/mantidproject/mantid> | ||
Code Documentation is available at: <http://doxygen.mantidproject.org> | ||
*/ | ||
class DLLExport AverageLogData : public API::Algorithm | ||
{ | ||
public: | ||
AverageLogData(); | ||
virtual ~AverageLogData(); | ||
|
||
virtual const std::string name() const; | ||
virtual int version() const; | ||
virtual const std::string category() const; | ||
|
||
private: | ||
virtual void initDocs(); | ||
void init(); | ||
void exec(); | ||
|
||
|
||
}; | ||
|
||
|
||
} // namespace Algorithms | ||
} // namespace Mantid | ||
|
||
#endif /* MANTID_ALGORITHMS_AVERAGELOGDATA_H_ */ |
147 changes: 147 additions & 0 deletions
147
Code/Mantid/Framework/Algorithms/src/AverageLogData.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
/*WIKI* | ||
TODO: Enter a full wiki-markup description of your algorithm here. You can then use the Build/wiki_maker.py script to generate your full wiki page. | ||
*WIKI*/ | ||
|
||
#include "MantidAlgorithms/AverageLogData.h" | ||
#include "MantidKernel/TimeSeriesProperty.h" | ||
using namespace Mantid::Kernel; | ||
using namespace Mantid::API; | ||
namespace Mantid | ||
{ | ||
namespace Algorithms | ||
{ | ||
|
||
// Register the algorithm into the AlgorithmFactory | ||
DECLARE_ALGORITHM(AverageLogData) | ||
|
||
|
||
|
||
//---------------------------------------------------------------------------------------------- | ||
/** Constructor | ||
*/ | ||
AverageLogData::AverageLogData() | ||
{ | ||
} | ||
|
||
//---------------------------------------------------------------------------------------------- | ||
/** Destructor | ||
*/ | ||
AverageLogData::~AverageLogData() | ||
{ | ||
} | ||
|
||
|
||
//---------------------------------------------------------------------------------------------- | ||
/// Algorithm's name for identification. @see Algorithm::name | ||
const std::string AverageLogData::name() const { return "AverageLogData";}; | ||
|
||
/// Algorithm's version for identification. @see Algorithm::version | ||
int AverageLogData::version() const { return 1;}; | ||
|
||
/// Algorithm's category for identification. @see Algorithm::category | ||
const std::string AverageLogData::category() const { return "DataHandling\\Logs";} | ||
|
||
//---------------------------------------------------------------------------------------------- | ||
/// Sets documentation strings for this algorithm | ||
void AverageLogData::initDocs() | ||
{ | ||
std::string summary = "Computes the proton charge averaged value of a given log."; | ||
this->setWikiSummary(summary); | ||
this->setOptionalMessage(summary); | ||
} | ||
|
||
//---------------------------------------------------------------------------------------------- | ||
/** Initialize the algorithm's properties. | ||
*/ | ||
void AverageLogData::init() | ||
{ | ||
declareProperty(new WorkspaceProperty<API::MatrixWorkspace>("InputWorkspace","",Direction::Input), "An input workspace that contains a Sample log property, and a proton charge property."); | ||
declareProperty("LogName", "", "Name of the log to be averaged"); | ||
declareProperty("FixZero", true, "If checked, the proton charge and the log value time series are assumed to start at the same moment."); | ||
declareProperty("Average", EMPTY_DBL(),"", Direction::Output); | ||
declareProperty("Error", EMPTY_DBL(),"", Direction::Output); | ||
} | ||
|
||
//---------------------------------------------------------------------------------------------- | ||
/** Execute the algorithm. | ||
*/ | ||
void AverageLogData::exec() | ||
{ | ||
MatrixWorkspace_sptr inputWS = getProperty("InputWorkspace"); | ||
std::string logname = this->getProperty("LogName"); | ||
if (logname.empty()) | ||
{ | ||
throw std::runtime_error("Failed to supply a LogName"); | ||
} | ||
if (!inputWS->run().hasProperty(logname)) | ||
{ | ||
throw std::runtime_error("There is no property "+logname+" in the workspace."); | ||
} | ||
|
||
Kernel::TimeSeriesProperty<double> * slog = dynamic_cast<Kernel::TimeSeriesProperty<double> *>( inputWS->run().getLogData(logname) ); | ||
if(!slog) | ||
{ | ||
throw std::runtime_error("Problem reading property "+logname); | ||
} | ||
Kernel::TimeSeriesProperty<double> * pclog = dynamic_cast<Kernel::TimeSeriesProperty<double> *>( inputWS->run().getLogData("proton_charge") ); | ||
if(!pclog) | ||
{ | ||
throw std::runtime_error("Problem reading the proton charge property"); | ||
} | ||
|
||
double average(0),error(0),protoncharge(0); | ||
double diffSeconds=static_cast<double>((slog->firstTime()-pclog->firstTime()).total_nanoseconds())*1e-9; | ||
if (getProperty("FixZero")) | ||
{ | ||
diffSeconds=0.; | ||
} | ||
std::vector<double> stime=slog->timesAsVectorSeconds(); | ||
std::vector<double> svalue=slog->valuesAsVector(); | ||
std::vector<double> pctime=pclog->timesAsVectorSeconds(); | ||
std::vector<double> pcvalue=pclog->valuesAsVector(); | ||
|
||
stime.push_back(EMPTY_DBL()); | ||
svalue.push_back(0.0); | ||
pctime.push_back(EMPTY_DBL()*1.1);//larger than stime | ||
pcvalue.push_back(0.0); | ||
|
||
std::vector<double>::iterator istime=stime.begin(),isvalue=svalue.begin(), ipctime=pctime.begin(),ipcvalue=pcvalue.begin(); | ||
|
||
for(;istime<(--stime.end());++istime) | ||
{ | ||
//ignore all proton pulses before the lowest time for the log | ||
while((*ipctime)<(*istime)+diffSeconds) | ||
{ | ||
++ipctime; | ||
++ipcvalue; | ||
} | ||
// add together proton pulses before the current log time and the next log time | ||
while((*ipctime)<(*(istime+1))+diffSeconds) | ||
{ | ||
protoncharge+=(*ipcvalue); | ||
average+=(*ipcvalue)*(*isvalue); | ||
error+=(*ipcvalue)*(*isvalue)*(*isvalue); | ||
++ipctime; | ||
++ipcvalue; | ||
} | ||
++isvalue; | ||
} | ||
|
||
if(protoncharge!=0) | ||
{ | ||
g_log.warning()<<"Proton charge is 0. Average and standard deviations are NANs"<<std::endl; | ||
} | ||
g_log.debug()<<"Sum = "<<average<<std::endl<<"Sum squares = "<<error<<std::endl<<"PC = "<<protoncharge<<std::endl; | ||
average/=protoncharge; | ||
error/=protoncharge; | ||
error=std::sqrt(std::fabs(error-average*average)); | ||
|
||
g_log.information()<<"Average value of "<<logname<<" is "<<average<<" +/- "<<error<<std::endl; | ||
setProperty("Average",average); | ||
setProperty("Error",error); | ||
} | ||
|
||
|
||
|
||
} // namespace Algorithms | ||
} // namespace Mantid |
56 changes: 56 additions & 0 deletions
56
Code/Mantid/Framework/Algorithms/test/AverageLogDataTest.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#ifndef MANTID_ALGORITHMS_AverageLogDATATEST_H_ | ||
#define MANTID_ALGORITHMS_AverageLogDATATEST_H_ | ||
|
||
#include <cxxtest/TestSuite.h> | ||
|
||
#include "MantidAlgorithms/AverageLogData.h" | ||
#include "MantidTestHelpers/WorkspaceCreationHelper.h" | ||
using Mantid::Algorithms::AverageLogData; | ||
|
||
class AverageLogDataTest : public CxxTest::TestSuite | ||
{ | ||
public: | ||
// This pair of boilerplate methods prevent the suite being created statically | ||
// This means the constructor isn't called when running other tests | ||
static AverageLogDataTest *createSuite() { return new AverageLogDataTest(); } | ||
static void destroySuite( AverageLogDataTest *suite ) { delete suite; } | ||
|
||
|
||
void test_Init() | ||
{ | ||
AverageLogData alg; | ||
TS_ASSERT_THROWS_NOTHING( alg.initialize() ) | ||
TS_ASSERT( alg.isInitialized() ) | ||
} | ||
|
||
void test_exec() | ||
{ | ||
// Name of the output workspace. | ||
/* std::string WSName("AverageLogDataTest_OutputWS"); | ||
AverageLogData alg; | ||
TS_ASSERT_THROWS_NOTHING( alg.initialize() ) | ||
TS_ASSERT( alg.isInitialized() ) | ||
TS_ASSERT_THROWS_NOTHING( alg.setPropertyValue("REPLACE_PROPERTY_NAME_HERE!!!!", "value") ); | ||
TS_ASSERT_THROWS_NOTHING( alg.setPropertyValue("OutputWorkspace", outWSName) ); | ||
TS_ASSERT_THROWS_NOTHING( alg.execute(); ); | ||
TS_ASSERT( alg.isExecuted() ); | ||
/* | ||
// Retrieve the workspace from data service. TODO: Change to your desired type | ||
Workspace_sptr ws; | ||
TS_ASSERT_THROWS_NOTHING( ws = AnalysisDataService::Instance().retrieveWS<Workspace>(outWSName) ); | ||
TS_ASSERT(ws); | ||
if (!ws) return; | ||
// TODO: Check the results | ||
// Remove workspace from the data service. | ||
AnalysisDataService::Instance().remove(outWSName);*/ | ||
} | ||
|
||
|
||
|
||
}; | ||
|
||
|
||
#endif /* MANTID_ALGORITHMS_AverageLogDATATEST_H_ */ |