Friday, July 8, 2011

Fancy Contrast Curve Plotting

Exciting day!
Today was code clean up/make graphs look pretty day. And by make graphs look pretty, I sure do mean I made some awesome-looking, well organized graphs.
Here's an example:

>>> from startup import*
>>> import InteractivePhot
>>> im=phot2.Image(arr)
>>> InteractivePhot.start(im)
Please enter percent darkpixels (0-1):  0.95

After entering the percent darkpixels, the main FITS file image will pop up: 

It waits for a mouse click on a pixel (Clicking outside the image will unfortunately still give an error....)
I clicked near the center object, and this figure popped up: 

Pretty neat huh!? I'm so excited it turned out looking so pretty. 

Unfortunately though, there still needs to be a little tweaking/debugging, which I'll continue to work on next week. 

-I can make beautiful graphs! :D
-How to align text inside a graph. (The text on the upper right corner of the Contrast Curve graph doesn't depend on on the coordinates of the graph. Instead it "clips on" to the maximum graph height and width.)
-How to create subplots
-How to customize tick marks and text
-Allow users to specify annulus space between the aperture and the innermost annulus radius (set to 0 as of now)
-Allow users to specify the dimensions of the cropped image (set to 40x40 as of now)
-Might want to try and make a dragging box that crops the image as opposed to a click that defines the center point... (that'll bypass the problem I have with allowing users to specify the dimensions of the cropped image)
-Somehow allow users to save the images?
-Somehow create a python file that'll run all my code in command line.
-I'm not actually sure that I'm plotting the right contrast curve (especially since the beginning of many curves tend to poke above 0 up to negative magnitudes, which seems a little odd...). I'll have to check my math eventually.

Thursday, July 7, 2011

Interactive Photometry

Nothing interesting happened yesterday. I read up a lot on how make methods that register mouse events. I also started to pseudo-code functions needed to make an interactive photometry program. Today I got a little farther.
The object of this program is (as I briefly stated in my previous post) to create a simple photometry program that will plot contrast curves. More specifically, I will create a program that will allow the user to 'upload' a FITS file image. The user will then be able to click around on the FITS file. One the program registers a click, it will look around for the nearest point source and plot a contrast curve centered on that point source.

To achieve this, I have created two methods in the file
def start(image): This method takes an Image object as an argument. It will plot the FITS image, and ask the user to specify parameters such as darkpix and ann_space. This method will be the basic startup function that the Interactive Photometry program will use.

The second method takes care of what happens when a user clicks on the FITS image.
def onclick(event): This function will (eventually) create a contrast curve centered on the closest point source. The user will be able to specify the size of the subplot image. The default size will be 40x40 pixels.

To allow these methods to use Image objects, I've created global variables to hold attributes of Image objects. (There might be better ways to do this since apparently global variables are a little iffy to work with)
A lot of errors in my code relate to the way the coordinates are defined in the picture and the indices of the FITS array. Because of the way 2-D arrays work in python, the first index is actually the "y-coordinate" of the picture, and the second is the "x-coordinate". I switched some things around in my contrast curve codes to align everything with the image's coordinate system as opposed to the array system. This makes it easier for user to set arguments when they call a function.

-How to use global variables
-More about events/handling in python
-Finish up my two methods in

Tuesday, July 5, 2011

Contrast Curve Plot

Created my contrast curve plot today:

def contrast(flux1,flux2): Finds the difference in magnitude (contrast) between two fluxes. It returns this: -2.5*log10(flux1/flux2). This is not an Image class method; it's a function outside the class inside the module.

def plotcontrastcurve(self,ann_space=0,fig=1):  Plots a contrast curve of a star in relation to the radial distance from the star. This method uses the function above. 

>>> from startup import* #This imports a bunch of stuff; most importantly, it creates an array arr from the fits file we're using. 
>>> im=phot2.Image(arr)
>>> sim=im.subplot(21,99,40,40) 
>>> sim.plotcontrastcurve()

Notice that the axes are flipped =] Also, note that I had to crop the original fits array. This is because the original array contains many point sources. In order for plotcontrastcurve(...) to work correctly, we need to crop the image so that it only contains one point sources; otherwise, the fitgaussian(...) function plotcontrastcurve(...) is using won't work correctly. 

-More about classes/inheritance
-There's this neat little function in pylab called gca(). It returns the current axes, or creates a new axes if there isn't one. This means that I can plot and modify axes without making a figure container that messes with my utils.setfig(...) code! 
-Using this code to create a new pair of axes, I then used a function called invert_yaxis() to invert the labels on the y-axes. 
-The subclass I created handles all the header information in the FITS file; however, I would like to access it in the ancestor class in order to title the contrast curve I created with the name of the object. 
-Eventually, I'll have to start making a stand-alone program (I guess what I more accurately mean is one that doesn't require a Python Interpreter to run). This program will allow me to open a FITS image, click on/near a point source, and immediately return a contrast curve and some other information about that point source.