About Chandra Archive Proposer Instruments & Calibration Newsletters Data Analysis HelpDesk Calibration Database NASA Archives & Centers Chandra Science Links

Skip the navigation links
Last modified: 19 June 2009
Hardcopy (PDF): A4 | Letter

Running Scripts in Sherpa

Sherpa Threads (CIAO 4.1)

[Python Syntax]



Overview

Last Update: 19 Jun 2009 - original version

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.

Proceed to the HTML or hardcopy (PDF: A4 | letter) version of the thread.





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

                  or

	 unix% sherpa -l python 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()". Note that the "-l python" startup option is not necessary if your CIAO_SCRIPT_LANG environment variable is set to "python"; in this case, Sherpa defaults to the Python interface. See the Sherpa thread "Starting Sherpa" for details on 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.1.2 Thursday, April 2, 2009


	 sherpa-1> execfile("scriptname")
        


History

19 Jun 2009 original version

Return to Threads Page: Top | All | Intro
Hardcopy (PDF): A4 | Letter
Last modified: 19 June 2009


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-2004. All rights reserved.