Last modified: December 2024

URL: https://cxc.cfa.harvard.edu/sherpa/ahelp/load_ascii_with_errors.html
Jump to: Description · Examples · PARAMETERS · Notes · Bugs · See Also


AHELP for CIAO 4.17 Sherpa

load_ascii_with_errors

Context: data

Synopsis

Load an ASCII file with asymmetric errors as a data set.

Syntax

load_ascii_with_errors(id, filename=None, colkeys=None, sep=' ',
comment='#', func=average, delta=False)

Description

Create a dataset with asymmetric error bars which can be used with resample_data to fit a model using the asymmetric errors with a parametric bootstrap approach. Note that the func argument is used to provide an estimate for a symmetric error (the default is to average the low and high limits) which is then used with calls like calc_stat and fit.


Examples

Example 1

Read in the first four columns of the file, as the independent (X), dependent (Y), error low (ELO) and error high (EHI) columns of the default data set:

>>> load_ascii_with_errors('sources.dat')

Example 2

Read in the first four columns (x, y, elo, ehi) where elo and ehi are of the form y - delta_lo and y + delta_hi, respectively.

>>> load_ascii_with_errors('sources.dat', delta=True)

Example 3

Read in the first four columns (x, y, elo, ehi) where elo and ehi are of the form delta_lo and delta_hi, respectively. The `func` argument is used to calculate the error based on the elo and ehi column values, and uses the RMS value of the low and high values:

>>> def rms(lo, hi):
...     return numpy.sqrt(lo * lo + hi * hi)
...
>>> load_ascii_with_errors('sources.dat', func=rms)

PARAMETERS

The parameters for this function are:

Parameter Type information Definition
id int or str, optional The identifier for the data set to use. If not given then the default identifier is used, as returned by `get_default_id` .
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).
sep str, optional The separator character. The default is ' ' .
comment str, optional The comment character. The default is '#' .
func python function, optional The function used to combine the lo and hi values to estimate an error. The function should take two arguments (lo, hi) and return a single NumPy array, giving the per-bin error. The default function used is numpy.average.
delta boolean, optional The flag is used to indicate if the asymmetric errors for the third and fourth columns are delta values from the second (y) column or not. The default value is False

Notes

The function does not follow the normal Python standards for parameter use, since it is designed for easy interactive use. When called with a single un-named argument, it is taken to be the `filename` parameter. If given two un-named arguments, then they are interpreted as the `id` and `filename` parameters, respectively. The remaining parameters are expected to be given as named arguments.

The column order for the different data types are as follows, where x indicates an independent axis, y the dependent axis, the asymmetric errors elo and ehi . elo and ehi assumed to be positive values. They are used to calculate staterror for fit with chi2 statistics. Note that set_stat will not impact the statistics values for the fitting this type of data and fit will always use staterror in this case. resample_data will assume set_stat setting in calculating the statistics for bootstrap sampling.

Identifier Required Fields
Data1DAsymmetricErrs x, y, elo, ehi

Bugs

See the bugs pages on the Sherpa website for an up-to-date listing of known bugs.

See Also

data
load_ascii, resample_data