本文整理汇总了C++中api::MatrixWorkspace_sptr::replaceAxis方法的典型用法代码示例。如果您正苦于以下问题:C++ MatrixWorkspace_sptr::replaceAxis方法的具体用法?C++ MatrixWorkspace_sptr::replaceAxis怎么用?C++ MatrixWorkspace_sptr::replaceAxis使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类api::MatrixWorkspace_sptr
的用法示例。
在下文中一共展示了MatrixWorkspace_sptr::replaceAxis方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setUpOutputWorkspace
void RadiusSum::setUpOutputWorkspace(std::vector<double> &values) {
g_log.debug() << "Output calculated, setting up the output workspace\n";
API::MatrixWorkspace_sptr outputWS = API::WorkspaceFactory::Instance().create(
inputWS, 1, values.size() + 1, values.size());
g_log.debug() << "Set the data\n";
MantidVec &refY = outputWS->dataY(0);
std::copy(values.begin(), values.end(), refY.begin());
g_log.debug() << "Set the bins limits\n";
MantidVec &refX = outputWS->dataX(0);
double bin_size = (max_radius - min_radius) / num_bins;
for (int i = 0; i < (static_cast<int>(refX.size())) - 1; i++)
refX[i] = min_radius + i * bin_size;
refX.back() = max_radius;
// configure the axis:
// for numeric images, the axis are the same as the input workspace, and are
// copied in the creation.
// for instrument related, the axis Y (1) continues to be the same.
// it is necessary to change only the axis X. We have to change it to radius.
if (inputWorkspaceHasInstrumentAssociated(inputWS)) {
API::Axis *const horizontal = new API::NumericAxis(refX.size());
auto labelX = UnitFactory::Instance().create("Label");
boost::dynamic_pointer_cast<Units::Label>(labelX)->setLabel("Radius");
horizontal->unit() = labelX;
outputWS->replaceAxis(0, horizontal);
}
setProperty("OutputWorkspace", outputWS);
}
示例2: exec
void LoadDaveGrp::exec()
{
const std::string filename = this->getProperty("Filename");
int yLength = 0;
MantidVec *xAxis = new MantidVec();
MantidVec *yAxis = new MantidVec();
std::vector<MantidVec *> data;
std::vector<MantidVec *> errors;
this->ifile.open(filename.c_str());
if (this->ifile.is_open())
{
// Size of x axis
this->getAxisLength(this->xLength);
// Size of y axis
this->getAxisLength(yLength);
// This is also the number of groups (spectra)
this->nGroups = yLength;
// Read in the x axis values
this->getAxisValues(xAxis, static_cast<std::size_t>(this->xLength));
// Read in the y axis values
this->getAxisValues(yAxis, static_cast<std::size_t>(yLength));
// Read in the data
this->getData(data, errors);
}
this->ifile.close();
// Scale the x-axis if it is in micro-eV to get it to meV
const bool isUeV = this->getProperty("IsMicroEV");
if (isUeV)
{
MantidVec::iterator iter;
for (iter = xAxis->begin(); iter != xAxis->end(); ++iter)
{
*iter /= 1000.0;
}
}
// Create workspace
API::MatrixWorkspace_sptr outputWorkspace = \
boost::dynamic_pointer_cast<API::MatrixWorkspace>\
(API::WorkspaceFactory::Instance().create("Workspace2D", this->nGroups,
this->xLength, yLength));
// Force the workspace to be a distribution
outputWorkspace->isDistribution(true);
// Set the x-axis units
outputWorkspace->getAxis(0)->unit() = Kernel::UnitFactory::Instance().create(this->getProperty("XAxisUnits"));
API::Axis* const verticalAxis = new API::NumericAxis(yLength);
// Set the y-axis units
verticalAxis->unit() = Kernel::UnitFactory::Instance().create(this->getProperty("YAxisUnits"));
outputWorkspace->replaceAxis(1, verticalAxis);
for(int i = 0; i < this->nGroups; i++)
{
outputWorkspace->dataX(i) = *xAxis;
outputWorkspace->dataY(i) = *data[i];
outputWorkspace->dataE(i) = *errors[i];
verticalAxis->setValue(i, yAxis->at(i));
delete data[i];
delete errors[i];
}
delete xAxis;
delete yAxis;
outputWorkspace->mutableRun().addProperty("Filename",filename);
this->setProperty("OutputWorkspace", outputWorkspace);
}