Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/feature/10374_fits_nxtomo_beam_d…
Browse files Browse the repository at this point in the history
…ata'
  • Loading branch information
raquelalvarezbanos committed Dec 8, 2014
2 parents c4ada99 + ba6d92b commit 5b37064
Show file tree
Hide file tree
Showing 7 changed files with 566 additions and 172 deletions.
1 change: 1 addition & 0 deletions Code/Mantid/Framework/DataHandling/CMakeLists.txt
Expand Up @@ -411,6 +411,7 @@ set ( TEST_FILES
SaveMaskTest.h
SaveNISTDATTest.h
SaveNXSPETest.h
SaveNXTomoTest.h
SaveNexusProcessedTest.h
SaveNexusTest.h
SavePARTest.h
Expand Down
Expand Up @@ -24,6 +24,7 @@ struct FITSInfo {
double tof;
double timeBin;
double scale;
int imageKey;
long int countsInImage;
long int numberOfTriggers;
string extension;
Expand Down Expand Up @@ -127,6 +128,7 @@ namespace DataHandling
string m_headerOffsetKey;
string m_headerBitDepthKey;
string m_headerRotationKey;
string m_headerImageKeyKey;
string m_mapFile;
std::vector<std::string> m_headerAxisNameKeys;

Expand Down
Expand Up @@ -5,10 +5,10 @@
// Includes
//---------------------------------------------------
#include <vector>
#include "MantidAPI/Algorithm.h"
#include "MantidDataObjects/Workspace2D.h"
#include "MantidGeometry/Instrument/RectangularDetector.h"


namespace Mantid
{
namespace DataHandling
Expand Down Expand Up @@ -76,20 +76,19 @@ namespace Mantid
void exec();

/// Creates the format for the output file if it doesn't exist
::NeXus::File setupFile(bool resizeData = false);
::NeXus::File setupFile();

/// Writes a single workspace into the file
void writeSingle(const DataObjects::Workspace2D_sptr workspace, ::NeXus::File &nxFile);
void writeSingleWorkspace(const DataObjects::Workspace2D_sptr workspace, ::NeXus::File &nxFile);

/// Write various pieces of data from the workspace log with checks on the structure of the nexus file
void writeLogValues(const DataObjects::Workspace2D_sptr workspace, ::NeXus::File &nxFile, int thisFileInd);
void writeIntensityValue(const DataObjects::Workspace2D_sptr workspace, ::NeXus::File &nxFile, int thisFileInd);
void writeImageKeyValue(const DataObjects::Workspace2D_sptr workspace, ::NeXus::File &nxFile, int thisFileInd);

/// Main exec routine, called for group or individual workspace processing.
void processAll();

/// 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);

// Include error data in the written file
bool m_includeError;
bool m_overwriteFile;
Expand All @@ -100,6 +99,8 @@ namespace Mantid
std::string m_filename;
// Dimensions for axis in nxTomo file.
std::vector<int64_t> m_dimensions;
// Infinite file range dimensions / for use with makeData data and error
std::vector<int64_t> m_infDimensions;

/// file format version
static const std::string NXTOMO_VER;
Expand Down
36 changes: 33 additions & 3 deletions Code/Mantid/Framework/DataHandling/src/LoadFITS.cpp
Expand Up @@ -21,6 +21,7 @@ namespace
static const std::string BIT_DEPTH_NAME = "BitDepthName";
static const std::string ROTATION_NAME = "RotationName";
static const std::string AXIS_NAMES_NAME = "AxisNames";
static const std::string IMAGE_KEY_NAME = "ImageKeyName";
static const std::string HEADER_MAP_NAME = "HeaderMapFile";

/**
Expand Down Expand Up @@ -74,12 +75,18 @@ namespace DataHandling

declareProperty(new API::WorkspaceProperty<API::Workspace>("OutputWorkspace", "", Kernel::Direction::Output));

declareProperty(new PropertyWithValue<int>("ImageKey", -1, Kernel::Direction::Input),
"Image type to set these files as. 0=data image, 1=flat field, 2=open field, -1=use the value from FITS header.");

declareProperty(new PropertyWithValue<string>(BIT_DEPTH_NAME, "BITPIX", Kernel::Direction::Input),
"Name for the pixel bit depth header key.");
declareProperty(new PropertyWithValue<string>(ROTATION_NAME, "ROTATION", Kernel::Direction::Input),
"Name for the rotation header key.");
declareProperty(new PropertyWithValue<string>(AXIS_NAMES_NAME, "NAXIS1,NAXIS2", Kernel::Direction::Input),
"Names for the axis header keys, comma separated string of all axis.");
declareProperty(new PropertyWithValue<string>(IMAGE_KEY_NAME, "IMAGEKEY", Kernel::Direction::Input),
"Names for the image type, key.");


declareProperty(new FileProperty(HEADER_MAP_NAME, "", FileProperty::OptionalDirectory, "", Kernel::Direction::Input),
"A file mapping header keys to the ones used by ISIS [line separated values in the format KEY=VALUE, e.g. BitDepthName=BITPIX ");
Expand All @@ -95,6 +102,7 @@ namespace DataHandling
m_headerScaleKey = "BSCALE";
m_headerOffsetKey = "BZERO";
m_headerBitDepthKey = "BITPIX";
m_headerImageKeyKey = "IMAGEKEY";
m_headerRotationKey = "ROTATION";
m_mapFile = "";
m_headerAxisNameKeys.push_back("NAXIS1");
Expand Down Expand Up @@ -145,6 +153,13 @@ namespace DataHandling
allHeaderInfo[i].isFloat = false;
}

// Add the image key, use the property if it's not -1, otherwise use the header value
allHeaderInfo[i].imageKey = boost::lexical_cast<int>(getPropertyValue("ImageKey"));
if(allHeaderInfo[i].imageKey == -1)
{
allHeaderInfo[i].imageKey = boost::lexical_cast<int>(allHeaderInfo[i].headerKeys[m_headerImageKeyKey]);
}

allHeaderInfo[i].bitsPerPixel = lexical_cast<int>(tmpBitPix);
allHeaderInfo[i].numberOfAxis = static_cast<int>(m_headerAxisNameKeys.size());

Expand All @@ -163,7 +178,7 @@ namespace DataHandling
catch(std::exception &)
{
//todo write error and fail this load with invalid data in file.
throw std::runtime_error("Unable to locate one or more valid BITPIX, NAXIS, TOF, TIMEBIN, N_COUNTS or N_TRIGS values in the FITS file header.");
throw std::runtime_error("Unable to locate one or more valid BITPIX, NAXIS or IMAGEKEY values in the FITS file header.");
}

allHeaderInfo[i].scale = (allHeaderInfo[i].headerKeys[m_headerScaleKey] == "") ? 1 : lexical_cast<double>(allHeaderInfo[i].headerKeys[m_headerScaleKey]);
Expand Down Expand Up @@ -286,7 +301,7 @@ namespace DataHandling
else
{
// Invalid files, record error
throw std::runtime_error("Loader currently doesn't support FITS files with non-standard extensions, greater than two axis of data, or has detected that all the files are not similar.");
throw std::runtime_error("Loader currently doesn't support FITS files with non-standard extensions, greater than two axis of data, or has detected that all the files are not similar.");
}
}

Expand Down Expand Up @@ -332,7 +347,15 @@ namespace DataHandling
if(rotation != -1)
ws->mutableRun().addLogData(new PropertyWithValue<double>("Rotation", rotation));


// Add axis information to log. Clear first from copied WS
ws->mutableRun().removeLogData("Axis1",true);
ws->mutableRun().addLogData(new PropertyWithValue<int>("Axis1", static_cast<int>(fileInfo.axisPixelLengths[0])));
ws->mutableRun().removeLogData("Axis2",true);
ws->mutableRun().addLogData(new PropertyWithValue<int>("Axis2", static_cast<int>(fileInfo.axisPixelLengths[1])));

// Add image key data to log. Clear first from copied WS
ws->mutableRun().removeLogData("ImageKey",true);
ws->mutableRun().addLogData(new PropertyWithValue<int>("ImageKey", static_cast<int>(fileInfo.imageKey)));

m_progress->report();

Expand Down Expand Up @@ -589,6 +612,11 @@ namespace DataHandling
std::string propVal = getProperty(AXIS_NAMES_NAME);
boost::split(m_headerAxisNameKeys, propVal, boost::is_any_of(","));
}

if(lineSplit[0] == IMAGE_KEY_NAME && lineSplit[1] != "")
{
m_headerImageKeyKey = lineSplit[1];
}
}

fStream.close();
Expand Down Expand Up @@ -619,6 +647,8 @@ namespace DataHandling
std::string propVal = getProperty(AXIS_NAMES_NAME);
boost::split(m_headerAxisNameKeys, propVal, boost::is_any_of(","));
}
if(getPropertyValue(IMAGE_KEY_NAME) != "")
m_headerImageKeyKey = getPropertyValue(IMAGE_KEY_NAME);
}


Expand Down

0 comments on commit 5b37064

Please sign in to comment.