From 509e4daa0d9ec5f8f019f3384eaecb3e9bc73d21 Mon Sep 17 00:00:00 2001 From: Andrei Savici Date: Mon, 12 Nov 2012 15:49:08 -0500 Subject: [PATCH] Updated tests and wiki. Refs #460 --- .../Algorithms/src/AverageLogData.cpp | 8 +- .../Algorithms/test/AverageLogDataTest.h | 119 +++++++++++++++--- 2 files changed, 108 insertions(+), 19 deletions(-) diff --git a/Code/Mantid/Framework/Algorithms/src/AverageLogData.cpp b/Code/Mantid/Framework/Algorithms/src/AverageLogData.cpp index a6360344c870..18142dea514e 100644 --- a/Code/Mantid/Framework/Algorithms/src/AverageLogData.cpp +++ b/Code/Mantid/Framework/Algorithms/src/AverageLogData.cpp @@ -1,5 +1,9 @@ /*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. +The algorithm will calculate a proton_charge weighted averaf=ge and standard deviation of any log value of numeric series type. +All proton charges earlier than the first data are ignored. Any proton pulse is counted for the log value on the right. This +means that if all proton pulses happen before the first value, and FixZero is false, the average and standard deviations are NANs. +If all the proton pulses occur after the last value, and FixZero is false, the average is equal to the last value, and the +standard deviation is zero. *WIKI*/ #include "MantidAlgorithms/AverageLogData.h" @@ -57,7 +61,7 @@ namespace Algorithms { declareProperty(new WorkspaceProperty("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("FixZero", true, "If true, 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); } diff --git a/Code/Mantid/Framework/Algorithms/test/AverageLogDataTest.h b/Code/Mantid/Framework/Algorithms/test/AverageLogDataTest.h index d48071a0209b..4f09dd4f0409 100644 --- a/Code/Mantid/Framework/Algorithms/test/AverageLogDataTest.h +++ b/Code/Mantid/Framework/Algorithms/test/AverageLogDataTest.h @@ -4,7 +4,11 @@ #include #include "MantidAlgorithms/AverageLogData.h" +#include "MantidKernel/TimeSeriesProperty.h" #include "MantidTestHelpers/WorkspaceCreationHelper.h" +#include + + using Mantid::Algorithms::AverageLogData; class AverageLogDataTest : public CxxTest::TestSuite @@ -15,7 +19,6 @@ class AverageLogDataTest : public CxxTest::TestSuite static AverageLogDataTest *createSuite() { return new AverageLogDataTest(); } static void destroySuite( AverageLogDataTest *suite ) { delete suite; } - void test_Init() { AverageLogData alg; @@ -23,32 +26,114 @@ class AverageLogDataTest : public CxxTest::TestSuite TS_ASSERT( alg.isInitialized() ) } - void test_exec() + void test_basic() { - // Name of the output workspace. - /* std::string WSName("AverageLogDataTest_OutputWS"); - + makeWS(0.); 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.setPropertyValue("InputWorkspace",inputWS) ); + TS_ASSERT_THROWS_NOTHING( alg.setPropertyValue("LogName", "p1") ); 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(outWSName) ); - TS_ASSERT(ws); - if (!ws) return; - - // TODO: Check the results + + //check average + const double av=alg.getProperty("Average"),err=alg.getProperty("Error"); + TS_ASSERT_DELTA(av,0.1,1e-8); + TS_ASSERT_DELTA(err,0.3,1e-8); - // Remove workspace from the data service. - AnalysisDataService::Instance().remove(outWSName);*/ + // Remove workspace from the data service.*/ + Mantid::API:: AnalysisDataService::Instance().remove(inputWS); } + void test_shift() + { + makeWS(-200.); + AverageLogData alg; + TS_ASSERT_THROWS_NOTHING( alg.initialize() ) + TS_ASSERT( alg.isInitialized() ) + + TS_ASSERT_THROWS_NOTHING( alg.setPropertyValue("InputWorkspace",inputWS) ); + TS_ASSERT_THROWS_NOTHING( alg.setPropertyValue("LogName", "p1") ); + TS_ASSERT_THROWS_NOTHING( alg.execute(); ); + TS_ASSERT( alg.isExecuted() ); + + //check average + const double av=alg.getProperty("Average"),err=alg.getProperty("Error"); + TS_ASSERT_DELTA(av,0.1,1e-8); + TS_ASSERT_DELTA(err,0.3,1e-8); + + // Remove workspace from the data service.*/ + Mantid::API:: AnalysisDataService::Instance().remove(inputWS); + } + + void test_noshiftneg() + { + makeWS(-200.); + AverageLogData alg; + TS_ASSERT_THROWS_NOTHING( alg.initialize() ) + TS_ASSERT( alg.isInitialized() ) + TS_ASSERT_THROWS_NOTHING( alg.setPropertyValue("InputWorkspace",inputWS) ); + TS_ASSERT_THROWS_NOTHING( alg.setPropertyValue("LogName", "p1") ); + TS_ASSERT_THROWS_NOTHING( alg.setPropertyValue("FixZero", "0") ); + TS_ASSERT_THROWS_NOTHING( alg.execute(); ); + TS_ASSERT( alg.isExecuted() ); + + //check average + const double av=alg.getProperty("Average"),err=alg.getProperty("Error"); + TS_ASSERT_DELTA(av,1.,1e-8); + TS_ASSERT_DELTA(err,0.,1e-8); + + // Remove workspace from the data service.*/ + Mantid::API:: AnalysisDataService::Instance().remove(inputWS); + } + + void test_noshiftpos() + { + makeWS(200.); + AverageLogData alg; + TS_ASSERT_THROWS_NOTHING( alg.initialize() ) + TS_ASSERT( alg.isInitialized() ) + + TS_ASSERT_THROWS_NOTHING( alg.setPropertyValue("InputWorkspace",inputWS) ); + TS_ASSERT_THROWS_NOTHING( alg.setPropertyValue("LogName", "p1") ); + TS_ASSERT_THROWS_NOTHING( alg.setPropertyValue("FixZero", "0") ); + TS_ASSERT_THROWS_NOTHING( alg.execute(); ); + TS_ASSERT( alg.isExecuted() ); + + //check average + const double av=alg.getProperty("Average"),err=alg.getProperty("Error"); + TS_ASSERT(boost::math::isnan(av)); + TS_ASSERT(boost::math::isnan(err)); + + // Remove workspace from the data service.*/ + Mantid::API:: AnalysisDataService::Instance().remove(inputWS); + } + + +private: + std::string inputWS; + void makeWS(double shift) + { + inputWS="AverageLogDataTestWS"; + Mantid::DataObjects::Workspace2D_sptr w=WorkspaceCreationHelper::Create2DWorkspace(1,1); + Mantid::Kernel::DateAndTime run_start("2010-01-01"); + Mantid::Kernel::TimeSeriesProperty *pc,*p1; + pc=new Mantid::Kernel::TimeSeriesProperty("proton_charge"); + pc->setUnits("picoCoulomb"); + for (double i=0; i<100; i++) + pc->addValue( run_start+i, 1.0); + w->mutableRun().addProperty( pc ); + //value p1 0 to 89, 1 to 99 average=0.1, error =0.3 + p1=new Mantid::Kernel::TimeSeriesProperty("p1"); + p1->addValue( run_start+shift, 0.); + p1->addValue( run_start+shift+90., 1.); + w->mutableRun().addProperty( p1 ); + Mantid::API::AnalysisDataService::Instance().addOrReplace(inputWS, w ); + + } };