[AstroPy] Getting Started with Python and FITS

Maximilian Fabricius mxhf@gmx....
Wed Apr 1 07:07:29 CDT 2009


yes, well Fits has science! data...so yes its a matrix :)

I guess I would use pyfits to read the data matrix from the fits file
and then use
the imshow command from matplotlib to present it to the user.

import pyfits
import matplotlib as pylab

hdulist = pyfits.open("YOURFITSFILE.FITS")
data = hdulist[0].data # I assume its in the first extension

pylab.imshow(data)
pylab.show()

(sorry, I did not have time to test this....)

Hope that helps...

Maximilian

On Wed, Apr 1, 2009 at 2:05 PM, Maximilian Fabricius
<mfabricius@gmail.com> wrote:
> Wayne,
>
> yes, well Fits has science! data...so yes its a matrix :)
>
> I guess I would use pyfits to read the data matrix from the fits file
> and then use
> the imshow command from matplotlib to present it to the user.
>
> import pyfits
> import matplotlib as pylab
>
> hdulist = pyfits.open("YOURFITSFILE.FITS")
> data = hdulist[0].data # I assume its in the first extension
>
> pylab.imshow(data)
> pylab.show()
>
> (sorry, I did not have time to test this....)
>
> Hope that helps...
>
> Maximilian
>
> On Wed, Apr 1, 2009 at 2:00 PM, Wayne Watson
> <sierra_mtnview@sbcglobal.net> wrote:
>> (I see that somehow I got off posting to the group, and sent the original of
>> this thread to you. That's probably caused by the need to use Reply to All,
>> which seems necessary for Python mail lists. I'm working without my contacts
>> this morning, so I'm not real agile reading things. It'll be another 6 hours
>> until I insert them again.)
>>
>> The image buried in the fits file. Isn't that part of the data section. I
>> think that's what it's called. The manual seems to suggest that it's in some
>> sort of matrix form. In any case, I want to display the image using PIL. It
>> seems like there ought to be a way to construct a bit map image that can be
>> displayed via Python's PIL. Maybe pyfits has a way.  For example in Tkinter,
>>
>> import Tkinter as tk
>> import Image
>> import ImageTk
>> import ImageDraw
>> import sys
>>
>> im = Image.open("wagon.tif")
>>
>> draw = ImageDraw.Draw(im)
>> draw.line((0, 0) + im.size, fill=128)
>> draw.line((0,0)+(20,140), fill=128)
>>
>> draw = ImageDraw.Draw(im)
>> draw.line((0, 0) + im.size, fill=128)
>> draw.line(((0,0)+(20,140)), fill=128)
>>
>> root = tk.Tk()
>> pi = ImageTk.PhotoImage(im)
>> label = tk.Label(root, image=pi)
>> label.pack()
>> root.mainloop()
>>
>>
>>
>> Maximilian Fabricius wrote:
>>
>> Wayne,
>>
>> I do not understand, I am sorry! What image do you mean? Is that part
>> of any library that you were trying to get to run?
>>
>> Maximilian
>>
>> On Wed, Apr 1, 2009 at 12:23 AM, Wayne Watson
>> <sierra_mtnview@sbcglobal.net> wrote:
>>
>>
>> Installation was easy. Odd though that the manual uses input.fits as an
>> example but doesn't include it in the file I untarred. I see no suggestions
>> on how to display the image. I guess they assume the user is going to use
>> PIL. That leads me to ask what format is the image? I used pyfits to find
>> the dimensions, but would expect PIL to need to know the format of the
>> image. bmp?
>>
>> Maximilian Fabricius wrote:
>>
>> Hmmm you are a metor hunter then? :)
>>
>> Sorry, I never had to deploy my programs. I know it is a bit a pain
>> to install all libraries ....
>>
>> But still, to install python libraries is not too difficult.
>>
>> Feel encouraged! I never had such a fast start with any other
>> programming or scripting language.
>> (I tried many ...)
>>
>> The only thing you need to become - maybe - familiar with is the
>> handeling of arrays and the
>> differences of arrays and lists. If you have done IDL before, this
>> will be a piece of cake for
>> you. If not...don't worry...its easy!
>>
>> Cheers and good luck!
>>
>> Maximilian
>>
>> On Mon, Mar 30, 2009 at 12:09 PM, Wayne Watson
>> <sierra_mtnview@sbcglobal.net> wrote:
>>
>>
>> Thanks very much, This sounds encouraging. I guess my other worry is about
>> distributing the application I'm working on. It has to do with video meteor
>> observations. The users are very unfamiliar with Python, but the original
>> authors of the program have made it fairly simple for the users to install.
>> The include a couple of (self?) installable library files, like PIL, that
>> are pretty easy for people to install. For example,
>> matplotlib-0.98.1.win32-py2.5.exe. I hope this will be the case here. I'm
>> pretty new to Python, and am making mods to the program, which I did not
>> write. I am making progress, sometimes a bit slowly.
>>
>> Here's what we now use (Python 2.5):
>> from Tkinter import *
>> from numpy import *
>> import Image
>> import ImageChops
>> import ImageTk
>> import ImageDraw # wtw
>> import time
>> import string
>> import binascii
>> import tkMessageBox
>> import tkSimpleDialog
>> from pylab import plot, xlabel, ylabel, title, show, xticks, bar
>>
>> from tkFileDialog import asksaveasfilename, asksaveasfile
>> from tkFileDialog import askopenfilename
>>
>> import MakeQTE
>>
>> import socket
>> import struct
>> import glob
>> import bisect
>> import os, os.path
>> import datetime
>>
>> from os.path import basename, splitext
>>
>> Maximilian Fabricius wrote:
>>
>> Wayne,
>>
>> I have been using pyfits from STSci for about a year and a half now.
>> Since then, I have made extensive use of it. I must admit that I use it
>> on Linux and MaxOSX and not on Windows. Tho' on those two
>> platforms it runs so smoothly and I had such a good time with it
>>  that I strongly recommend using it even
>> for the most simple things that you are doing - because quite frankly -
>> I would not know anything simpler than that (tried FITSIO, Java,
>> IRAF+Pyraf, MIDAS+pymidas,
>> IDL, LTL, ...).
>>
>> You do not need to dig though the whole Pyfits documentation. They have a
>> very nice summary at the beginning of their document, I never read
>> anything else. It
>> should get you to where you want to be in 10min...
>>
>> I also recommend to use pyfits together with scipy. These two are really all
>> you need to do sophisticated data reduction.
>>
>> Writing a fits file is as simple as this:
>>
>> import pyfits
>> from scipy import *
>> data = zeros([1000,1000])
>> hdu = pyfits.PrimaryHDU(data)
>> hdu.writeto("youfile.fits")
>>
>>
>> Maximilian
>>
>> 2009/3/30 Wayne Watson <sierra_mtnview@sbcglobal.net>:
>>
>>
>> I've downloaded the tar for fits from the STSci page, and untarred it. I'm
>> using Win XP. Is this download applicable to Win? The STSci has a lot of
>> tutorial material. Is this necessary to just using Python to write a modest
>> fits file? I want to put lat/long, time, and maybe a few other parameters in
>> the header, but that's about it. Of course, I want to include an image.
>>
>> A few months I bookmarked a web site from the U of Wash about fits and maybe
>> python. It seems to be gone. Anyone know about i?. It looked like it belong
>> to someone by the last name of Owens.
>> --
>>
>>            Wayne Watson (Watson Adventures, Prop., Nevada City, CA)
>>
>>              (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time)
>>
>>
>>                 “Life is one damn thing after another."
>>                      -- Mark Twain
>>
>> _______________________________________________
>> AstroPy mailing list
>> AstroPy@scipy.org
>> http://mail.scipy.org/mailman/listinfo/astropy
>>
>>
>>
>>
>>
>>
>> --
>>
>>            Wayne Watson (Watson Adventures, Prop., Nevada City, CA)
>>
>>              (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time)
>>
>>
>>                 “Life is one damn thing after another."
>>                      -- Mark Twain
>>
>>
>>
>>
>>
>> --
>>
>>            Wayne Watson (Watson Adventures, Prop., Nevada City, CA)
>>
>>              (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time)
>>
>>
>>           The Obama Administration plans to double the production
>>           in solar energy from 1% to 2% of the total energy
>>           supply in the next few years. One nuclear reaction
>>           would do the same. Heard on Bill Wattenburg, KGO-AM
>>
>>           "Less than all cannot satisfy Man." -- William Blake
>>
>>
>>
>>
>>
>>
>> --
>>
>>            Wayne Watson (Watson Adventures, Prop., Nevada City, CA)
>>
>>              (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time)
>>
>>
>>           The Obama Administration plans to double the production
>>           in solar energy from 1% to 2% of the total energy
>>           supply in the next few years. One nuclear reaction
>>           would do the same. Heard on Bill Wattenburg, KGO-AM
>>
>>           "Less than all cannot satisfy Man." -- William Blake
>>
>>
>
>
>
> --
> --------------------------------------------------------------------
>  Maximilian Fabricius
>  * Max Planck Institute for Extraterrestrial Physics (MPE)
>     Giessenbachstrasse, D-85748 Garching, Germany
>  * University Observatory Munich /   Wendelstein Observatory
>     Scheinerstr. 1, D-81679 München, Germany
>  eMail:  mxhf@mpe.mpg.de
>  Phone:  +49 89 30000 3694
>  FAX:    +49 89 30000 3495
>  --------------------------------------------------------------------
>



-- 
--------------------------------------------------------------------
  Maximilian Fabricius
  * Max Planck Institute for Extraterrestrial Physics (MPE)
     Giessenbachstrasse, D-85748 Garching, Germany
  * University Observatory Munich /   Wendelstein Observatory
     Scheinerstr. 1, D-81679 München, Germany
  eMail:  mxhf@mpe.mpg.de
  Phone:  +49 89 30000 3694
  FAX:    +49 89 30000 3495
  --------------------------------------------------------------------


More information about the AstroPy mailing list