Skip to content

Commit

Permalink
Refs #7215 expose PeakInfo to python
Browse files Browse the repository at this point in the history
  • Loading branch information
Vickie Lynch committed Jun 4, 2013
1 parent 8a64104 commit 7d6acc0
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 0 deletions.
1 change: 1 addition & 0 deletions Code/Mantid/Framework/API/inc/MantidAPI/IPeaksWorkspace.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ namespace API
* @returns special Q3D coordinate system to use being used by this PeaksWorkspace object. Probably the one the workspace was generated with.
*/
virtual Mantid::API::SpecialCoordinateSystem getSpecialCoordinateSystem() const = 0;
virtual int PeakInfoNumber(Kernel::V3D QLabFrame , bool lab_coords) const =0;
};


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ namespace DataObjects
const Peak & getPeak(int peakNum) const;
API::IPeak* createPeak(Kernel::V3D QLabFrame, double detectorDistance=1.0) const;
std::vector<std::pair<std::string,std::string> > PeakInfo(Kernel::V3D QLabFrame , bool lab_coords) const;
int PeakInfoNumber(Kernel::V3D QFrame, bool lab_coords) const;
std::vector<Peak> & getPeaks();
const std::vector<Peak> & getPeaks() const;
virtual bool hasIntegratedPeaks() const;
Expand Down
46 changes: 46 additions & 0 deletions Code/Mantid/Framework/DataObjects/src/PeaksWorkspace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,52 @@ namespace Mantid
return Result;
}

/**
* Returns selected information for a "peak" at QLabFrame.
*
* @param QFrame An arbitrary position in Q-space. This does not have to be the
* position of a peak.
* @param lab_coords Set true if the position is in the lab coordinate system, false if
* it is in the sample coordinate system.
* @return a vector whose elements contain different information about the "peak" at that position.
* each element is a pair of description of information and the string form for the corresponding
* value.
*/
int PeaksWorkspace::PeakInfoNumber(Kernel::V3D QFrame,
bool lab_coords) const
{
std::vector<std::pair<std::string, std::string> > Result;
std::ostringstream oss;
oss<<std::setw(12)<<std::fixed<<std::setprecision(3)<<(QFrame.norm());
std::pair<std::string, std::string> QMag("|Q|",oss.str());
Result.push_back(QMag);

oss.str(""); oss.clear();
oss<<std::setw(12)<<std::fixed<<std::setprecision(3)<<(2.0 * M_PI / QFrame.norm());

std::pair<std::string, std::string> dspc("d-spacing",oss.str());
oss.str(""); oss.clear();
Result.push_back(dspc);

int seqNum = -1;
double minDist = 10000000;

for (int i = 0; i < getNumberPeaks(); i++)
{
Peak pk = getPeak(i);
V3D Q = pk.getQLabFrame();
if (!lab_coords)
Q = pk.getQSampleFrame();
double D = QFrame.distance(Q);
if (D < minDist)
{
minDist = D;
seqNum = i + 1;
}

}
return seqNum;
}

//---------------------------------------------------------------------------------------------
/** Return a reference to the Peaks vector */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ void export_IPeaksWorkspace()
.def("hasIntegratedPeaks", &IPeaksWorkspace::hasIntegratedPeaks, "Determine if the peaks have been integrated")
.def("getRun", &IPeaksWorkspace::mutableRun, return_internal_reference<>(),
"Return the Run object for this workspace")
.def("PeakInfoNumber", &IPeaksWorkspace::PeakInfoNumber, "Peak info number at Q vector for this workspace")
;

REGISTER_SINGLEVALUE_HANDLER(IPeaksWorkspace_sptr);
Expand Down

0 comments on commit 7d6acc0

Please sign in to comment.