read_data
- sherpa.io.read_data(filename: str, ncols: int = 2, colkeys: Sequence[str] | None = None, sep: str = ' ', dstype=<class 'sherpa.data.Data1D'>, comment: str = '#', require_floats: bool = True) Data[source] [edit on github]
Create a data object from an ASCII file.
- Parameters:
- filename
str The name of the ASCII file to read in.
- ncols
int,optional The number of columns to read in (the first
ncolscolumns in the file). This is ignored ifcolkeysis given.- colkeys
arrayofstr,optional An array of the column name to read in. The default is
None.- sep
str,optional The separator character. The default is
' '.- dstype
dataclasstouse,optional The class of the data object to create.
- comment
str,optional The comment character. The default is
'#'.- require_floatsbool,
optional If
True(the default), non-numeric data values will raise aValueError.
- filename
- Returns:
dataThe data object (created by calling the dstype constructor with the filename and then the data columns from the file).
- Raises:
sherpa.utils.err.IOErrRaised if a requested column is missing or the file appears to be a binary file.
ValueErrorIf a column value can not be converted into a numeric value and the
require_floatsparameter is True.
See also
Notes
The file format is described in
get_ascii_data.Examples
Create a 1D data object from the first two columns in the file:
>>> dat = read_data('src.dat')
Use the third column as the error column (statistical):
>>> dat = read_data('src.dat', ncols=3)
Read in a histogram data set, using the columns XLO, XHI, and Y:
>>> cols = ['XLO', 'XHI', 'Y'] >>> dat = read_data('hist.dat', colkeys=cols, dstype=sherpa.data.Data1DInt)
Use the first and third column from the file cols.dat, where the file has no header information:
>>> dat = read_data('cols.dat', colkeys=['col1', 'col3'])