The National Institute for Computational Sciences

Kraken Software

Python

Category: Program Dev-Languages

Description

Python is a clear and powerful object-oriented programming language, comparable to Perl, Ruby, Scheme, or Java.

For more information see the Python home page .

Two versions of python, 2.7.1 and 3.1.1, are provided and can be used by loading their corresponding module file. (see Usage
Python/2.7.1 installation also includes the following python packages. Please see the website for each of these packages (linked below) for their description:

Some examples and usage of some of these packages is described below in the Python Packages section. Python/3.1.1 only includes a subset of the above packages since the majority of the above-mentioned packages do not support python 3 yet. The included packages are:

Usage

A version of python (2.6) is available by default when you login. However, this version does not have any python packages such as Numpy and Scipy installed for it. If you wish to use python with these packages, you may load the python/2.7.1 module (the default).
A newer version of python (3.1.1) is also available as module. This version does not have as many python packages installed with it.
To view the versions available you can use:

 module avail python 
If you simply want to load the default version (i.e. python/2.7.1) use:
module load python
if you want to load version 3.1.1 use:
module load python/3.1.1

Python Packages

Numpy

NumPy is a general-purpose array-processing package designed to efficiently manipulate large multi-dimensional arrays of arbitrary records without sacrificing too much speed for small multi-dimensional arrays. NumPy is built on the Numeric code base and adds features introduced by numarray as well as an extended C-API and the ability to create arrays of arbitrary type which also makes NumPy suitable for interfacing with general-purpose data-base applications.

This package contains:

  • a powerful N-dimensional array object
  • sophisticated (broadcasting) functions
  • basic linear algebra functions
  • basic Fourier transforms
  • sophisticated random number capabilities
  • tools for integrating Fortran code
  • tools for integrating C/C++ code

Numpy module can be invoked using the following statement inside python interpreter or script:

 from numpy import * 
or
 import numpy 

Scipy

SciPy (pronounced "Sigh Pie") is open-source software for mathematics, science, and engineering. It is also the name of a very popular conference on scientific programming with Python. The SciPy library depends on NumPy, which provides convenient and fast N-dimensional array manipulation. The SciPy library is built to work with NumPy arrays, and provides many user-friendly and efficient numerical routines such as routines for numerical integration and optimization.

Scipy module can be invoked using the following statement inside python interpreter or script:

 from scipy import * 
or
 import scipy 

Matplotlib

matplotlib is a python 2D plotting library which produces publication quality figures in a variety of hardcopy formats and interactive environments across platforms. matplotlib can be used in python scripts, the python and ipython shell (ala matlab or mathematica), web application servers, and six graphical user interface toolkits.

matplotlib tries to make easy things easy and hard things possible. You can generate plots, histograms, power spectra, bar charts, errorcharts, scatterplots, etc, with just a few lines of code. For a sampling, see the screenshots, thumbnail gallery, and examples directory

Matplotlib package is included in python/2.7.1 installation, Please see the matplotlib Matplotlib User Guide for more information

Note that the default matplotlib behavior is to defer drawing a plot until the end of a script. If you want to change this behavior, then create your own .matplotlibrc file with "interactive" set to True.

The interactive property of the pyplot interface controls whether a figure canvas is drawn on every pyplot command. If interactive is False (default setting), then the figure state is updated on every plot command, but will only be drawn on explicit calls to draw(). When interactive is True, then every pyplot command triggers a draw. The pyplot interface provides four commands that are useful for interactive control:

   isinteractive() -  returns the interactive setting True|False
   ion() - turns interactive mode on
   ioff() - turns interactive mode off
   draw() - forces a figure redraw

Example 1: To generate simple plot, do the following:

python
>>> from pylab import *
>>> ion()
>>> plot([1,2,3])

Example 2: To generate 10,000 Gaussian random numbers and make a histogram plot binning the data into 100 bins, you simply need to type

python
>>> from pylab import randn, hist
>>> x = randn(10000)
>>> hist(x,100)

Support

This package has the following support level : Supported

Available Versions

Version Available Builds
pgi intel gnu Other
3.1.1
v
2.7.1
?
v
?