Skip to content

Commit

Permalink
Refs #8590 Merge remote-tracking branch 'origin' into feature/8590
Browse files Browse the repository at this point in the history
Conflicts:
	Code/Mantid/scripts/Interface/ui/reflectometer/refl_gui.py
  • Loading branch information
keithnbrown committed Jan 29, 2014
2 parents 4370b23 + 09e4fe3 commit 0e46b72
Show file tree
Hide file tree
Showing 143 changed files with 5,626 additions and 2,990 deletions.
2 changes: 2 additions & 0 deletions Code/Mantid/Framework/API/inc/MantidAPI/ExperimentInfo.h
Expand Up @@ -120,6 +120,8 @@ namespace API
void saveExperimentInfoNexus(::NeXus::File * file) const;
/// Loads an experiment description from the open NeXus file
void loadExperimentInfoNexus(::NeXus::File * file, std::string & parameterStr);
/// Load the sample and log info from an open NeXus file.
void loadSampleAndLogInfoNexus(::NeXus::File * file);
/// Populate the parameter map given a string
void readParameterMap(const std::string & parameterStr);

Expand Down
2 changes: 2 additions & 0 deletions Code/Mantid/Framework/API/inc/MantidAPI/ICatalog.h
Expand Up @@ -67,6 +67,8 @@ class DLLExport ICatalog
virtual void getFileLocation(const long long&,std::string& )=0;
/// get URLs of the files
virtual void getDownloadURL(const long long& fileid,std::string&)=0;
/// get URL of where to PUT (publish) files.
virtual const std::string getUploadURL(const std::string &, const std::string &)=0;
/// keep alive
virtual void keepAlive()=0;
///keep alive in minutes
Expand Down
30 changes: 20 additions & 10 deletions Code/Mantid/Framework/API/src/ExperimentInfo.cpp
Expand Up @@ -864,19 +864,11 @@ namespace API
}

//--------------------------------------------------------------------------------------------
/** Load the object from an open NeXus file.
/** Load the sample and log info from an open NeXus file.
* @param file :: open NeXus file
* @param[out] parameterStr :: special string for all the parameters.
* Feed that to ExperimentInfo::readParameterMap() after the instrument is done.
* @throws Exception::NotFoundError If instrument definition is not in the nexus file and cannot
* be loaded from the IDF.
*/
void ExperimentInfo::loadExperimentInfoNexus(::NeXus::File * file, std::string & parameterStr)
void ExperimentInfo::loadSampleAndLogInfoNexus(::NeXus::File * file)
{
std::string instrumentName;
std::string instrumentXml;
std::string instrumentFilename;

// First, the sample and then the logs
int sampleVersion = mutableSample().loadNexus(file, "sample");
if (sampleVersion == 0)
Expand All @@ -892,6 +884,24 @@ namespace API
// Newer style: separate "logs" field for the Run object
this->mutableRun().loadNexus(file, "logs");
}
}

//--------------------------------------------------------------------------------------------
/** Load the object from an open NeXus file.
* @param file :: open NeXus file
* @param[out] parameterStr :: special string for all the parameters.
* Feed that to ExperimentInfo::readParameterMap() after the instrument is done.
* @throws Exception::NotFoundError If instrument definition is not in the nexus file and cannot
* be loaded from the IDF.
*/
void ExperimentInfo::loadExperimentInfoNexus(::NeXus::File * file, std::string & parameterStr)
{
// load sample and log info
loadSampleAndLogInfoNexus(file);

std::string instrumentName;
std::string instrumentXml;
std::string instrumentFilename;

// Try to get the instrument file
file->openGroup("instrument", "NXinstrument");
Expand Down
59 changes: 48 additions & 11 deletions Code/Mantid/Framework/Algorithms/src/ExtractMaskToTable.cpp
@@ -1,9 +1,20 @@
/*WIKI*
The masking from the InputWorkspace property is extracted by creating a new MatrixWorkspace with a single X bin where:
* 0 = masked;
* 1 = unmasked.
The spectra containing 0 are also marked as masked and the instrument link is preserved so that the instrument view functions correctly.
==== InputWorskpace ====
It can be either a MaskWorkspace, containing the masking information, or a Data workspace (EventWorkspace or Workspace2D), having
detectors masked.
==== Optional MaskTableWorkspace ====
If the optional input 'MaskTableWorkspace' is given, it must be a table workspace having the
same format as output TableWorkspace such that it contains 3 columns, XMin, XMax and DetectorIDsList.
The contents in this mask table workspace will be copied to output workspace.
If a detector is masked in this input 'MaskTableWorkspace', and it is also masked in input MaskWorkspace or data workspace,
the setup (Xmin and Xmax) in MaskTableWorkspace has higher priority, i.e., in the output mask table workspace,
the masked detector will be recorded in the row copied from input MaskTableWrokspace.
*WIKI*/

#include "MantidAlgorithms/ExtractMaskToTable.h"
Expand Down Expand Up @@ -56,11 +67,11 @@ namespace Algorithms
*/
void ExtractMaskToTable::init()
{
auto inwsprop = new WorkspaceProperty<MatrixWorkspace>("InputWorkspace", "Anonymous", Direction::Input);
declareProperty(inwsprop, "A workspace whose masking is to be extracted");
auto inwsprop = new WorkspaceProperty<MatrixWorkspace>("InputWorkspace", "", Direction::Input);
declareProperty(inwsprop, "A workspace whose masking is to be extracted or a MaskWorkspace. ");

auto intblprop = new WorkspaceProperty<TableWorkspace>("MaskTableWorkspace", "", Direction::Input, PropertyMode::Optional);
declareProperty(intblprop, "A workspace containing the masked spectra as zeroes and ones. ");
declareProperty(intblprop, "A mask table workspace containing 3 columns: XMin, XMax and DetectorIDsList. ");

auto outwsprop = new WorkspaceProperty<TableWorkspace>("OutputWorkspace", "", Direction::Output);
declareProperty(outwsprop, "A comma separated list or array containing a list of masked detector ID's ");
Expand Down Expand Up @@ -108,7 +119,7 @@ namespace Algorithms
vector<detid_t> prevmaskeddetids;
if (m_inputTableWS)
{
g_log.notice("[To implement] Parse input table workspace.");
g_log.notice("Parse input masking table workspace.");
parseMaskTable(m_inputTableWS, prevmaskeddetids);
}
else
Expand Down Expand Up @@ -143,12 +154,37 @@ namespace Algorithms
//----------------------------------------------------------------------------------------------
/** Parse input TableWorkspace to get a list of detectors IDs of which detector are already masked
* @param masktablews :: TableWorkspace containing masking information
* @param maskeddetectorids :: List for holding masked detector IDs
* @param maskeddetectorids :: (output) vector of detector IDs that are masked
*/
void ExtractMaskToTable::parseMaskTable(DataObjects::TableWorkspace_sptr masktablews, std::vector<detid_t>& maskeddetectorids)
{
// Clear input
maskeddetectorids.clear();;
maskeddetectorids.clear();

// Check format of mask table workspace
if (masktablews->columnCount() != 3)
{
g_log.error("Mask table workspace must have more than 3 columns. First 3 must be Xmin, Xmax and Spectrum List.");
return;
}
else
{
vector<string> colnames = masktablews->getColumnNames();
vector<string> chkcolumans(3);
chkcolumans[0] = "XMin";
chkcolumans[1] = "XMax";
chkcolumans[2] = "DetectorIDsList";
for (int i = 0; i < 3; ++i)
{
if (colnames[i] != chkcolumans[i])
{
g_log.error() << "Mask table workspace " << masktablews->name() << "'s " << i << "-th column name is "
<< colnames[i] << ", while it should be " << chkcolumans[i] << ". MaskWorkspace is invalid"
<< " and thus not used.\n";
return;
}
}
}

// Parse each row
size_t numrows = masktablews->rowCount();
Expand Down Expand Up @@ -319,7 +355,8 @@ namespace Algorithms
}

//----------------------------------------------------------------------------------------------
/** Add a list of spectra (detector IDs) to the output table workspace
/** Add a list of spectra (detector IDs) to the output table workspace.
* If a detector is masked in input MaskTableWorkspace, then it will not be added to a new row
* @param outws :: table workspace to write
* @param maskeddetids :: vector of detector IDs of which detectors masked
* @param xmin :: minumim x
Expand Down
34 changes: 19 additions & 15 deletions Code/Mantid/Framework/Algorithms/src/GeneratePythonScript.cpp
@@ -1,22 +1,28 @@
/*WIKI*
Accepts an input workspace and the name of a file. Retrieves the algorithm history of the workspace, and then dumps it to file in the format of a Python script.
Retrieves the algorithm history of the workspace and saves it to a Python script file or Python variable.
Example format:
=== Example usage: ===
<div style="border:1pt dashed black; background:#f9f9f9;padding: 1em 0;">
<source lang="python">
######################################################################
#Python Script Generated by GeneratePythonScript Algorithm
######################################################################
LoadRaw(Filename='G:/Spencer/Science/Raw/irs26173.raw',OutputWorkspace='IPG',SpectrumMin='3',SpectrumMax='53')
ConvertUnits(InputWorkspace='IPG',OutputWorkspace='Spec',Target='Wavelength')
LoadRaw(Filename='G:/Spencer/Science/Raw/irs26173.raw',OutputWorkspace='Mon_in',SpectrumMax='1')
</source></div>
# Optional: Store the contents of the workspace to a file to your desktop.
GeneratePythonScript("MUSR00022725", "/home/userName/Desktop/MUSR00022725.py")
{{AlgorithmLinks|GeneratePythonScript}}
# Store the contents of the workspace history into the hist variable
wsHistory = GeneratePythonScript("MUSR00022725")
# Output the contents of the hist variable.
print wsHistory
######################################################################
#Python Script Generated by GeneratePythonScript Algorithm
######################################################################
Load(Filename=r'/home/userName/workspace/mantid/Test/AutoTestData/MUSR00022725.nxs',OutputWorkspace='MUSR00022725')
RenameWorkspace(InputWorkspace='MUSR00022725',OutputWorkspace='test')
</source></div>
{{AlgorithmLinks|GeneratePythonScript}}
*WIKI*/
#include "MantidAlgorithms/GeneratePythonScript.h"
Expand All @@ -38,13 +44,11 @@ namespace Algorithms
// Register the algorithm into the AlgorithmFactory
DECLARE_ALGORITHM(GeneratePythonScript)



//----------------------------------------------------------------------------------------------
/// Sets documentation strings for this algorithm
void GeneratePythonScript::initDocs()
{
this->setWikiSummary("Generate a Python script file to reproduce the history of a workspace.");
this->setWikiSummary("Reproduce the history of a workspace and save it to a Python script file or Python variable.");
this->setOptionalMessage("An Algorithm to generate a Python script file to reproduce the history of a workspace.");
}

Expand All @@ -59,8 +63,8 @@ void GeneratePythonScript::init()
exts.push_back(".py");

declareProperty(new API::FileProperty("Filename","", API::FileProperty::OptionalSave, exts),
"The file into which the Python script will be generated.");
declareProperty("ScriptText", "",Direction::Output);
"The name of the file into which the workspace history will be generated.");
declareProperty("ScriptText", std::string(""), "Saves the history of the workspace to a variable.",Direction::Output);
}

