In [8]:
# Pay no attention to this cell
# All will be revealed in due time.
import pandas as pd
from IPython.display import Image
syllabus=pd.read_csv('syllabus.csv',header=0)
syllabus=syllabus.fillna("")
syllabus.index = range(1,len(syllabus)+1)

SIO 113: Introduction to Computational Earth Science

Authors: Lisa Tauxe, ltauxe@ucsd.edu & Hanna Asefaw, hasefaw@ucsd.edu

  • Winter 2018
  • Lectures: MWF 1-1:50
  • Discussion Section: Tue 10-10:50
  • Location: Eckart 225

Computers in Earth Science

Computers are essential to all modern Earth Science research. We use them for compiling and analyzing data, preparing illustrations like maps or data plots, writing manuscripts, and so on. In this class, you will learn to write computer programs with special applications useful to Earth Scientists. We will learn Python, an object-oriented programming language, and use jupyter notebooks to write our Python programs.

Python

So, why learn Python?

  • Flexible, freely available, cross platform
  • Easier to learn than many other languages
  • It has many numerical, statistical and visualization packages
  • It is well supported and has lots of online documentation
  • The name 'Python' refers to 'Monty Python' - not the snake - and many examples in the Python documentation use jokes from the old Monty Python skits. If you have never heard of Monty Python, look it up on youtube; you are in for a treat.

Which Python?

  • Python is undergoing a transition from 2.7 to 3. The notebooks in this class, apart from a few exceptions, are compatible with both.
  • If you decide to use a personal computer, we recommend that you install the most recent version of Anaconda python for your operating system : https://www.anaconda.com/download/

Grading

  • 25% Daily Practice Problems
  • 25% Final Project
  • 50% Weekly Homework assignment

Class Structure

  • There will be three lectures a week and one discussion session.
  • Students are expected to read the lecture prior to attending class.
  • Download the lecture before hand from TritonEd or from here
  • Each lecture begins with a quick review (~5 min) and proceeds to the topic of the day. Lecture time will be devoted to practicing the skills that we covered in the lecture.
  • At the end of every lecture, students will submit their practice problems- (jupyter) notebooks- on TritonEd.
  • Each student will have the opportunity to present a practice solution to the class. You will be informed of your assignment ahead of time. Lecture notebooks will count toward 25% of the final grade (approximately one point per lecture).
  • There will be a programming assignment every week, due BEFORE CLASS one week from the assignment. Assignments will count for 50% of the grade (approximately 5 points per assignment).
  • Help with assignments and the solutions will be disussed during weekly discussion section, both before they are due and after they have been graded.
  • In lieu of a final exam, there will be a final project - a program of your own design and a one page description of the project. There is a great deal of flexibility in what the program will do, but there are a few minimum requirements. We will discuss the final project in more detail later. Final projects will count for 25% of the final grade. In addition to the project, students will prepare a 5 minute presentation of their work, to be given the last week of class.

Class Expectations

  • Attendence is strongly suggested and weekly homework assignements are mandatory as is the final project.
  • Homework will not be accepted late.
  • You may consult any online resources (Stackoverflow is a wonderful resource) or any of your fellow students or your instructors to help you solve your problems. Although this is encouraged, do NOT copy what you find verbatim. You must re-work the solutions through your own brain and in your own words and style, otherwise you will not learn how to program. Copying programs does not help you learn and in fact it is "cheating". Cheating will be reported to the authorities.
  • The best way to learn how to program is to attend the lecture, complete the practice problems and assignments, and attend the discussion section where your TA can help.
In [9]:
syllabus[['Date','Topic','Application', 'Assignment']]
Out[9]:
Date Topic Application Assignment
1 1/8/18 Intro to the class
2 1/10/18 Variables and Operations
3 1/12/18 Data structures
4 1/17/18 Dictionaries, program loops (if, while and for)
5 1/19/18 functions and modules HW 1 due
6 1/22/18 NumPy and matplotlib seismic record
7 1/24/18 NumPy arrays
8 1/26/18 file systems and paths HW 2 due
9 1/29/18 Pandas, file I/O P-S wave arrival times
10 1/31/18 object oriented programming objects and classes
11 2/2/18 recursions and exceptions fibonacci spiral HW 3 due
12 2/5/18 lambda, map, filter reduce, list comprehension
13 2/7/18 data wrangling with Pandas seismic travel time plots
14 2/9/18 subplots, bar charts pie charts elemental abundances HW 4 due
15 2/12/18 histograms and cumulative distribution functions hypsometric curve
16 2/14/18 statistics 101 Univariate data
17 2/16/18 hypothesis testing t, F HW 5 and project proposal due
18 2/21/18 application to grain sizes grain sizes
19 2/23/18 line and curve fitting Bivariate data & Hubble plot HW 6 due
20 2/26/18 maps spatial data; earthquake locations/ depths
21 2/28/18 gridding and contouring IGRF
22 3/2/18 rose diagrams and equal area projections glacial striations HW 7 due
23 3/5/18 matrix math - dot and cross products poles to planes and more
24 3/7/18 plotting great and small circles
25 3/9/18 3D plots of points and surfaces benioff zone HW 8 due
26 3/12/18 Time series - periodograms temporal data
27 3/13/18 Student Presentations (Pt I)
28 3/14/18 Animations Indian plate motion
29 3/16/18 Student Presentations (Pt II) HW 9 due
30 3/23/118 Final projects due

