Synopsis
Save the information about the current session to a text file.
Syntax
save_all(outfile=None, clobber: bool = False, auto_load: bool = True) No return value.
Description
This differs to the `save` command in that the output is human readable. Three consequences are:
- numeric values may not be recorded to their full precision
- data sets are not included in the file
- some settings and values may not be recorded (such as header information).
Examples
Example 1
Write the current Sherpa session to the screen:
>>> save_all()
Example 2
Save the session to the file 'fit.sherpa', overwriting it if it already exists:
>>> save_all('fit.sherpa', clobber=True)Example 3
Write the contents to a StringIO object:
>>> from io import StringIO >>> store = StringIO() >>> save_all(store) >>> print(store.getvalue()) import numpy from sherpa.astro.ui import * ...
Example 4
The two files should re-create the same session but restore2.py will include lines such as load_arf and load_bkg that are not necessary, as Sherpa will load them due to the ANCRFILE, BACKFILE, and RESPFILE keywords in the PHA file(s).
>>> save_all("restore1.py")
>>> save_all("restore2.py", auto_load=False)PARAMETERS
The parameters for this function are:
| Parameter | Type information | Definition |
|---|---|---|
| outfile | str or file-like, optional | If given, the output is written to this file, and the `clobber` parameter controls what happens if the file already exists. `outfile` can be a filename string or a file handle (or file-like object, such as StringIO ) to write to. If not set then the standard output is used. |
| clobber | bool, optional | If `outfile` is a filename, then this flag controls whether an existing file can be overwritten ( True ) orysif it raises an exception ( False , the default setting). |
| auto_load | bool, optional | If set to False then automatically-loaded PHA files, such as backgrounds, ARFS, and RMFs, will be included in the output with `load_arf` , `load_rmf` , and `load_bkg` calls. |
Notes
This command will create a series of commands that restores the current Sherpa set up. It does not save the original set of commands used, and not all Sherpa settings are saved. Items not fully restored include:
- data changed from the version on disk - e.g. by calls to `set_counts` - will not be restored correctly,
- any optional keywords to commands such as `load_data` ,
- user models may not be restored correctly,
- and only a subset of Sherpa commands are saved.
The `save` command can also be used for storing a Sherpa session and avoids some of these issues. However, it is not recommended if the session is likely to be restored with newer versions of Sherpa. It is suggested that the output of both should be checked when the output may be used long term.
Using the output of `save_all` depends on what interpreter is being used. If it is IPython then the %run command can be used. So, if save_all("save.out") was used then the output file can be loaded with:
%run -i save.out
When using the Python interactive environment the following can be used:
exec(open("save.out").read())Changes in CIAO
Changed in CIAO 4.18
Handling of PHA data has been improved, and the output now defaults to not including automatically-loaded ancillary files (such as background and responses). Set the auto_load flag to False to add these commands back to the save file (and match previous versions).
Changed in CIAO 4.17
The file will now contain a `set_default_id` call if the default identifier has been changed.
Changed in CIAO 4.16
Any set_psf calls are now included in the output file. The filter is no longer included if it does not exclude any data, and the code tries to recreate manually-created datasets (e.g. use of `dataspace1d` or `load_arrays` ), but not all situations are handled. XSPEC table models are now correctly restored.
Bugs
See the bugs pages on the Sherpa website for an up-to-date listing of known bugs.
See Also
- contrib
- save_chart_spectrum, save_marx_spectrum
- modeling
- save_model, save_source
- saving
- restore, save, 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, script