[July 24-25] Software Carpentry at UCL: Bash, Git, and Python Workshop

:tada: Welcome!

:calendar: Day 1 - Day 2

:ballot_box_with_check: Sign-in

Exercises

Lesson Material


Staff

DAY 1:

Instructors: Will Graham, Krishnakumar Gopalakrishnan
Helpers: David Wong, Nik Khadijah Nik Aznan

DAY 2:

Instructors: Will Graham, Paddy Roddy
Helpers: Katic Buntic

Sign In

Add your name to the list below, use a dash (-) to start a new bullet point on a new line!

Notes

If you missed setting the Git options:

git config --global user.name "YOUR NAME"
git config --global user.email "YOUR EMAIL"
git config --global core.autocrlf input # only run if you're on MAC or Linux
git config --global core.autocrlf true # only run if you're on Windows
git config --global core.editor "nano -w"
git config --global init.defaultBranch main
# We are now going to make a plot of the average inflammation on each day # First, we need to compute the average inflammation on each day, and save it avg_inflammation_each_day = np.mean(data, axis=0) # Create the plot and graph! fig = plt.figure() # This gives us a "figure box" to draw things in! ax = fig.add_subplot(1, 1, 1) # Add an x/y axis for us to draw on. The 1, 1, 1 is a positioning thing for the figure box # Populate our axes with our data! ax.plot(avg_inflammation_each_day, ".r") ax.set_xlabel("Day of trial") ax.set_ylabel("Avg. Inflammation") # Display our graph! plt.show()

Longer, plotting on 3 different axes:

# Actually, I want to make 3 plots in the same figure, for the max, min, and average # First, we need to compute the average, max, and min inflammation on each day, and save it avg_inflammation_each_day = np.mean(data, axis=0) max_inflammation_each_day = np.max(data, axis=0) min_inflammation_each_day = np.min(data, axis=0) # I still need a figure window fig = plt.figure(figsize=(10., 3.)) # Keep the figure a certain size # I need 3 x-y axes side-by-side, rather than just one for each plot. min_axes = fig.add_subplot(1, 3, 1) # 1st of 3 sets of axes max_axes = fig.add_subplot(1, 3, 2) # 2nd of 3 sets of axes avg_axes = fig.add_subplot(1, 3, 3) # 3rd of 3 sets of axes # Plot the relevant data on its corresponding axis min_axes.plot(min_inflammation_each_day, "green") max_axes.plot(max_inflammation_each_day, "red") avg_axes.plot(avg_inflammation_each_day, "blue") # Add axis labels to each set of axes min_axes.set_ylabel("Min") max_axes.set_ylabel("Max") avg_axes.set_ylabel("Avg") # Get rid of the lable clipping into other plots fig.tight_layout() # Display the plot! plt.show()

On lists:

odds = [1, 3, 5, 7] # Make a list print(odds) # Get items from the list print(odds[0], odds[1], odds[2], odds[3]) odds.reverse() # reverse a list print(odds) odds.pop(1) # Remove the item at INDEX 1 in the list (removes 3) print(odds) odds.pop(1) # Remove the item at INDEX 1 in the list (removes 5) print(odds)

Combining Lists, Loops, and Plotting

import numpy as np import matplotlib.pyplot as plt import glob filenames = sorted(glob.glob("data/inflammation-??.csv")) for filename in filenames[:3]: # Only loop over the first 3 files print(filename) # Load data for the current file we're looking at data = np.loadtxt(fname=filename, delimiter=",") # Make the plot window and the x-y axes we need fig = plt.figure() ax1 = fig.add_subplot(1, 3, 1) ax2 = fig.add_subplot(1, 3, 2) ax3 = fig.add_subplot(1, 3, 3) # Now, setup each axes with a plot # ax1 plots the average ax1.set_ylabel("Average") ax1.plot(data.mean(axis=0)) # ax2 plots the max ax2.set_ylabel("Max") ax2.plot(data.max(axis=0)) # ax3 plots the min ax2.set_ylabel("Min") ax2.plot(data.min(axis=0)) # Fixes captions being in the wrong place fig.tight_layout() # Show the figure plt.show()