Skip to content
Brett Morris edited this page May 23, 2013 · 1 revision

Get the source for loadingPickles.py here.

loadingPickles.py is a script that demonstrates how to acces just a few of the data that are stored in the oscaar.dataBase() object when you use oscaar.save(). We think these will be the most commonly tinkered-with saved parameters, so let's practice plotting them in interesting ways with matplotlib.

First, let's import that packages that we will use:

import numpy as np
from matplotlib import pyplot as plt
import oscaar

Perhaps most importantly, we will load in the data that oscaar produced in a particular sample run using oscaar.load():

sampleData = oscaar.load('sampleOutput/oscaarDataBase.pkl')

Next, let's set up a grid of 4x4 subplots so that we can view lots of different parameters on the same figure

## Set up the figure
fig = plt.figure(figsize=(10,10))
axis1 = fig.add_subplot(221)
axis2 = fig.add_subplot(222)
axis3 = fig.add_subplot(223)
axis4 = fig.add_subplot(224)

Then we will plot the transit light curve, in the way that we typically like to see transit light curves. We'll plotted the expected ingress and egress times with dotted vertical lines. This is handy if the signal-to-noise of our observations is low and it's difficult to make out the transit in the data. This subplot will go in the top left of the grid of subplots.

## Plot light curve
axis1.set_title('Transit light curve')
axis1.set_xlabel('Time (JD)')
axis1.set_ylabel('Relative Flux')
axis1.plot(sampleData.times,sampleData.lightCurve,'.')	## Plot Light Curve
axis1.axvline(ymin=0,ymax=1,x=sampleData.ingress,linestyle=":")
axis1.axvline(ymin=0,ymax=1,x=sampleData.egress,linestyle=":")

Our next subplot (top-right in the grid) will be a trace of the (x,y) position of the target star. oscaar.astrometry.trackSmooth() tracked the stellar centroid throughout the run, and it stayed mostly in the neighborhood of just a few pixels. This particular dataset was a simulated one, so the pattern of centroids is a particularly geometric one. When you plot these same data for a star in your real observations, you'll likely trace the stars as they drift on the detector if your telescope isn't perfectly polar aligned (like mine!).

The data pertaining to each star is stored in a Python data type called a dictionary. We'll first store the saved dictionary in a variable called starDictionary, and then access the available keys in the dictionary using sampleData.keys. The first key will be the target star's key, and all others will be keys for comparison stars.

The position of the star for each exposure is stored in two arrays that you can access with the ['x-pos'] and ['y-pos'], keys as shown below:

## Trace (x,y) position of the target star 
starDictionary = sampleData.getDict()	## The position data is stored in a dictionary
starKeys = sampleData.keys				## There are keys for each star in the dictionary
targetX = starDictionary[starKeys[0]]['x-pos'] ## Access the position data with this dictionary look-up
targetY = starDictionary[starKeys[0]]['y-pos']
axis2.plot(targetX,targetY)
axis2.set_title('Target centroid pixel position (trace)')
axis2.set_xlabel('X')
axis2.set_ylabel('Y')

But what if we wanted to see how the (x,y) position changes as a function of time, rather than just tracing it in a crazy spirograph pattern like we did above? We can do that by accessing the times

## Show the x and y position of the star over time
axis3.plot(sampleData.times,targetX,label='X')
axis3.plot(sampleData.times,targetY,label='Y')
axis3.legend()
axis3.set_title('Target centroid pixel position (over time)')
axis3.set_xlabel('Time (JD)')
axis3.set_ylabel('Pixel position of stellar centroid')

And lastly, let's see what the raw fluxes measured by oscaar.photometry.phot() measured for each star. These fluxes are not scaled in any way, and we'll see all of the telluric variations in the fluxes. If the telluric variations are small enough and the signal-to-noise high enough, we may see the transit in the target star. In this simulated dataset I'd bet you can figure out which one is the target.

## Plot the raw fluxes of each star
for star in sampleData.keys:
	axis4.errorbar(sampleData.times,starDictionary[star]['rawFlux'],yerr=starDictionary[star]['rawError'],fmt='o',label=("Star %s" % star))
axis4.set_title('Raw flux for each star')
axis4.set_xlabel('Time (JD)')
axis4.set_ylabel('Raw flux (counts)')

Then let's show the plots

plt.subplots_adjust(hspace=0.3,wspace=0.3)
plt.show()

and we see:

screenshot

Clone this wiki locally