Skip to content

Commit

Permalink
Updated tests and wiki. Refs #460
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreiSavici committed Nov 12, 2012
1 parent 4d150d5 commit 509e4da
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 19 deletions.
8 changes: 6 additions & 2 deletions 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"
Expand Down Expand Up @@ -57,7 +61,7 @@ namespace Algorithms
{
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("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);
}
Expand Down
119 changes: 102 additions & 17 deletions Code/Mantid/Framework/Algorithms/test/AverageLogDataTest.h
Expand Up @@ -4,7 +4,11 @@
#include <cxxtest/TestSuite.h>

#include "MantidAlgorithms/AverageLogData.h"
#include "MantidKernel/TimeSeriesProperty.h"
#include "MantidTestHelpers/WorkspaceCreationHelper.h"
#include <boost/math/special_functions/fpclassify.hpp>


using Mantid::Algorithms::AverageLogData;

class AverageLogDataTest : public CxxTest::TestSuite
Expand All @@ -15,40 +19,121 @@ class AverageLogDataTest : public CxxTest::TestSuite
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()
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<Workspace>(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<double> *pc,*p1;
pc=new Mantid::Kernel::TimeSeriesProperty<double>("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<double>("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 );

}

};

Expand Down

0 comments on commit 509e4da

Please sign in to comment.