Python for Scientists

by Pietro Zambelli

Who I am?

  • I'm a ph.D. student of the University of Treno;
  • I like cycling and travlling;

What I'm doing?

  • The topic of my ph.D. is about the caracterization of the urban microenvironment for air pollutants combining sensor data and GIS tools;
  • During my second year of ph.D I partecipated to the Googel Summer of School to add to GRASS a python interface to the lower C API;
  • During the last year of my ph.D I've worked mainly to combine Object based image classification and several machine learining techniques;
  • At the moment I'm working at the Centre for Ecology & Hydrology (CEH) of Edinburgh, to develop a Graphic User Interface (GUI) to analyze spatiol temporal data.

Object based image classification

What I'm doing with python?

  • GIS and data modelling;
  • Data analysis and visualization.

I've started to contribute to two main opensource projects:

  • GRASS -> link
  • pyqtgraph -> link

What I like of python?

  • Python is simple and clean;
  • It has a big standard library and a huge number of libraries;
  • push programmers to think about their code and find not only a working solution but the most elegant one.
In [1]:
import this
The Zen of Python, by Tim Peters

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!

What about the EURAC course?

The python course is splittet in three main part:

  1. An introduction on Python data types and syntax, only for people that never played with: list, dictionary, strings, cycle for, if/elif/esle statement, etc. and have no clue of what is a programming language [the next hours until lunch];
  2. A detail explanation of the language, for all, this part is more interacttive and you should have time to write your own code [start after lunch until tomorrow evening];
  3. A small overview for several scientific libraries/tools and common problems like binding C/Fortran function, multiprocessing, etc, only for people interested to a certain topic.

I dedicate almost half of the time to the language because If you know how the language works it is quite easy to understand how to use external libraries.

Time schedule

Day 1
10:00 - 12:00Data structure in Python integer, float, complex, boolean, string, tuple, list, set, dictionary, Statement while, for, if
13:30 - 14:30Source Control hg, git 14:30 - 15:30Objects (basics) attributes, methods, inheritance
Day 2
10:00 - 11:00Objects (advance) magic methods, property, class attributes 11:00 - 12:00Testing doctest, unittest, python debugger
13:30 - 14:30Functions function arguments, default arguments, undefined arguments 14:30 - 15:30Closures and decorators why closure? Why decorators?
Day 3
10:00 - 11:00Numpy 11:00 - 12:00Matplotlib
13:30 - 15:30Scipy
Day 4
10:00 - 12:00Pandas
13:30 - 14:30Command Line Interface (CLI), configuration files, shell GUI, GUI. 14:30 - 15:30Sympy, Math and Symbolic computations
Day 5
10:00 - 12:00Profiling and optimizations: timeit, cProfile, numexpress, bootleneck, multiprocessing, call C and Fortran from python
13:30 - 15:30Database and Object Relational Mapping (ORM).

Course guide lines

  • feel free to interupt me, ask me if something is not clear.
  • I will hold the course using the slide, but you should be able to follow and play the example using ipython, to run each "cell" of code you have to press Ctrl+Enter.
In [3]:
2 * 2
In [ ]: