bool IMDDimensionComparitor::isXDimension( const Mantid::Geometry::IMDDimension &queryDimension) { // Compare dimensions on the basis of their ids. Mantid::Geometry::IMDDimension_const_sptr actualXDimension = m_workspace->getXDimension(); return queryDimension.getDimensionId() == actualXDimension->getDimensionId(); }
bool IMDDimensionComparitor::istDimension( const Mantid::Geometry::IMDDimension &queryDimension) { Mantid::Geometry::IMDDimension_const_sptr actualtDimension = m_workspace->getTDimension(); if (actualtDimension) { // Compare dimensions on the basis of their ids. return queryDimension.getDimensionId() == actualtDimension->getDimensionId(); } else { return false; // MDImages may have 1 dimension or more. } }
/** Set the labels for the Y dimensions * @param dim : IMDDimension */ void XYLimitsDialog::setYDim(Mantid::Geometry::IMDDimension_const_sptr dim) { ui.lblYName->setText( QString::fromStdString(dim->getName()) ); ui.lblYUnits->setText( QString::fromStdString(dim->getUnits()) ); }
//---------------------------------------------------------------------------------------------- /// Run the algorithm void QueryMDWorkspace::exec() { // Extract the required normalisation. std::string strNormalisation = getPropertyValue("Normalisation"); MDNormalization requestedNormalisation = whichNormalisation(strNormalisation); IMDWorkspace_sptr input = getProperty("InputWorkspace"); const bool transformCoordsToOriginal = getProperty("TransformCoordsToOriginal"); // Define a table workspace with a specific column schema. ITableWorkspace_sptr output = WorkspaceFactory::Instance().createTable(); const std::string signalColumnName = "Signal/" + strNormalisation; const std::string errorColumnName = "Error/" + strNormalisation; output->addColumn("double", signalColumnName); output->addColumn("double", errorColumnName); output->addColumn("int", "Number of Events"); const size_t ndims = input->getNumDims(); for (size_t index = 0; index < ndims; ++index) { Mantid::Geometry::IMDDimension_const_sptr dim = input->getDimension(index); std::string dimInUnit = dim->getName() + "/" + dim->getUnits().ascii(); output->addColumn("double", dimInUnit); // Magic numbers required to configure the X axis. output->getColumn(dimInUnit)->setPlotType(1); } // Magic numbers required to configure the Y axis. output->getColumn(signalColumnName)->setPlotType(2); output->getColumn(errorColumnName)->setPlotType(5); IMDIterator *it = input->createIterator(); it->setNormalization(requestedNormalisation); bool bLimitRows = getProperty("LimitRows"); int maxRows = 0; if (bLimitRows) { maxRows = getProperty("MaximumRows"); } // Use the iterator to loop through each MDBoxBase and create a row for each // entry. int rowCounter = 0; Progress progress(this, 0, 1, int64_t(input->getNPoints())); while (true) { size_t cellIndex = 0; output->appendRow(); output->cell<double>(rowCounter, cellIndex++) = it->getNormalizedSignal(); output->cell<double>(rowCounter, cellIndex++) = it->getNormalizedError(); output->cell<int>(rowCounter, cellIndex++) = int(it->getNumEvents()); VMD center = it->getCenter(); const size_t numberOriginal = input->getNumberTransformsToOriginal(); if (transformCoordsToOriginal && numberOriginal > 0) { const size_t index = numberOriginal - 1; CoordTransform const *transform = input->getTransformToOriginal(index); VMD temp = transform->applyVMD(center); center = temp; } for (size_t index = 0; index < ndims; ++index) { output->cell<double>(rowCounter, cellIndex++) = center[index]; } progress.report(); if (!it->next() || (bLimitRows && ((rowCounter + 1) >= maxRows))) { break; } rowCounter++; } setProperty("OutputWorkspace", output); delete it; // IMDEventWorkspace_sptr mdew; CALL_MDEVENT_FUNCTION(this->getBoxData, input); }
/** * Make 1D MatrixWorkspace */ void ConvertMDHistoToMatrixWorkspace::make1DWorkspace() { IMDHistoWorkspace_sptr inputWorkspace = getProperty("InputWorkspace"); // This code is copied from MantidQwtIMDWorkspaceData Mantid::Geometry::VecIMDDimension_const_sptr nonIntegDims = inputWorkspace->getNonIntegratedDimensions(); std::string alongDim = ""; if (!nonIntegDims.empty()) alongDim = nonIntegDims[0]->getDimensionId(); else alongDim = inputWorkspace->getDimension(0)->getDimensionId(); size_t nd = inputWorkspace->getNumDims(); Mantid::Kernel::VMD start = VMD(nd); Mantid::Kernel::VMD end = VMD(nd); size_t id = 0; for (size_t d = 0; d < nd; d++) { Mantid::Geometry::IMDDimension_const_sptr dim = inputWorkspace->getDimension(d); if (dim->getDimensionId() == alongDim) { // All the way through in the single dimension start[d] = dim->getMinimum(); end[d] = dim->getMaximum(); id = d; // We take the first non integrated dimension to be the diemnsion // of interest. } else { // Mid point along each dimension start[d] = (dim->getMaximum() + dim->getMinimum()) / 2.0f; end[d] = start[d]; } } // Unit direction of the line Mantid::Kernel::VMD dir = end - start; dir.normalize(); std::string normProp = getPropertyValue("Normalization"); Mantid::API::MDNormalization normalization; if (normProp == "NoNormalization") { normalization = NoNormalization; } else if (normProp == "VolumeNormalization") { normalization = VolumeNormalization; } else if (normProp == "NumEventsNormalization") { normalization = NumEventsNormalization; } else { normalization = NoNormalization; } auto line = inputWorkspace->getLineData(start, end, normalization); MatrixWorkspace_sptr outputWorkspace = WorkspaceFactory::Instance().create( "Workspace2D", 1, line.x.size(), line.y.size()); outputWorkspace->dataY(0).assign(line.y.begin(), line.y.end()); outputWorkspace->dataE(0).assign(line.e.begin(), line.e.end()); const size_t numberTransformsToOriginal = inputWorkspace->getNumberTransformsToOriginal(); CoordTransform_const_sptr transform = boost::make_shared<NullCoordTransform>(inputWorkspace->getNumDims()); if (numberTransformsToOriginal > 0) { const size_t indexToLastTransform = numberTransformsToOriginal - 1; transform = CoordTransform_const_sptr( inputWorkspace->getTransformToOriginal(indexToLastTransform), NullDeleter()); } assert(line.x.size() == outputWorkspace->dataX(0).size()); std::string xAxisLabel = inputWorkspace->getDimension(id)->getName(); const bool autoFind = this->getProperty("FindXAxis"); if (autoFind) { // We look to the original workspace if possbible to find the dimension of // interest to plot against. id = findXAxis(start, end, transform.get(), inputWorkspace.get(), g_log, id, xAxisLabel); } for (size_t i = 0; i < line.x.size(); ++i) { // Coordinates in the workspace being plotted VMD wsCoord = start + dir * line.x[i]; VMD inTargetCoord = transform->applyVMD(wsCoord); outputWorkspace->dataX(0)[i] = inTargetCoord[id]; } boost::shared_ptr<Kernel::Units::Label> labelX = boost::dynamic_pointer_cast<Kernel::Units::Label>( Kernel::UnitFactory::Instance().create("Label")); labelX->setLabel(xAxisLabel); outputWorkspace->getAxis(0)->unit() = labelX; outputWorkspace->setYUnitLabel("Signal"); setProperty("OutputWorkspace", outputWorkspace); }
/** Set the labels for the X dimensions * @param dim : IMDDimension */ void XYLimitsDialog::setXDim(Mantid::Geometry::IMDDimension_const_sptr dim) { ui.lblXName->setText(QString::fromStdString(dim->getName())); ui.lblXUnits->setText(toQStringInternal(dim->getUnits().utf8())); }