Skip to content

Commit

Permalink
Refs #9445. PoldiPeakCollection now holds peak intensity type
Browse files Browse the repository at this point in the history
A PoldiPeakCollection now stores information about the type of intensity
information assigned to the contained peaks. Some parts need to work
with the peak maxima, others need the area. This information is now put
into the workspace logs and processed.
  • Loading branch information
Michael Wedel committed May 21, 2014
1 parent bb69812 commit 4f5f6ea
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 2 deletions.
Expand Up @@ -42,8 +42,13 @@ using namespace Mantid::DataObjects;
using namespace Mantid::API;

class MANTID_SINQ_DLL PoldiPeakCollection
{
{
public:
enum IntensityType {
Maximum,
Integral
};

PoldiPeakCollection();
PoldiPeakCollection(TableWorkspace_sptr workspace);
virtual ~PoldiPeakCollection() {}
Expand All @@ -55,14 +60,21 @@ class MANTID_SINQ_DLL PoldiPeakCollection

TableWorkspace_sptr asTableWorkspace();

IntensityType intensityType() const;

protected:
void prepareTable(TableWorkspace_sptr table);
void peaksToTable(TableWorkspace_sptr table);

void constructFromTableWorkspace(TableWorkspace_sptr tableWorkspace);
bool checkColumns(TableWorkspace_sptr tableWorkspace);
std::string getIntensityTypeFromTable(TableWorkspace_sptr tableWorkspace);

std::string intensityTypeToString(IntensityType type) const;
IntensityType intensityTypeFromString(std::string typeString) const;

std::vector<PoldiPeak_sptr> m_peaks;
IntensityType m_intensityType;
};

typedef boost::shared_ptr<PoldiPeakCollection> PoldiPeakCollection_sptr;
Expand Down
@@ -1,6 +1,7 @@
#include "MantidSINQ/PoldiUtilities/PoldiPeakCollection.h"
#include "MantidAPI/TableRow.h"
#include "MantidAPI/WorkspaceFactory.h"
#include "MantidAPI/LogManager.h"
#include "boost/format.hpp"
#include "boost/algorithm/string/join.hpp"

Expand All @@ -14,7 +15,8 @@ using namespace Mantid::API;
using namespace Mantid::DataObjects;

PoldiPeakCollection::PoldiPeakCollection() :
m_peaks()
m_peaks(),
m_intensityType(Maximum)
{
}

Expand Down Expand Up @@ -55,13 +57,21 @@ TableWorkspace_sptr PoldiPeakCollection::asTableWorkspace()
return peaks;
}

PoldiPeakCollection::IntensityType PoldiPeakCollection::intensityType() const
{
return m_intensityType;
}

void PoldiPeakCollection::prepareTable(TableWorkspace_sptr table)
{
table->addColumn("str", "HKL");
table->addColumn("str", "d");
table->addColumn("str", "Q");
table->addColumn("str", "Intensity");
table->addColumn("str", "FWHM (rel.)");

LogManager_sptr tableLog = table->logs();
tableLog->addProperty<std::string>("IntensityType", intensityTypeToString(m_intensityType));
}

