/** * Add information to the workspace being loaded: labels, units, logs related to * the image size, etc. * * @param ws workspace to manipulate * * @param loadAsRectImg if true, the workspace has one spectrum per * row and one bin per column * * @param fileInfo information for the current file * * @param binSize size to rebin (1 == no re-bin == default) * * @param cmpp centimeters per pixel (already taking into account * possible rebinning) */ void LoadFITS::addAxesInfoAndLogs(Workspace2D_sptr ws, bool loadAsRectImg, const FITSInfo &fileInfo, int binSize, double cmpp) { // add axes size_t width = fileInfo.axisPixelLengths[0] / binSize; size_t height = fileInfo.axisPixelLengths[1] / binSize; if (loadAsRectImg) { // width/X axis auto axw = new Mantid::API::NumericAxis(width + 1); axw->title() = "width"; for (size_t i = 0; i < width + 1; i++) { axw->setValue(i, static_cast<double>(i) * cmpp); } ws->replaceAxis(0, axw); // "cm" width label unit boost::shared_ptr<Kernel::Units::Label> unitLbl = boost::dynamic_pointer_cast<Kernel::Units::Label>( UnitFactory::Instance().create("Label")); unitLbl->setLabel("width", "cm"); ws->getAxis(0)->unit() = unitLbl; // height/Y axis auto axh = new Mantid::API::NumericAxis(height); axh->title() = "height"; for (size_t i = 0; i < height; i++) { axh->setValue(i, static_cast<double>(i) * cmpp); } ws->replaceAxis(1, axh); // "cm" height label unit unitLbl = boost::dynamic_pointer_cast<Kernel::Units::Label>( UnitFactory::Instance().create("Label")); unitLbl->setLabel("height", "cm"); ws->getAxis(1)->unit() = unitLbl; ws->setDistribution(true); } else { // TODO: what to do when loading 1pixel - 1 spectrum? } ws->setYUnitLabel("brightness"); // Add all header info to log. for (const auto &headerKey : fileInfo.headerKeys) { ws->mutableRun().removeLogData(headerKey.first, true); ws->mutableRun().addLogData( new PropertyWithValue<std::string>(headerKey.first, headerKey.second)); } // Add rotational data to log. Clear first from copied WS auto it = fileInfo.headerKeys.find(m_sampleRotation); ws->mutableRun().removeLogData("Rotation", true); if (fileInfo.headerKeys.end() != it) { double rot = boost::lexical_cast<double>(it->second); if (rot >= 0) { ws->mutableRun().addLogData( new PropertyWithValue<double>("Rotation", rot)); } } // 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<std::string>("ImageKey", fileInfo.imageKey)); }