In [5]:
from IPython.display import Image
Image(filename='IPy_header.png')


Out[5]:

In [6]:
Image(filename='jupyter-logo.png')


Out[6]:

In [ ]:


In [ ]:

iPython Notebook Tutorial

To have plots show up in this page you add:


In [2]:
%matplotlib inline

Let's look at an example.


In [8]:
import matplotlib.pyplot as pl
import numpy

x = numpy.linspace(0, 100)
y = x**3

pl.plot(x, y, label='Curve', color='black')
pl.yscale('log')
pl.legend(loc=4)
pl.show()


Let's define a functions.


In [9]:
def distance_modulus (distance):
    return 2.5*numpy.log(distance)

distance_modulus(400)


Out[9]:
14.978661367769954

In [11]:
def distance (apparent, absolute):
    log_distance = (apparent - absolute + 5)/5
    return 10**(log_distance)

distance(12.34, -24.75)


Out[11]:
261818300.82189918

In [13]:
cepheid_apparent = numpy.linspace(11, 18)
cepheid_absolute = numpy.linspace(-21, -29)

distance(cepheid_apparent, cepheid_absolute)


Out[13]:
array([  2.51188643e+07,   2.89217448e+07,   3.33003639e+07,
         3.83418858e+07,   4.41466709e+07,   5.08302738e+07,
         5.85257434e+07,   6.73862717e+07,   7.75882432e+07,
         8.93347463e+07,   1.02859616e+08,   1.18432088e+08,
         1.36362162e+08,   1.57006766e+08,   1.80776868e+08,
         2.08145654e+08,   2.39657948e+08,   2.75941059e+08,
         3.17717266e+08,   3.65818198e+08,   4.21201390e+08,
         4.84969343e+08,   5.58391470e+08,   6.42929370e+08,
         7.40265918e+08,   8.52338773e+08,   9.81378942e+08,
         1.12995520e+09,   1.30102522e+09,   1.49799445e+09,
         1.72478392e+09,   1.98590827e+09,   2.28656564e+09,
         2.63274116e+09,   3.03132606e+09,   3.49025488e+09,
         4.01866341e+09,   4.62707056e+09,   5.32758776e+09,
         6.13416003e+09,   7.06284364e+09,   8.13212567e+09,
         9.36329209e+09,   1.07808514e+10,   1.24130227e+10,
         1.42922973e+10,   1.64560853e+10,   1.89474609e+10,
         2.18160194e+10,   2.51188643e+10])

In [14]:
cepheid_distances = distance(cepheid_apparent, cepheid_absolute)

pl.plot(cepheid_distances, cepheid_absolute)
pl.gca().invert_yaxis()
pl.xlabel('Distance')


Out[14]:
<matplotlib.text.Text at 0x10d190e50>

Let's define some classes.

BIG

small

In [15]:
class A(object):
    def __init__(self):
        self.x = 'Hello'

    def method_a(self, y,z):
        print self.x + ' ' + y + z
        
a = A()
a.method_a('everbody!', 'Bye')


Hello everbody!Bye

Type

ndksnvanskncklansvjkdsvkl


In [26]:
class Galaxy:
    def __init__(self, sfr, mass):
        self.sfr = sfr
        self.mass = mass

gal1 = Galaxy(1.0, 1e12)
gal2 = Galaxy(3.0, 2e12)

def some_operation(gal):
    return gal.mass / gal.sfr

print some_operation(gal1)
print some_operation(gal2)


1e+12
6.66666666667e+11

In [ ]: