Up Next

Chapter 1  Introduction

Python is an excellent language for doing many types of scientific (i. e., numerical) calculations. However, documentation for Python tends to be widely scattered and not very suitable for tutorial use. These notes attempt to document the scientific use of Python in a manner that allows the programmer with some knowledge of other computer languages to begin to do useful work quickly. The scientific use of Python is only presented for Unix-like systems, such as Unix itself and Linux. Apple’s Mac OS-X mostly works the same way, but some gotchas may exist. Windows potentially presents many more difficulties. Caveat emptor!

This guide tries to present the features of a useful subset of Python in the rough order in which an increasingly sophisticated user will need them. The judgement of what to present comes largely from my own experience. Others may judge differently, so your mileage may vary.

The power of Python derives from the fact that external modules, some defined in computationally efficient compiled languages such as C and Fortran, can be accessed from Python. Since Python is an interpreted language, this speeds up computations over those done strictly in Python by an order of magnitude or more. It also provides access to some of the best numerical software which otherwise might remain inaccessible to most users. The modules NumPy (version 1.2 or greater) and Matplotlib (version 0.99 or greater) will be used extensively here. These modules respectively provide fast, array-based numerical tools and publication quality graphics.

This version of the tutorial emphasizes Python 3. The code in the general python tutorial section as well as that for NumPy and Matplotlib should work also for Python 2. However, the Candis interface to Python changed significantly between Python 2 and Python 3; Pycandis works for Python 2 and Py3io works for Python 3; both are included in the Candis distribution. An interface for NetCDF exists in the form of a slightly modified version of the Pupynere package, which is also included in Candis.


Up Next