Python is a general purpose, high-level, free and open-source programming language that is readable and intuitive. It has strong scientific computing packages like NumPy, SciPy, and Matplotlib that allow it to be used for tasks like MATLAB. Python emphasizes code readability and reusability through standards like PEP8 and version control, making it well-suited for collaboration between individual, institutional, and developer users in its large, diverse community.
1. What is Python?
An overview of Python for science
Nicholas Pringle
2. What is Python?
Python1 is a
â—Ź general purpose2,
â—Ź high-level3,
â—Ź free and open-source4,
â—Ź readable and intuitive
programming language which provides strong guidelines.
It has been called the glue5, but is now becoming the swiss
army knife, of scientific programming.
3. Why should we use it?
It integrates well with other languages like R6,
MATLAB7, C8 or FORTRAN9.
¹³²
It has a large community of users.
It has mature and well documented scientific
packages...
4. The scientific packages
The most important packages are Numpy,
SciPy and Matplotlib.
Together these libraries allow one to use
Python in a manner similar to MATLAB.
They can be used with an IDE like Spyder...
5. Spyder
Explore the
variables
here...
2
I can write my code here…
(syntax errors are shown)
1
And investigate my data in an
interactive terminal here…
This includes plotting inline
3
6. Numpy
Support for large multidimensional arrays and
matrices10
Together with Scipy and Matplotlib attempt to
provide MATLAB functionality.
Or at least thats how it started...
7. Scipy
Builds on Numpy and provides:
â—Ź Signal processing
â—Ź Linear algebra routines
â—Ź Statistics
â—Ź Optimization
â—Ź Interpolation
â—Ź and more...
8. Matplotlib...
Has many plotting options and
additional libraries like Basemap.
[Gallery link]
9. What makes it so great?
The size of the community means that it is easy to find a solution to your
problem. Additionaly there are many great online courses. e.g. Coursera
It is easy to learn and easy to read.
Your code is generally cross-platform and not sensitive to package versions.
My code is too - so we can share! Which is useful for things like downloading
and cleaning data within an organisation. An automated workflow can be
established.
10. The Python community
Python users fall into 3 broad categories:
â—Ź individual users
o write their own scripts (statistical analysis of their data, creation of figures)
â—Ź institutional users
o are working on projects as a team
o collaboration is very important
o Need to provide products
â—Ź scientific python developers
o contribute to the scientific packages
(from Van der plas, 2013)
11. The community is diverse
â—Ź Astronomy [AstroPy]
â—Ź Remote Sensing [Link, Link, Link]
â—Ź Oceanography [Link]
â—Ź Web development [Django]
â—Ź Game Development
â—Ź Finance (Data Analysis)
â—Ź High Performance computing [ANL]
12. The community is fun
You can make minesweeper animations… [Link]
Or make XKCD style plots… [Link]
Learn when to have your case favourably
reviewed by a judge… [Link]
Build a prediction engine for betting on horse
races (and lose money) [Link]
“Writing your own solution is a good indication that you
don’t know what you’re doing...” - Nathan Taggart
13. What else does Python offer
â—Ź IPython Notebook11 - executable code
â—Ź Pandas12 - the new R
â—Ź Scikit Learn13 - Machine Learning
â—Ź Numba, Blaze - lightning fast, big data
â—Ź Bokeh - plotting
â—Ź Wakari - Python in the cloud
14. How to collaborate (lofty goals)
● Use virtual environments which don’t rely on
your system packages14
â—Ź Use version control to keep track of
development and to share15
â—Ź Use PEP816 as a standard for readability
â—Ź Try and fit your code to a MVC17 pattern
â—Ź Write good test coverage18, 19
15. Python Scientific Distributions
Python is easiest to use in a linux or unix environment.
However, there are some very good all-in-one packages
available. And they are free.
â—Ź Enthought Canopy [Link]
â—Ź Anaconda (I recommend) [Link]
â—Ź or $ pip install in a virtualenv
Python2 or Python3?
You can use both but try for Python3.4
Try one of them
out today!
17. A simple example
import numpy as np # imports the numpy package into the namespace
from matplotlib import pyplot as plt # imports plotting from matplotlib
def straight_line(m, x, c):
y = m*x + c
return y
gradient = 2
x_coords = np.arange(-10, 11) # create 1D array from -10 to 10
y_int = -2
line = straight_line(gradient, x_coords, y_int)
plt.plot(x_coords, line)
plt.grid()
18. What is python?
Python is a general purpose, high-level programming
language.
General purpose: a wide variety of application domains
High-level: it does the hard work for you
19. What else is Python?
Python is a free and open source, so this guarantees end
users (individuals, organizations, companies) the freedoms
to use, study, share (copy), and modify the software.
Python emphasizes code readability, so it is easy to
understand ones own code and that of others.
Additionally there are are quite strong guidelines which
means everybody is on the same page.
20. Python is moving forward
There are exciting packages being added at an alarming
rate.
Current packages are improving all the time.
Continuum Analytics received $3 million in funding.
There are great python conferences - EuroPy/EuroSciPy
21. Model, View, Controller
MVC is a software architectural pattern for implementing user interfaces. Using this pattern can
provide a solid foundation for collaboration.
Model
â—Ź HDF5, NETCDF4, PyTables
View
â—Ź PyQT, Matplotlib
Controller
â—Ź Numpy; Scipy, Pandas, etc...
22. Other resources
Version control (Github) [Link]
Using version control on anything you work on can save
you a lot of trouble, it also makes working with other much
simpler. [example]
Stackexchange [Link]
The stackexchange network is a group of Q&A forums
where you can get help on a variety of topics.
23. More Links...
Some key people in the python community:
â—Ź Travis Oliphant [Link]
â—Ź Jake Vanderplas [Link]
â—Ź Wes McKinney [Link]
â—Ź Randal Olson [Link]