Skip to content

Commit

Permalink
Merge branch 'master' into feature/10376_refl_ui_menu_bar
Browse files Browse the repository at this point in the history
Refs #10376

Conflicts:
	Code/Mantid/MantidQt/CustomInterfaces/src/ReflMainViewPresenter.cpp
  • Loading branch information
Harry Jeffery committed Oct 23, 2014
2 parents b16c6e6 + e6e3deb commit dca08ed
Show file tree
Hide file tree
Showing 40 changed files with 4,240 additions and 769 deletions.
4 changes: 3 additions & 1 deletion Code/Mantid/Build/class_maker.py
Expand Up @@ -129,6 +129,8 @@ def write_source(subproject, classname, filename, args):
algorithm_source = """
//----------------------------------------------------------------------------------------------
/// Algorithms name for identification. @see Algorithm::name
const std::string %s::name() const { return "%s"; }
/// Algorithm's version for identification. @see Algorithm::version
int %s::version() const { return 1;};
Expand Down Expand Up @@ -156,7 +158,7 @@ def write_source(subproject, classname, filename, args):
// TODO Auto-generated execute stub
}
""" % (classname, classname, classname, classname, classname)
""" % (classname, classname, classname, classname, classname, classname, classname)

if not args.alg:
algorithm_top = ""
Expand Down
2 changes: 2 additions & 0 deletions Code/Mantid/Framework/DataHandling/CMakeLists.txt
Expand Up @@ -128,6 +128,7 @@ set ( SRC_FILES
src/SaveNXSPE.cpp
src/SaveNexus.cpp
src/SaveNexusProcessed.cpp
src/SaveNXTomo.cpp
src/SaveParameterFile.cpp
src/SavePAR.cpp
src/SavePHX.cpp
Expand Down Expand Up @@ -266,6 +267,7 @@ set ( INC_FILES
inc/MantidDataHandling/SaveNXSPE.h
inc/MantidDataHandling/SaveNexus.h
inc/MantidDataHandling/SaveNexusProcessed.h
inc/MantidDataHandling/SaveNXTomo.h
inc/MantidDataHandling/SaveParameterFile.h
inc/MantidDataHandling/SavePAR.h
inc/MantidDataHandling/SavePHX.h
Expand Down
Expand Up @@ -145,6 +145,13 @@ namespace DataHandling
/// Filter by a maximum time-of-flight
double filter_tof_max;

/// Spectra list to load
std::vector<int32_t> m_specList;
/// Minimum spectrum to load
int32_t m_specMin;
/// Maximum spectrum to load
int32_t m_specMax;

/// Filter by start time
Kernel::DateAndTime filter_time_start;
/// Filter by stop time
Expand Down Expand Up @@ -248,6 +255,9 @@ namespace DataHandling

void filterDuringPause(API::MatrixWorkspace_sptr workspace);

// Validate the optional spectra input properties and initialize m_specList
void createSpectraList(int32_t min, int32_t max);

public:
/// name of top level NXentry to use
std::string m_top_entry_name;
Expand Down
Expand Up @@ -57,6 +57,9 @@ namespace DataHandling
/// Returns a confidence value that this algorithm can load a file
virtual int confidence(Kernel::NexusDescriptor & descriptor) const;

/// Confidence in identifier.
static int identiferConfidence(const std::string& value);

private:

/// Initialise the properties
Expand Down
106 changes: 106 additions & 0 deletions Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/SaveNXTomo.h
@@ -0,0 +1,106 @@
#ifndef MANTID_DATAHANDLING_SAVENXTOMO_H_
#define MANTID_DATAHANDLING_SAVENXTOMO_H_

//---------------------------------------------------
// Includes
//---------------------------------------------------
#include "vector"
#include "MantidGeometry/Instrument/RectangularDetector.h"

namespace Mantid
{
namespace DataHandling
{

/**
* Saves a workspace into a NeXus/HDF5 NXTomo file.
* File format is defined here: http://download.nexusformat.org/sphinx/classes/applications/NXtomo.html
*
* Required properties:
* <ul>
* <li> InputWorkspace - The workspace to save. </li>
* <li> Filename - The filename for output </li>
* </ul>
*
* @author John R Hill, RAL
* @date 10/09/2014
*
* This file is part of Mantid.
*
* Mantid is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* Mantid is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* File change history is stored at: <https://github.com/mantidproject/mantid>
* Code Documentation is available at: <http://doxygen.mantidproject.org>
*
*/

class DLLExport SaveNXTomo: public API::Algorithm
{
public:
SaveNXTomo();
/// Virtual dtor
virtual ~SaveNXTomo() {}

/// Algorithm's name for identification overriding a virtual method
virtual const std::string name() const { return "SaveNXTomo"; }

///Summary of algorithms purpose
virtual const std::string summary() const {return "Writes a MatrixWorkspace to a file in the NXTomo format.";}

/// Algorithm's version
virtual int version() const { return (1); }

/// Algorithm's category for identification
virtual const std::string category() const { return "DataHandling\\Nexus;DataHandling\\Tomo;Diffraction"; }

private:
/// Initialisation code
void init();
/// Execution code
void exec();

/// Save all data to file

/// Save batch of images to the file

/// Fetch all rectangular Detector objects defined for an instrument
std::vector<boost::shared_ptr<const Mantid::Geometry::RectangularDetector>> getRectangularDetectors(const Geometry::Instrument_const_sptr &instrument);

/// Populate dims_array with the dimensions defined in the rectangular detector in the instrument
std::vector<int64_t> getDimensionsFromDetector(const std::vector<boost::shared_ptr<const Mantid::Geometry::RectangularDetector>> &rectDetectors, size_t useDetectorIndex = 0);

// Number of rows to
size_t m_numberOfRows;

// Include error data in the written file
bool m_includeError;

///the number of bins in each histogram, as the histogram must have common bins this shouldn't change
//size_t m_nBins;
/// The filename of the output file
std::string m_filename;

// Some constants to be written for masked values.
/// Value for data if pixel is masked
static const double MASK_FLAG;
/// Value for error if pixel is masked
static const double MASK_ERROR;
/// file format version
static const std::string NXTOMO_VER;
};

} // namespace DataHandling
} // namespace Mantid

#endif // MANTID_DATAHANDLING_SAVENXTOMO_H_
155 changes: 135 additions & 20 deletions Code/Mantid/Framework/DataHandling/src/LoadEventNexus.cpp
Expand Up @@ -165,9 +165,15 @@ namespace Mantid

// ---- Pre-counting events per pixel ID ----
auto & outputWS = *(alg->WS);

if (alg->precount)
{

if ( alg->m_specMin !=EMPTY_INT() && alg->m_specMax !=EMPTY_INT() )
{
m_min_id = alg->m_specMin;
m_max_id = alg->m_specMax;
}

std::vector<size_t> counts(m_max_id-m_min_id+1, 0);
for (size_t i=0; i < numEvents; i++)
{
Expand Down Expand Up @@ -1108,7 +1114,14 @@ namespace Mantid
setPropertyGroup("FilterMonByTimeStart", grp4);
setPropertyGroup("FilterMonByTimeStop", grp4);

declareProperty(
declareProperty("SpectrumMin",(int32_t)EMPTY_INT(), mustBePositive,
"The number of the first spectrum to read.");
declareProperty("SpectrumMax",(int32_t)EMPTY_INT(), mustBePositive,
"The number of the last spectrum to read.");
declareProperty(new ArrayProperty<int32_t>("SpectrumList"),
"A comma-separated list of individual spectra to read.");

declareProperty(
new PropertyWithValue<bool>("MetaDataOnly", false, Direction::Input),
"If true, only the meta data and sample logs will be loaded.");

Expand Down Expand Up @@ -2134,6 +2147,10 @@ namespace Mantid
const bool monitorsOnly, const std::vector<std::string> &bankNames)
{
bool spectramap = false;
m_specMin = getProperty("SpectrumMin");
m_specMax = getProperty("SpectrumMax");
m_specList = getProperty("SpectrumList");

// set up the
if( !monitorsOnly && !bankNames.empty() )
{
Expand Down Expand Up @@ -2174,8 +2191,10 @@ namespace Mantid
if( !spectramap )
{
g_log.debug() << "No custom spectra mapping found, continuing with default 1:1 mapping of spectrum:detectorID\n";
auto specList= WS->getInstrument()->getDetectorIDs(true);
createSpectraList(*std::min_element(specList.begin(),specList.end()),*std::max_element(specList.begin(),specList.end()));
// The default 1:1 will suffice but exclude the monitors as they are always in a separate workspace
WS->padSpectra();
WS->padSpectra(m_specList);
g_log.debug() << "Populated 1:1 spectra map for the whole instrument \n";
}
}
Expand Down Expand Up @@ -2332,23 +2351,43 @@ namespace Mantid
}
else
{
g_log.debug() << "Loading only detector spectra from " << filename << "\n";
SpectrumDetectorMapping mapping(spec,udet, monitors);
WS->resizeTo(mapping.getMapping().size());
// Make sure spectrum numbers are correct
auto uniqueSpectra = mapping.getSpectrumNumbers();
auto itend = uniqueSpectra.end();
size_t counter = 0;
for(auto it = uniqueSpectra.begin(); it != itend; ++it)
{
WS->getSpectrum(counter)->setSpectrumNo(*it);
++counter;
}
// Fill detectors based on this mapping
WS->updateSpectraUsing(mapping);
}
return true;
}
g_log.debug() << "Loading only detector spectra from " << filename << "\n";

// If optional spectra are provided, if so, m_specList is initialized. spec is used if necessary
createSpectraList(*std::min_element(spec.begin(),spec.end()), *std::max_element(spec.begin(),spec.end()));

if ( !m_specList.empty() ) {
int i=0;
std::vector<int32_t> spec_temp, udet_temp;
for(auto it=spec.begin(); it!=spec.end(); it++)
{
if ( find(m_specList.begin(),m_specList.end(),*it)!= m_specList.end() ) // spec element *it is not in spec_list
{
spec_temp.push_back( *it );
udet_temp.push_back( udet.at(i) );
}
i++;
}
spec=spec_temp;
udet=udet_temp;
}

SpectrumDetectorMapping mapping(spec,udet, monitors);
WS->resizeTo(mapping.getMapping().size());
// Make sure spectrum numbers are correct
auto uniqueSpectra = mapping.getSpectrumNumbers();
auto itend = uniqueSpectra.end();
size_t counter = 0;
for(auto it = uniqueSpectra.begin(); it != itend; ++it)
{
WS->getSpectrum(counter)->setSpectrumNo(*it);
++counter;
}
// Fill detectors based on this mapping
WS->updateSpectraUsing(mapping);
}
return true;
}

/**
* Set the filters on TOF.
Expand Down Expand Up @@ -2728,6 +2767,82 @@ namespace Mantid
return out;
}

/**
* Check the validity of the optional spectrum range/list provided and identify if partial data should be loaded.
*
* @param min :: The minimum spectrum number read from file
* @param max :: The maximum spectrum number read from file
*/

void LoadEventNexus::createSpectraList(int32_t min, int32_t max){

// check if range [SpectrumMin, SpectrumMax] was supplied
if( m_specMin != EMPTY_INT() || m_specMax != EMPTY_INT() )
{
if ( m_specMax == EMPTY_INT() )
{
m_specMax = max;
}
if ( m_specMin == EMPTY_INT() )
{
m_specMin = min;
}

if ( m_specMax > max )
{
throw std::invalid_argument("Inconsistent range property: SpectrumMax is larger than maximum spectrum found in file.");
}

// Sanity checks for min/max
if ( m_specMin > m_specMax )
{
throw std::invalid_argument("Inconsistent range property: SpectrumMin is larger than SpectrumMax.");
}

// Populate spec_list
for (int32_t i=m_specMin; i<=m_specMax; i++)
m_specList.push_back(i);
}
else{
// Check if SpectrumList was supplied

if ( !m_specList.empty() )
{
// Check no negative/zero numbers have been passed
std::vector<int32_t>::iterator itr = std::find_if(m_specList.begin(), m_specList.end(), std::bind2nd(std::less<int32_t>(), 1));
if( itr != m_specList.end() )
{
throw std::invalid_argument("Negative/Zero SpectraList property encountered.");
}

// Check range and set m_specMax to maximum value in m_specList
if ( (m_specMax=*std::max_element(m_specList.begin(),m_specList.end())) > *std::max_element(m_specList.begin(),m_specList.end()) )
{
throw std::invalid_argument("Inconsistent range property: SpectrumMax is larger than number of spectra.");
}

// Set m_specMin to minimum value in m_specList
m_specMin=*std::min_element(m_specList.begin(),m_specList.end());
}

}

if ( !m_specList.empty() ) {

// Check that spectra supplied by user do not correspond to monitors
auto nmonitors = WS->getInstrument()->getMonitors().size();

for( size_t i = 0; i < nmonitors; ++i )
{
if ( std::find(m_specList.begin(),m_specList.end(),i+1)!= m_specList.end() )
{
throw std::invalid_argument("Inconsistent range property: some of the selected spectra correspond to monitors.");
}
}

}

}

} // namespace DataHandling
} // namespace Mantid

0 comments on commit dca08ed

Please sign in to comment.