Each gray box with

In []:

beside it is a bit of computer code and you run then by pressing the play button or pressing "Shift-Enter".


In [1]:
#this is a comment - the computer will remember it but not act on it.
print("this is a command or function, it tells the computer to print out the text")


this is a command or function, it tells the computer to print out the text

In [2]:
#try to display "hello world":
print("hello world")


hello world

In [3]:
#these commands setup our python environment for scientific programming and plotting
%pylab
%matplotlib inline
import astropy.io.fits as fits

rcParams['image.cmap'] = 'viridis' 
plt.xkcd() #this gives us squiggly XKCD style figures (http://matplotlib.org/xkcd/examples/showcase/xkcd.html)


Using matplotlib backend: Qt4Agg
Populating the interactive namespace from numpy and matplotlib
Out[3]:
<matplotlib.rc_context at 0x7fbb82569d68>

Just like algebra

We can assign a number to a variable and do math


In [4]:
x = 2
a = 3.5
y = x + a

print(y)


5.5

In [5]:
#you can skip a step and do math inside the print function:
print(y/x)


2.75

The it remembered our variables from one box to the next --- spooky?

Debugging


In [6]:
print(z)
z=x*a


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-6-dece632b3baa> in <module>()
----> 1 print(z)
      2 z=x*a

NameError: name 'z' is not defined

we can do lots of math at once

This is good -- astronomers are lazy


In [7]:
x=array([3,2,5,2,2,2,2,1])
a=array([5,5,5,5,5,5,5,5,])
SubtractedArrays=a-x
print(SubtractedArrays)


[2 3 0 3 3 3 3 4]

In [8]:
plot(SubtractedArrays)
plt.xlabel("location of number in arrays")
plt.ylabel("a-x")


Out[8]:
<matplotlib.text.Text at 0x7fbb7a9ff630>
/home/edouglas/anaconda3/lib/python3.5/site-packages/matplotlib/font_manager.py:1288: UserWarning: findfont: Font family ['Humor Sans', 'Comic Sans MS'] not found. Falling back to Bitstream Vera Sans
  (prop.get_family(), self.defaultFamily[fontext]))

Just look at the first four numbers


In [9]:
plot(SubtractedArrays[:4])
plt.xlabel("location of number in arrays")
plt.ylabel("a-x")


Out[9]:
<matplotlib.text.Text at 0x7fbb7a4d35c0>
/home/edouglas/anaconda3/lib/python3.5/site-packages/matplotlib/font_manager.py:1288: UserWarning: findfont: Font family ['Humor Sans', 'Comic Sans MS'] not found. Falling back to Bitstream Vera Sans
  (prop.get_family(), self.defaultFamily[fontext]))

In [10]:
SubtractedArrays


Out[10]:
array([2, 3, 0, 3, 3, 3, 3, 4])

Let's get some real data

Last night we collected some images of the interacting galaxies NGC 6240

(https://en.wikipedia.org/wiki/NGC_6240)


In [11]:
image = fits.getdata("data/wiyn0_9/2016june18/NGC6240/c7558t0054o00.fits")

In [12]:
#decrease the vmax until you can see the galaxies
figure(figsize=(10,10))
imshow(image,vmax=10000)
colorbar()


Out[12]:
<matplotlib.colorbar.Colorbar at 0x7fbb7a434080>
/home/edouglas/anaconda3/lib/python3.5/site-packages/matplotlib/font_manager.py:1288: UserWarning: findfont: Font family ['Humor Sans', 'Comic Sans MS'] not found. Falling back to Bitstream Vera Sans
  (prop.get_family(), self.defaultFamily[fontext]))

more debugging -- getting help


In [13]:
#you can call a function with a ? to get help on it.
imshow?

Removing Bias levels

per the HDI reduction guide, it's preferable to subtract an average bias from the frame than to use one from earlier in the night

"calculate bias 1a. compute mean value, M, of pixels in overscan columns 4100 - 4140" ( HDI data reduction tutorial Michael Richmond, July 8, 2014 ,http://stupendous.rit.edu/richmond/wiyn/hdi_oct2013/tech_7/tech_7.html)


In [14]:
#calculate the average bias in the overscan pixels.
overscan=image[4100:4140,4100:4140] 
mean_bias=mean(overscan) #this is the average

image_without_bias = image - mean_bias

In [15]:
#plot it
figure(figsize=(12,10))
imshow(image_without_bias,vmax=9000,vmin=5000)
colorbar()


Out[15]:
<matplotlib.colorbar.Colorbar at 0x7fbb78b03518>
/home/edouglas/anaconda3/lib/python3.5/site-packages/matplotlib/font_manager.py:1288: UserWarning: findfont: Font family ['Humor Sans', 'Comic Sans MS'] not found. Falling back to Bitstream Vera Sans
  (prop.get_family(), self.defaultFamily[fontext]))