本文整理汇总了C++中Workspace2D_sptr::getAxis方法的典型用法代码示例。如果您正苦于以下问题:C++ Workspace2D_sptr::getAxis方法的具体用法?C++ Workspace2D_sptr::getAxis怎么用?C++ Workspace2D_sptr::getAxis使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Workspace2D_sptr
的用法示例。
在下文中一共展示了Workspace2D_sptr::getAxis方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setUnit
//----------------------------------------------------------------------------------------------
void LoadPDFgetNFile::setUnit(Workspace2D_sptr ws) {
// 1. Set X
string xcolname = mColumnNames[0];
if (xcolname.compare("Q") == 0) {
string unit = "MomentumTransfer";
ws->getAxis(0)->setUnit(unit);
} else if (xcolname.compare("r") == 0) {
ws->getAxis(0)->unit() = UnitFactory::Instance().create("Label");
Unit_sptr unit = ws->getAxis(0)->unit();
boost::shared_ptr<Units::Label> label =
boost::dynamic_pointer_cast<Units::Label>(unit);
label->setLabel("AtomicDistance", "Angstrom");
} else {
stringstream errss;
errss << "X axis " << xcolname << " is not supported for unit. " << endl;
g_log.warning() << errss.str() << endl;
}
// 2. Set Y
string ycolname = mColumnNames[1];
string ylabel("");
if (ycolname.compare("G(r)") == 0) {
ylabel = "PDF";
} else if (ycolname.compare("S") == 0) {
ylabel = "S";
} else {
ylabel = "Intensity";
}
ws->setYUnitLabel(ylabel);
return;
}
示例2: runtime_error
/** Remove peaks from a input workspace
*/
Workspace2D_sptr
RemovePeaks::removePeaks(API::MatrixWorkspace_const_sptr dataws, int wsindex,
double numfwhm) {
// Check
if (m_vecPeakCentre.empty())
throw runtime_error("RemovePeaks has not been setup yet. ");
// Initialize vectors
const MantidVec &vecX = dataws->readX(wsindex);
const MantidVec &vecY = dataws->readY(wsindex);
const MantidVec &vecE = dataws->readE(wsindex);
size_t sizex = vecX.size();
vector<bool> vec_useX(sizex, true);
// Exclude regions
size_t numbkgdpoints =
excludePeaks(vecX, vec_useX, m_vecPeakCentre, m_vecPeakFWHM, numfwhm);
size_t numbkgdpointsy = numbkgdpoints;
size_t sizey = vecY.size();
if (sizex > sizey)
--numbkgdpointsy;
// Construct output workspace
Workspace2D_sptr outws = boost::dynamic_pointer_cast<Workspace2D>(
WorkspaceFactory::Instance().create("Workspace2D", 1, numbkgdpoints,
numbkgdpointsy));
outws->getAxis(0)->setUnit(dataws->getAxis(0)->unit()->unitID());
MantidVec &outX = outws->dataX(0);
MantidVec &outY = outws->dataY(0);
MantidVec &outE = outws->dataE(0);
size_t index = 0;
for (size_t i = 0; i < sizex; ++i) {
if (vec_useX[i]) {
if (index >= numbkgdpoints)
throw runtime_error("Programming logic error (1)");
outX[index] = vecX[i];
++index;
}
}
index = 0;
for (size_t i = 0; i < sizey; ++i) {
if (vec_useX[i]) {
if (index >= numbkgdpointsy)
throw runtime_error("Programming logic error (2)");
outY[index] = vecY[i];
outE[index] = vecE[i];
++index;
}
}
return outws;
}
示例3: 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;
}
示例4: createSANSInstrumentWorkspace
/*
* Generate a SANS test workspace, with instrument geometry.
* The geometry is the SANSTEST geometry, with a 30x30 pixel 2D detector.
*
* @param workspace: name of the workspace to be created.
*/
Workspace2D_sptr SANSInstrumentCreationHelper::createSANSInstrumentWorkspace(
std::string workspace) {
// Create a test workspace with test data with a well defined peak
// The test instrument has two monitor channels
Workspace2D_sptr ws = WorkspaceCreationHelper::create2DWorkspace123(
nBins * nBins + nMonitors, 1, 1);
AnalysisDataService::Instance().addOrReplace(workspace, ws);
ws->getAxis(0)->unit() =
Mantid::Kernel::UnitFactory::Instance().create("Wavelength");
ws->setYUnit("");
// Load instrument geometry
runLoadInstrument("SANSTEST", ws);
runLoadMappingTable(ws, nBins, nBins);
return ws;
}
示例5: exec
void PoldiPeakSearch::exec() {
g_log.information() << "PoldiPeakSearch:" << std::endl;
Workspace2D_sptr correlationWorkspace = getProperty("InputWorkspace");
MantidVec correlationQValues = correlationWorkspace->readX(0);
MantidVec correlatedCounts = correlationWorkspace->readY(0);
g_log.information() << " Auto-correlation data read." << std::endl;
Unit_sptr xUnit = correlationWorkspace->getAxis(0)->unit();
if (xUnit->caption() == "") {
g_log.information()
<< " Workspace does not have unit, defaulting to MomentumTransfer."
<< std::endl;
xUnit = UnitFactory::Instance().create("MomentumTransfer");
} else {
g_log.information() << " Unit of workspace is " << xUnit->caption() << "."
<< std::endl;
}
setMinimumDistance(getProperty("MinimumPeakSeparation"));
setMinimumPeakHeight(getProperty("MinimumPeakHeight"));
setMaximumPeakNumber(getProperty("MaximumPeakNumber"));
if (m_doubleMinimumDistance > static_cast<int>(correlatedCounts.size())) {
throw(std::runtime_error("MinimumPeakSeparation is smaller than number of "
"spectrum points - no peaks possible."));
}
g_log.information() << " Parameters set." << std::endl;
MantidVec summedNeighborCounts = getNeighborSums(correlatedCounts);
g_log.information() << " Neighboring counts summed, contains "
<< summedNeighborCounts.size() << " data points."
<< std::endl;
std::list<MantidVec::const_iterator> peakPositionsSummed =
findPeaks(summedNeighborCounts.begin(), summedNeighborCounts.end());
g_log.information() << " Peaks detected in summed spectrum: "
<< peakPositionsSummed.size() << std::endl;
/* This step is required because peaks are actually searched in the
* "sum-of-neighbors"-spectrum.
* The mapping removes the offset from the peak position which results from
* different beginning
* of this vector compared to the original correlation counts.
*/
std::list<MantidVec::const_iterator> peakPositionsCorrelation =
mapPeakPositionsToCorrelationData(peakPositionsSummed,
summedNeighborCounts.begin(),
correlatedCounts.begin());
g_log.information() << " Peak positions transformed to original spectrum."
<< std::endl;
/* Since intensities are required for filtering, they are extracted from the
* original count data,
* along with the Q-values.
*/
std::vector<PoldiPeak_sptr> peakCoordinates =
getPeaks(correlatedCounts.begin(), correlatedCounts.end(),
peakPositionsCorrelation, correlationQValues, xUnit);
g_log.information()
<< " Extracted peak positions in Q and intensity guesses." << std::endl;
UncertainValue backgroundWithSigma =
getBackgroundWithSigma(peakPositionsCorrelation, correlatedCounts);
g_log.information() << " Calculated average background and deviation: "
<< UncertainValueIO::toString(backgroundWithSigma)
<< std::endl;
if ((*getProperty("MinimumPeakHeight")).isDefault()) {
setMinimumPeakHeight(minimumPeakHeightFromBackground(backgroundWithSigma));
}
std::vector<PoldiPeak_sptr> intensityFilteredPeaks(peakCoordinates.size());
auto newEnd = std::remove_copy_if(
peakCoordinates.begin(), peakCoordinates.end(),
intensityFilteredPeaks.begin(),
boost::bind(&PoldiPeakSearch::isLessThanMinimum, this, _1));
intensityFilteredPeaks.resize(
std::distance(intensityFilteredPeaks.begin(), newEnd));
g_log.information() << " Peaks above minimum intensity ("
<< m_minimumPeakHeight
<< "): " << intensityFilteredPeaks.size() << std::endl;
std::sort(intensityFilteredPeaks.begin(), intensityFilteredPeaks.end(),
boost::bind<bool>(&PoldiPeak::greaterThan, _1, _2,
&PoldiPeak::intensity));
for (std::vector<PoldiPeak_sptr>::const_iterator peak =
intensityFilteredPeaks.begin();
peak != intensityFilteredPeaks.end(); ++peak) {
m_peaks->addPeak(*peak);
}
/* The derived background error is set as error in the workspace containing
* correlation data, so it may be used as weights for peak fitting later on.
*/
//.........这里部分代码省略.........
示例6: 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));
}