Monday, October 20, 2014

How do I use the standalone build of Sherpa to fit my data?


I've put together a simple IPython notebook showing off the new standalone Sherpa build. The notebook runs through a simple polynomial fit and is based on the "Introduction to NumPy/SciPy" course from the Practical Python for Astronomers site. 

It highlights

  • using the Sherpa standalone package along with other Python packages (astropy, matplotlib, numpy)
  • how to use the "high-level" API (as described in the CIAO documentation), which provides  data management in a manner similar to the Xspec spectral fitting package
  • how to use the "low-level" API, which is unfortunately poorly documented as this time 
One thing it doesn't really cover is how easy it is to switch from a polynomial model to a more-complex one. Oh well, perhaps next time.

Mentioning a next time, hopefully I'll have time to add more notebooks soon; check at the notebook viewer page to see if any have been added, or go to the GitHub page for this project. If you'd like to see any topic covered, please mention it in the comments.

Saturday, October 4, 2014

Sherpa 4.7b binary release


Sherpa standalone binary package was released on 26 September, 2014.  It was built and tested on Linux 32, Linux 64 and Mac OSX and can be installed into Anaconda Python. The plan is to migrate the code to github for  December source release.

Thursday, January 30, 2014

Sherpa Fitting in ds9

You can now use Sherpa fitting directly from ds9. Several basic spectral and image models are loaded via CIAO analysis tools for a quick look at the model parameters. Here is the video from Kenny showing you how to do it: Fitting in ds9

Tuesday, July 9, 2013

Standalone Sherpa 4.5.1 Released as Source Code (Bug Fixes for GCC, clang, Macports)

I have released the standalone version of Sherpa 4.5.1 at the Sherpa website:

http://cxc.cfa.harvard.edu/contrib/sherpa/

And on github at the Sherpa repository:

https://github.com/cxcdev/sherpa

As in past releases, the purpose is to allow Python users to install Sherpa as a Python module, without reference to any other CIAO package or program.

No new features have been added since the release of Sherpa 4.5.0. However, I have added bug fixes to allow Sherpa to build with GCC 4.7 and 4.8; with clang on OS X; and to install in /opt/local/lib for Macports.

These fixes were contributed by Tim van Werkhoven of Leiden University.

I release the source code tarball, sherpa-4.5.1.tar.gz, that contains all the Sherpa source code we released with CIAO 4.5, plus these latest bug fixes.  Release notes for the patch can be found at NOTES-4.5.1.txt; release notes for the original Sherpa 4.5.0 release can still be found at NOTES-4.5.0.txt

This is a minor release, to allow Sherpa to build with newer compilers.

Wednesday, June 19, 2013

Use 'fake' function to generate image with Poisson noise


I often get a question whether it is possible to generate simulated image data in Sherpa. It is really easy to do it using fake() function. This function will use the specified model expression and add a Poisson noise to that model and generate an image.

Here are the simple steps in Sherpa interactive session:

dataspace2d( [256, 256 ])                   # set the size of the image data
set_model( beta2d.bb +const2d.cc )    # define model expression 
                                                         # in Sherpa - beta2d and constant 
set_par(bb.xpos, 128.)                        # x coordinate for  the beta2d model
set_par(bb.ypos, 128.)                        # y coordinates for the beta2d model
set_par(bb.ampl, 10.)                          # amplitude of the beta2d model
fake()                                                # generate the counts data from the model
                                                        #  with Poisson noise
image_fit()                                         # display simulated data, model and 
                                                        # residual images


ds9 image below shows the simulated data
on the left and model image on the right
the residual image on the bottom.


Wednesday, February 13, 2013

Running IPython Notebook in CIAO/Sherpa

I wanted to work with  IPython Notebook  in CIAO to create a nice record of analysis for my collaborators. Sherpa uses IPython 0.13, but CIAO does not come with 'pyzmq' and 'tornado'  required for running the Notebook. I also needed to install zmq library.  

Here are my installation steps after my downloading and installing CIAO 4.5 binaries on my iMAC OS 10.6.8:

1/ Start with "zmq" library. 

   Download  zeromq-3.2.2.tar.gz (version from23-Nov-2012 09:01) from: http://download.zeromq.org

tar xvf zeromq-3.2.2.tar.gz       
cd zeromq-3.2.2      
 ./configure
make
sudo make install

2/  Install pyzmq into CIAO area.

    Need to "source $ASCDS_INSTALL/bin/ciao.csh" to be in CIAO environment for installation in CIAO Python site-packages area. This can be done with "ciaorun" as I did below:
download the source file pyzmq-2.2.0.tar.gz from: http://pypi.python.org/pypi/pyzmq/2.2.0

tar xvf pyzmq-2.2.0.tar.gz
cd pyzmq-2.2.0
ciaorun python setup.py install \
  --prefix=$ASCDS_INSTALL

3/ Install tornado into CIAO area.

 Download the source file tornado-2.4.1.tar.gz from: http://pypi.python.org/pypi/tornado

tar xvf tornado-2.4.1.tar.gz
cd tornado-2.4.1/
ciaorun python setup.py install \
  --prefix=$ASCDS_INSTALL

4/ Run IPython Notebook


ipython notebook will start  a notebook session in your browser. Open the New Notebook to get to the interactive session. In the first cell type:

import numpy as np
from sherpa.astro.ui import *
from pychips import *

and then shift-return to run it. In the second cell:

x = np.arange(20)
y = np.sin(x)
add_curve(x,y)

shift-return to run it. You should see the CHIPS plot appearing outside the browser.

Monday, January 21, 2013

Standalone Sherpa Installation for X-ray Analysis

Tom just updated the instructions for building Standalone 4.5 Sherpa for X-ray Analysis. This build is good for all types of data modeling not only X-rays.  Check out the AstroPython web page: http://www.astropython.org/