Prerequisites:

Preliminaries

It is easy to understand how to use some tools. A hammer is easy to figure out. Other tools require more skill — a milling machine for example. Our goal here is to help you learn how to use computers as tools for doing science. Everyone, including scientists, use computers to write papers and access information, but scientists use computers in a unique way. They might use computers to control laboratory equipment, analyze data, or solve problems that are too difficult or impossible to solve analytically. Here we emphasize using computers for data analysis and computational problem solving. Most of the examples on this site are drawn from the fields of physics, astronomy, and chemistry, but the techniques described can be used to analyze scientific data sets or numerically solve problems in any of the sciences. Our tool of choice for this computing task is an interpreted programming language called Python augmented by a collection of libraries specifically designed for scientific computing.

Our main goal isn't to teach you how to program, but you will learn quite a bit about programming along the way. If you've had a programming course in the past, you will feel right at home. But, if you haven't, don't worry; most of the programming tools you will need to learn will be straightforward.

Python is a general-purpose high-level programming language. A high-level programming language uses commands much like a natural language. A program is just a sequence of instructions (call it code if you want to sound like a programmer), written in a format that can be converted into a computer's native language. There is a huge amount of Python code written for doing science. One of the advantages of Python is that it is very easy to import already existing code. A collection of of importable Python code is called a library or package. One of the most useful libraries for scientific computing is called SciPy. SciPy is an open source library of algorithms and mathematical tools for the Python programming language. It is actually a huge collection of modules for all sorts of tasks common in science and engineering. Another important package is called matplotlib. Matplotlib is a python library publication quality figures. If all of this sounds a little confusing, that's because it is. Don't worry, we will soon see that it's all manageable.

Making friends with the command line

The most common way to run Python is by using the command-line interface. Macs, Linux, and, Windows computers all have a command-line interface. If you don't know how to use the command line, now is a good time to learn. The links in the list below will take you to some relatively short command-line tutorials.

Software setup

You will need access to a computer with a text editor, Python, and the required modules installed. Python and all of the modules you need are open source so in principle you can download and install all of the software for free. This can be a formidable task. Fortunately, there are alternatives. The Enthought Python Distribution and Anaconda are both bundled distributions that include all of the modules needed for these tutorials. All of the tutorials on this site were developed using the Anaconda distribution of Python 3. You can download the Anaconda Distribution for free. Students or employees from degree-granting institutions can download a free version of Enthought Canopy for academic use.

If you plan to use the code on this site I strongly encourage you to use the latest Python 3 Anacaonda distribution.

Text editors

Both of the above Python distributions include sophisticated IDEs (integrated development environments). Most IDEs include a text editor for editing a source code, a source code debugger, and a facility for running programs. The IDE for Enthought Python is called Canopy and is relatively simple. Anaconda uses a very sophisticated IDE called Spyder.

IDEs are useful, but if you wish to use all of the features they have a steep learning curve. Another option is to use a text editor to write your code and run Python from the command-line interface. Text editors are not word processing programs! Word processors like Microsoft Word or Apple Pages save formatting information along with the text and aren't programming friendly. There are several free open-source text editors that are optimized for writing computer programs. The text editor we have chosen for these tutorials is called Atom. Atom runs on all modern operating systems—macOS, Windows, and Linux.

How to use this site

Think of this site as a computing toolbox. For example, suppose you need to solve an ordinary differential equation (ODE), just go to the ODE page and it will describe how to use the necessary computational tools. Each page not only describes how to use the tools, but gives lots of example code that you can modify for your own use. You can get a copy all of the code examples from the Source Code Downloads page. Feel free to modify the code for your own use. It's often much easier to modify existing code than write a new program from scratch. The end of each page has table that summarizes the commands introduced on that page. All of these tables are reproduced on the Command Summary page for quick reference.

In order to use some tools you need a some prerequisite skills. The Prerequisites box in the top-right corner of each page lists the prerequisite Toolbox pages. This page is considered a prerequisite for all for all of the pages on the site. Of course, this page has no prerequisites, but I did include a Prerequisites box so you know what they look like.

Typographic conventions

The following conventions are used on this site:

For example, a program code listing looks like this:

x = linspace(0,10,100)
y = x**2
plot(x,y)

An interactive session with the Python command line looks like this:

>>> print("Hello world")
Hello world
>>> print("My name is your name here")
My name is your name here
>>>