Wednesday, June 22, 2011

Classy!

Created my first class Image in phot.py:
It's far from done, but I'll post up some stuff I've written so far.

Here's the "constructor". It takes a fits file and converts it into an Image instance.
class Image:
   """Class to be used with a FITS file image"""
   def __init__(self,filename):
       self.filename=filename
       self.data,self.hdr=f.getdata(self.filename,header=True)
       self.object=self.hdr['TARGNAME']


Methods:
def header(self): prints the header of the FITS file


def phot(self,xc,yc,rad=5,ann_in=8,ann_out=10): basically a remake of the aper_phot function I made yesterday. The data argument is simply replaced with self.data (data of the FITS file)

def show(self): displays the fits file image on a graph


def histcol(self,col,bins=50,tite="",fig=1): takes one column (all rows in that column), and creates a histogram of all the values found in the elements in that column


def histrow(self,row,bins=50,tite="",fig=1): takes one row (all columns in that row), and creates a histogram of all the values found in the elements in that row

------
Some examples: (assuming I created an instance called im)
The original FITS file's data looks like this:
>>>im.show()

>>> a=im.phot(xc=94,yc=71)
>>> im.show
>>> im.histcol(71)
>>> p.show()
-----
I also created a nice file called startup.py so that I wouldn't have to import all the files by hand every time I opened up the command prompt. 

Learned:
-Stuff about displaying an array as an image
-A little bit more about how classes work (bound, unbound methods, etc)
-a pretty cool numpy.argmax(array) function I haven't quite used yet
Problems:
-Wow setfig(fig,title) is still causing problems =[
-How to manipulate/control what colors arrays display
To-Do:
-make a findptsource(self) function that finds possible point sources depending on the array values in self.data


No comments:

Post a Comment