PSB: Resources for Python


Contents

Installing scientific Python
Getting starting
Checking Python is working
Course material
Useful links
Other books
Moving on

Installing Python, IPython, and SciPy

There are several packages for installing Python, IPython, NumPy, Matplotlib, and SciPy together. I prefer Anaconda (the Python 3 version), which comes with Jupyter notebooks, BioPython, and the Spyder development environment. An alternative is the Enthought Python distribution.


Getting started

There are multiple options for programming Python. We will typically use IPython, which can be accessed in diverse ways:

  1. Using a Jupyter notebook: a good choice because your assignments must be performed in a Jupyter notebook. To open a notebook, type

    jupyter notebook

    in a Terminal, which should cause a web browser to open.

    Note that you must simultaneously press shift and return to actually run IPython. There are some useful guides and keyboard shortcuts.

  2. Using the Spyder or PyCharm development environments, which include an editor for writing code and a de-bugger to help fix coding errors.

  3. Open an IPython window and use a stand-alone editor. Possible choices include gedit and notepad++.

    To start IPython on a Mac, type

    ipython --pylab

    On Windows, choose the -qtconsole option from the Anaconda launcher (you may be asked to download this option first).


Checking Python is working

To check that everything has installed correctly, try:

import matplotlib.pyplot as plt
import numpy as np
plt.plot(np.arange(1,10))
plt.show()

which should generate a plot of a straight-line.


Course Material

My notes on Python.

Using Jupyter notebooks
To start a notebook, type jupyter notebook in the terminal on a Mac or click on a Jupyter icon on Windows.

Lecture recording

Objects and coding equations
Lecture recording

Displaying strings, arrays, and plotting
Lecture recording

More on arrays and accessing their elements
Lecture recording

Selecting subarrays and looping
Lecture recording

If statements and functions
Lecture recording

Solving differential equations
Solving differential equations using SciPy and simulating bistability.
There is a lecture recording and a Jupyter notebook with an example.

Running stochastic simulation
Performing stochastic simulations using StochPy, which you will need to install, but there are instructions online. If you have pip working — it comes with Anacaonda, then the easiest way to install is to type

    pip install stochpy

in a terminal. There is a recording with examples, an example Jupyter notebook, and some exercises and solutions.

Fitting models to data
Fitting models to data using SciPy's minimize function. There is more information on fitting in the Appendix of the notes, an example Jupyter notebook, and some exercises and solutions.

Useful links


Other books

All books are available online through the university library:


Moving on

There are many modules to enable Python to be used in other areas. For example, biopython for bioinformatics, scikit-learn for machine learning and keras and pytorch for neural networks, pandas for data analysis and interacting with spreadsheets such as Excel, scikit-image and opencv for image processing, sage and sympy for computer algebra, and seaborn for beautiful visualization of data.