Friday, August 12, 2011

New Implementation

I talked with Tim and Justin about my code. The problem seems to be that in my current program, I am overestimating the amount of background noise since I'm calculating noise by averaging the flux from individual pixels. What I should do instead was to average noise from little regions and calculate the noise from the average of those regions. It seems like I'm just working with slightly bigger pixels, but by first averaging the flux from each region, I am able to smooth out my background and ultimately decrease the noise in each image.

So now, I have to code a different approach to finding point sources. It will still use much of what I have already written, but it's definitely the biggest change yet to my code.

Here's a rough outline of what I'm about to do:
I will partition each annulus into little circular regions of data. I will then average the flux in each region, and then find the standard deviation from the regions. This will be used to create sigma. The background mean will also be calculated from the regions. Detection of a point source apart from the main source will determined by if the a region has an average intensity greater than thresh*sigma. My program might pinpoint the specific location of the point source less precisely, but at least it won't detect fake point sources that turned out to just be speckles. The contrast curve will still be created in much the same way. It's just the way I determine background noise that will change the most significantly. 


I'll start working on this next week. 

Thursday, August 11, 2011

Sanity Check

I've been debugging my program for the last few days without much success. I've sent some preliminary testing results to Tim, but the results are definitely not good.

Here are two main problems I noticed:
-The point source finder is too sensitive. It detects almost anything that is greater than thresh*sigma. Unfortunately, there are many pixels in the picture that seem rather "grainy" and are registered as false point sources. I need to somehow eliminate these false point sources.
-The range of delta mags (contrast) for the contrast curves are way too small. The delta mags themselves are also high values, often hovering just below 0. This indicates that my program is not finding too much contrast within the annuli of the star compared to the central flux of the star, which seems intuitively wrong. However, this is most likely caused by the small size of the cropped image. The small images size makes my program calculate the background noise as part of the annulus of the star, which is incorrect as there is light pollution from the star. The problem is somewhat fixed when I increase the size of the cropped image; however, compared to Justin's results the delta mags still seem too small.

Professor Johnson suggested I do some sanity checks on my math yesterday, and I've been trying to figure out what really is going on with the math behind the contrast curves.

I'll post some more if I find anything interesting, but for now, it is just alone time for me and a buggy program.

Tuesday, August 9, 2011

Code Testing

Another colleague, Justin, sent Tim and I a MATLAB fitswriter file, which turns matlab .fig files into .fits files.

I have been setting up Matlab and using it to convert images into .fits files. I am then able to test my code on these new files, and compare my results with those of Justin's. Unfortunately, they don't seem to match up. The images that Justin sent me also seem to focus on objects with large FWHM's, which ultimately means that I obtain less points for my contrast curve because of the way I've implemented my code.

I am currently trying to compile a .pfd document containing the contrast curves I obtained using my code, and comparing my data to Justin's data. Hopefully this will give me a clearer indication of what the differences are between our results, and how I should change my code.

Friday, August 5, 2011

Saving Text Files and Figures

Today I finished a function that will allow me to save text files of some important data associated with the contrast curve plots I made.

When a user saves a figure, an associated text file will save the lists of data returned from phot3.contrastcurve(...). That is, it will save a list of points used in the creation of a contrast curve as well as any point sources the program may have found in the annuli of the main star. The text file will also save the center coordinates of that star.

The text file will save to the name of x-y_fitsfilename-results.txt, where x,y are the center coordinates, and fitsfilename is the name of the fits file.

Here's an example of the kind of text file it will save:

C:\[Your path here]>IPhot CK00012_snap_20110412.fits
CK00012_snap_20110412.fits
Press Q/q to quit, or any other key to load next image.

Clicking on point (22,100) and pressing W will save this picture... 
...as well as a .txt file containing this information:


Center Pts
(22, 100)
Coordiates (Radius,Contrast)
[(1.0310396072149, 1.2019494856629946), (1.2028795417507165, 1.8693450269793654), (1.3747194762865333, 2.1077248753625968), (1.5465594108223499, 2.3778325825061946), (1.718399345358167, 2.4598854750345436), (1.8902392798939833, 2.5393921380320639), (2.0620792144297999, 2.5689754466690302), (2.2339191489656169, 2.5851800258224134), (2.4057590835014335, 2.5950414542085398), (2.5775990180372501, 2.5998551889539634), (2.7494389525730667, 2.6055135477309928), (2.9212788871088833, 2.6096344474456359), (3.0931188216446999, 2.6104568644975972)]
Additional Point Sources at Each Radius (if any)
[[], [], [], [], [], [], [], [], [], [], [], [], []]


Saved to C:\Documents and Settings\Administrator\Desktop\CC22-100_CK00012_snap_2
0110412.png
Saved to C:\Documents and Settings\Administrator\Desktop\22-100_CK00012_snap_201
10412-results.txt
q
Quitting program...

C:\[Your path here]>

-----
Note that I also created a little compass on the lower right corner of each Image object. =]

To-Do:
-Somehow scale the axis ticks of the subplot images to arcseconds as opposed to pixels.
-Maybe at some point figure out how to load directories of FITS files into my command line as opposed to a list of file names (which are very tedious to type).

-----
EDIT:
I have changed the output of the text file so that it no longer returns a list of lists of point sources. It will simply return a list of point sources, or an empty list if there are none.

Wednesday, August 3, 2011

IPhot Changes

I successfully linked the two functions together in IPhot's createfigure(...) today after working on it for the past two days.

def createfigure(x,y): Creates a figure with a cropped image centering on the clicked point source by using phot3.plotptsmarking(...). If there are no other point sources in the cropped image, this function will plot a contrast curve using phot3.plotcontrastcurve(...), and the cropped image will be an inset on the top right corner of the contrast curve. Both of these functions were described in the previous post. x,y are the x and y coordinates of the mouse click. The cropped image specifications are specified by what the user enters in the command line and the mouse click, which indicates which point to center on. 


Example: (Using command line)


C:\[Your path here]>IPhot CK00012_snap_20110412.fits -s 2
CK00012_snap_20110412.fits
Press Q/q to quit, or any other key to load next image.


Clicking on the center point source at around (94,72), we get this:
Detected point source: (94, 76)

Clicking on the point source at around (22,100), we get this:

q
Quitting program...


C:\[Your path here]>


Note that I used an annulus spacing of 2. This shows up in both of the cropped images. The inner circle around the point source represents the aperture radius. The larger circle around the point source indicates the innermost annulus radius, or where the program will begin to sample the contrast between the point source and the background around it. 

In the first cropped image, there is also a smaller circle (with a fixed radius of 1) that indicates where other point sources are in the image.

Learned:
-How to create inset graphs (in two ways actually!). I can either use the axes(...) function from pylab or the inset_axes(...) function from mpl_toolkits
To-Do:
-Test my program and debug it. There are probably still some minor problems or aesthetic issues I still need to fix. 

Tuesday, August 2, 2011

Phot3.py - Two Functions

Today I finished coding two plotting functions.
def plotcontrastcurve(self,ann_space=0,darkpix=0.95,adj=3,thresh=5,fig=1): The original plotcontrastcurve(...) function wasn't nearly as fancy as this one. This function also allows the user to specify the number of adjacent pixels (adj) and the number of deviations from the mean background (thresh) that determines whether a pixel is a point source or not. The math behind the contrast curve has also changed. The shape looks pretty good, but I'm concerned that a lot of the curve is up in the negatives for contrast...

def plotptsmarking(self,cx,cy,filename="",ann_space=0,darkpix=0.95,adj=3,thresh=5): This function makes one of those subplot images that circles the aperture, the innermost annulus, and other point sources in the picture (if possible). It also has arguments for thresh and adj

Tomorrow I will link these two methods together in IPhot.

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.