=== Perry Greenfield - pyfits and pyraf === --- pyfits --- >>> import pyfits >>> pyfits.info('pix.fits') # get info >>> im = pyfits.getdata('py.fits) # load >>> import numdisplay >>> numdisplay.display(im) # view image with, e.g., ds9 >>> hdr = pyfits.getheader('pix.fits') # FITS headers have keywords and values; load to memory >>> print hdr['date'] # use as a dictionary >>> hdr['date'] = '4th of July' >>> hdr.update('newkey','value') # but do this to add key # lots more stuff in adding 'cards', writing data to file... >>> tab = pyfits.getdata('alpha.fits') # can also work with tables (FITS BinTableHDU rather than ImageHDU) >>> tab.names # fields (i.e., columns) >>> tab.shape # record will show as one element >>> tab[0] # first row >>> flux = tab.field('flux') # create numpy array as view into data >>> wave[0] = 0 # can use view to change table # there's also an object-oriented interface to files >>> ff = pyfits.open('pix.fits') # open file object >>> sum = 0 >>> for hdu in ff[1:]: # look over images in this file, skip header sum = sum + hdu.data hdu.data = None # delete from memory to save space >>> ff.close() # can create new FITS tables starting from numpy arrays === David Cournapeau - numscons === - for users: - customization, ease of use - for developers: - dependency handling - fine-grained control of build - better configuration (libraries, platform) - new features (ctypes) - easier to understand - numscons - 0.9.1 on pypi - builds numpy and scipy all libraries - supports libraries - can change CFLAGS, CC on the fly... numscons will recompile objects - can build in parallel - extends scons to build Python extensions and fortran - scons - is python - has basic configuration system - each target can be built differently - is extensible - extensible, has good manual, good community - scons basics - Builder's - SharedLibrary("foo.c") - StaticLibrary("foo.c") - Program("foo.c") - each object is customizable - dependency handling through DAG - detected automatically by scanning source files - Environment's - global object to keep configurations - builders attach to environments - checking for library dependencies - config = env.Configure() - config.CheckLib(...) - config.Finish() - should know about pkgconfig - scons tools - e.g., a compiler - a python module with two public methods - sets up Environment values - complicated unfortunately... - as a build system or numpy, scipy - uses scons for low level build - simple, clear separation between core and customization - packages, subpackages, - numscons basics - NumpyEnvironment extends NumpyEnvironment - need setup.py (with add_sconscript), SConstruct, SConscript (do the real work): - env.DistutilsPythonExtension("hello", source = [...]) - env.NumpyPythonExtension - env.NumpyCtypesExtension - NumpyConfigure() - can generate a config.h header - Can use .in processor as in autoconf - env['SUBST_DICT] = {'@FOO1@': 'foo'} - env.SubstInFile('header.h','header.h.in') - for instance, use for f77 compiler mangling === Robert Bradshaw - Writing optimized extensions with Cython === - cython - almost a Python compiler - extended Python language for fast extensions, interfacing C/C++ libraries - not a dedicated wrapper like C - a Nov 2006 fork of Pyrex - efficient code - conditions and loops run 2-8x faster than Python - thanks to optional type declarations (Cython generates C rather than Python) - reads .pyx file and produces .c -> compiled into .so - cython basics - cdef keyword (in the future, use decorators?) - cdef type var - cdef return-type function - external functions - cdef extern from "math.h": double sin(double) double cos(double) - either link the library, or include the source code in the extension - put declarations in .pxd files; some already in Cython/Includes - memory management - full in Python, not in C - Cython has both - pointers - use int* for list of ints (malloced?) - cdef int* mylist = malloc(sizeof(int) * n) - access elements with [...] - but Python list is pretty fast - numpy integration (Dag Seljebotn) - new interface works for any object with buffer protocol - cimport numpy - cdef numpy.ndarray[int,dim=1] arr = x - use @cython.boundscheck(False) from "cimport cython" before function to speed it up - make it faster also by using unsigned indices (perhaps with casts) - extension classes - can have c attributes and methods - but not dictionaries, multiple inheritance - need cpdef to call methods from python - cython can wrap C++ somewhat - fool it by defining a structure - with special functions for new and delete