Starting Sherpa
![[CXC Logo]](/ciao/imgs/cxc-logo.gif)
Sherpa Threads (CIAO 4.3 Sherpa v1)
Overview
Synopsis:
This thread describes how to start Sherpa for the first time, how to access the help files for Sherpa commands in a variety of ways, as well as how to customize the Sherpa environment.
Last Update:
15 Dec 2010 - updated with an explanation of the Sherpa start-up banner
Contents
- Starting Sherpa for the First Time
- Getting Help
- Finding a Command
- Running CIAO and unix commands from the Sherpa Prompt
- Exiting Sherpa
- Command-line options for Sherpa
- Using Sherpa from Python
- Customizing the Sherpa Environment
- History
Starting Sherpa for the First Time
When Sherpa is started from within the CIAO environment, the user is informed of the CIAO version number, Sherpa package number, and date at which CIAO was installed on the user's system:
unix% ciao CIAO 4.3 Thursday, December 2, 2010 bindir : /soft/ciao/bin unix% sherpa ----------------------------------------------------- Welcome to Sherpa: CXC's Modeling and Fitting Package ----------------------------------------------------- CIAO 4.3 Sherpa version 1 Thursday, December 2, 2010
The Sherpa package number is indicated by "version 1" in the above message. This means this is the first version of Sherpa released with CIAO 4.3 - i.e., the major release version. If an intermediate patch of Sherpa is later released for CIAO 4.3, the package number will be incremented for that patch release, and the above text would change to "version 2".
The Sherpa script loads the Sherpa (Python) module, as well as the Crates module, which handles file input and output, and the ChIPS module, which provides the plotting capabilities.
Default Sherpa settings are defined in the $HOME/.sherpa.rc file, which is processed when Sherpa is started; this file can be modified as described in the section Customizing the Sherpa Environment.
The Sherpa and ChIPS applications use the $HOME/.ipython-ciao/ directory to store configuration information. The first time Sherpa or ChIPS is started you will see a message asking whether you want to update your ipythonrc-sherpa or ipythonrc-chips file.
unix% ciao unix% sherpa ATTENTION: Out of date IPython profile for Sherpa found in: /home/username/.ipython-ciao Local version (40201) vs latest (40301). Update to latest? [Y/N] :
Unless you have manually changed your $HOME/.ipython-ciao/ipythonrc-sherpa(or -chips) file, it is safe to answer "Y" here. The outdated file is renamed with a timestamp to preserve it. The new profile is installed read-only. If you would like to modify how Sherpa uses IPython functions, or call "execfile" to load Python scripts when Sherpa starts, the customization file ~/.ipython-ciao/ipythonrc-sherpa-user should be used. If you would like IPython profiles to be somewhere other than ~/.ipython-ciao, you can set IPYTHONDIR to point to the desired directory.
Sherpa is run in the Python scripting language. As of the release of Sherpa version 2 in CIAO 4.2, the Sherpa S-Lang interface is no longer supported; there is no longer any means of importing Sherpa as a S-Lang module. Therefore, the "-l" command-line option has been removed, and Sherpa no longer reads the environment variables CIAO_SCRIPT_LANG or SHERPA_SCRIPT_LANG. The following are the remaining command-line options which may be specified when Sherpa is started:
unix% sherpa -h -- sherpa usage: sherpa [-x] [-n] [-b] [-rcfile file] [norcfile] <file> -x launch sherpa shell in separate display terminal -n do not print banner -b batch mode -rcfile load a user specifiable preference file -norcfile do not load any user specifiable preference file (overrides -rcfile) <file> appropriate python command file to execute
See the section Command-line Options for Sherpa for more details on these Sherpa startup options.
Getting Help
There are several ways to access the Sherpa help files.
From the CIAO command line
-
Python syntax, description and examples for a specific command:
unix% ahelp <command>
From within Sherpa
From within Python, ahelp may be called in several ways:
-
Python:
sherpa> ahelp "<command>"
or
sherpa> !ahelp <command>
or
sherpa> ,ahelp <command>
Finding a Command
Here are some tips on how to find the name of a command while working in Sherpa.
In Python: ? and <TAB>
To search for a phrase, use the "?" system; the ? is placed after the string:
sherpa-6> *arf* ? get_arf get_arf_plot get_bkg_arf is_arf load_arf load_bkg_arf load_multi_arfs plot_arf read_arf set_arf unpack_arf write_arf
Type the start of a command and hit <TAB> for all possible completions:
sherpa-7> write_ write_arf write_file write_pha write_rmf
Running CIAO and unix commands from the Sherpa Prompt
Any line beginning with "!" is passed from Sherpa to the shell. This allows you to run CIAO and shell commands from the Sherpa prompt.
For example:
sherpa-8> !pwd /data/ciao_demo/threads/acis-s/1838/primary sherpa-9> !ls acisf01838_000N001_bpix1.fits acisf01838N001_src2.fits acisf01838N001_evt2.fits pcadf084244404N001_asol1.fits sherpa-10> !dmkeypar acisf01838N001_evt2.fits OBJECT echo+ G21.5-0.9 sherpa-11> !dmcopy "acisf01838N001_evt2.fits[energy=300:10000]" 1838_energy.fits
Command-line options for Sherpa
The Sherpa command-line options can be listed with the -h flag:
unix% sherpa -h -- sherpa usage: sherpa [-x] [-n] [-b] [-rcfile file] [norcfile] <file> -x launch sherpa shell in separate display terminal -n do not print banner -b batch mode -rcfile load a user specifiable preference file -norcfile do not load any user specifiable preference file (overrides -rcfile) <file> appropriate python command file to execute
- -x
-
This will create a new Xterm and start Sherpa in it.
- -n
-
This switch causes Sherpa to start without a banner:
unix% sherpa -n sherpa-1>
- -b
-
This flag does not work correctly in CIAO 4.2.
- -rcfile
-
This option allows the user to specify a specific .sherpa.rc file to use; refer to "ahelp sherparc" for details.
- -norcfile
-
This option specifies that a .sherpa.rc file should not be loaded; overrides "-rcfile" if both are set.
- <file>
-
The contents of the file are executed before the user is prompted for further commands. The command must be in the same language as used at the interactive prompt. So, if simple.py contained
unix% cat simple.py load_pha("src.pi") plot_data() print "Loaded and plotted data"
then we will load and plot the data if Sherpa is started by saying:
unix% sherpa python simple.py ----------------------------------------------------- Welcome to Sherpa: CXC's Modeling and Fitting Package ----------------------------------------------------- CIAO 4.3 Sherpa version 1 Thursday, December 2, 2010 read ARF file src.arf read RMF file src.rmf read background file bgnd.pi Loaded and plotted data sherpa-2> print info() Window [win1] Frame [frm1] Plot [plot1] (0.15,0.15) .. (0.90,0.90) Border bottom [bx1] top [bx2] left [by1] right [by2] X Axis [ax1] Y Axis [ay1] Curve [crv1] sherpa-3>
Using Sherpa from Python
The Sherpa, ChIPS, and Crates modules can be loaded into Python by typing:
from sherpa.astro.ui import * from pychips import * from pychips.hlui import * from pycrates import *
Customizing the Sherpa Environment
When Sherpa is started, it processes the $HOME/.sherpa.rc resource file, which defines the default behavior for Sherpa commands. You can modify the settings in this file in any text editor to suit your preferences; see the .sherpa.rc ahelp file for detailed descriptions of the available settings.
For example, if you have installed the plotting package PyLab and would like Sherpa to plot with this program instead of the default CIAO plotting package (ChIPS), you would change the entry for the 'plot_pkg' option in the Sherpa resource file from 'chips' to 'pylab':
unix% grep plot_pkg ~/.sherpa.rc plot_pkg : pylab
If the plotting package is ChIPS, any preferences set in the $HOME/.chips.rc resource file will be available during plotting. There is an option to override the .chips.rc settings in .sherpa.rc; refer to the "[chips]" section of the .sherpa.rc ahelp file for details.
History
14 Nov 2007 | new for CIAO 4.0 Beta 3 |
15 Dec 2008 | CIAO 4.1 - when Sherpa is started a banner is now displayed (by default); Python or S-Lang mode for Sherpa can now be chosen using the -l flag; the SHERPA_SCRIPT_LANG environment variable has been superceded by the CIAO_SCRIPT_LANG variable; a number of command-line options are now available |
31 Mar 2009 | added section "Customizing the Sherpa Environment" |
15 Dec 2009 | updated for CIAO 4.2 |
29 Jun 2010 | updated for Sherpa v2 in CIAO 4.2: the Sherpa S-lang interface has been removed. Users who are running CIAO 4.2 Sherpa v1 may refer to the version of this thread on the Sherpa v1 site. |
15 Dec 2010 | updated with an explanation of the Sherpa start-up banner |