what is python? an overview of python for science

Post on 19-Jan-2017

1.275 Views

Category:

Science

2 Downloads

Preview:

Click to see full reader

TRANSCRIPT

What is Python?An overview of Python for science

Nicholas Pringle

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.

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

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

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

NumpySupport for large multidimensional arrays and matrices10

Together with Scipy and Matplotlib attempt to provide MATLAB functionality.

Or at least thats how it started...

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

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

[Gallery link]

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.

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)

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]

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

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

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

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!

More slides… should there be time.

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()

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

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.

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

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

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.

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

top related