[AstroPy] functional interface for PyFITS?

Perry Greenfield perry at stsci.edu
Mon Mar 21 09:17:54 CST 2005

Vicki Laidler has persuaded me that PyFITS should have a more 
functional interface as well as it's more object-oriented current 
interface. The gist of the argument is that many astronomers would like 
a simple call to get data or a header and not mess with opening, then 
digging down in the object structure to get at the data. I find that 
hard to argue with. Here are some proposed functions

getdata(filename, [ext, extname, extver, etc])
getheader(filename, [ext, extname, extver, etc])
getdataheader( [ext, extname, extver, etc]) # returns the data and 
header as a tuple
    # i.e., im, hdr = pyfits.getdataheader('mydata.fits')
    # Shorter name better? getdatahdr? getdh?

The defaults for these functions are the primary header if it contains 
data, if not the first extension. Otherwise the user must select the 
extension desired. The semantics are that these are file "atomic" 
operations. The file is opened, the data and/or the header are read, 
and then the file is closed. Memory mapped mode will not be supported 
(at least initially).

I don't see why it should not be possible to use a functional interface 
for writing and updates as well. Likewise, they open and close the 
specified file.

writeto(filename, data, hdr) # simple fits file is created
append(filename, data, hdr,) # appends if exists, created if it doesn't
update(filename, data, hdr, {ext or extname/extver required})
info(filename) # to print information on a FITS file

These functions should pass relevant validation keywords to the 
underlying functions and methods being used.

Comments? Any missing functions?


More information about the AstroPy mailing list