//----------------------------------------------------------------------------------------------
Expand Down
46 changes: 13 additions & 33 deletions Code/Mantid/Framework/Algorithms/test/ExtractMaskToTableTest.h
Expand Up @@ -31,7 +31,8 @@ class ExtractMaskToTableTest : public CxxTest::TestSuite
static ExtractMaskToTableTest *createSuite() { return new ExtractMaskToTableTest(); }
static void destroySuite( ExtractMaskToTableTest *suite ) { delete suite; }

/** Test a method
//----------------------------------------------------------------------------------------------
/** Test method 'subtractVector'
*/
void test_method()
{
Expand All @@ -40,7 +41,7 @@ class ExtractMaskToTableTest : public CxxTest::TestSuite
vector<int> vecA;
vector<int> vecB;

// All B's items are in A
// Case: A constains B
for (size_t i = 0; i < 20; ++i)
{
vecA.push_back(static_cast<int>(i)+5);
Expand All @@ -52,13 +53,10 @@ class ExtractMaskToTableTest : public CxxTest::TestSuite
}

vector<int> vecC = alg.subtractVector(vecA, vecB);
for (size_t i = 0;i < vecC.size(); ++i)
cout << "Item " << i << "\t = \t" << vecC[i] << ".\n";
cout << "\n";

TS_ASSERT_EQUALS(vecC.size(), vecA.size()-vecB.size());

// Not all B's item are in A
// Case: A does not contain B; but the intersection between A and B is not empty
vecA.clear();
vecB.clear();

Expand All @@ -70,13 +68,9 @@ class ExtractMaskToTableTest : public CxxTest::TestSuite

vecC = alg.subtractVector(vecA, vecB);

for (size_t i = 0;i < vecC.size(); ++i)
cout << "Item " << i << "\t = \t" << vecC[i] << ".\n";
cout << "\n";

TS_ASSERT_EQUALS(vecC.size(), 7);

// B has a large range than A
// Case: B has a larger range than A
vecA.clear();
vecB.clear();

Expand All @@ -91,14 +85,13 @@ class ExtractMaskToTableTest : public CxxTest::TestSuite
vecB.push_back(30);

vecC = alg.subtractVector(vecA, vecB);
for (size_t i = 0;i < vecC.size(); ++i)
cout << "Item " << i << "\t = \t" << vecC[i] << ".\n";
cout << "\n";

TS_ASSERT_EQUALS(vecC.size(), 5);

return;
}

