This chapter is taken from book A Primer on Scientific Programming with Python by H. P. Langtangen, 4th edition, Springer, 2014.
An excellent platform for doing computational science is the IPython notebook. The notebook is accessed through a web browser and provides support for mathematical text, Python code, and graphics - all you need to document scientific work. There are two excellent web services with notebooks: SageMathCloud at https://cloud.sagemath.com/ and Wakari at https://www.wakari.io/wakari. At both sites you must create an account before you can write notebooks in the web browser and download them to your own computer.
Sign in, click on New Project, give a title to your project and
decide whether it should be private or public, click on the project
when it appears in the browser, and click on Create or Import a File,
Worksheet, Terminal or Directory.... If your Python program needs
graphics, you need to choose IPython Notebook, otherwise you can
choose File. Write the name of the file above the row of
buttons. Assuming we do not need any graphics, we create a plain Python
file, say with name
py1.py
. By clicking File you are brought to a browser window with
a text editor where you can write Python code. Write some code and
click Save. To run the program, click on the plus icon (New),
choose Terminal, and you have a plain Unix terminal window where you
can write python py1.py
to run the program. Tabs over the terminal
(or editor) window make it easy to jump between the editor and the
terminal. To download the file, click on Files, point on the
relevant line with the file, and a download icon appears to the very
right. The IPython notebook option works much in the same way, see
the section Writing IPython notebooks.
After having logged in at the wakari.io
site, you automatically
enter an IPython notebook with a short introduction to how the
notebook can be used. Click on the New Notebook button to start a
new notebook. Wakari enables creating and editing plain Python files too:
click on the Add file icon in pane to the left, fill in the program
name, and you enter an editor where you can write a program. Pressing
Execute launches an IPython session in a terminal window, where you
can run the program by run prog.py
if prog.py
is the name of the
program. To download the file, select test2.py
in the left pane and
click on the Download file icon.
There is a pull-down menu where you can choose what type of terminal window you want: a plain Unix shell, an IPython shell, or an IPython shell with Matplotlib for plotting. Using the latter, you can run plain Python programs or commands with graphics. Just choose the type of terminal and click on +Tab to make a new terminal window of the chosen type.
Both SageMathCloud and Wakari let you install your own Python
packages.
To install any package packagename
available at PyPi, run
pip install --user packagename
To install the SciTools package, create a Terminal (with a Unix shell) and run the command
pip install --user -e \
git+https://github.com/hplgit/scitools.git#egg=scitools