Showing posts with label Week 1. Show all posts
Showing posts with label Week 1. Show all posts

Monday, June 20, 2011

Test Scripts in Python-II (Tues-Fri last week)

Over the next four days I played around with Python's matplotlib's various graphing capabilities.

Tuesday-Wednesday:
Made a file called gauss.py:
-Made a Gaussian function that returns the gaussian at a certain x for a given sigma and mu
-Made a plotting function that plotted the gaussian at a range of x values, using the function described above. This graph definitely had some other nice things thrown in: choice of having a vertical line at mu, x and y labels, title, and resolution specifications.
Graph:

Wednesday-Friday Morning:
Made a file called mc_pi:
-Made a function that estimated the value of pi using the Monte Carlo Method given a number n (it can only go up to 1e8 though, or my computer will complain and crash).
-Created an array of pi values estimated given a certain number n with a specified number of array elements (niter).
-Put these array values into a histogram graph, where the user can specify the number of "bins", n, and niter. Also graphed a gaussian curve over it (sigma=standard deviation, mu=mean). The dotted line is at Pi. 
Graph:
-Finally, I plotted a log graph (x-axis) where pi is estimated with an array of n values, niter times for each value. The error bars are of length sigma=1, and the dots are given by mu.
Graph:

Tim also helped me install matplotlibrc on my computer; however it doesn't seem to work in Python. I still need to try changing all the backends.

Also, on Wednesday I started a new file called utils.py; in here, I'll add random functions that will be useful during this summer/in general so that I won't have to retype them every time I need them. Currently only hosting:
-a distance function that finds distance in 3-space given x,y,z coordinates
-a coordDist function that finds distances in 2-space given two points (tuples)
-a setfig function that has been rather abandoned as Python seems to automatically set the figure number of each graph

Friday
No plotting exercise today! Today I made a file called makecirc.py
-It hosts one function. Given a 2-D data array, it makes an array of the same dimensions and fills them with zeros. Then within a circle with a fixed center and radius specified by the user, it fills the circle with ones. This will definitely be useful when I  have to plot the brightness of stars with respect to a radius (distance from the center of the star).
Here's an example:
Given:


>>>from numpy import*
>>>import makecirc.py
>>>dataArr=zeros((10,10))
>>> dataArr
array([[ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.]])

>>> makecirc.makecirc(dataArr,5,4,3)
[[ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.]
 [ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.]
 [ 0.  0.  0.  0.  1.  0.  0.  0.  0.  0.]
 [ 0.  0.  1.  1.  1.  1.  1.  0.  0.  0.]
 [ 0.  0.  1.  1.  1.  1.  1.  0.  0.  0.]
 [ 0.  1.  1.  1.  1.  1.  1.  1.  0.  0.]
 [ 0.  0.  1.  1.  1.  1.  1.  0.  0.  0.]
 [ 0.  0.  1.  1.  1.  1.  1.  0.  0.  0.]
 [ 0.  0.  0.  0.  1.  0.  0.  0.  0.  0.]
 [ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.]]

Tim also helped me install PyFITS on my computer, which is nice as now I open up pretty pictures of stars on my computer (the FITS files). I also learned some command line code as we had so much trouble installing PyFITS on a Windows computer.

Stuff Learned:
-Too much to write on here. Mostly how to use different functions of matplotlib and how making graphics in Python works. I wrote them in my notebook.
Problems: 
-matplotlibrc won't work.
To Do:
-Next week I'll start making a 2-D Gaussian plot.
-Learn more about how to use PyFITS.
-Read assigned research papers.

Test Scripts in Python-I (Monday last week)

Tim was kind enough to provide me with a few Python exercises to familiarize myself with Python's syntax, as I originally programmed in Java.

My first ever Python file contained four simple functions:
-A swap function that swapped two variables.
-A fun 8-ball function that randomly gave you an answer out of an array of six types of answers
-A Fibonacci function that printed Fibonacci numbers up to a maximum specified value
-And a modified Fibonacci numbers that printed a user-selected-character up to a maximum specified time

The rest of the week would be spent on plotting exercises.

Stuff Learned:
-General Python syntax
-How to use tuples
-Python is FUN! (And so much better than Java)

Project Overview

Hi!

Over the next ten weeks (well, nine weeks from now as this post is one week late), I'll be working in Professor John Johnson's Exolab with Tim Morton at Caltech's astrophysics department. The Exolab is interested in the study of extrasolar planets.

PROJECT
Background: Transits and False Positives
An extrasolar planet is commonly detected through studying its transit across a star. Generally, astronomers find this planet by plotting the flux of a star with respect to time and finding the transit signal. If there is a dip in the amount of flux, then something could be blocking the light of the star; hopefully that something is a small planet moving across the star's surface from our point of view. Typically, however, the amount of light blocked is very small. The value is called delta, which varies with (Rplanet/Rstar)^2. For a Jupiter-sized planet, delta ~ 0.01, and for an Earth-sized planet, delta ~10^-4!

However, there are other things that can cause the flux to dip. Binary star systems can also cause the flux to lower, though delta is usually much greater for binary stars in comparison to planets (delta ~ 0.1). Also, for binary star systems, if we plot the flux vs time graph long enough, there should be a second dip as the other companion gets blocked behind the first star. Under certain conditions, however, binary star systems can be misinterpreted as extrasolar planets transiting across stars due to the way their transit signal looks, or the way the light is collected, leading to what we call a false positive. 

Solution (Where I come in)
In order to avoid interpreting false positives as transiting planets, we need to be able to better plot the light from each star as a function of its distance. Thus, for my project, I will be analyzing CCD images taken by the Palomar 60'' telescope fitted with the Robo-AO and plotting the brightness across each CCD image. If there are any anomalies in the light curve, such as a sharp spike in brightness far away from the star, we can conclude that there are other sources contributing to the amount of light in the CCD image. This light can then be subtracted out (along with background noise) to get the light curve of the main star. This technique is called photometry, or the measurement of the star's flux.

In Tim's words, what I'm doing in a nutshell is determining "with a certain degree of confidence" if there are or aren't any bright objects in a patch of sky that can influence the transit signal.

Approach
I will be doing photometry using CCD's/FITS files and writing scripts with Python.

Background: CCDs
A CCD is a device that contains an array of "wells" capable of holding around ~40k photons per well. As a certain number of photons hits the well, an electron will be emitted and registered onto a pixel. These pixels, along with some other information, form an image called a FITS file. The ratio of electrons emitted (in ADU's, or Astronomical Data Units) to the photons absorbed (or counts) is called the Gain of the CCD.

Though a star is considered as a point source of light, due to atmospheric effects, or seeing, the light of the star is smeared out across a circle of pixels determined by the point spread function. The point spread function should theoretically be determined by the resolution (wavelength/diameter of the telescope); however due to seeing it is not. Thus, the FITS files we obtain of the stars will have a bright center surrounded by rings of increasingly dim pixels.

Plotting
We can plot the intensity of the light with respect to radius and obtain a bell curve. Significant deviations from the bell curve can be marked as potential sources of light and subtracted out. However, a trickier problem is finding the brightest an object can be and yet not be detected at five times the noise (which we will call sigma). This has to do with measuring and subtracting the background noise of the sky.

The final plot I will make will be a plot of the magnitude of the star as distance from its center increases. If there are no other significant sources of light, this plot should be smoothly declining.