(Brief) Intro to (Scientific) Python!

80
(Brief) Intro to (Scientific) Python! Dr. Paige Martin COESSING 2019

Transcript of (Brief) Intro to (Scientific) Python!

Page 1: (Brief) Intro to (Scientific) Python!

(Brief) Intro to (Scientific) Python!

Dr. Paige MartinCOESSING 2019

Page 2: (Brief) Intro to (Scientific) Python!

What is oceanographic data?

Page 3: (Brief) Intro to (Scientific) Python!

What is oceanographic data?

In-Situ Observations

Page 4: (Brief) Intro to (Scientific) Python!

What is oceanographic data?

In-Situ Observations

Satellite Data

Page 5: (Brief) Intro to (Scientific) Python!

What is oceanographic data?

In-Situ Observations

Satellite Data

Model output

Page 6: (Brief) Intro to (Scientific) Python!

Why do we need data analysis?

Page 7: (Brief) Intro to (Scientific) Python!

Why do we need data analysis?• Data analysis is how we translate raw data into interesting scientific results!

Page 8: (Brief) Intro to (Scientific) Python!

Why do we need data analysis?• Data analysis is how we translate raw data into interesting scientific results!

• Data analysis:

Page 9: (Brief) Intro to (Scientific) Python!

Why do we need data analysis?• Data analysis is how we translate raw data into interesting scientific results!

• Data analysis: • Manipulate data

Page 10: (Brief) Intro to (Scientific) Python!

Why do we need data analysis?• Data analysis is how we translate raw data into interesting scientific results!

• Data analysis: • Manipulate data

Velocity v Kinetic energy = ½ m v2

Page 11: (Brief) Intro to (Scientific) Python!

Why do we need data analysis?• Data analysis is how we translate raw data into interesting scientific results!

• Data analysis: • Manipulate data

Velocity v Kinetic energy = ½ m v2

• Visualize data

Page 12: (Brief) Intro to (Scientific) Python!

What is Python?

Page 13: (Brief) Intro to (Scientific) Python!

What is Python?

• It’s a computer language – it allows us as humans to communicate with the computer and make it do what we want!

Page 14: (Brief) Intro to (Scientific) Python!

What is Python?

• It’s a computer language – it allows us as humans to communicate with the computer and make it do what we want!

Page 15: (Brief) Intro to (Scientific) Python!

What is Python?

• It’s a computer language – it allows us as humans to communicate with the computer and make it do what we want!

Page 16: (Brief) Intro to (Scientific) Python!

How does Python work?

Page 17: (Brief) Intro to (Scientific) Python!

How does Python work?

Write Python code

Page 18: (Brief) Intro to (Scientific) Python!

How does Python work?

Write Python code

Run thecode

Page 19: (Brief) Intro to (Scientific) Python!

How does Python work?

Write Python code

Run thecode

View the result!

Page 20: (Brief) Intro to (Scientific) Python!

How does Python work?

Write Python code

Run thecode

View the result!

Page 21: (Brief) Intro to (Scientific) Python!

How does Python work?

Write Python code

Run thecode

View the result!

Run the code

Page 22: (Brief) Intro to (Scientific) Python!

How does Python work?

Write Python code

Run thecode

View the result!

Run the code

Page 23: (Brief) Intro to (Scientific) Python!

How does Python work?

Write Python code

Run thecode

View the result!

Page 24: (Brief) Intro to (Scientific) Python!

How does Python work?

Write Python code

Run thecode

View the result!

Page 25: (Brief) Intro to (Scientific) Python!

How does Python work?

Write Python code

Run thecode

View the result!

Run the code

Page 26: (Brief) Intro to (Scientific) Python!

How does Python work?

Write Python code

Run thecode

View the result!

Run the code

Page 27: (Brief) Intro to (Scientific) Python!

How do I write Python code?

Page 28: (Brief) Intro to (Scientific) Python!

How do I write Python code?

• Line-by-line:

Page 29: (Brief) Intro to (Scientific) Python!

How do I write Python code?

• Line-by-line:

• Usually, we write scripts –• Many lines of code• Run the entire script all together

Page 30: (Brief) Intro to (Scientific) Python!

What editor should I use?

Page 31: (Brief) Intro to (Scientific) Python!

What editor should I use?

• There are many to choose from!

Page 32: (Brief) Intro to (Scientific) Python!

What editor should I use?

• There are many to choose from!• Terminal (command line)

Page 33: (Brief) Intro to (Scientific) Python!

What editor should I use?

• There are many to choose from!• Terminal (command line)• Jupyter Notebook

Page 34: (Brief) Intro to (Scientific) Python!

What editor should I use?

• There are many to choose from!• Terminal (command line)• Jupyter Notebook• Spyder, PyCharm, Atom, …

