Skip to content

Commit

Permalink
Enabled to import mask file. Refs #9643.
Browse files Browse the repository at this point in the history
Also
1. Add unit test file;
2. Write a new unit test for it;
  • Loading branch information
wdzhou committed Jul 7, 2014
1 parent 4f067ab commit 04076eb
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ namespace DataHandling
/// Set up grouping workspace
void setupGroupingWorkspace();

/// Set up mask workspace
void setupMaskWorkspace();

void generateOffsetsWorkspace();

/// Read VULCAN's offset file
Expand Down
60 changes: 56 additions & 4 deletions Code/Mantid/Framework/DataHandling/src/LoadVulcanCalFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ namespace DataHandling
// LoadVulcanCalFile::getInstrument3WaysInit(this);

declareProperty(new FileProperty("OffsetFilename", "", FileProperty::Load, ".dat"),
"Path to the VULCAN offset file. ");
"Path to the VULCAN offset file. ");

vector<string> groupoptions;
groupoptions.push_back("6Modules");
Expand Down Expand Up @@ -104,6 +104,9 @@ namespace DataHandling
// Grouping workspace
setupGroupingWorkspace();

// Mask workspace
setupMaskWorkspace();

// Genreate Offset workspace
generateOffsetsWorkspace();

Expand All @@ -114,7 +117,8 @@ namespace DataHandling
}


/**
//----------------------------------------------------------------------------------------------
/** Process input and output
*/
void LoadVulcanCalFile::processInOutProperites()
{
Expand Down Expand Up @@ -192,8 +196,6 @@ namespace DataHandling
m_offsetsWS->mutableRun().addProperty("Filename",m_offsetFilename);
setProperty("OutputOffsetsWorkspace", m_offsetsWS);



declareProperty(new WorkspaceProperty<MaskWorkspace>(
"OutputMaskWorkspace", WorkspaceName + "_mask", Direction::Output),
"Set the output MaskWorkspace. ");
Expand Down Expand Up @@ -263,6 +265,56 @@ namespace DataHandling
return;
}

//----------------------------------------------------------------------------------------------
/** Set up masking workspace
*/
void LoadVulcanCalFile::setupMaskWorkspace()
{
// Skip if bad pixel file is not given
if (m_badPixFilename.size() == 0) return;

// Open file
std::ifstream maskss(m_badPixFilename.c_str());
if (!maskss.is_open())
{
g_log.warning("Bad pixel file cannot be read.");
return;
}

string line;
while (std::getline(maskss, line))
{
// Get the bad pixel's detector ID. One per line
stringstream liness(line);
int pixelid;

try
{
liness >> pixelid;

// Set mask
m_maskWS->setValue(pixelid, 1.0);
}
catch (invalid_argument e)
{
continue;
}
}

// Mask workspace index
for (size_t i = 0; i < m_maskWS->getNumberHistograms(); ++i)
if (m_maskWS->readY(i)[0] > 0.5)
{
m_maskWS->maskWorkspaceIndex(i);
m_maskWS->dataY(i)[0] = 1.0;
g_log.notice() << "Mask workspace " << i << ", DataY = " << m_maskWS->readY(i)[i] << "\n";
}

maskss.close();

return;
}


//----------------------------------------------------------------------------------------------
/** Generate offset workspace
Expand Down
38 changes: 30 additions & 8 deletions Code/Mantid/Framework/DataHandling/test/LoadVulcanCalFileTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ class LoadVulcanCalFileTest : public CxxTest::TestSuite

TS_ASSERT_EQUALS(groupWS->getNumberHistograms(), 7392);

TS_ASSERT_EQUALS( int(groupWS->dataY(0)[0]), 1 );
TS_ASSERT_EQUALS( int(groupWS->dataY(7391)[0]), 6 );
TS_ASSERT_EQUALS( int(groupWS->readY(0)[0]), 1 );
TS_ASSERT_EQUALS( int(groupWS->readY(7391)[0]), 6 );

//Check if filename is saved
TS_ASSERT_EQUALS(alg.getPropertyValue("OffsetFilename"), groupWS->run().getProperty("Filename")->value());
Expand All @@ -65,10 +65,11 @@ class LoadVulcanCalFileTest : public CxxTest::TestSuite
TS_ASSERT(offsetsWS); if (!offsetsWS) return;

TS_ASSERT_DELTA( offsetsWS->getValue(26250), -0.000472175, 1e-7 );
TS_ASSERT_DELTA( offsetsWS->dataY(7391)[0], 6.39813e-05, 1e-7 );
TS_ASSERT_DELTA( offsetsWS->readY(7391)[0], 6.39813e-05, 1e-7 );
//Check if filename is saved
TS_ASSERT_EQUALS(alg.getPropertyValue("OffsetFilename"),offsetsWS->run().getProperty("Filename")->value());

// Masking
SpecialWorkspace2D_sptr maskWS;
TS_ASSERT_THROWS_NOTHING( maskWS = AnalysisDataService::Instance().retrieveWS<SpecialWorkspace2D>(outWSName+"_mask") );
TS_ASSERT(maskWS); if (!maskWS) return;
Expand All @@ -82,7 +83,7 @@ class LoadVulcanCalFileTest : public CxxTest::TestSuite
}


void Xtest_exec2Banks()
void test_exec2BanksBadPixel()
{
// Name of the output workspace.
std::string outWSName("LoadVulcanCalFileTest");
Expand All @@ -104,12 +105,33 @@ class LoadVulcanCalFileTest : public CxxTest::TestSuite
TS_ASSERT_THROWS_NOTHING( alg.execute(); );
TS_ASSERT( alg.isExecuted() );

return;

// TS_ASSERT_EQUALS( int(groupWS->getValue(1212)), 1 );
// TS_ASSERT_EQUALS( int(groupWS->getValue(23232)), 6 );
// Retrieve the workspace from data service. TODO: Change to your desired type
GroupingWorkspace_sptr groupWS;
TS_ASSERT_THROWS_NOTHING( groupWS = AnalysisDataService::Instance().retrieveWS<GroupingWorkspace>(outWSName+"_group") );
TS_ASSERT(groupWS); if (!groupWS) return;

TS_ASSERT_EQUALS( int(groupWS->getValue(26410)), 1 );
TS_ASSERT_EQUALS( int(groupWS->getValue(34298)), 2 );

// FIXME - Need more output check
// Masking
SpecialWorkspace2D_sptr maskWS;
TS_ASSERT_THROWS_NOTHING( maskWS = AnalysisDataService::Instance().retrieveWS<SpecialWorkspace2D>(outWSName+"_mask") );
TS_ASSERT(maskWS); if (!maskWS) return;

size_t nummasked = 0;
for (size_t i = 0; i < maskWS->getNumberHistograms(); ++i)
{
if (maskWS->readY(i)[0] > 0.5)
{
++nummasked;
TS_ASSERT(maskWS->getDetector(i)->isMasked());
}
}

TS_ASSERT_EQUALS(nummasked, 6);

return;
}

};
Expand Down
11 changes: 11 additions & 0 deletions Test/AutoTestData/bad_pids_vulcan_new_6867_7323.dat
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@


1
2
26336
26337
26338
26339
26340
26341

0 comments on commit 04076eb

Please sign in to comment.