Friday, July 29, 2011

Phot3.py and Other Major Changes

Due to my recent major change to my findptsources(...) function, I had to also implement major changes to my overall phot2.py module. The result was that I decided to just start over and make a new module called phot3.py. It is essentially the same module, but I've streamlined it a bit and deleted some functions that I now don't need because of my more efficient findptsources(...) function. 


I've also been given suggestions to present my data in a more space-conserving and visually appealing way. 


I am working on creating a subplot image within a contrast curve plot. The subplot image will be like it is now - it will center on the point source and indicate where its aperture extends to and where its innermost annulus begins. 


I am also working on changing what happens when a user clicks a point source. When a click is registered, a cropped image centering around the point source will appear. If there are no point sources detected within the annuli of that cropped image, a contrast curve will appear as mentioned above. If there are point sources detected within the annuli, they will be marked with respective circles and the program will return a printed list of detected point source coordinates.

I'll continue working on this next week.

Thursday, July 28, 2011

Editing More Code...

This week has just been a major code-editing week.

Today I made a major change to the way I find point sources.

def findptsources(self,datalist,darkpix=0.95,adj=4,thresh=5): Finds a list of point sources (points brighter than their surrounding points where the number of adjacent pixels (adj) is brighter than thresh*sigma).

The new findptsources(...) function can be adjusted in sensitivity:

thresh gives the user the ability to specify how many deviations from the mean background noise the flux of a point has to be to note it as a potential point source. Thus, instead of only having 5*sigma, we can also ask the program to search for all potential point sources in which a point source is defined by any point greater than 3*sigma.

The new findptsources function can be adjusted in sensitivity by setting values for adj (0-4). It indicates how many of the neighboring points have to also be greater than thresh*sigma in order for the central point to be flagged as a point source.

You may note that the new findptsources(...) requires an array input, which seems kind of silly at first glance. However, this function is also being used to find the point sources in each annulus around a main point source, which means that it needs to be able to take the annulus array as an input, even though the main FITS file array might be different.

The new point source finder kind of already acts like a point source detector because it can look for point sources within annuli, which means that I don't need my old point source detector code I was working on earlier this week.

I tested this new point source finder, and these are the results:
>>>im=phot3.Image(arr)

>>> im.findptsources(im.data)
[(116, 22), (83, 40), (25, 53), (94, 72), (94, 76), (22, 100), (52, 128)]
>>>


As you can see, this is exactly the same array as before. I haven't had time to extensively test this yet, but I believe I'm at least on the right track. 

Learned:
-Neat way to use booleans as integers (0 and 1's) to meet threshold requirements.
To-Do:
-Debug more (I think you're seeing the trend by now...)

Wednesday, July 27, 2011

Still editing that point source detector...

Functions created: 

def addsource(self,cx,cy,peak_flux,FWHM=1): Adds a point source to current Image object and returns a new Image object. cx, cy are the coordinates for the point source, peak_flux is the maximum flux at (cx,cy), and FWHM is... well, the full-width-half-max. 

Other than that, today was mostly spent trying to correct tiny errors and figuring out how to correctly implement my Point Source Detector so that it looks for 3 points that are brighter than 5*sigma (the 5*sigma of the annulus it is positioned in). The current "filler" function I'm using for my Point Source Detector is the point source function I use to find my main point sources. However, this is technically incorrect, since the background noise affecting the main point sources is the background noise in the sky. The background noise for the non-main point sources (the faint point sources that might be polluting the light from the main point source) depends on the brightness of each annulus around each main point source. 

So I guess I'll just continue to work on this tomorrow. 

Tuesday, July 26, 2011

I feel like a happy frog...

...because I caught a major bug in my code today.
Well, I suppose that means I did something horribly wrong in the past weeks, but it definitely feels good to at least know that I've fixed it. Anyways, I again edited my code for findptsources(...). You may have noticed that in my previous posts dealing with point sources, the aperture rings were off-center. They're fine now. See the picture below:
The aperture ring is very nicely centered on the brightest parts of the object. This is because the array of point sources changed. If I open up the Python interpreter and type:

>>> from startup import*
>>> im=phot2.Image(arr)
>>> im.findptsources(darkpix=0.95)

I get this:
[(116, 22), (83, 40), (25, 53), (94, 72), (94, 76), (22, 100), (52, 128)]

All the point sources are isolated, and there are very few of them, which is nice to start with. Also notice that (94,72) instead of (92,72) is the point source, which makes sense, since if we type in:

>>> im.maxx
94
>>> im.maxy
72

we get the x and y coordinates of the pixel in the graphic with the maximum flux, and thus the point source (assuming of course it's not a cosmic ray).

So, hopefully this will be the last time I edit the point source finder code. And hopefully tomorrow I can just focus on making my point source simulator.

-----
I also worked a little bit on the Point Source Simulator today and cleaned up some coding for my Point Source Detector. But then I got distracted by the bug mentioned above...
-----
Learned (the hard way):
-Array elements are organized differently than pixel coordinates! >.<
To-Do:
-Finish the Point Source Simulator
-Edit some more code for my Point Source Detector and make it more precise in detecting point sources (as in, not make it accidentally detect cosmic rays)

Monday, July 25, 2011

Point Source Detector

Hello!

I finished the basic code for the Point Source Detector today. (Though I haven't quite had time to test it yet).

def ptsdetector(subim, aperture, darkpix=0.95): Given a subplot of an Image object (cropped Image object basically), the aperture around the main point source, and an optional darkpix argument, we can detect whether there are any point sources near or within the aperture of the main star.

Now, if we load the main FITS file and click on it, this figure will pop up:
If there are actual point sources within the aperture (significant addition to the light of the main point source), the program will print an additional message stating "Detected point source within aperture: (x,y)" and indicate the x and y coordinates where that point source was found. 

Note that there are two smaller circles. These denote where the point sources are in the picture. The concentric circles indicate that this is the main point source we are focusing on (the point source that was selected by the user). The other small circle indicate that there is another point source near the main point source. 

In this case, however, it should be noted that the slit in the picture is messing around with the object's light, and so we are given another "point source" when in fact it is just the light from the main source on the other side of the slit. I'm eager to test this with some other images that hopefully do not have slits on the main point source. 

Learned:
-Not much new stuff.... today was mainly coding
To-Do:
-Clean the point source detector code a little
-Start on the point source simulator