Skip to content

Commit

Permalink
Re #11619. Renamed and moved the algorithm.
Browse files Browse the repository at this point in the history
  • Loading branch information
mantid-roman committed Apr 24, 2015
1 parent 10bf85d commit fe26fe1
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 51 deletions.
3 changes: 3 additions & 0 deletions Code/Mantid/Framework/Algorithms/CMakeLists.txt
Expand Up @@ -197,6 +197,7 @@ set ( SRC_FILES
src/RemoveBins.cpp
src/RemoveExpDecay.cpp
src/RemoveLowResTOF.cpp
src/RemoveMaskedSpectra.cpp
src/RemovePromptPulse.cpp
src/RemoveWorkspaceHistory.cpp
src/RenameWorkspace.cpp
Expand Down Expand Up @@ -455,6 +456,7 @@ set ( INC_FILES
inc/MantidAlgorithms/RemoveBins.h
inc/MantidAlgorithms/RemoveExpDecay.h
inc/MantidAlgorithms/RemoveLowResTOF.h
inc/MantidAlgorithms/RemoveMaskedSpectra.h
inc/MantidAlgorithms/RemovePromptPulse.h
inc/MantidAlgorithms/RemoveWorkspaceHistory.h
inc/MantidAlgorithms/RenameWorkspace.h
Expand Down Expand Up @@ -706,6 +708,7 @@ set ( TEST_FILES
RemoveBinsTest.h
RemoveExpDecayTest.h
RemoveLowResTOFTest.h
RemoveMaskedSpectraTest.h
RemovePromptPulseTest.h
RemoveWorkspaceHistoryTest.h
RenameWorkspaceTest.h
Expand Down
@@ -1,14 +1,13 @@
#ifndef MANTID_DATAHANDLING_CROPWORKSPACEBYMASK_H_
#define MANTID_DATAHANDLING_CROPWORKSPACEBYMASK_H_
#ifndef MANTID_ALGORITHMS_REMOVEMASKEDSPECTRA_H_
#define MANTID_ALGORITHMS_REMOVEMASKEDSPECTRA_H_

#include "MantidKernel/System.h"
#include "MantidAPI/Algorithm.h"

namespace Mantid {
namespace DataHandling {
namespace Algorithms {

/** CropWorkspaceByMask crops a MatrixWorkspace by a mask. It removes all masked
spectra.
/** RemoveMaskedSpectra removes all masked spectra.
Copyright © 2015 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge
National Laboratory & European Spallation Source
Expand All @@ -31,10 +30,10 @@ namespace DataHandling {
File change history is stored at: <https://github.com/mantidproject/mantid>
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
class DLLExport CropWorkspaceByMask : public API::Algorithm {
class DLLExport RemoveMaskedSpectra : public API::Algorithm {
public:
CropWorkspaceByMask();
virtual ~CropWorkspaceByMask();
RemoveMaskedSpectra();
virtual ~RemoveMaskedSpectra();

virtual const std::string name() const;
virtual int version() const;
Expand All @@ -44,11 +43,11 @@ class DLLExport CropWorkspaceByMask : public API::Algorithm {
private:
void init();
void exec();
/// Fill in a vector with spectra indices to be extracted.
void makeIndexList(std::vector<size_t>& indices, const API::MatrixWorkspace* maskedWorkspace);
void makeIndexList(std::vector<size_t> &indices,
const API::MatrixWorkspace *maskedWorkspace);
};

} // namespace DataHandling
} // namespace Algorithms
} // namespace Mantid

#endif /* MANTID_DATAHANDLING_CROPWORKSPACEBYMASK_H_ */
#endif /* MANTID_ALGORITHMS_REMOVEMASKEDSPECTRA_H_ */
@@ -1,48 +1,51 @@
#include "MantidDataHandling/CropWorkspaceByMask.h"
#include "MantidAlgorithms/RemoveMaskedSpectra.h"
#include "MantidDataObjects/MaskWorkspace.h"
#include "MantidAPI/WorkspaceFactory.h"

namespace Mantid {
namespace DataHandling {
namespace Algorithms {

using namespace Kernel;
using namespace API;

// Register the algorithm into the AlgorithmFactory
DECLARE_ALGORITHM(CropWorkspaceByMask)
DECLARE_ALGORITHM(RemoveMaskedSpectra)

//----------------------------------------------------------------------------------------------
/// Constructor
CropWorkspaceByMask::CropWorkspaceByMask() {}
/** Constructor
*/
RemoveMaskedSpectra::RemoveMaskedSpectra() {}

//----------------------------------------------------------------------------------------------
/// Destructor
CropWorkspaceByMask::~CropWorkspaceByMask() {}
/** Destructor
*/
RemoveMaskedSpectra::~RemoveMaskedSpectra() {}

//----------------------------------------------------------------------------------------------

/// Algorithms name for identification. @see Algorithm::name
const std::string CropWorkspaceByMask::name() const {
return "CropWorkspaceByMask";
const std::string RemoveMaskedSpectra::name() const {
return "RemoveMaskedSpectra";
}

/// Algorithm's version for identification. @see Algorithm::version
int CropWorkspaceByMask::version() const { return 1; };
int RemoveMaskedSpectra::version() const { return 1; };

/// Algorithm's category for identification. @see Algorithm::category
const std::string CropWorkspaceByMask::category() const {
const std::string RemoveMaskedSpectra::category() const {
return "Transforms\\Splitting";
}

/// Algorithm's summary for use in the GUI and help. @see Algorithm::summary
const std::string CropWorkspaceByMask::summary() const {
const std::string RemoveMaskedSpectra::summary() const {
return "Extracts unmasked spectra from a workspace and places them in a new "
"workspace.";
}

//----------------------------------------------------------------------------------------------
/// Initialize the algorithm's properties.
void CropWorkspaceByMask::init() {
/** Initialize the algorithm's properties.
*/
void RemoveMaskedSpectra::init() {
declareProperty(
new WorkspaceProperty<>("InputWorkspace", "", Direction::Input),
"An input workspace.");
Expand All @@ -58,12 +61,17 @@ void CropWorkspaceByMask::init() {
}

//----------------------------------------------------------------------------------------------
/// Execute the algorithm.
void CropWorkspaceByMask::exec() {
/** Execute the algorithm.
*/
void RemoveMaskedSpectra::exec() {
MatrixWorkspace_sptr inputWorkspace = getProperty("InputWorkspace");
MatrixWorkspace_sptr maskedWorkspace = getProperty("MaskedWorkspace");

if ( !maskedWorkspace ) maskedWorkspace = inputWorkspace;
if (!maskedWorkspace){
maskedWorkspace = inputWorkspace;
} else if (inputWorkspace->getNumberHistograms() != maskedWorkspace->getNumberHistograms()) {
throw std::runtime_error("Masked workspace has a different number of spectra.");
}

std::vector<size_t> indices;
makeIndexList(indices, maskedWorkspace.get());
Expand All @@ -72,19 +80,22 @@ void CropWorkspaceByMask::exec() {
size_t nSpectra = indices.size();
// Number of bins/data points in the cropped workspace.
size_t nBins = inputWorkspace->blocksize();
size_t histogram = inputWorkspace->isHistogramData()? 1 : 0;
size_t histogram = inputWorkspace->isHistogramData() ? 1 : 0;

// Create the output workspace
MatrixWorkspace_sptr outputWorkspace = WorkspaceFactory::Instance().create(
inputWorkspace, nSpectra, nBins, nBins - histogram);

for (size_t i = 0; i < nSpectra; ++i) {
auto j = indices[i];
}
}

//----------------------------------------------------------------------------------------------
/// Fill in a vector with spectra indices to be extracted.
/// @param indices :: A reference to a vector to fill with the indices.
/// @param maskedWorkspace :: A workspace with masking information.
void CropWorkspaceByMask::makeIndexList(
void RemoveMaskedSpectra::makeIndexList(
std::vector<size_t> &indices, const API::MatrixWorkspace *maskedWorkspace) {
auto mask = dynamic_cast<const DataObjects::MaskWorkspace *>(maskedWorkspace);
if (mask) {
Expand All @@ -101,13 +112,12 @@ void CropWorkspaceByMask::makeIndexList(
} catch (Exception::NotFoundError &) {
continue;
}

if (det->isMasked()) {
indices.push_back(i);
}
}
}
}

} // namespace DataHandling
} // namespace Algorithms
} // namespace Mantid
@@ -1,35 +1,35 @@
#ifndef MANTID_DATAHANDLING_CROPWORKSPACEBYMASKTEST_H_
#define MANTID_DATAHANDLING_CROPWORKSPACEBYMASKTEST_H_
#ifndef MANTID_ALGORITHMS_REMOVEMASKEDSPECTRATEST_H_
#define MANTID_ALGORITHMS_REMOVEMASKEDSPECTRATEST_H_

#include <cxxtest/TestSuite.h>

#include "MantidDataHandling/CropWorkspaceByMask.h"
#include "MantidAlgorithms/RemoveMaskedSpectra.h"

using Mantid::DataHandling::CropWorkspaceByMask;
using Mantid::Algorithms::RemoveMaskedSpectra;
using namespace Mantid::API;

class CropWorkspaceByMaskTest : public CxxTest::TestSuite
class RemoveMaskedSpectraTest : public CxxTest::TestSuite
{
public:
// This pair of boilerplate methods prevent the suite being created statically
// This means the constructor isn't called when running other tests
static CropWorkspaceByMaskTest *createSuite() { return new CropWorkspaceByMaskTest(); }
static void destroySuite( CropWorkspaceByMaskTest *suite ) { delete suite; }
static RemoveMaskedSpectraTest *createSuite() { return new RemoveMaskedSpectraTest(); }
static void destroySuite( RemoveMaskedSpectraTest *suite ) { delete suite; }


void test_Init()
{
CropWorkspaceByMask alg;
RemoveMaskedSpectra alg;
TS_ASSERT_THROWS_NOTHING( alg.initialize() )
TS_ASSERT( alg.isInitialized() )
}

void test_exec()
{
// Name of the output workspace.
std::string outWSName("CropWorkspaceByMaskTest_OutputWS");
std::string outWSName("RemoveMaskedSpectraTest_OutputWS");

CropWorkspaceByMask alg;
RemoveMaskedSpectra alg;
TS_ASSERT_THROWS_NOTHING( alg.initialize() )
TS_ASSERT( alg.isInitialized() )
TS_ASSERT_THROWS_NOTHING( alg.setPropertyValue("REPLACE_PROPERTY_NAME_HERE!!!!", "value") );
Expand Down Expand Up @@ -58,4 +58,4 @@ class CropWorkspaceByMaskTest : public CxxTest::TestSuite
};


#endif /* MANTID_DATAHANDLING_CROPWORKSPACEBYMASKTEST_H_ */
#endif /* MANTID_ALGORITHMS_REMOVEMASKEDSPECTRATEST_H_ */
3 changes: 0 additions & 3 deletions Code/Mantid/Framework/DataHandling/CMakeLists.txt
Expand Up @@ -7,7 +7,6 @@ set ( SRC_FILES
src/CreateModeratorModel.cpp
src/CreateSampleShape.cpp
src/CreateSimulationWorkspace.cpp
src/CropWorkspaceByMask.cpp
src/DefineGaugeVolume.cpp
src/DeleteTableRows.cpp
src/DetermineChunking.cpp
Expand Down Expand Up @@ -162,7 +161,6 @@ set ( INC_FILES
inc/MantidDataHandling/CreateModeratorModel.h
inc/MantidDataHandling/CreateSampleShape.h
inc/MantidDataHandling/CreateSimulationWorkspace.h
inc/MantidDataHandling/CropWorkspaceByMask.h
inc/MantidDataHandling/DefineGaugeVolume.h
inc/MantidDataHandling/DeleteTableRows.h
inc/MantidDataHandling/DetermineChunking.h
Expand Down Expand Up @@ -316,7 +314,6 @@ set ( TEST_FILES
CreateModeratorModelTest.h
CreateSampleShapeTest.h
CreateSimulationWorkspaceTest.h
CropWorkspaceByMaskTest.h
DefineGaugeVolumeTest.h
DeleteTableRowsTest.h
DetermineChunkingTest.h
Expand Down
Expand Up @@ -20,23 +20,23 @@ Usage
autotestdata\UsageData and the following tag unindented
.. include:: ../usagedata-note.txt
**Example - CropWorkspaceByMask**
**Example - RemoveMaskedSpectra**

.. testcode:: CropWorkspaceByMaskExample
.. testcode:: RemoveMaskedSpectraExample

# Create a host workspace
ws = CreateWorkspace(DataX=range(0,3), DataY=(0,2))
or
ws = CreateSampleWorkspace()

wsOut = CropWorkspaceByMask()
wsOut = RemoveMaskedSpectra()

# Print the result
print "The output workspace has %i spectra" % wsOut.getNumberHistograms()

Output:

.. testoutput:: CropWorkspaceByMaskExample
.. testoutput:: RemoveMaskedSpectraExample

The output workspace has ?? spectra

Expand Down

0 comments on commit fe26fe1

Please sign in to comment.