SaveMDToAscii v1#
Summary#
Save an MDHistoWorkspace to a plain ASCII file, one row per bin, with dimension coordinate columns followed by intensity and error.
See Also#
Properties#
Name |
Direction |
Type |
Default |
Description |
|---|---|---|---|---|
InputWorkspace |
Input |
IMDHistoWorkspace |
Mandatory |
Input MDHistoWorkspace to save. |
Filename |
Input |
string |
Mandatory |
Output filename. Allowed extensions: [‘.dat’, ‘.txt’] |
ExtraHeader |
Input |
string |
If not empty, this text is written at the top of the file’s header, above the column names and shape lines. Each line is prefixed with ‘#’, the same as the rest of the header; if this text spans multiple lines, every one of them is prefixed individually. |
|
ExcludeIntegratedDimensions |
Input |
boolean |
True |
If True (default), integrated dimensions (those with a single bin) are excluded from the output columns. If False, all dimensions are written as columns. |
Normalization |
Input |
string |
FromWorkspace |
Normalization to apply to the signal and error before writing. ‘FromWorkspace’ (default) uses the workspace’s own displayNormalizationHisto() setting. The other choices force that normalization regardless of what the workspace reports: ‘NumEventsNormalization’ divides by the number of events in each bin, and ‘VolumeNormalization’ multiplies by the workspace’s inverse bin volume. Allowed values: [‘FromWorkspace’, ‘NoNormalization’, ‘VolumeNormalization’, ‘NumEventsNormalization’] |
Separator |
Input |
string |
Space |
Column delimiter to use in the output file. ‘UserDefined’ requires CustomSeparator to be set. Allowed values: [‘CSV’, ‘Tab’, ‘Space’, ‘Colon’, ‘SemiColon’, ‘UserDefined’] |
CustomSeparator |
Input |
string |
Used as the column delimiter when Separator is set to ‘UserDefined’. |
|
Precision |
Input |
number |
Optional |
Number of digits after the decimal point in scientific notation for the numeric columns. If not set, a default of 6 is used. |
Description#
This algorithm saves an MDHistoWorkspace to a plain ASCII
text file, with one row per bin. Each row contains, in order, the bin-centre coordinate for every
dimension written out, followed by the Intensity and the Error for that bin.
An integrated dimension is one with exactly one bin (getNBins() == 1). By default such dimensions are
excluded from the output columns, since their coordinate is constant across the whole workspace; set
ExcludeIntegratedDimensions to False to include them instead, as constant-value columns. If every
dimension is integrated and ExcludeIntegratedDimensions is left as True, the algorithm fails since
there would be no dimension columns left to write.
Normalization defaults to whatever the workspace itself declares via its display normalization
(MDNormalization, as set for example by BinMD v1 or
ConvertToMD v1). Set Normalization explicitly to override the workspace’s own setting:
NumEventsNormalization divides Intensity and Error by the number of events in each bin, and
VolumeNormalization multiplies Intensity and Error by the workspace’s inverse bin volume.
Separator and CustomSeparator control the column delimiter used in the output file.
Precision controls the number of digits after the decimal point in scientific notation used for the
numeric columns (Intensity, Error, and the dimension coordinates).
If ExtraHeader is set to a non-empty string, it is written at the top of the file’s header, above the
column names and shape lines. Every line is prefixed with #, the same as the rest of the header; if
ExtraHeader itself spans multiple lines, each one is prefixed individually.
Usage#
import os
signalInput = [i for i in range(1, 10)]
errorInput = [1 for i in range(1, 10)]
ws = CreateMDHistoWorkspace(SignalInput=signalInput, ErrorInput=errorInput, Dimensionality='2',
Extents='-1,1,-1,1', NumberOfBins='3,3', Names='A,B', Units='U,V')
savefile = os.path.join(config["defaultsave.directory"], "mdws_ascii.dat")
SaveMDToAscii(InputWorkspace=ws, Filename=savefile, Separator='Space', Precision=3)
print("File created: {}".format(os.path.exists(savefile)))
File created: True
Categories: AlgorithmIndex | MDAlgorithms\DataHandling
Source#
Python: SaveMDToAscii.py