Newer
Older
Federico Montesino Pouzols
committed
*
* @param rebin bin size (n to make blocks of n*n pixels)
* @param imageY raw data (Y values)
* @param imageE raw data (E/error values)
Federico Montesino Pouzols
committed
* @param rebinnedY raw data after rebin (Y values)
* @param rebinnedE raw data after rebin (E/error values)
Federico Montesino Pouzols
committed
*/
Federico Montesino Pouzols
committed
void LoadFITS::doRebin(size_t rebin, MantidImage &imageY, MantidImage &imageE,
MantidImage &rebinnedY, MantidImage &rebinnedE) {
if (1 >= rebin)
return;
for (size_t j = 0; j < (rebinnedY.size() - rebin + 1); ++j) {
for (size_t i = 0; i < (rebinnedY[0].size() - rebin + 1); ++i) {
double accumY = 0.0;
double accumE = 0.0;
size_t origJ = j * rebin;
size_t origI = i * rebin;
Federico Montesino Pouzols
committed
for (size_t k = 0; k < rebin; ++k) {
for (size_t l = 0; l < rebin; ++l) {
accumY += imageY[origJ + k][origI + l];
accumE += imageE[origJ + k][origI + l];
}
}
rebinnedY[j][i] = accumY;
rebinnedE[j][i] = accumE;
}
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
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
/**
* 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