//----------------------------------------------------------------------------------------------
/** Test initialization of the algorithm
*/
void test_Init()
Expand All @@ -108,6 +101,7 @@ class ExtractMaskToTableTest : public CxxTest::TestSuite
TS_ASSERT(alg.isInitialized());
}

//----------------------------------------------------------------------------------------------
/** Test for writing a new line to a new table workspace
*/
void test_writeToNewTable()
Expand All @@ -130,27 +124,13 @@ class ExtractMaskToTableTest : public CxxTest::TestSuite

AnalysisDataService::Instance().addOrReplace("TestWorkspace1", inputws);

/*
for (size_t i = 0; i < inputws->getNumberHistograms(); ++i)
{
IDetector_const_sptr det = inputws->getDetector(i);
cout << "WorkspaceIndex = " << i << " X Size = " << inputws->readX(i).size()
<< "; Detector ID = " << det->getID() << ".\n";
}
Instrument_const_sptr instrument = inputws->getInstrument();
vector<detid_t> detids = instrument->getDetectorIDs();
cout << "Number of detectors = " << detids.size() << ".\n";
for (size_t i = 0; i < detids.size(); ++i)
cout << "Detector " << i << ": ID = " << detids[i] << ".\n";
*/

// Call algorithms
ExtractMaskToTable alg;
alg.initialize();

// Set up properties
alg.setProperty("InputWorkspace", "TestWorkspace1");
alg.setProperty("OutputWorkspace", "MaskTable1");
alg.setPropertyValue("InputWorkspace", "TestWorkspace1");
alg.setPropertyValue("OutputWorkspace", "MaskTable1");
alg.setProperty("XMin", 1234.0);
alg.setProperty("XMax", 12345.6);

Expand All @@ -173,7 +153,6 @@ class ExtractMaskToTableTest : public CxxTest::TestSuite
string specstr;
therow >> xxmin >> xxmax >> specstr;

cout << "XMin = " << xxmin << ", XMax = " << xxmax << ", Spec list = " << specstr << ".\n";
string expectedspec(" 1, 6-8, 11, 21, 31, 41");
TS_ASSERT_EQUALS(specstr, expectedspec);
TS_ASSERT_DELTA(xxmin, 1234.0, 0.0001);
Expand All @@ -186,6 +165,7 @@ class ExtractMaskToTableTest : public CxxTest::TestSuite
return;
}

//----------------------------------------------------------------------------------------------
/** Test for appending a new line to an existing table workspace
*/
void test_appendToExistingTable()
Expand Down Expand Up @@ -250,15 +230,15 @@ class ExtractMaskToTableTest : public CxxTest::TestSuite

TableRow therow = outws->getRow(2);
therow >> xxmin >> xxmax >> specstr;
cout << "XMin = " << xxmin << ", XMax = " << xxmax << ", Spec list = " << specstr << ".\n";

string expectedspec(" 1, 6-8, 11, 21, 31, 41");
TS_ASSERT_EQUALS(specstr, expectedspec);
TS_ASSERT_DELTA(xxmin, 1234.0, 0.0001);
TS_ASSERT_DELTA(xxmax, 12345.6, 0.0001);

TableRow therow1 = outws->getRow(1);
therow1 >> xxmin >> xxmax >> specstr;
cout << "XMin = " << xxmin << ", XMax = " << xxmax << ", Spec list = " << specstr << ".\n";

string expectedspec2("43");
TS_ASSERT_DELTA(xxmin, 2345.1, 0.0001);
TS_ASSERT_DELTA(xxmax, 78910.5, 0.0001);
Expand Down

0 comments on commit 0e46b72

Please sign in to comment.