Page 35: (Brief) Intro to (Scientific) Python!

What editor should I use?

• There are many to choose from!• Terminal (command line)• Jupyter Notebook• Spyder, PyCharm, Atom, …• I will focus on Jupyter Notebook, because it’s what I use. It is a way of writing

interactive Python code.

Page 36: (Brief) Intro to (Scientific) Python!

What editor should I use?

• There are many to choose from!• Terminal (command line)• Jupyter Notebook• Spyder, PyCharm, Atom, …• I will focus on Jupyter Notebook, because it’s what I use. It is a way of writing

interactive Python code.• I highly suggest downloading Python via Anaconda

Page 37: (Brief) Intro to (Scientific) Python!

What editor should I use?

• There are many to choose from!• Terminal (command line)• Jupyter Notebook• Spyder, PyCharm, Atom, …• I will focus on Jupyter Notebook, because it’s what I use. It is a way of writing

interactive Python code.• I highly suggest downloading Python via Anaconda• Anaconda packages the Python language together with many useful libraries

and script editors

Page 38: (Brief) Intro to (Scientific) Python!

What editor should I use?

• There are many to choose from!• Terminal (command line)• Jupyter Notebook• Spyder, PyCharm, Atom, …• I will focus on Jupyter Notebook, because it’s what I use. It is a way of writing

interactive Python code.• I highly suggest downloading Python via Anaconda• Anaconda packages the Python language together with many useful libraries

and script editors• Anaconda includes Jupyter notebook – an interactive Python editor

Page 39: (Brief) Intro to (Scientific) Python!

How do I write a Python script in Jupyter notebook?

Page 40: (Brief) Intro to (Scientific) Python!

How do I write a Python script in Jupyter notebook?

Let’s look at a sample script!

Page 41: (Brief) Intro to (Scientific) Python!

How do I write a Python script in Jupyter notebook?

Page 42: (Brief) Intro to (Scientific) Python!

How do I write a Python script in Jupyter notebook?Import libraries

Page 43: (Brief) Intro to (Scientific) Python!

How do I write a Python script in Jupyter notebook?Import libraries

Comments

Page 44: (Brief) Intro to (Scientific) Python!

How do I write a Python script in Jupyter notebook?Import libraries

Main code

Comments

Page 45: (Brief) Intro to (Scientific) Python!

How do I write a Python script in Jupyter notebook?Import libraries

Load your data

Main code

Comments

Page 46: (Brief) Intro to (Scientific) Python!

How do I write a Python script in Jupyter notebook?Import libraries

Load your data

Data analysis Main code

Comments

Page 47: (Brief) Intro to (Scientific) Python!

How do I write a Python script in Jupyter notebook?Import libraries

Load your data

Data analysis

Visualize yourdata

Main code

Comments

Page 48: (Brief) Intro to (Scientific) Python!

How do I write a Python script in Jupyter notebook?Import libraries

Load your data

Data analysis

Visualize yourdata

Main code

Comments

Page 49: (Brief) Intro to (Scientific) Python!

How do I write a Python script in Jupyter notebook?Import libraries

Load your data

Data analysis

Visualize yourdata

Main code

Comments

Page 50: (Brief) Intro to (Scientific) Python!

Common Python libraries for science

Page 51: (Brief) Intro to (Scientific) Python!

Common Python libraries for science

• NumPy – numeric library with lots of mathematical functions (e.g. average, trig functions, etc.), and also has array formatting that is very convenient

Page 52: (Brief) Intro to (Scientific) Python!

Common Python libraries for science

• NumPy – numeric library with lots of mathematical functions (e.g. average, trig functions, etc.), and also has array formatting that is very convenient• Matplotlib – plotting library for Python

Page 53: (Brief) Intro to (Scientific) Python!

Common Python libraries for science

• NumPy – numeric library with lots of mathematical functions (e.g. average, trig functions, etc.), and also has array formatting that is very convenient• Matplotlib – plotting library for Python• Pandas – efficient and easy-to-use data structures and other data

analysis tools

Page 54: (Brief) Intro to (Scientific) Python!

Common Python libraries for science

• NumPy – numeric library with lots of mathematical functions (e.g. average, trig functions, etc.), and also has array formatting that is very convenient• Matplotlib – plotting library for Python• Pandas – efficient and easy-to-use data structures and other data

analysis tools• We need to import libraries each

time we start a new script

Page 55: (Brief) Intro to (Scientific) Python!

Common Python libraries for science

• NumPy – numeric library with lots of mathematical functions (e.g. average, trig functions, etc.), and also has array formatting that is very convenient• Matplotlib – plotting library for Python• Pandas – efficient and easy-to-use data structures and other data analysis

