[AstroPy] Coding in Python to Read/Write a fits file.

Wayne Watson sierra_mtnview@sbcglobal....
Wed Apr 8 06:50:59 CDT 2009


I'm trying to focus on a part of the thread above ("Getting Started 
...."), so that it isn't lost in that very long thread and is simpler to 
deal with.  It appears that, at least, one can use pyfits to read fits 
files, and one can embed this code in a Python program.  I posted the 
coding aspects of doing this in a thread above, and finally someone 
responded with code that looks like:

    from matplotlib import pyplot as plt
    import pyfits

    image = pyfits.getdata('mpl51.fits')

    fig = plt.figure()
    ax = fig.add_subplot(111)
    ax.imshow(image)
    fig.canvas.draw()
    plt.show()

This is close to what I'm looking for. That is, executable Python code, 
and not interactive code one enters line by line. Right now I'm lacking 
a way to read, say, a jpg, fits, or gif file, and convert it to fits. 
I'm also lacking a way to convert the internal image format to fits. The 
latter is very important. The internal format is simple. An image 
640x480 pixels and 8-bits deep, b/w. jpg, etc. is already done for 
writing the internal file.  For fits files, I'd like to write very 
simple headers that have, say, lat/long of observer, a time stamp, and 
some other assorted items.

Items like plotting, manipulating (IP, for example) and displaying are 
secondary to the need to write a fits file from the internal file.
-- 

           Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

             (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time)****

          "Less than all cannot satisfy Man." -- William Blake
          




More information about the AstroPy mailing list