Newer
Older
Federico Montesino Pouzols
committed
/**
* Looks for headers used by specific instruments/cameras, or finds if
* the instrument does not appear to be IMAT, which is the only one
* for which we have a camera-instrument definition and because of
* that is the only one loaded for the moment.
*
* @param hdr FITS header information
*
Federico Montesino Pouzols
committed
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
* @return whether this file seems to come from 'another' camera such
* as Starlight Xpress, etc.
*/
bool LoadFITS::isInstrOtherThanIMAT(FITSInfo &hdr) {
bool res = false;
// Images taken with Starlight camera contain this header entry:
// INSTRUME='Starlight Xpress CCD'
auto it = hdr.headerKeys.find("INSTRUME");
if (hdr.headerKeys.end() != it && boost::contains(it->second, "Starlight")) {
// For now, do nothing, just tell
// Cameras used for HiFi and EMU are in principle only used
// occasionally for calibration
g_log.information()
<< "Found this in the file headers: " << it->first << " = "
<< it->second
<< ". This file seems to come from a Starlight camera, "
"as used for calibration of the instruments HiFi and EMU (and"
"possibly others). Not "
"loading instrument definition." << std::endl;
}
return res;
}
* Returns the trailing number from a string minus leading 0's (so 25 from
Federico Montesino Pouzols
committed
* workspace_00025).
*
* @param name string with a numerical suffix
* @returns A numerical representation of the string minus leading characters
* and leading 0's
size_t LoadFITS::fetchNumber(const std::string &name) {
std::string tmpStr = "";
for (auto it = name.end() - 1; isdigit(*it); --it) {
tmpStr.insert(0, 1, *it);
}
while (tmpStr.length() > 0 && tmpStr[0] == '0') {
tmpStr.erase(tmpStr.begin());
return (tmpStr.length() > 0) ? boost::lexical_cast<size_t>(tmpStr) : 0;
}
/**
Federico Montesino Pouzols
committed
* Adds 0's to the front of a number to create a string of size
* totalDigitCount including number
*
* @param number input number to add padding to
Federico Montesino Pouzols
committed
*
* @param totalDigitCount width of the resulting string with 0s followed by
* number
*
* @return A string with the 0-padded number
*/
std::string LoadFITS::padZeros(const size_t number,
const size_t totalDigitCount) {
std::ostringstream ss;
ss << std::setw(static_cast<int>(totalDigitCount)) << std::setfill('0')
<< static_cast<int>(number);
return ss.str();
}
/**
* Maps the header keys to specified values
*/
void LoadFITS::mapHeaderKeys() {
if ("" == getPropertyValue(g_HEADER_MAP_NAME))
Federico Montesino Pouzols
committed
return;
// If a map file is selected, use that.
std::string name = getPropertyValue(g_HEADER_MAP_NAME);
std::ifstream fStream(name.c_str());
Federico Montesino Pouzols
committed
try {
// Ensure valid file
if (fStream.good()) {
// Get lines, split words, verify and add to map.
std::string line;
std::vector<std::string> lineSplit;
Federico Montesino Pouzols
committed
while (getline(fStream, line)) {
boost::split(lineSplit, line, boost::is_any_of("="));
if (lineSplit[0] == g_ROTATION_NAME && lineSplit[1] != "")
Federico Montesino Pouzols
committed
m_headerRotationKey = lineSplit[1];
if (lineSplit[0] == g_BIT_DEPTH_NAME && lineSplit[1] != "")
Federico Montesino Pouzols
committed
m_headerBitDepthKey = lineSplit[1];
if (lineSplit[0] == g_AXIS_NAMES_NAME && lineSplit[1] != "") {
Federico Montesino Pouzols
committed
m_headerAxisNameKeys.clear();
boost::split(m_headerAxisNameKeys, lineSplit[1],
boost::is_any_of(","));
if (lineSplit[0] == g_IMAGE_KEY_NAME && lineSplit[1] != "") {
Federico Montesino Pouzols
committed
m_headerImageKeyKey = lineSplit[1];
}
Federico Montesino Pouzols
committed
fStream.close();
} else {
throw std::runtime_error(
"Error while trying to read header keys mapping file: " + name);
Federico Montesino Pouzols
committed
} catch (...) {
g_log.error("Cannot load specified map file, using property values "
"and/or defaults.");
Federico Montesino Pouzols
committed
} // namespace DataHandling
} // namespace Mantid