The best way to learn how to program is to do something useful, so this introduction to Python is built around a common scientific task: data analysis.
Sea surface waves
In this exercise we will read and manipulate ocean data. The data used has been generated by a spectral wave model WaveWatch III, which is a numerical tool for simulating and forecasting sea state.
When it is very windy or storms pass-over large sea areas, surface waves grow from short choppy wind-sea waves into powerful swell waves. The height and energy of the waves is larger in winter time, when there are more storms.
The example file contains a time series of wave data. The numbers representing the significant wave height: the mean wave height (trough to crest) of the highest third of the waves.
These values are monthly averages, over a period of 37 years. The first two columns are related to the timing of the data, years in the first column, then months. The wave height data are in the third column.
To investigate the wave data, we would like to
- Calculate an average and maximum
- Observe the seasonal cycle
- Take averages per month over successive years
- Find which months have the smallest and largest waves
- Plot the result to discuss and share with colleagues
Data Format
The data sets are stored in comma-separated values (CSV) format:
- the data represent waves at one location in the North Atlantic Ocean
- each row holds information for a single months,
- 3 columns represent year, month, and then the data value
The first seven rows of our first file look like this:
1979,1,3.788
1979,2,3.768
1979,3,4.774
1979,4,2.818
1979,5,2.734
1979,6,2.086
1979,7,2.066
Each data value represents the significant wave height in metres, an average over the month.
For example, value “2.066” at row 7 column 3 of the data set above means that during the seventh month (July) of the first year (1979), the wave height was an average of 2.066 m.
In order to analyze this data and report to our colleagues, we’ll have to learn a little bit about programming.
Prerequisites
You need to understand the concepts of files and directories and how to start a Python interpreter before tackling this lesson. This lesson sometimes references Jupyter Notebook although you can use any Python interpreter mentioned in the Setup.
The commands in this lesson pertain to Python 3.
Getting Started
To get started, follow the directions on the “Setup” page to download data and install a Python interpreter.