University College London

April 30 - May 1, 2012
9:00 am - 4:30 pm

This course is now fully booked and has a long waiting list. If you would like to be informed of similar events in the future, please e-mail us on swc2012@ucl.ac.uk.

What: Our goal is to help scientists and engineers become more productive by teaching them basic computing skills like program design, version control, testing, and task automation. In this two-day bootcamp, short tutorials will alternate with hands-on practical exercises. Participants will be encouraged both to help one another, and to apply what they have learned to their own research problems during and between sessions. Attendants are offered online office hours: regular events to get one-on-one help from Software Carpentry instructors, online.

Who: The course is aimed at postgraduate students and other scientists who are familiar with basic programming concepts (like loops, conditionals, arrays, and functions) but need help to translate this knowledge into practical tools to help them work more productively.

Requirements: Participants must bring a laptop with a few specific software packages installed. (The list will be sent to participants a week before the bootcamp.)

Content: The syllabus for this bootcamp will include:

counter.py

# Count data records in file.
# Reads from standard input if no filename given.
# Reads from a single file if filename given.
# Title and comments don't count.
import sys

def count_records(reader):
    number = 0
    expected = None
    for line in reader:
        if line.startswith('#-'):
            junk, expected = line.split()
            expected = int(expected)
        elif line.startswith('#'):
            pass
        elif line.startswith('D'): # FIXME
            pass
        else:
            number = number + 1
    return number, expected

if len(sys.argv) == 2:
    filename = sys.argv[1]
    source = file(filename, 'r')
else:
    source = sys.stdin
number, expected = count_records(source)
source.close()
if expected == None:
    print 'number of records:', number
elif expected == number:
    print 'pass'
else:
    print 'fail'

fun.py

def double(x):
    return 2 * x

def add_three(x):
    return x + 3

def sub_one(x):
    return x - 1

def do_for_each(func, values):
    result = []
    for v in values:
        temp = func(v)
        result.append(temp)
    return result

start = [3, 7, 42, 96]

doubled = do_for_each(double, start)
added = do_for_each(add_three, start)
subtracted = do_for_each(sub_one, start)

print 'started with', start
print 'doubled', doubled
print 'incremented', added
print 'subtracted', subtracted

Databases

Person

Login LastName FirstName
skol Kovalevskaya Sofia
mlom Lomonosov Mikhail
dmitri Mendeleev Dmitri
ivan Pavlov Ivan

Project

ProjectId ProjectName
1214 Antigravity
1709 Teleportation
1737 Time Travel

Experiment

ProjectId ExperimentId NumInvolved ExperimentDate Hours
1214 1 1 1.5
1214 2 1 1889-11-01 14.3
1709 1 3 1891-01-22 7.0
1709 2 1 1891-02-23 7.2
1737 1 1 1900-07-05 -1.0
1737 2 2 1900-07-05 -1.5

Involved

ProjectId ExperimentId InvolvedId Login
1214 1 1 mlom
1214 2 1 mlom
1709 1 1 dmitri
1709 1 2 skol
1709 1 3 ivan
1709 2 1 mlom
1737 1 1 skol
1737 2 1 skol
1737 2 2 ivan

Sample Query

-- Get the people who worked on each project.
select distinct Project.ProjectName, Involved.Login
from Project join Involved
where Project.ProjectId = Involved.ProjectId
order by Involved.Login;

Homework

Homework

Get project name, person's last name, experiment ID, and hours worked in one table.

select '# $Revision:$';
select '# db version' || VersionId from DatabaseVersion;
select Project.ProjectName,
       Person.LastName,
       Experiment.ExperimentId,
       Experiment.Hours
from Person join Project join Experiment join Involved
where (Project.ProjectId = Experiment.ProjectId)
  and (Involved.ProjectId = Project.ProjectId)
  and (Involved.Login = Person.Login)
  and (Experiment.ExperimentId = Involved.ExperimentId);

Access from Python

import sqlite3

connection = sqlite3.connect("experiments.db")
cursor = connection.cursor()
cursor.execute("SELECT FirstName, LastName FROM Person;")
results = cursor.fetchall();
for r in results:
    print r[0], r[1]
cursor.close();
connection.close();

Nose tests for rectangle overlap

from overlap import overlap

def test_overlap_on_one_corner():
    assert overlap([0, 2, 0, 2],
                   [1, 3, 1, 3]) == [1, 2, 1, 2]

def test_no_overlap_at_all():
    assert overlap([0, 1, 0, 1],
                   [3, 4, 3, 4]) == None

def test_one_inside_another():
    assert overlap([0, 10, 0, 10],
                   [2, 3, 2, 3]) == [2, 3, 2, 3]

def test_overlap_along_one_edge():
    assert overlap([0, 3, 0, 3],
                   [3, 5, 0, 3]) == None

def test_inside_on_one_axis():
    assert overlap([0, 3, 0, 3],
                   [1, 2, 1, 4]) == [1, 2, 1, 3]