void PoldiPeakCollection::peaksToTable(TableWorkspace_sptr table)
Expand All @@ -82,6 +92,8 @@ void PoldiPeakCollection::constructFromTableWorkspace(TableWorkspace_sptr tableW
size_t newPeakCount = tableWorkspace->rowCount();
m_peaks.resize(newPeakCount);

m_intensityType = intensityTypeFromString(getIntensityTypeFromTable(tableWorkspace));

for(size_t i = 0; i < newPeakCount; ++i) {
TableRow nextRow = tableWorkspace->getRow(i);
std::string hklString, dString, qString, intensityString, fwhmString;
Expand Down Expand Up @@ -114,5 +126,40 @@ bool PoldiPeakCollection::checkColumns(TableWorkspace_sptr tableWorkspace)
return columnNames == shouldNames;
}

std::string PoldiPeakCollection::getIntensityTypeFromTable(TableWorkspace_sptr tableWorkspace)
{
LogManager_sptr tableLog = tableWorkspace->logs();

if(tableLog->hasProperty("IntensityType")) {
return tableLog->getPropertyValueAsType<std::string>("IntensityType");
}

return "";
}

std::string PoldiPeakCollection::intensityTypeToString(PoldiPeakCollection::IntensityType type) const
{
switch(type) {
case Maximum:
return "Maximum";
case Integral:
return "Integral";
}

throw std::runtime_error("Unkown intensity type can not be processed.");
}

PoldiPeakCollection::IntensityType PoldiPeakCollection::intensityTypeFromString(std::string typeString) const
{
std::string lowerCaseType(typeString);
std::transform(lowerCaseType.begin(), lowerCaseType.end(), lowerCaseType.begin(), ::tolower);

if(lowerCaseType == "integral") {
return Integral;
}

return Maximum;
}

}
}
53 changes: 53 additions & 0 deletions Code/Mantid/Framework/SINQ/test/PoldiPeakCollectionTest.h
Expand Up @@ -91,6 +91,59 @@ class PoldiPeakCollectionTest : public CxxTest::TestSuite
}
}

void testIntensityTypeFromString()
{
TestablePoldiPeakCollection collection;

TS_ASSERT_EQUALS(collection.intensityTypeFromString("Maximum"), PoldiPeakCollection::Maximum);
TS_ASSERT_EQUALS(collection.intensityTypeFromString("maximum"), PoldiPeakCollection::Maximum);
TS_ASSERT_EQUALS(collection.intensityTypeFromString("mAxIMuM"), PoldiPeakCollection::Maximum);

TS_ASSERT_EQUALS(collection.intensityTypeFromString("Integral"), PoldiPeakCollection::Integral);
TS_ASSERT_EQUALS(collection.intensityTypeFromString("integral"), PoldiPeakCollection::Integral);
TS_ASSERT_EQUALS(collection.intensityTypeFromString("InTEgrAl"), PoldiPeakCollection::Integral);

TS_ASSERT_EQUALS(collection.intensityTypeFromString("Garbage"), PoldiPeakCollection::Maximum);
TS_ASSERT_EQUALS(collection.intensityTypeFromString(""), PoldiPeakCollection::Maximum);
}

void testIntensityTypeToString()
{
TestablePoldiPeakCollection collection;
TS_ASSERT_EQUALS(collection.intensityTypeToString(PoldiPeakCollection::Maximum), "Maximum");
TS_ASSERT_EQUALS(collection.intensityTypeToString(PoldiPeakCollection::Integral), "Integral");
}

void testIntensityTypeRecovery()
{
PoldiPeakCollection collection(m_dummyData);

TS_ASSERT_EQUALS(collection.intensityType(), PoldiPeakCollection::Maximum);

TableWorkspace_sptr newDummy(m_dummyData->clone());
newDummy->logs()->addProperty<std::string>("IntensityType", "Integral");

PoldiPeakCollection otherCollection(newDummy);
TS_ASSERT_EQUALS(otherCollection.intensityType(), PoldiPeakCollection::Integral);
}

void testIntensityTypeRecoveryConversion()
{
TableWorkspace_sptr newDummy(m_dummyData->clone());
newDummy->logs()->addProperty<std::string>("IntensityType", "Integral");

PoldiPeakCollection collection(newDummy);

TableWorkspace_sptr compare = collection.asTableWorkspace();

TS_ASSERT(compare->logs()->hasProperty("IntensityType"));
TS_ASSERT_EQUALS(compare->logs()->getPropertyValueAsType<std::string>("IntensityType"), "Integral");

PoldiPeakCollection otherCollection(compare);

TS_ASSERT_EQUALS(otherCollection.intensityType(), PoldiPeakCollection::Integral);
}

void testAddPeak()
{
PoldiPeakCollection peaks;
Expand Down

0 comments on commit 4f5f6ea

Please sign in to comment.