Jupyter notebooks

This class is entirely structured around a special programming environment called jupyter notebooks. A Jupyter notebook is a development environment where you can write, debug, and execute your programs. Put all the lectures and other directories associated with this class into a folder on your computer. To launch a notebook, follow the instructions on this website:

jupyter-notebook-beginner-guide.readthedocs.io/en/latest/execute.html

Launch Lecture_01_syllabus.ipynb

You should now be looking at this notebook.

Jupyter notebook anatomy

Jupyter notebooks have two basic cells:

  • Markdown: for typesetting notes. This cell is an example of a markdown cell.

  • Code: for writing python code

You can insert a new cell by selecting Insert Cell Below in the drop-down menu:

In [3]:
Image(filename='Figures/insertCell.png')
Out[3]:

You change the cell "flavor" with the menu that defaults to 'Code' and can be changed to "Markdown".

And you "execute" a cell (either typeset or run the code) by clicking on the run key (sideways triangle with vertical line) or select Run Cells under the Cell drop-down menu.

In [4]:
Image(filename='Figures/menuBar.png')
Out[4]:

Practice with inserting cells

Insert a cell below this one. Change it to ‘Markdown’ and type some notes. You can just type most things, but special features like Section headers, bullets, numbered lists and other fun things require special formatting. For a pretty good explanation see this link: https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet

Run the cell to typeset your notes. If you want to change them, just double click on the cell, type away, then 'run' it again.

Practice with markdown cells

If you see plain text in one of the cells in the lecture notebooks, just double click on it and all will be revealed. Try double clicking on THIS cell to see how to make section headers - then run it.

Practice with code cells

Insert another cell, keeping it the default of Code.

type: print("Hello World") in the cell and then run that cell.

It should look like this:

In [5]:
print ("Hello World")
Hello World

Congratulations! That was your first Python program.

In a code block, you can only type valid python statements EXCEPT after a pound sign - everything after that will be ignored.
That is how you write "comments" in your code to remind yourself or tell others what you were thinking:

In [6]:
# I can type anything here
but not here
  File "<ipython-input-6-ae00b29ef7b9>", line 2
    but not here
               ^
SyntaxError: invalid syntax

That was an example of a bug which oculd be fixed by commenting out the second line, or making it a valid statement:

In [7]:
# I can type anything here
# but not here
print ("but not here")
but not here

How to take notes in class

Now you know how to insert a markdown cell and write in it, you should take advantage of these notebooks to add your own comments to the lecture notebook as you go. You could even have a separate notebook open in another window in which you can type notes. For that, you need to know how to create your own notebook and save it. And it would be handy to know how to split your screen to have two side by side notebooks.

Creating new notebooks, naming and saving.

To open a new notebook, pull down the 'File' menu and select the 'New Notebook => Python 3' option. You can 'tear' the notebook off so it is in a separate window if you like seeing both together.

To rename the notebook, choose 'Rename' under the File menu.

To save it, click on the disk icon on the menu bar. Wait until the 'checkpoint created...' message disappears before you try to exit the notebook.

Splitting your screen

Click on the green button in the top left corner of your browser and drag it to the side you want your lecture in. Click your "notes" notebook and it will be placed on the other side.

We will learn much more about markdown and code blocks in the coming weeks as you begin to understand how to write programs.

Practice with notebooks

Open a new notebook, rename it to, for example, 'Lecture_01_notes', split your screen if you like, make a Markdown cell, write some notes, and save the file. Now look in your folder and see your brand new notebook!

Final project

As you learn new concepts, start thinking about what you'd like to create for your final project.

There is a great deal of flexibility on the exact nature of the final project but it must be related to Earth and Space Science and, at the bare minimum, it must:

  • include at least one module with three functions
  • read in at least one data file
  • make at least one plot
  • use at least three markdown blocks:
    • a description of what the program does,
    • instructions on how to use the program,
    • a summary of the scientific conclusions

Turn the project in as a zipped directory with all the parts required to run it (the data files, figures, modules, etc.).

Here are a few ideas:

1) Make a movie:

  • of lightning strikes across the continental US
  • of volcanic eruptions across the western US
  • of plate motion over the last 200 Ma
  • your choice

2) Make a 2D image of the solar system with orbiting planets

3) Recreate your favorite plot from a number of examples

4) Design your own project:

In Week 6, you will be asked to turn in a proposal for the final project. In the proposal, you'll describe the final project and how it relates to Earth and Space Science. At that stage, you still may not have all the skills required to complete your project, but we can let you know if it is possible and substantial enough for the final project.