There is no doubt that the labor of scientists in the twenty-first century is more comprehensive and interdisciplinary than in previous generations. Members of scientific communities connect in larger teams and work together on mission-oriented goals and across their fields. This paradigm on research is also reflected in the computational resources employed by researchers. No longer are researchers restricted to one type of commercial software, operating system, or vendor, but inspired by open source contributions made available and tested by research institutions and open source communities; research work often spans over various platforms and technologies.
This book presents the highly-recognized open source programming environment till date — a system based on two libraries of the computer language Python: NumPy and SciPy. In the following sections, we will guide you through examples from science and engineering on the usage of this system.
The ideal programming environment for computational mathematics enjoys the following characteristics:
Among the best-known environments for numerical computations used by the scientific community is MATLAB, which is commercial, expensive, and which does not allow any tampering with the code. Maple and Mathematica are more geared towards symbolic computation, although they can match many of the numerical computations from MATLAB. These are, however, also commercial, expensive, and closed to modifications. A decent alternative to MATLAB and based on a similar mathematical engine is the GNU Octave system. Most of the MATLAB code is easily portable to Octave, which is open source. Unfortunately, the accompanying programming environment is not very user friendly, it is also very much restricted to numerical computations. One environment that combines the best of all worlds is Python with the open source libraries NumPy and SciPy for numerical operations. The first property that attracts users to Python is, without a doubt, its code readability. The syntax is extremely clear and expressive. It has the advantage of supporting code written in different paradigms: object oriented, functional, or old school imperative. It allows packing of Python codes and to run them as standalone executable programs through the py2exe
, pyinstaller
, and cx_Freeze
libraries, but it can also be used interactively or as a scripting language. This is a great advantage when developing tools for symbolic computation. Python has therefore been a firm competitor to Maple and Mathematica: the open source mathematics software Sage (System for Algebra and Geometry Experimentation).
NumPy is an open source extension to Python that adds support for multidimensional arrays of large sizes. This support allows the desired acquisition, storage, and complex manipulation of data mentioned previously. NumPy alone is a great tool to solve many numerical computations.
On top of NumPy, we have yet another open source library, SciPy. This library contains algorithms and mathematical tools to manipulate NumPy objects with very definite scientific and engineering objectives.
The combination of Python, NumPy, and SciPy (which henceforth are coined as "SciPy" for brevity) has been the environment of choice of many applied mathematicians for years; we work on a daily basis with both pure mathematicians and with hardcore engineers. One of the challenges of this trade is to bring about the scientific production of professionals with different visions, techniques, tools, and software to a single workstation. SciPy is the perfect solution to coordinate computations in a smooth, reliable, and coherent manner.
Constantly, we are required to produce scripts with, for example, combinations of experiments written and performed in SciPy itself, C/C++, Fortran, and/or MATLAB. Often, we receive large amounts of data from some signal acquisition devices. From all this heterogeneous material, we employ Python to retrieve and manipulate the data, and once finished with the analysis, to produce high-quality documentation with professional-looking diagrams and visualization aids. SciPy allows performing all these tasks with ease.
This is partly because many dedicated software tools easily extend the core features of SciPy. For example, although graphing and plotting are usually taken care of with the Python libraries of matplotlib, there are also other packages available, such as Biggles (http://biggles.sourceforge.net/), Chaco (https://pypi.python.org/pypi/chaco), HippoDraw (https://github.com/plasmodic/hippodraw), MayaVi for 3D rendering (http://mayavi.sourceforge.net/), the Python Imaging Library or PIL (http://pythonware.com/products/pil/), and the online analytics and data visualization tool Plotly (https://plot.ly/).
Interfacing with non-Python packages is also possible. For example, the interaction of SciPy with the R statistical package can be done with RPy (http://rpy.sourceforge.net/rpy2.html). This allows for much more robust data analysis.
18.118.142.166