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

LoadAscii v2

../_images/LoadAscii-v2_dlg.png

LoadAscii dialog.

Summary

Loads data from a text file and stores it in a 2D workspace or Table Workspace.

See Also

SaveAscii

Properties

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’, ‘AtomicDistance’, ‘Degrees’, ‘DeltaE’, ‘DeltaE_inFrequency’, ‘DeltaE_inWavenumber’, ‘dSpacing’, ‘dSpacingPerpendicular’, ‘Empty’, ‘Energy’, ‘Energy_inWavenumber’, ‘Label’, ‘Momentum’, ‘MomentumTransfer’, ‘Phi’, ‘QSquared’, ‘SpinEchoLength’, ‘SpinEchoTime’, ‘Temperature’, ‘Time’, ‘TOF’, ‘Wavelength’]

SkipNumLines

Input

number

Optional

If given, skip this number of lines at the start of the file.

ForceDistributionTrue

Input

boolean

False

(default: false) If true, the loaded workspace is set to Distribution=true. If true, the Distribution flag, which may be in the file header, is ignored.

Description

The LoadAscii2 algorithm reads in spectra data from a text file and stores it in a Workspace2D as data points, or a Table Workspace if it is table data. 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 (Workspace 2D):

  • A single integer or blank line to denote a new spectra

  • For each bin, between two and four columns of delimited data in the following order: 1st column=X, 2nd column=Y, 3rd column=E, 4th column=DX (X error)

  • Comments can be included by prefixing the line with a non-numerical character which must be consistent throughout the file and specified when you load the file. Defaults to “#”

  • The number of bins is defined by the number of rows and must be identical for each spectra

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

The format must be (Table Workspace):

  • Two commented header lines

  • The first containing the column names

  • The second containing the column types (str, int, unit, long64, size_t, float, double, bool, V3D)

  • The number of column names, types and data items must match

The following is an example valid file of two columns:

# Instrument Name , Run Number
# str , int
MUSR,10245
IRIS,8465
SANS2D,20462

Usage

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: AlgorithmIndex | DataHandling\Text

Source

C++ header: LoadAscii2.h

C++ source: LoadAscii2.cpp