load_table_model

sherpa.astro.ui.load_table_model(modelname, filename, *args, **kwargs) None

Load tabular or image data and use it as a model component.

A table model is defined on a grid of points which is interpolated onto the independent axis of the data set. The model has a single parameter, ampl, which is used to scale the data, and it can be fixed or allowed to vary during a fit. The load_xstable_model routine must be used with XSPEC table models.

Tables can take many forms. The most common are 1D data (with 2 columns), 1D data with integrated bins (with columns xlow, xhigh, y), and 2D data such as an image. This function will try to infer the format of the data from the structure of the file given. Details also depend on the file type (fits or ascii) and the backend in use (crates, astropy, or just the build-in ascii reader).

Parameters:
modelnamestr

The identifier for this table model.

filenamestr

The name of the file containing the data, which should contain two columns, which are the x and y values for the data, or be an image.

methodfunc, optional

The interpolation method to use to map the input data onto the coordinate grid of the data set. Sherpa provides linear_interp, nearest_interp, neville, and neville2d in sherpa.utils but other functions with the same signature can be used.

kwargs

The accepted keyword arguments depend on the file type and backend used to read in the data. They are listed in the “notes” section below.

See also

load_conv

Load a 1D convolution model.

load_psf

Create a PSF model

load_template_model

Load a set of templates and use it as a model component.

load_xstable_model

Load a XSPEC table model.

set_model

Set the source model expression for a data set.

set_full_model

Define the convolved model expression for a data set.

Notes

  • Keywords for ASCII tables

    ncolsint, optional

    The number of columns to read in (the first ncols columns in the file). This is ignored if colkeys is given.

    colkeysarray of str, optional

    An array of the column name to read in. The default is None.

    sepstr, optional

    The separator character. The default is ' '.

    dstypedata class to use, optional

    Used to check that the data file contains enough columns.

    commentstr, optional

    The comment character. The default is '#'.

    require_floatsbool, optional

    If True (the default), non-numeric data values will raise a ValueError.

  • Keywords for FITS tables

    ncols: int, optional

    The number of columns to read in when colkeys is not set (the first ncols columns are chosen).

    colkeys: sequence of str or None, optional

    If given, what columns from the table should be selected, otherwise the backend selects. The default is None. Names are compared using a case insensitive match.

    make_copy: bool, optional

    If set then the returned NumPy arrays are explicitly copied, rather than using a reference from the data structure created by the backend. Backends are not required to honor this setting. The default is True.

    fix_type: bool, optional

    Should the returned arrays be converted to the sherpa.utils.numeric_types.SherpaFloat type. The default is True.

    blockname: str or None, optional

    The name of the “block” (HDU) to read the column data (useful for data structures containing multiple blocks/HDUs) or None. Names are compared using a case insensitive match.

    hdrkeys: sequence of str or None, optional

    If set, the table structure must contain these keys, and the values are returned. Names are compared using a case insensitive match.

  • Keywords for FITS images

    coord{ ‘logical’, ‘image’, ‘physical’, ‘world’, ‘wcs’ }, optional

    Ensure that the image contains the given coordinate system.

    dstypeoptional

    The image class to use. The default is DataIMG.

Examples

Load in the data from “filt.fits” and use it to multiply the source model (a power law and a gaussian). Allow the amplitude for the table model to vary between 1 and 1e6, starting at 1e3.

>>> load_table_model('filt', 'filt.fits')
>>> set_source(filt * (powlaw1d.pl + gauss1d.gline))
>>> set_par(filt.ampl, 1e3, min=1, max=1e6)

Load in an image (“broad.img”) and use the pixel values as a model component for data set “img”:

>>> load_table_model('emap', 'broad.img')
>>> set_source('img', emap * gauss2d)