Programming and Plotting in Python

U.S. Geological Survey

Online

June 16, 2022

8:00 am - 3:30 pm PDT (11:00 am - 6:30 pm EDT)

Instructors: Marc Hunter, Madison Langseth

Helpers: Christopher Sherwood, Brandon Serna, Amber Jones

General Information

Software Carpentry aims to help researchers get their work done in less time and with less pain by teaching them basic research computing skills. This hands-on workshop will cover basic concepts and tools, including program design, version control, data management, and task automation. Participants will be encouraged to help one another and to apply what they have learned to their own research problems.

For more information on what we teach and why, please see our paper "Best Practices for Scientific Computing".

Who: The course is aimed at people of all career stages with little or no experience with Python. You don't need to have any previous knowledge of the tools that will be presented at the workshop.

Where: This training will take place online. The instructors will provide you with the information you will need to connect to this meeting.

When: June 16, 2022. Add to your Google Calendar.

Requirements: Participants must have access to a computer with a Mac, Linux, or Windows operating system (not a tablet, Chromebook, etc.) that they have administrative privileges on. They should have a few specific software packages installed (listed below).

Accessibility: We are dedicated to providing a positive and accessible learning environment for all. Please notify the instructors in advance of the workshop if you require any accommodations or if there is anything we can do to make this workshop more accessible to you.

Contact: Please email mahunter@usgs.gov or mlangseth@usgsg.gov for more information.

Roles: To learn more about the roles at the workshop (who will be doing what), refer to our Workshop FAQ.


Code of Conduct

Everyone who participates in Carpentries activities is required to conform to the Code of Conduct. This document also outlines how to report an incident if needed.


Collaborative Notes

We will use this collaborative document for chatting, taking notes, and sharing URLs and bits of code.


Surveys

Please be sure to complete these surveys before and after the workshop.

Pre-workshop Survey

Post-workshop Survey


Schedule

June 15, 2022 8:00 - 9:00 PDT

The intoduction session will ensure everyone has the correct software installed and exercise data downloaded. Use this link to join.

June 16, 2022 8:00 - 3:30 PDT

Before starting Pre-workshop survey
08:00 Running and Quitting How can I run Python programs?
08:15 Variables and Assignment How can I store data in programs?
08:35 Data Types and Type Conversion What kinds of data do programs store?
How can I convert one type to another?
08:55 Built-in Functions and Help How can I use built-in functions?
How can I find out what they do?
What kind of errors can occur in programs?
09:30 Morning Coffee Break
09:35 Libraries How can I use software that other people have written?
How can I find out what that software does?
09:55 Reading Tabular Data into DataFrames How can I read tabular data?
10:15 Pandas DataFrames How can I do statistical analysis of tabular data?
10:45 Plotting How can I plot my data?
How can I save my plot for publishing?
11:15 Lunch Break
12:00 Lists How can I store multiple values?
12:20 For Loops How can I make a program do many things?
12:45 Conditionals How can programs do different things for different data?
1:10 Looping Over Data Sets How can I process many data sets with a single command?
1:25 Afternoon Coffee Break
1:40 Writing Functions How can I create my own functions?
2:05 Variable Scope How do function calls actually work?
How can I determine where errors occurred?
2:25 Programming Style How can I make my programs more readable?
How do most programmers format their code?
How can programs check their own operation?
2:55 Wrap-Up What have we learned?
What else is out there and where do I find it?
3:15 Feedback How did the class go?
3:30 Finish

Setup

To participate in a Software Carpentry workshop, you will need access to software as described below. In addition, you will need an up-to-date web browser.

We maintain a list of common issues that occur during installation as a reference for instructors that may be useful on the Configuration Problems and Solutions wiki page.

Install the videoconferencing client

Microsoft Teams will be required to participate in this course. Use this Teams Meeting link to join.

Set up your workspace

Like other Carpentries workshops, you will be learning by "coding along" with the Instructors. To do this, you will need to have both the window for the tool you will be learning about (a terminal, RStudio, your web browser, etc..) and the window for the Teams meeting client open. In order to see both at once, we recommend using one of the following set up options:

This blog post includes detailed information on how to set up your screen to follow along during the workshop.

Python

Python is a popular language for research computing, and great for general-purpose programming as well. Installing all of its research packages individually can be a bit difficult, so we recommend Anaconda, an all-in-one installer.

Regardless of how you choose to install it, please make sure you install Python version 3.x (e.g., 3.6 is fine).

We will teach Python using the JupyterLab, a programming environment that runs in a web browser (JupyterLab will be installed by Anaconda). For this to work you will need a reasonably up-to-date browser. The current versions of the Chrome, Safari and Firefox browsers are all supported (some older browsers, including Internet Explorer version 9 and below, are not).

  1. Open https://www.anaconda.com/products/individual#download-section with your web browser.
  2. Download the Anaconda for Windows installer with Python 3. (If you are not sure which version to choose, you probably want the 64-bit Graphical Installer Anaconda3-...-Windows-x86_64.exe)
  3. Install Python 3 by running the Anaconda Installer, using all of the defaults for installation except make sure to check Add Anaconda to my PATH environment variable.

Video Tutorial

  1. Open https://www.anaconda.com/products/individual#download-section with your web browser.
  2. Download the Anaconda Installer with Python 3 for macOS (you can either use the Graphical or the Command Line Installer).
  3. Install Python 3 by running the Anaconda Installer using all of the defaults for installation.

Video Tutorial

  1. Open https://www.anaconda.com/products/individual#download-section with your web browser.
  2. Download the Anaconda Installer with Python 3 for Linux.
    (The installation requires using the shell. If you aren't comfortable doing the installation yourself stop here and request help at the workshop.)
  3. Open a terminal window and navigate to the directory where the executable is downloaded (e.g., `cd ~/Downloads`).
  4. Type
    bash Anaconda3-
    and then press Tab to autocomplete the full file name. The name of file you just downloaded should appear.
  5. Press Enter (or Return depending on your keyboard). You will follow the text-only prompts. To move through the text, press Spacebar. Type yes and press enter to approve the license. Press Enter (or Return) to approve the default location for the files. Type yes and press Enter (or Return) to prepend Anaconda to your PATH (this makes the Anaconda distribution the default Python).
  6. Close the terminal window.

Get the Data

The data we will be using is taken from the gapminder dataset. To obtain it, download and unzip the file python-novice-gapminder-data.zip. In order to follow the presented material, you should launch the JupyterLab server in the root directory (see Starting JupyterLab).