本文整理汇总了C++中Workspace2D_sptr::replaceAxis方法的典型用法代码示例。如果您正苦于以下问题:C++ Workspace2D_sptr::replaceAxis方法的具体用法?C++ Workspace2D_sptr::replaceAxis怎么用?C++ Workspace2D_sptr::replaceAxis使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Workspace2D_sptr
的用法示例。
在下文中一共展示了Workspace2D_sptr::replaceAxis方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: funcvalues
/** Construct output
*/
Workspace2D_sptr RefinePowderInstrumentParameters2::genOutputWorkspace(FunctionDomain1DVector domain,
FunctionValues rawvalues)
{
// 1. Create and set up output workspace
size_t lenx = m_dataWS->readX(m_wsIndex).size();
size_t leny = m_dataWS->readY(m_wsIndex).size();
Workspace2D_sptr outws = boost::dynamic_pointer_cast<Workspace2D>
(WorkspaceFactory::Instance().create("Workspace2D", 6, lenx, leny));
outws->getAxis(0)->setUnit("dSpacing");
TextAxis* taxis = new TextAxis(outws->getNumberHistograms());
taxis->setLabel(0, "Data");
taxis->setLabel(1, "Model");
taxis->setLabel(2, "DiffDM");
taxis->setLabel(3, "Start");
taxis->setLabel(4, "DiffDS");
taxis->setLabel(5, "Zdiff");
outws->replaceAxis(1, taxis);
// 3. Re-calculate values
FunctionValues funcvalues(domain);
m_positionFunc->function(domain, funcvalues);
// 4. Add values
// a) X axis
for (size_t iws = 0; iws < outws->getNumberHistograms(); ++iws)
{
MantidVec& vecX = outws->dataX(iws);
for (size_t n = 0; n < lenx; ++n)
vecX[n] = domain[n];
}
// b) Y axis
const MantidVec& dataY = m_dataWS->readY(m_wsIndex);
for (size_t i = 0; i < domain.size(); ++i)
{
outws->dataY(0)[i] = dataY[i];
outws->dataY(1)[i] = funcvalues[i];
outws->dataY(2)[i] = dataY[i] - funcvalues[i];
outws->dataY(3)[i] = rawvalues[i];
outws->dataY(4)[i] = dataY[i] - rawvalues[i];
}
// 5. Zscore
vector<double> zscore = Kernel::getZscore(outws->readY(2));
for (size_t i = 0; i < domain.size(); ++i)
outws->dataY(5)[i] = zscore[i];
return outws;
}
示例2: addAxesInfoAndLogs
/**
* 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));
}