PeaksWorkspace#
This is a Python binding to the C++ class Mantid::DataObjects::PeaksWorkspace.
bases: mantid.api.IPeaksWorkspace
The PeaksWorkspace is a special Workspace that holds a list of single crystal Peak objects.
Creating a PeaksWorkspace#
FindPeaksMD will find peaks in reciprocal space in a MDWorkspace.
FindSXPeaks will find peaks in detector space.
PredictPeaks will predict peak positions in a workspace given a UB matrix.
The LoadIsawPeaks algorithm will load a PeaksWorkspace from file.
The SaveIsawPeaks algorithm will save a PeaksWorkspace to a file.
CreatePeaksWorkspace will create an empty PeaksWorkspace that you can then edit.
Viewing a PeaksWorkspace#
Double-click a PeaksWorkspace to see the full list of data of each Peak object.
In MantidWorkbench, you can drag/drop a PeaksWorkspace from the list of workspaces onto the Instrument View. This will overlay the peaks onto the detector face.
Peaks overlay in the Sliceviewer.
Each peak object contains several pieces of information. Not all of them are necessary
Detector position and wavelength
Q position (calculated from the detector position/wavelength)
H K L indices (optional)
Goniometer rotation matrix (for finding Q in the sample frame)
Integrated intensity and error (optional)
Row/column of detector (only for RectangularDetectors )
An integration shape (see below)
The Peak Shape#
Each Peak object contains a PeakShape. Typically the integration algorithms which act on, and return PeaksWorkspaces set the shape of the peaks. The PeakShape is owned by the Peak, not the PeaksWorkspace, so when PeaksWorkspaces are split, or concatinated, the integration shapes are unaltered. Aside from the Null Peak Shape, each peak shape contains at least the following information.
The algorithm used to perform the integration
The version of the algorithm used to perform the integration
The frame in which the integration has been performed
Subtypes of PeakShape will then provide additional information. For example PeakShapeSpherical provides the radius as well as background inner, and background outer radius.
Creating peak shapes in Python#
You can manually create the peak shape and set it on a peak from Python. This peak shape is not used by any integration algorithm but will allow you to visualize the shapes with Sliceviewer.
from mantid.kernel import V3D
from mantid.dataobjects import NoShape, PeakShapeSpherical, PeakShapeEllipsoid
pws = mtd['name_of_peaks_workspace']
no_shape = NoShape()
pws.getPeak(0).setPeakShape(no_shape)
sphere = PeakShapeSpherical(peakRadius=0.5)
pws.getPeak(1).setPeakShape(sphere)
sphere_with_background = PeakShapeSpherical(peakRadius=0.5,
backgroundInnerRadius=0.6,
backgroundOuterRadius=0.7)
pws.getPeak(2).setPeakShape(sphere_with_background)
ellipse = PeakShapeEllipsoid(directions=[V3D(1, 0, 0), V3D(0, 1, 0), V3D(0, 0, 1)],
abcRadii=[0.1, 0.2, 0.3],
abcRadiiBackgroundInner=[0.4, 0.5, 0.6],
abcRadiiBackgroundOuter=[0.7, 0.8, 0.9])
pws.getPeak(3).setPeakShape(ellipse)
Calculate Goniometer For Constant Wavelength#
If you set the wavelength (in Å) or energy (in meV) property on a PeaksWorkspace, or if the instrument on the PeaksWorkspace has the wavelength parameter, the goniometer rotation will be calculated when the createPeak method is used. This allows you to use one instrument definition for multiple goniometer rotations, for example adding peaks in Slice Viewer from multiple combined MD workspaces. It only works for a constant wavelength source and only for Q sample workspaces. It also assumes the goniometer rotation is around the y-axis only. For details on the calculation see “Calculate Goniometer For Constant Wavelength” at FindPeaksMD.
pws = mtd['name_of_peaks_workspace']
pws.run().addProperty('wavelength', 1.54, True)
# or
pws.run().addProperty('energy', 34.48, True)
Using PeaksWorkspaces in Python#
The PeaksWorkspace and Peak objects are exposed to python.
PeaksWorkspace Python Interface#
pws = mtd['name_of_peaks_workspace']
pws.getNumberPeaks()
p = pws.getPeak(12)
pws.removePeak(34)
Peak Python Interface#
You can get a handle to an existing peak with:
p = pws.getPeak(12)
Or you can create a new peak in this way:
qlab = V3D(1.23, 3.45, 2.22) # Q in the lab frame of the peak
detector_distance = 2.5 # sample-detector distance in meters. Detector distances are optional. Calculated in not provided.
p = pws.createPeak(qlab, detector_distance)
# The peak can later be added to the workspace
pws.addPeak(p)
Once you have a handle on a peak “p” you have several methods to query/modify its values:
hkl = p.getHKL()
p.setHKL(-5, 4, 3)
q = p.getQSampleFrame()
q = p.getQLabFrame()
detid = p.getDetectorID()
p.setIntensity(1000.0)
p.setSigmaIntensity(31.6)
counts = p.getIntensity()
wl = p.getWavelength()
tof = p.getTOF()
d = p.getDSpacing()
shape = p.getPeakShape()
Reference#
- class mantid.dataobjects.PeaksWorkspace#
- addColumn((ITableWorkspace)self, (str)type, (str)name) bool :#
Add a named column with the given type. Recognized types are: int,float,double,bool,str,V3D,long64
- addColumn( (ITableWorkspace)self, (str)type, (str)name, (int)plottype) -> bool :
Add a named column with the given datatype (int,float,double,bool,str,V3D,long64) and plottype (0 = None, 1 = X, 2 = Y, 3 = Z, 4 = xErr, 5 = yErr, 6 = Label).
- addPeak((IPeaksWorkspace)self, (IPeak)peak) None :#
Add a peak to the workspace
- addPeak( (IPeaksWorkspace)self, (object)data, (mantid.kernel._kernel.SpecialCoordinateSystem)coord_system) -> None :
Add a peak to the workspace
- addReadOnlyColumn((ITableWorkspace)self, (str)type, (str)name) bool :#
Add a read-only, named column with the given type. Recognized types are: int,float,double,bool,str,V3D,long64
- addRow((ITableWorkspace)self, (object)row_items_seq) None :#
Appends a row with the values from the given sequence. It it assumed that the items are in the correct order for the defined columns.
- addRow( (ITableWorkspace)self, (dict)row_items_dict) -> None :
Appends a row with the values from the dictionary.
- cell((ITableWorkspace)self, (object)value, (int)row_or_column) object :#
Return the value in the given cell. If the value argument is a number then it is interpreted as a row otherwise it is interpreted as a column name.
- clone(InputWorkspace)#
Copies an existing workspace into a new one.
Property descriptions:
InputWorkspace(Input:req) Workspace Name of the input workspace. Must be a MatrixWorkspace (2D or EventWorkspace), a PeaksWorkspace or a MDEventWorkspace.
OutputWorkspace(Output:req) Workspace Name of the newly created cloned workspace.
- column((ITableWorkspace)self, (object)column) object :#
Return all values of a specific column as a list.
- columnArray((ITableWorkspace)self, (object)column) object :#
Return all values of a specific column (either index or name) as a numpy array.
- columnCount((ITableWorkspace)self) int :#
Returns the number of columns in the workspace.
- columnTypes((ITableWorkspace)self) list :#
Return the types of the columns as a list
- componentInfo((ExperimentInfo)self) mantid.geometry._geometry.ComponentInfo :#
Return a const reference to the
ComponentInfoobject.
- convertUnits(InputWorkspace, Target, EMode=None, EFixed=None, AlignBins=None, ConvertFromPointData=None)#
Performs a unit change on the X values of a workspace
Property descriptions:
InputWorkspace(Input:req) MatrixWorkspace Name of the input workspace
OutputWorkspace(Output:req) MatrixWorkspace Name of the output workspace, can be the same as the input
Target(Input:req) string The name of the units to convert to (must be one of those registered in the Unit Factory)[DeltaE, DeltaE_inFrequency, DeltaE_inWavenumber, dSpacing, dSpacingPerpendicular, Energy, Energy_inWavenumber, Momentum, MomentumTransfer, QSquared, SpinEchoLength, SpinEchoTime, TOF, Wavelength]
EMode(Input) string The energy mode (default: elastic)[Elastic, Direct, Indirect]
EFixed(Input) number Value of fixed energy in meV : EI (EMode=’Direct’) or EF (EMode=’Indirect’) . Must be set if the target unit requires it (e.g. DeltaE)
AlignBins(Input) boolean If true (default is false), rebins after conversion to ensure that all spectra in the output workspace have identical bin boundaries. This option is not recommended (see http://docs.mantidproject.org/algorithms/ConvertUnits).
ConvertFromPointData(Input) boolean When checked, if the Input Workspace contains Points the algorithm ConvertToHistogram will be run to convert the Points to Bins. The Output Workspace will contains Bins.
- createPeak((IPeaksWorkspace)self, (object)data) IPeak :#
Create a Peak and return it from its coordinates in the QLab frame
- createPeak( (IPeaksWorkspace)self, (object)data, (float)detector_distance) -> IPeak :
Create a Peak and return it from its coordinates in the QLab frame, detector-sample distance explicitly provided
- createPeakHKL((IPeaksWorkspace)self, (object)data) IPeak :#
Create a Peak and return it from its coordinates in the HKL frame
- createPeakQSample((IPeaksWorkspace)self, (object)data) IPeak :#
Create a Peak and return it from its coordinates in the QSample frame
- delete(Workspace)#
Removes a workspace from memory.
Property descriptions:
Workspace(Input:req) Workspace Name of the workspace to delete.
- detectorInfo((ExperimentInfo)self) mantid.geometry._geometry.DetectorInfo :#
Return a const reference to the
DetectorInfoobject.
- getColumnNames((ITableWorkspace)self) numpy.ndarray :#
Return a list of the column names.
- getComment((Workspace)self) str :#
Returns the comment field on the workspace
- getEMode((ExperimentInfo)self) mantid.kernel._kernel.DeltaEModeType :#
Returns the energy mode.
- getHistory((Workspace)self) WorkspaceHistory :#
Return read-only access to the
WorkspaceHistory
- getInstrument((ExperimentInfo)self) mantid.geometry._geometry.Instrument :#
Returns the
Instrumentfor this run.
- static getInstrumentFilename((str)instrument[, (str)date='']) str :#
Returns IDF filename
- getLinkedYCol((ITableWorkspace)self, (object)column) int :#
Get the data column associated with a given error column.
- getMemorySize((Workspace)self) int :#
Returns the memory footprint of the workspace in KB
- getName((Workspace)self) str :#
Returns the name of the workspace. This could be an empty string
- getNumberPeaks((IPeaksWorkspace)self) int :#
Returns the number of peaks within the workspace
- getPeak((IPeaksWorkspace)self, (int)peak_num) IPeak :#
Returns a peak at the given index
- getPlotType((ITableWorkspace)self, (object)column) int :#
Get the plot type of given column as an integer. Accepts column name or index. Possible return values: (0 = None, 1 = X, 2 = Y, 3 = Z, 4 = xErr, 5 = yErr, 6 = Label).
- static getResourceFilenames((str)prefix, (list)fileFormats, (list)directoryNames, (str)date) list :#
Compile a list of files in compliance with name pattern-matching, file format, and date-stamp constraints
Ideally, the valid-from and valid-to of any valid file should encapsulate the argument date. If this is not possible, then the file with the most recent valid-from stamp is selected
prefix: the name of a valid file must begin with this pattern fileFormats: list of valid file extensions directoryNames: list of directories to be searched date : the ‘valid-from’ and ‘valid-to ‘dates of a valid file will encapsulate this date (e.g ‘1900-01-31 23:59:00’)
returns : list of absolute paths for each valid file
- getRun((IPeaksWorkspace)self) Run :#
Return the Run object for this workspace
- getRunNumber((ExperimentInfo)self) int :#
Returns the run identifier for this run.
- getTitle((Workspace)self) str :#
Returns the title of the workspace
- hasIntegratedPeaks((IPeaksWorkspace)self) bool :#
Determine if the peaks have been integrated
- id((DataItem)self) str :#
The string ID of the class
- isColumnReadOnly((ITableWorkspace)self, (object)column) bool :#
Gets whether or not a given column of this workspace is be read-only. Columns can be selected by name or by index
- isDirty((Workspace)self[, (int)n]) bool :#
True if the workspace has run more than n algorithms (Default=1)
- isGroup((Workspace)self) bool :#
Returns if it is a group workspace
- keys((ITableWorkspace)self) numpy.ndarray :#
Return a list of the column names.
- maskDetectors(Workspace, SpectraList=None, DetectorList=None, WorkspaceIndexList=None, MaskedWorkspace=None, ForceInstrumentMasking=None, StartWorkspaceIndex=None, EndWorkspaceIndex=None, ComponentList=None)#
An algorithm to mask a detector, or set of detectors, as not to be used. The workspace spectra associated with those detectors are zeroed.
Property descriptions:
Workspace(InOut:req) Workspace The name of the input and output workspace on which to perform the algorithm.
SpectraList(Input) int list A list of spectra to mask
DetectorList(Input) int list A list of detector ID’s to mask
WorkspaceIndexList(Input) unsigned int list A list of the workspace indices to mask
MaskedWorkspace(Input) MatrixWorkspace If given but not as a SpecialWorkspace2D, the masking from this workspace will be copied. If given as a SpecialWorkspace2D, the masking is read from its Y values.[]
ForceInstrumentMasking(Input) boolean Works when ‘MaskedWorkspace’ is provided and forces to use spectra-detector mapping even in case when number of spectra in ‘Workspace’ and ‘MaskedWorkspace’ are equal
StartWorkspaceIndex(Input) number If other masks fields are provided, it’s the first index of the target workspace to be allowed to be masked from by these masks, if not, its the first index of the target workspace to mask. Default value is 0 if other masking is present or ignored if not.
EndWorkspaceIndex(Input) number If other masks are provided, it’s the last index of the target workspace allowed to be masked to by these masks, if not, its the last index of the target workspace to mask. Default is number of histograms in target workspace if other masks are present or ignored if not.
ComponentList(Input) str list A list names of components to mask
- name((DataItem)self) str :#
The name of the object
- peakInfoNumber((IPeaksWorkspace)self, (mantid.kernel._kernel.V3D)qlab_frame, (bool)lab_coordinate) int :#
Peak info number at Q vector for this workspace
- populateInstrumentParameters((ExperimentInfo)self) None :#
Update parameters in the instrument-parameter map. Logs must be loaded before calling this method
- readLock((DataItem)self) None :#
Acquires a read lock on the data item.
- removeColumn((ITableWorkspace)self, (str)name) None :#
Remove the named column.
- removePeak((IPeaksWorkspace)self, (int)peak_num) None :#
Remove a peak from the workspace
- removePeaks((IPeaksWorkspace)self, (object)peak_num) None :#
Remove specified peaks from the workspace
- row((ITableWorkspace)self, (int)row) object :#
Return all values of a specific row as a dict.
- rowCount((ITableWorkspace)self) int :#
Returns the number of rows within the workspace.
- run((ExperimentInfo)self) Run :#
Return the
Runobject. This cannot be modified, use mutableRun to modify.
- sample((ExperimentInfo)self) Sample :#
Return the
Sampleobject. This cannot be modified, use mutableSample to modify.
- setCell((IPeaksWorkspace)self, (object)row_or_column, (int)column_or_row, (object)value) None :#
Sets the value of a given cell. If the row_or_column argument is a number then it is interpreted as a row otherwise it is interpreted as a column name.
- setColumnReadOnly((ITableWorkspace)self, (object)column, (bool)read_only) None :#
Sets whether or not a given column of this workspace should be read-only. Columns can be selected by name or by index
- setComment((Workspace)self, (str)comment) None :#
Set the comment field of the workspace
- setLinkedYCol((ITableWorkspace)self, (object)errColumn, (int)dataColumn) None :#
Set the data column associated with a given error column.
- setPlotType((ITableWorkspace)self, (object)column, (int)ptype[, (int)linkedCol=-1]) None :#
Set the plot type of given column. Accepts column name or index. Possible type values: (0 = None, 1 = X, 2 = Y, 3 = Z, 4 = xErr, 5 = yErr, 6 = Label).
- setRowCount((ITableWorkspace)self, (int)count) None :#
Resize the table to contain count rows.
- setTitle((Workspace)self, (str)title) None :#
Set the title of the workspace
- spectrumInfo((ExperimentInfo)self) SpectrumInfo :#
Return a const reference to the
SpectrumInfoobject.
- threadSafe((DataItem)self) bool :#
Returns true if the object can be accessed safely from multiple threads
- toDict((ITableWorkspace)self) dict :#
Gets the values of this workspace as a dictionary. The keys of the dictionary will be the names of the columns of the table. The values of the entries will be lists of values for each column.
- unlock((DataItem)self) None :#
Unlocks a read or write lock on the data item.