Python Astronomy
Python Astronomy
Lecture 1
Yogesh Wadadekar
NCRA-TIFR
July-August 2010
Topical course
1 / 33
prerequisites
Topical course
2 / 33
prerequisites
URL: http://www.ncra.tifr.res.in/yogesh/python_course_2010
Topical course
2 / 33
prerequisites
URL: http://www.ncra.tifr.res.in/yogesh/python_course_2010
please interrupt and ask questions at any time.
Topical course
2 / 33
prerequisites
URL: http://www.ncra.tifr.res.in/yogesh/python_course_2010
please interrupt and ask questions at any time.
programming background of the audience?
Topical course
2 / 33
Why Python?
A powerful, general purpose programming language, yet easy to
learn. Strong, but optional, Object Oriented Programming support
Very large user and developer community, very extensive and
broad library base
Very extensible with C, C++, or Fortran, portable distribution
mechanisms available
Free; non-restrictive license; open source
fast becoming the standard scripting language for astronomy
very powerful array processing capabilities (numpy)
extensive documentation - Many books and on-line documentation
resources available (for the language and its libraries and
modules)
Topical course
3 / 33
Why python?
Plotting (matplotlib)
framework (matplotlib) more extensible and general
Better font support and portability (only one way to do it too!)
Usable within many windowing framework (GTK, Tk, WX, Qt...)
backends
Standard plotting functionality independent of framework used
plots are embeddable within other GUIs
more powerful image handling (multiple simultaneous LUTS,
optional resampling/rescaling, alpha blending, etc)
Topical course
4 / 33
Disadvantages of Python
Topical course
5 / 33
Topical course
6 / 33
Extremely popular
Interactive, great visualization, good libraries
but...
Not really general purpose
Vendor lock-in
fairly expensive, source code of core libraries not changeable.
Topical course
7 / 33
Topical course
8 / 33
Topical course
9 / 33
Topical course
10 / 33
Basic methodology
Topical course
11 / 33
Basic methodology
Topical course
11 / 33
Basic methodology
Topical course
11 / 33
Basic methodology
Topical course
11 / 33
Basic methodology
Topical course
11 / 33
Topical course
12 / 33
Topical course
13 / 33
Topical course
14 / 33
Topical course
15 / 33
Topical course
16 / 33
Topical course
17 / 33
Python Cookbook
Topical course
18 / 33
Topical course
19 / 33
Topical course
20 / 33
Topical course
21 / 33
http://www.tramy.us/guidetoscipy.html
Topical course
22 / 33
Topical course
23 / 33
Online Material
www.python.org
Topical course
24 / 33
Online Material
www.python.org
Start with the Python tutorial - http://docs.python.org/tutorial/ we
will cover all of it and more in this course.
Topical course
24 / 33
Online Material
www.python.org
Start with the Python tutorial - http://docs.python.org/tutorial/ we
will cover all of it and more in this course.
Python for astronomers http://www.scipy.org/wikis/topical_software/Tutorial Excellent
tutorial by Greenfield and Jedrzejewski
Topical course
24 / 33
Online Material
www.python.org
Start with the Python tutorial - http://docs.python.org/tutorial/ we
will cover all of it and more in this course.
Python for astronomers http://www.scipy.org/wikis/topical_software/Tutorial Excellent
tutorial by Greenfield and Jedrzejewski
SciPy conferences - http://conference.scipy.org - lots of interesting
talks (some with video versions)
Topical course
24 / 33
Online Material
www.python.org
Start with the Python tutorial - http://docs.python.org/tutorial/ we
will cover all of it and more in this course.
Python for astronomers http://www.scipy.org/wikis/topical_software/Tutorial Excellent
tutorial by Greenfield and Jedrzejewski
SciPy conferences - http://conference.scipy.org - lots of interesting
talks (some with video versions)
Astropy mailing list - http://mail.scipy.org/mailman/listinfo/astropy
Topical course
24 / 33
Python on MS Windows
Topical course
25 / 33
Python on Linux
Topical course
26 / 33
Topical course
27 / 33
Python Version 2 or 3?
Python 3 is newer but Python 2 has more existing third party software.
For this reason, in this course, we will use Python 2 only. However,
within a year or so it should be possible to move to Python 3.
Topical course
28 / 33
Topical course
29 / 33
Starting Python
Topical course
30 / 33
Topical course
31 / 33
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
2
0
-4711
07, 022 # Octal tuple
0x9, 0xa, 0XF # Hexadecimal tuple
17 + 4 # Expression
0xa - 2
23 (2+3) # Power
7 / 2, 7 / -2 # Int division
from __future__ import division
7/2
Topical course
32 / 33
Floats
>>>
>>>
>>>
>>>
>>>
>>>
>>>
2.3
-4.
0.1, .1
2.99E10, 6.62607e-27, -1e10
1.7 + .4
17. + 4
7./2., 7./2, 7/2.
Topical course
33 / 33