RSS Feed


Comments RSS

PyFITS Cheat Sheet

PyFITS is a Python module to facilitate the reading, editing and creation of Flexible Image Transfer System (FITS) files.  FITS is a common data interchange medium in the astronomical community.

PyFITS Cheat Sheet, working with the FITS file Header Data Unit(HDU)

extracted from The PyFITS Handbook

see also:  A Primer on the FITS Data Format

#load the pyfits module into Python
import pyfits

#initialize a fits file object
hdulist =‘input.fits’)

#when finished close the file object

#get info from the fits file

#get the value of a particular keyword in the HDU

#get the value of a particular keyword index in the HDU

#assign new values to keywords or indexes in the HDU
prihdr = hdulist[0].header
prihdr[’targname’] = ’NGC121-a’
prihdr[27] = 99

#view the entire HDU contents
prihdr = hdulist[0].header

#update (add) the HDU with a new keyword and value
prihdr.update(’observer’, ’Edwin Hubble’)

#add history or comment records to HDU
prihdr.add_history(’I updated this file 2/26/09’)
prihdr.add_comment(’Edwin Hubble really knew his stuff’)

#access the HDU as Cards, display first three cards of HDU
print prihdr.ascardlist()[:3]
SIMPLE =    T / file does conform to FITS standard
BITPIX =    16 / number of bits per data pixel
NAXIS =     0 / number of data axes

#list all the keywords of the HDU

#write out the changes made to the in memory fits object

#saving changes to fits file using update mode
f =’original.fits’, mode=’update’)
… # making changes in data and/or header
f.flush() # changes are written back to original.fits

The Night Sky

I have always been a person of the countryside. I grew up in small Texas towns, usually outside of town in the countryside. Currently, I have the pleasure of living on the eastern edge of the Greens Creek valley here in Erath County, TX. It affords me a wonderful horizon from the South West to the West. Lately, I have taken notice of what a good location I have for star gazing. Several times in the last few weeks I have had exceptionally clear skies and the Milky Way seemed to be exploding across the sky. I have even seen a couple nice shooting stars. Nothing like a beautiful night sky to open up the wonders of creation before you. The majesty of the Creator seems to be made manifest at such times. I have taken an interest in star gazing and am beginning to pursue it now. I guess it was probably inevitable and a lot of factors have contributed to that. First, living in such a good viewing area. Second, having a good friend who is the manager of the planetarium at Tarleton State University and also the tech at the university observatory. He takes students and members of the public out on star watching parties at the observatory. Finally, I have installed a very nice astronomy program on my Ubuntu laptop called Stellarium. While not highly complex, it is an entirely useful and elegant free program. It is a very good guide to the night sky which helps as I am a complete novice at this. I have decided for now to just work on naked-eye astronomy, no external optics. I want to learn the sky as man learned it for eons. I want to see what they saw and notice what they noticed. I want to understand how men have found their way by the stars from time immemorial. I want to learn the sky for the times and the seasons and to look up and see the constellations come into view as the procession of the stars passes overhead. The night sky, such a beautiful thing.