Chandra X-Ray Observatory (CXC)
Skip to the navigation links
Last modified: 13 Dec 2012

URL: http://cxc.harvard.edu/sherpa/threads/runscripts/thread.html

Running Scripts in Sherpa

Sherpa Threads (CIAO 4.5 Sherpa v1)


Overview

Synopsis:

This thread lists the available options for running scripts of Sherpa commands in the Python interface of Sherpa. In this thread we refer to a "script" as an ASCII file containing a list of Python Sherpa commands.

Last Update: 13 Dec 2012 - Sherpa start-up banner updated for CIAO 4.5


Running scripts in Python

1) To run a script of Python Sherpa commands within the Python environment before starting a Sherpa session:

a) type the following at the Unix prompt:
         unix% sherpa scriptname
        
This will open Python Sherpa and run the batch of commands contained in the script. If you want to exit Sherpa after the script completes, add an exit line to the end of your script: "exit()". See the Sherpa thread "Starting Sherpa" for details on all startup options.

b) or complete the following steps:
  • add these lines to the top of the script of Python Sherpa commands so that you can execute the script from the Unix command line without having to explicitly start a Sherpa session:
 
	    #!/usr/bin/env python
	    from sherpa.astro.ui import *
          
  • make the script executable
            unix% chmod +x scriptname
          
  • and run the script by typing the script name at the Unix prompt.
	    unix% ./scriptname
          

Again, if you want to exit Sherpa after the script completes, add an exit line to the end of your script: "exit()".

2. If you would like to run a script from within a session of Python Sherpa, you can use the "execfile" command:

unix% sherpa 
-----------------------------------------------------
Welcome to Sherpa: CXC's Modeling and Fitting Package
-----------------------------------------------------
CIAO 4.5 Sherpa version 1 Thursday, December 13, 2012


sherpa-1> execfile("scriptname")
        

History

09 Jun 2009 original version
17 Dec 2009 updated for Sherpa 4.2
29 Jun 2010 updated for CIAO 4.2 Sherpa v2: the Sherpa S-Lang interface has been removed.
15 Dec 2010 Sherpa start-up banner updated for CIAO 4.3
15 Dec 2011 Sherpa start-up banner updated for CIAO 4.4
13 Dec 2012 Sherpa start-up banner updated for CIAO 4.5

Return to Threads Page: Top | All

Last modified: 13 Dec 2012
CXC logo

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