tools• We need to import libraries each

time we start a new script • We often import libraries as a shorter

name to keep typing to minimum, but this helps organize so that we know which functions are from which libraries

Page 56: (Brief) Intro to (Scientific) Python!

How do I write a Python script in Jupyter notebook?Import libraries

Load your data

Data analysis

Visualize yourdata

Main code

Comments

Page 57: (Brief) Intro to (Scientific) Python!

How do I write a Python script in Jupyter notebook?Import libraries

Load your data

Data analysis

Visualize yourdata

Main code

Comments

Page 58: (Brief) Intro to (Scientific) Python!

Common actions in Python

• Print statements

Page 59: (Brief) Intro to (Scientific) Python!

Common actions in Python

• Print statements• Assign variables

Page 60: (Brief) Intro to (Scientific) Python!

Common actions in Python

• Print statements• Assign variables • Do math

Page 61: (Brief) Intro to (Scientific) Python!

Common actions in Python

• Print statements• Assign variables • Do math • Use arrays and lists

• Accessing elements

Page 62: (Brief) Intro to (Scientific) Python!

Common actions in Python

• Print statements• Assign variables • Do math • Use arrays and lists

• Accessing elements• Plot data

Page 63: (Brief) Intro to (Scientific) Python!

Common actions in Python

• Print statements• Assign variables • Do math • Use arrays and lists

• Accessing elements• Plot data• Load data – we assign a name

to the dataset (e.g. ‘lon’) -same as assigning a variable!

Page 64: (Brief) Intro to (Scientific) Python!

Common actions in Python

• Print statements• Assign variables • Do math • Use arrays and lists

• Accessing elements• Plot data• Load data – we assign a name

to the dataset (e.g. lon) - same as assigning a variable!• if statements and for loops

Page 65: (Brief) Intro to (Scientific) Python!

Common actions in Python

• Print statements• Assign variables • Do math • Use arrays and lists

• Accessing elements• Plot data• Load data – we assign a name

to the dataset (e.g. lon) - same as assigning a variable!• if statements and for loops

Page 66: (Brief) Intro to (Scientific) Python!

Common actions in Python

• Print statements• Assign variables • Do math • Use arrays and lists

• Accessing elements• Plot data• Load data – we assign a name

to the dataset (e.g. lon) - same as assigning a variable!• if statements and for loops• Save new data or figure

Page 67: (Brief) Intro to (Scientific) Python!

There are other computer languages. Why Python?

Page 68: (Brief) Intro to (Scientific) Python!

There are other computer languages. Why Python?• Relatively easy to learn

Page 69: (Brief) Intro to (Scientific) Python!

There are other computer languages. Why Python?• Relatively easy to learn• Free and open source

Page 70: (Brief) Intro to (Scientific) Python!

There are other computer languages. Why Python?• Relatively easy to learn• Free and open source• Syntax is clean and easy to read

Page 71: (Brief) Intro to (Scientific) Python!

There are other computer languages. Why Python?• Relatively easy to learn• Free and open source• Syntax is clean and easy to read• Computationally efficient

Page 72: (Brief) Intro to (Scientific) Python!

There are other computer languages. Why Python?• Relatively easy to learn• Free and open source• Syntax is clean and easy to read• Computationally efficient• Can be used for many different applications

Page 73: (Brief) Intro to (Scientific) Python!

There are other computer languages. Why Python?• Relatively easy to learn• Free and open source• Syntax is clean and easy to read• Computationally efficient• Can be used for many different applications• Other languages/software: Matlab, C, C++, Fortran, R, etc.

Page 74: (Brief) Intro to (Scientific) Python!

Download and install instructions

Page 75: (Brief) Intro to (Scientific) Python!

Download and install instructions

• Download/install Python via Anaconda

Page 76: (Brief) Intro to (Scientific) Python!

Download and install instructions

• Download/install Python via Anaconda• Instructions for download are on COESSING website (”coessing.org”) under

the “Resources” tab

Page 77: (Brief) Intro to (Scientific) Python!

Download and install instructions

• Download/install Python via Anaconda• Instructions for download are on COESSING website (”coessing.org”) under

the “Resources” tab• Introductory Python and Jupyter lessons also under the “Resources”

tab

Page 78: (Brief) Intro to (Scientific) Python!

Download and install instructions

• Download/install Python via Anaconda• Instructions for download are on COESSING website (”coessing.org”) under

the “Resources” tab

• Introductory Python and Jupyter lessons also under the “Resources” tab• Tomorrow afternoon, Python lab in the RMU computer lab!

Page 79: (Brief) Intro to (Scientific) Python!

Let’s open Jupyter notebook!

Page 80: (Brief) Intro to (Scientific) Python!