\(\renewcommand\AA{\unicode{x212B}}\)

ImportMDHistoWorkspace v1

Summary

Reads a text file and generates an MDHistoWorkspace from it.

See Also

ImportMDEventWorkspace

Properties

Name

Direction

Type

Default

Description

Filename

Input

string

Mandatory

File of type txt. Allowed extensions: [‘.txt’]

Dimensionality

Input

number

Mandatory

Dimensionality of the data in the file.

Extents

Input

dbl list

A comma separated list of min, max for each dimension, specifying the extents of each dimension.

NumberOfBins

Input

int list

Number of bin in each dimension.

Names

Input

str list

A comma separated list of the name of each dimension. e.g. (‘[H,0,0]’,’[0,K,0]’,’[0,0,L]’)

Units

Input

str list

A comma separated list of the units of each dimension.

OutputWorkspace

Output

IMDHistoWorkspace

Mandatory

MDHistoWorkspace reflecting the input text file.

Frames

Input

str list

A comma separated list of the frames of each dimension. The frames can be General Frame: Any frame which is not a Q-based frame. QLab: Wave-vector converted into the lab frame. QSample: Wave-vector converted into the frame of the sample. HKL: Wave-vector converted into the crystal’s HKL indices. Note if nothing is specified then the General Frame is being selected. Also note that if you select a frame then this might override your unit selection if it is not compatible with the frame.

Description

This algorithm takes a text file (.txt extension) containing two columns and converts it into an MDHistoWorkspace.

Details

The columns are in the order signal then error. The file must only contain two columns, these may be separated by any whitespace character. The algorithm expects there to be 2*product(nbins in each dimension) entries in this file. So if you have set the dimensionality to be 4,4,4 then you will need to provide 64 rows of data, in 2 columns or 128 floating point entries.

The Names, Units, Extents and NumberOfBins inputs are all linked by the order they are provided in. For example, if you provide Names A, B, C and Units U1, U2, U3 then the dimension A will have units U1.

Signal and Error inputs are read in such that, the first entries in the file will be entered across the first dimension specified, and the zeroth index in the other dimensions. The second set of entries will be entered across the first dimension and the 1st index in the second dimension, and the zeroth index in the others.

Alternatives

A very similar algorithm to this is CreateMDHistoWorkspace, which takes it’s input signal and error values from arrays rather than a text file. Another alternative is to use ConvertToMD which works on MatrixWorkspaces, and allows log values to be included in the dimensionality.

Usage

Note

To run these usage examples please first download the usage data, and add these to your path. In Mantid this is done using Manage User Directories.

A 3D Example

ws = ImportMDHistoWorkspace('demo_mdhw.txt',Dimensionality='3',Extents='-1,1,-1,1,-1,1',
                            NumberOfBins='2,2,2',Names='A,B,C',Units='A,A,A')
print("Number of Dimensions = {:d}".format(ws.getNumDims()))
index = (1,0,1)
print("Signal at {} = {:.1f}".format(index, ws.getSignalArray()[index]))
print("Error Squared at {} = {:.2f}".format(index, ws.getErrorSquaredArray()[index]))

Output:

Number of Dimensions = 3
Signal at (1, 0, 1) = 6.0
Error Squared at (1, 0, 1) = 37.21

A 2D Example

ws = ImportMDHistoWorkspace('demo_mdhw.txt',Dimensionality='2',Extents='-1,1,-1,1',
                            NumberOfBins='4,2',Names='A,B',Units='A,A')
print("Number of Dimensions = {:d}".format(ws.getNumDims()))
index = (2,1)
print("Signal at {} = {:.1f}".format(index, ws.getSignalArray()[index]))
print("Error Squared at {} = {:.2f}".format(index, ws.getErrorSquaredArray()[index]))

Output:

Number of Dimensions = 2
Signal at (2, 1) = 7.0
Error Squared at (2, 1) = 50.41

Categories: AlgorithmIndex | MDAlgorithms\DataHandling

Source

C++ header: ImportMDHistoWorkspace.h

C++ source: ImportMDHistoWorkspace.cpp