23
What is Python? An overview of Python for science Nicholas Pring

What is Python? An overview of Python for science

Embed Size (px)

Citation preview

Page 1: What is Python? An overview of Python for science

What is Python?An overview of Python for science

Nicholas Pringle

Page 2: What is Python? An overview of Python for science

What is Python?Python1 is a● general purpose2,● high-level3,● free and open-source4,● readable and intuitiveprogramming language which provides strong guidelines.

It has been called the glue5, but is now becoming the swiss army knife, of scientific programming.

Page 3: What is Python? An overview of Python for science

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...

Page 4: What is Python? An overview of Python for science

The scientific packagesThe 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...

Page 5: What is Python? An overview of Python for science

Spyder

I can write my code here…(syntax errors are shown)

Explore the variables here...

And investigate my data in an interactive terminal here…This includes plotting inline

1

2

3

Page 6: What is Python? An overview of Python for science

NumpySupport for large multidimensional arrays and matrices10

Together with Scipy and Matplotlib attempt to provide MATLAB functionality.

Or at least thats how it started...

Page 7: What is Python? An overview of Python for science

ScipyBuilds on Numpy and provides:● Signal processing● Linear algebra routines● Statistics● Optimization● Interpolation● and more...

Page 8: What is Python? An overview of Python for science

Matplotlib...Has many plotting options and additional libraries like Basemap.

[Gallery link]

Page 9: What is Python? An overview of Python for science

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.

Page 10: What is Python? An overview of Python for science

The Python communityPython 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 teamo collaboration is very importanto Need to provide products

● scientific python developerso contribute to the scientific packages

(from Van der plas, 2013)

Page 11: What is Python? An overview of Python for science

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]

Page 12: What is Python? An overview of Python for science

The community is funYou 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

Page 13: What is Python? An overview of Python for science

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

Page 14: What is Python? An overview of Python for science

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

Page 15: What is Python? An overview of Python for science

Python Scientific DistributionsPython 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!

Page 16: What is Python? An overview of Python for science

More slides… should there be time.

Page 17: What is Python? An overview of Python for science

A simple exampleimport numpy as np # imports the numpy package into the namespacefrom matplotlib import pyplot as plt # imports plotting from matplotlib

def straight_line(m, x, c): y = m*x + c return y

gradient = 2x_coords = np.arange(-10, 11) # create 1D array from -10 to 10y_int = -2

line = straight_line(gradient, x_coords, y_int)plt.plot(x_coords, line)plt.grid()

Page 18: What is Python? An overview of Python for science

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

Page 19: What is Python? An overview of Python for science

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.

Page 20: What is Python? An overview of Python for science

Python is moving forwardThere 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

Page 21: What is Python? An overview of Python for science

Model, View, ControllerMVC is a software architectural pattern for implementing user interfaces. Using this pattern can provide a solid foundation for collaboration.

Model● HDF5, NETCDF4, PyTablesView● PyQT, MatplotlibController● Numpy; Scipy, Pandas, etc...

Page 22: What is Python? An overview of Python for science

Other resourcesVersion 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.

Page 23: What is Python? An overview of Python for science

More Links...Some key people in the python community:● Travis Oliphant [Link]● Jake Vanderplas [Link]● Wes McKinney [Link]● Randal Olson [Link]