Friday, July 22, 2011

Refined: findptsources(...)

I finished the refined version of findptsources(...). Unfortunately, there are a lot of cases to take care of, and I'm not sure I accounted for all of them. I tested my code with the two FITS file images I had, and the code worked well for both of those images. Hopefully the code works well for all FITS files, though I'm currently not 100% sure. I'm trying to get some more FITS files to work with at the moment.

Anyways, here's some examples:


>>> from startup import*
>>> im=phot2.Image(arr)
>>> im.findptsources()
[(115, 22), (116, 22), (83, 40), (25, 53), (90, 72), (91, 72), (92, 72), (93, 72), (94, 72), (92, 76), (93, 76), (94, 76), (18, 100), (19, 100), (20, 100), (21, 100), (22, 100), (51, 128), (52, 128)]


[(115, 22), (83, 40), (25, 53), (92, 72), (93, 76), (20, 100), (52, 128)]

As you can see, the second list of point sources is much shorter!
In case I haven't explained what my edited code does clearly, here's another attempt.

As you can see, the lists contain a bunch of tuples that represent coordinates of pixels in the FITS image. In the first list, many of these tuples have the same 'y-coordinate' (second number in each tuple), meaning that the pixels are aligned in a horizontal line (excuse my handwriting):
It's easy to see now that the second list of tuples takes the 'midpoint' of a line of pixels. By midpoint I mean that for any line of odd pixel length, it takes the mid point, but for any line of even pixel length, it picks one of the two middle most points. For a single point, the program still includes it, even though it might just be a cosmic ray. You can check that this is true with the second FITS image as well:

>>> im2=phot2.Image(arr2)
>>> im2.findptsources()
[(42, 64), (43, 64), (91, 72), (92, 72), (93, 72), (94, 73), (95, 73), (94, 76), (95, 76), (91, 77), (92, 77), (93, 77), (37, 79), (52, 95), (98, 100)]


[(42, 64), (92, 72), (95, 73), (95, 76), (92, 77), (37, 79), (52, 95), (98, 100)]


Obviously a lot of these points could be cosmic rays or point sources we are not concerned with (as in they don't affect the total flux of the main point source we are looking at). But my program includes these points as well because I don't want to make it rule out anything potentially interesting. 


On Monday I'll start working on the point source detector code, and perhaps the point source simulator as well.

Learned:
- How to write complicated if statements.
- How to follow complicated if statements.
To-Do:
- Write the point source detector code
- Create the point source simulator to test my code

Thursday, July 21, 2011

Array Splicing

I'm currently refining my code that finds point sources. However, I've been stuck on this same problem the whole day:

I have here a list of point sources from one of the FITS images:

[(42, 64), (43, 64), (91, 72), (92, 72), (93, 72), (94, 73), (95, 73), (94, 76), (95, 76), (91, 77), (92, 77), (93, 77), (37, 79), (52, 95), (98, 100)]
Each tuple is a coordinate (x,y). If you look carefully, you'll note that there seems to be many rows of "point sources". This is because at these points, the FITS array recorded the same amounts of photons. But a point source should be a single point that is brighter than all its surrounding points. It should be the point of the star (or whatever object you are looking at). So I need to somehow sum up all the x coordinates for each row and then return the average of the x coordinates to find the midpoint of each "row". For example, instead of returning (91, 77), (92, 77), (93, 77), the program should return only (92, 77) since it's the midpoint of the row at y coordinate 77. But to do this, I need to figure out a way to splice my array based solely on the row number (the y coordinate). This proves to be rather difficult - especially if I want to avoid as many for loops as I can. 


I'll think about this tomorrow. 


Learned:
-A bunch of array manipulation functions
To-Do:
-Finish this task
-Create a point source simulator

Wednesday, July 20, 2011

Save Function and Point Source Detector

I finished another save function today. It lets users save contrast curves by selecting the graph with the contrast curve and pressing "w" (w for 'write' since s is already taken).

For example, CK00012_snap_20110412.fits saves as CC94-72_CK00012_snap_20110412.png. 'CC' indicates that it is a graph containing a Contrast Curve. 94-72 indicates that it was saved at the original FITS files coordinates of (94,72). This way, users can save multiple contrast curve images from the same fits file without accidentally writing files over.

I addition, I have been outlining and planning out how to make a Point Source Detector that will detect if there is a point source close to the main point source in the picture. This, however, also requires me to fix up my existing code that finds point sources. "Close" is defined as probably within 1 FWHM of the main point source. That is, its light is merged with the main point source's light since it's within the main point source's aperture.

Learned:
-How to save files
-Key press functions
To-Do:
-Create my point source detector function
-Eventually create a point source simulator and test my detector function

Tuesday, July 19, 2011

Save Function and ... some other things.

Yesterday I was working/finishing up on a proposal for a competition that gives SURF students a chance to use the Hale Telescope at Palomar for a well-designed project. ...Yep.
-----

Today I attempted to learn a little bit about Python's (well...pylab's) savefig(...) function. It lets you save the current figure to a file. However, halfway through I realized that Python has its own save figure code. Simply by pressing 's', you can save the current figure that is selected!

The thing is, the save window will pop up and prompt you for a file name in this case. I'm hoping I can create a function that will allow me to save the figure with the press of a key, and automatically give it a filename without me having to specify one. Maybe something like figure_x, where x is the figure number. Unfortunately, this seems to be difficult to do since I also have to make sure I don't save over any previously saved data.
-----

Results from testing indicated that my code was, unfortunately, not mac compatible (so not much got tested). Apparently it had something to do with end-line characters. I wrote some more lines of code and sent my program back. This time, I'm hoping that it will work.
------

Learned:
-How to save things in Python
-Certain compatibility issues