Table of Contents
Name | Direction | Type | Default | Description |
---|---|---|---|---|
Filename | Input | string | Mandatory | The name of the text file to read, including its full or relative path. The file extension must be .txt, .dat, or .csv. Allowed values: [‘.dat’, ‘.txt’, ‘.csv’, ‘’] |
OutputWorkspace | Output | Workspace | Mandatory | The name of the workspace that will be created, filled with the read-in data and stored in the [[Analysis Data Service]]. |
Separator | Input | string | Automatic | The separator between data columns in the data file. The possible values are “CSV”, “Tab”, “Space”, “SemiColon”, “Colon” or a user defined value. (default: Automatic selection from comma, tab, space, semicolon or colon.). Allowed values: [‘Automatic’, ‘CSV’, ‘Tab’, ‘Space’, ‘Colon’, ‘SemiColon’, ‘UserDefined’] |
CustomSeparator | Input | string | If present, will override any specified choice given to Separator. | |
CommentIndicator | Input | string | # | Character(s) found front of comment lines. Cannot contain numeric characters |
Unit | Input | string | Energy | The unit to assign to the X axis (anything known to the [[Unit Factory]] or “Dimensionless”). Allowed values: [‘Dimensionless’, ‘Degrees’, ‘DeltaE’, ‘DeltaE_inFrequency’, ‘DeltaE_inWavenumber’, ‘dSpacing’, ‘dSpacingPerpendicular’, ‘Empty’, ‘Energy’, ‘Energy_inWavenumber’, ‘Label’, ‘Momentum’, ‘MomentumTransfer’, ‘QSquared’, ‘SpinEchoLength’, ‘SpinEchoTime’, ‘Time’, ‘TOF’, ‘Wavelength’] |
SkipNumLines | Input | number | Optional | If given, skip this number of lines at the start of the file. |
The LoadAscii2 algorithm reads in spectra data from a text file and stores it in a Workspace2D as data points. The data in the file must be organized in columns separated by commas, tabs, spaces, colons or semicolons. Only one separator type can be used throughout the file; use the “Separator” property to tell the algorithm which to use. The algorithm SaveAscii2 is normally able to produce such a file.
The format must be:
The following is an example valid file of 4 spectra of 2 bins each with no X error:
#. X , Y , E
1 2.00000000,2.00000000,1.00000000 4.00000000,1.00000000,1.00000000 2
2.00000000,5.00000000,2.00000000 4.00000000,4.00000000,2.00000000 3
2.00000000,3.00000000,1.00000000 4.00000000,0.00000000,0.00000000 4
2.00000000,0.00000000,0.00000000 4.00000000,0.00000000,0.00000000
Example
#import the os path libraries for directory functions
import os
# create histogram workspace
dataX1 = [0,1,2,3,4,5,6,7,8] # or use dataX1=range(0,10)
dataY1 = [0,1,2,3,4,5,6,7,8] # or use dataY1=range(0,9)
dataE1 = [1,1,1,1,1,1,1,1,1] # or use dataE1=[1]*9
ws1 = CreateWorkspace(dataX1, dataY1, dataE1)
#Create an absolute path by joining the proposed filename to a directory
#os.path.expanduser("~") used in this case returns the home directory of the current user
savefile = os.path.join(os.path.expanduser("~"), "AsciiFile.txt")
# perform the algorithm
SaveAscii(InputWorkspace=ws1,Filename=savefile)
#Load it again - Load would work just as well as LoadAscii
wsOutput = LoadAscii(savefile,Unit="Label")
print CompareWorkspaces(ws1,wsOutput)[0]
#clean up the file I saved
os.remove(savefile)
Output:
True
Categories: Algorithms | DataHandling\Text