Last modified: 15 December 2025

Writing out data to a file


Sherpa contains a number of routines that will write out data to a file. Most functions support writing out both ASCII and FITS binary files.

Writing out columns

The save_arrays is different to the other routines discussed here, in that you give it the columns to write out, rather than writing out a particular type of data, such as PHA or a data set.

The following will will create an ASCII and FITS binary table containing the independent and dependent axes of the default dataset as displayed by plot_data:

sherpa> dplot = get_data_plot()
sherpa> cols = [dplot.x, dplot.y]
sherpa> names = ["x", "y"]
sherpa> save_arrays("src.dat", cols, fields=names)
sherpa> save_arrays("src.fits", cols, fields=names, ascii=False)

Writing out data

The save_data, save_image, and save_table, functions will write out the basic components of a dataset.

Additional columns can be saved with one or more of: save_delchi, save_error, save_filter, save_resid, save_staterror, and save_syserror.

Evaluated models

The save_model and save_source functions will evaluate the model and write out the results, similar to the plot_model and plot_source calls.

PHA data

The save_arf, save_pha, and save_rmf routines will write out ARF, PHA, or RMF data.

The save_grouping and save_quality functions will write out the grouping and quality arrays, such as those created by calls to group_counts or group_snr.

Other commands

The save_all function is used to write out a Python file that will attempt to re-create the current session. This has the advantage of being human editable, as it is just a Python script, but it may not reflect all changes made to Sherpa (in particular if a file was loaded in but then the data was modified). It also does not save any other values created during the Sherpa session.

The save function will write out a binary file (a Python "pickled" file). This has the advantage of saving virtually everything needed (some special cases where external compiled code and modules have been loaded may not work), but

  1. these files are not guaranteed to load on machines running a differrent version of CIAO,
  2. and they are a huge security risk, as loading them in can end up running code which could do anything.

Great care should be taken before using the restore command to load in a file created by save.