unpack_ascii¶
-
sherpa.astro.ui.
unpack_ascii
(filename, ncols=2, colkeys=None, dstype=<class 'sherpa.data.Data1D'>, sep=' ', comment='#')¶ Unpack an ASCII file into a data structure.
Parameters: - filename (str) – The name of the file to read in. Selection of the relevant column depends on the I/O library in use (Crates or AstroPy).
- ncols (int, optional) – The number of columns to read in (the first ncols columns in the file). The meaning of the columns is determined by the dstype parameter.
- colkeys (array of str, optional) – An array of the column name to read in. The default is
None
. - sep (str, optional) – The separator character. The default is
' '
. - comment (str, optional) – The comment character. The default is
'#'
. - dstype (optional) – The data class to use. The default is Data1D and it is expected to be derived from sherpa.data.BaseData.
Returns: The type of the returned object is controlled by the dstype parameter.
Return type: instance
See also
load_ascii()
- Load an ASCII file as a data set.
set_data()
- Set a data set.
unpack_table()
- Unpack a FITS binary file into a data structure.
Examples
Read in the first two columns of the file, as the independent (X) and dependent (Y) columns of a data set:
>>> d = unpack_ascii('sources.dat')
Read in the first three columns (the third column is taken to be the error on the dependent variable):
>>> d = unpack_ascii('sources.dat', ncols=3)
Read in from columns ‘col2’ and ‘col3’:
>>> d = unpack_ascii('tbl.dat', colkeys=['col2', 'col3'])
The first three columns are taken to be the two independent axes of a two-dimensional data set (
x0
andx1
) and the dependent value (y
):>>> d = unpack_ascii('fields.dat', ncols=3, dstype=sherpa.astro.data.Data2D)
When using the Crates I/O library, the file name can include CIAO Data Model syntax, such as column selection. This can also be done using the colkeys parameter, as shown above:
>>> d = unpack_ascii('tbl.dat[cols rmid,sur_bri,sur_bri_err]', ncols=3)