Newer
Older
Federico Montesino Pouzols
committed
}
Federico Montesino Pouzols
committed
}
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
* @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). Note: not "
Federico Montesino Pouzols
committed
"loading instrument definition." << std::endl;
}
return res;
}
* Sets several keyword names with default (and standard) values. You
* don't want to change these unless you want to break compatibility
* with the FITS standard.
void LoadFITS::setupDefaultKeywordNames() {
// Inits all the absolutely necessary keywords
// standard headers (If SIMPLE=T)
m_headerScaleKey = "BSCALE";
m_headerOffsetKey = "BZERO";
m_headerBitDepthKey = "BITPIX";
m_headerImageKeyKey = "IMAGE_TYPE"; // This is a "HIERARCH Image/Type= "
m_headerRotationKey = "ROTATION";
m_headerNAxisNameKey = "NAXIS";
m_headerAxisNameKeys.push_back("NAXIS1");
m_headerAxisNameKeys.push_back("NAXIS2");
m_mapFile = "";
// extensions
m_sampleRotation = "HIERARCH Sample/Tomo_Angle";
m_imageType = "HIERARCH Image/Type";
}
/**
* 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
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
/**
* Returns the trailing number from a string minus leading 0's (so 25 from
* 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;
}
/**
* 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
*
* @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();
}
Federico Montesino Pouzols
committed
} // namespace DataHandling
} // namespace Mantid