Chandra X-Ray Observatory
Skip to the navigation links
Last modified: December 2015

Jump to: Description · Examples · Bugs · See Also

AHELP for CIAO 4.9 Sherpa v1


Context: modeling


Load a table model, including X-Spec atable and mtable forms


load_table_model( modelname, filename|TABLECrate,
[ncols=2,colkeys=None,dstype=Data1D, method=linear_interp])
load_table_model( modelname, filename|IMAGECrate, [coord="logical"] )


The load_table_model command reads data from a file or crate and assigns it to an instance of the table model class that can be combined arithmetically with the source model. The table can be an additive (atable) or multiplicative (mtable) XSPEC-style table model, in which case the model will contain multiple parameters, otherwise, the table model stores the y-values from an input data file contains one parameter, the ampliture (ampl) to multiply these values by.

The Sherpa table model supports linear, nearest-neighbor, and polynomial interpolation. Interpolation is used by the table model to match the data grid to the model grid - which must match before the fit statistics can be calculated for fitting. Importing sherpa.utils is required in order to access available interpolation methods.

The Sherpa table model also supports interpolation of data points on the data set grid from the grid supplied from file. The grids need not be of constant or comparable bin size. If the table model grid is not sorted, Sherpa will sort it in ascending order.

The input may be 1D data from a FITS table, ASCII table data, or 2D data from a FITS image file; allowed crates types are TABLECrate and IMAGECrate.

  • modelname - the name for the table model
  • filename|TABLECrate|IMAGECrate - the name of the file (with path) or crate which contains the data
  • ncols (table input) - number of columns to read; default=2
  • colkeys (table input) - list of column names; default=None
  • dstype (table input) - dataset type: Data1D, Data1DInt, Data2D, Data2DInt; default=Data1D
  • coord (image input) - the coordinate system: logical, image, physical, world, or wcs; default=logical
  • method - interpolation method in sherpa.utils: linear_interp, nearest_interp, neville, neville2d; default=linear_interp

Selecting table columns

The columns to load are specified by a Data Model filter on the filename or the colkeys option of the load_table_model command, as shown in the examples. Vector columns are separated to form two dstype columns when the file is loaded.

If no columns are specified, the first two columns in the file are read by default. If only one column is specified, the dstype is irrelevant.

The columns must be listed in the order required by the dataset type:

Dataset type Columns
Data1D x, y
Data1DInt xlo, xhi, y
Data2D x0, x1, y
Data2DInt x0lo, x1lo, x0hi, x1hi, y

Selecting the interpolation method

Selection of interpolation methods is available in sherpa.utils. Importing sherpa.utils is required to access these methods.

This can be done for a specific function:

from sherpa.utils import  neville, nearest_interp, neville2d, linear interp

Example 1

sherpa> load_table_model("emap", "expmap.fits")

A table model named "emap" is created from the exposure map image in expmap.fits. The model can be viewed:

sherpa> print(emap)
   Param        Type          Value          Min          Max      Units
   -----        ----          -----          ---          ---      -----
   emap.ampl    thawed            1     -3.4e+38      3.4e+38

Example 2

sherpa> from sherpa.utils import nearest_interp
sherpa> load_table_model("tab", "file.fits", nearest_interp)

Create a table model named "tab" by loading file.fits and use the nearest-neighbor interpolation method. Note the required import for selecting the interpolation method.

Example 3

sherpa> imgcr = read_file("psf.img")
sherpa> load_table_model("psfmod", imgcr)

The image is read into an IMAGECrate (named "imgcr") from source.img. The crate is then used to create a table model named "psfmod".

Example 4

sherpa> load_table_model("pul", "coplrefl.fits")
sherpa> set_source(xsphabs.galabs * pul)
sherpa> pul.xi = 1.5
sherpa> pul.e_cut = 25

Here the XSPEC table mode "coplrefl.fits" is loaded as the model component "pul" and then used in a source expression.

sherpa> show_source()
Model: 1
(xsphabs.galabs * xstablemodel.pul)
   Param        Type          Value          Min          Max      Units
   -----        ----          -----          ---          ---      -----
   galabs.nH    thawed            1            0       100000 10^22 atoms / cm^2
   pul.xi       thawed          1.5        1.477        3.977
   pul.gamma    thawed            1          0.5          1.5
   pul.e_cut    thawed           25            5           30
   pul.e_fold   thawed           15            5           30
   pul.redshift frozen            0            0            5
   pul.norm     thawed            1            0        1e+24

Note that both additive (atable) and multiplicative (mtable) XSPEC-style table models are supported using load_table_model.

Example 5

sherpa> load_table_model("ma", "model1.fits")
sherpa> load_table_model("mb", "model1.fits")
sherpa> load_table_model("mc", "model2.fits")

Multiple table models can be loaded at once. They can use the same input file, or different ones, and be used as components in either the same or different source expressions.


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

See Also

dataspace1d, dataspace2d, datastack, fake, get_bkg_plot, load_arf, load_arrays, load_ascii, load_bkg, load_bkg_arf, load_bkg_rmf, load_data, load_grouping, load_image, load_multi_arfs, load_multi_rmfs, load_pha, load_quality, load_rmf, load_staterror, load_syserror, load_table, pack_image, pack_pha, pack_table, unpack_arf, unpack_arrays, unpack_ascii, unpack_bkg, unpack_data, unpack_image, unpack_pha, unpack_rmf, unpack_table
get_default_id, list_bkg_ids, list_data_ids, list_model_ids, show_bkg_model, show_bkg_source
add_model, add_user_pars, clean, create_model_component, delete_bkg_model, delete_model, delete_model_component, get_model, get_model_autoassign_func, get_model_component, get_model_component_image, get_model_component_plot, get_model_plot, get_num_par, get_order_plot, get_par, get_pileup_model, get_source, get_source_component_image, get_source_component_plot, image_model, image_model_component, image_source, image_source_component, integrate, integrate1d, link, load_template_model, load_user_model, normal_sample, reset, save_model, save_source, set_bkg_model, set_full_model, set_model_autoassign_func, set_pileup_model, set_source, set_xsabund, set_xscosmo, set_xsxsect, set_xsxset, t_sample, uniform_sample
get_lrt_plot, get_lrt_results, get_pvalue_plot, get_pvalue_results, plot_cdf, plot_model, plot_model_component, plot_pdf, plot_pvalue, plot_scatter, plot_source, plot_source_component, plot_trace
delete_psf, load_conv
save_arrays, save_data, save_delchi, save_error, save_filter, save_grouping, save_image, save_pha, save_quality, save_resid, save_staterror, save_syserror, save_table
calc_chisqr, calc_energy_flux, calc_model_sum, calc_photon_flux, calc_source_sum, calc_stat, eqwidth
contour_model, contour_ratio, contour_resid, get_ratio, get_resid

Last modified: December 2015
Smithsonian Institute Smithsonian Institute

The Chandra X-Ray Center (CXC) is operated for NASA by the Smithsonian Astrophysical Observatory. 60 Garden Street, Cambridge, MA 02138 USA.   Email: Smithsonian Institution, Copyright © 1998-2017. All rights reserved.