But I would like to show how simple it really is to use sumatra to
people unfamiliar with this way of doing numerical experiments. I
will illustrate this with a script taken from
tamasis-map which performs
map-making for the
Herschel Space Observatory
and in particular the PACS instrument.

This script consists in a few simple functions parametrized by a small
number of keywords. It takes a FITS file
as input and output another FITS file. The script can be executed from
the command line but no argument can be passed from the command line.

This is not what Sumatra expects. Sumatra expects a script which
accepts a configuration file which defines the parameters of the
numerical experiment. The configuration file should be passed from the
command line to the script and parsed.

So we should rewrite our map-making script in this manner. We can
separate it in two parts. A part parsing the configuration file.
This can be done for instance with the ConfigParser package.

This is a long code. But the longest part is used to define the data
type of the arguments. The idea here is that a section of the
configuration file correspond to a step of the map-making script. A
dictionary storing the parameters of each step is filled from the
values in the corresponding section.

Now the map-making script can be rewritten as a function accepting a
dictionary of dictionaries as follows :

One of Numpy very usefull feature is its ability to define very easily
an array with a very large choice of data types. For instance, this
gives the possibility to very easily test an algorithm for its
robustness against error propagation due to the floating point
precision. You could write something like this :

Changing the data dtype from 64 bits to 32 bits can save your code a
factor of 2 in memory usage. This can be very important for data
intensive applications. Numpy even provide a 16 bits float which can
be useful if precision requirements are not very high.

Here is a small function which shows how one can display slices of a
3d array using matplotlib imshow and Slider. I give it here as I did
not see this exemple anywhere else.

defcube_show_slider(cube,axis=2,**kwargs):""" Display a 3d ndarray with a slider to move along the third dimension. Extra keyword arguments are passed to imshow """importmatplotlib.pyplotaspltfrommatplotlib.widgetsimportSlider,Button,RadioButtons# check dimifnotcube.ndim==3:raiseValueError("cube should be an ndarray with ndim == 3")# generate figurefig=plt.figure()ax=plt.subplot(111)fig.subplots_adjust(left=0.25,bottom=0.25)# select first images=[slice(0,1)ifi==axiselseslice(None)foriinxrange(3)]im=cube[s].squeeze()# display imagel=ax.imshow(im,**kwargs)# define slideraxcolor='lightgoldenrodyellow'ax=fig.add_axes([0.25,0.1,0.65,0.03],axisbg=axcolor)slider=Slider(ax,'Axis %i index'%axis,0,cube.shape[axis]-1,valinit=0,valfmt='%i')defupdate(val):ind=int(slider.val)s=[slice(ind,ind+1)ifi==axiselseslice(None)foriinxrange(3)]im=cube[s].squeeze()l.set_data(im,**kwargs)fig.canvas.draw()slider.on_changed(update)plt.show()