read_table

sherpa.astro.io.read_table(arg, ncols=2, colkeys=None, dstype=<class 'sherpa.data.Data1D'>)[source]

Create a dataset from a tabular file.

The supported file types (e.g. ASCII or FITS) depends on the selected I/O backend.

Parameters:
  • arg – The name of the file or a representation of the file (the type depends on the I/O backend).
  • ncols (int, optional) – The first ncols columns are read from the file.
  • colkeys (None or list of strings, optional) – If given, select these columns from the file.
  • dstype (optional) – The data type to create (it is expected to follow the sherpa.data.BaseData interface).
Returns:

data

Return type:

a sherpa.data.BaseData derived object

Examples

The following examples do not contain argument types specific to a particular I/O backend.

Create a sherpa.data.Data1D object from the first two columns in the file src.fits:

>>> d = read_table('src.fits')

Create A sherpa.data.Data1DInt object from the first three columns in the file src.fits:

>>> d = read_table('src.fits', ncols=3, dstype=Data1DInt)

Create a sherpa.data.Data1D data set from the specified columns in tbl.fits, where WLEN is used for the independent axis, FLUX the dependent axis, and FLUXERR for the statistical error on the dependent axis:

>>> d = read_table('tbl.fits', colkeys=['WLEN', 'FLUX', 'FLUXERR'])