Developing Sherpa with Python

Sherpa is the general purpose fitting and modeling application for CIAO, the Chandra Interactive Analysis of Observations system. We have modified the original design and implemented a new version in Python. This version will be part of the upcoming CIAO4.0 release. We have previously presented a modular, flexible design for CIAO4.0 with the goal of packaging many models, fitting methods and statistics for analysis of astronomical data. The new design promised to be more robust than the previous Sherpa, and more easily extensible with user-written scripts. (We already see some sign of this, in that there were 50,000 lines of code in the CIAO3.0 implementation; with our new, cleaner design, implemented in Python, only half that number of lines were required.) We present the latest updates to our design, and our progress developing Sherpa. A major feature of this work has been the use of Python to implement the data structures from our design. Each part of Sherpa—models, fitting methods, statistics, and so on—has been implemented as a Python module. We have also developed application code to bind together data, models, statistics, and fitting methods for performing fits to data, as well as a high-level UI that makes it simple for users to read in data, define models, and perform fits. Working in Python has been a great aid in speeding development of Sherpa. We expect that Python will also simplify extending and maintaining the Sherpa code base, as well as making it possible to interoperate with other Python-based astronomy packages. To make Sherpa fully accessible to S–Lang users, we use PySL, a new package that is an interface between Python and S– Lang. Users are now able to import other Python or S–Lang modules to extend Sherpa; in addition, users may write and use scripts of their own, written in either Python or S–Lang. 1. Design and Python Implementation The design of Sherpa is in three layers, as shown in Figure 1. The base modules constitute the first layer; each module provides a set of functions (models, optimization functions, statistics, and also astronomy-specific functions) that are needed by the application. But each base module is independent, and can be used by itself in other programs. The C++ or Fortran functions they wrap can be directly linked to standalone programs (e.g., a C program that needs only to calculate Sherpa models), without having to link to Python or any other Sherpa modules. Any of the modules in this layer can also be loaded into Python. We 543