owned this note changed 4 years ago
Linked with GitHub

RSLondon Software Carpentry 2020-11-25/27

General information

This collaborative document (hackmd) is synchronized as you type, so that everyone viewing this page sees the same text. This allows you to collaborate seamlessly on documents.

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
Users are expected to follow our code of conduct.

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
The Workshop webpage contains the installations instructions for the software that we will use during the next three days.

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
Zoom links for each day will be shared via e-mail.

Pre-workshop Questionnaire

Sessions

Wed 25 Thu 26 Fri 27
10'00 Command line
14'00 Version control with Git Python 1/2 Python 2/2

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
Roll call + Check in

  • name / [Additional info, e.g. email / pronoun / social media handle / favorite emoji] / GitHub name
    (👨‍🏫 - instructor; 🧚 - helpers; )
  • 🧚 Jeremy Cohen (organiser/helper), he/him, Imperial College London,
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
    jeremy.cohen@imperial.ac.uk,
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
    @jcohen02
  • 🧚 Iain Stenson (helper), Research Software Engineer at QMUL.
  • 🧚 Alessandro Felder (helper), RSE at UCL, he/him, - ,
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
    , @alessandrofelder .
  • 🧚 Jay DesLauriers (Helper), Researcher at University of Westminster
  • 🧚 Jazz Mack Smith (Helper), Imperial College London
  • 🧚 Markus Löning (Helper) / PhD student at UCL / he/him / GitHub: @mloning
  • 🧚 Tom Bradford (Helper), IT Admin at QMUL
  • 🧚 Tony Yang (Helper), PhD Candidate at Imperial, @tonyyzy
  • 🧚 Anastasis Georgoulas (helper), Research Software Engineer at UCL, he/him, - ,
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
    , @ageorgou
  • 🧚 Jamie Quinn (helper), Research Software Engineer at UCL, he/him, - ,
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
    , @jamiejquinn

Breakout groups for Thursday (Python 1):

  • Tom Bradford and Jay DesLauriers (helpers). Room 4
    • Niyi Ogunbiyi, PhD student at University of Westminister @etioro
    • Jason Pott, (attendant), Phd student at QMUL C4TS Blizzard @jasonpott
    • Gerard Hernandez (attendant), Postdoctoral Researcher at QMUL, @AlanTheCat
    • Zeena Radwan - Phd student at University of Westminister.
    • Marta Ferreira - PhD student at QMUL
    • Oliver van Zwanenberg, PhD student at University of Westminister @OlivervZ11
    • Charlotte
    • Sara
    • Charlotte Lindsay - PhD student at QMUL C4TS
  • Jazz Mack Smith and Tony Yang (helpers). Room 5
    • Floriane Tissot, (attendant), Postdoc at Imperial College, 👩🏻‍🔬, @Flokhi
    • Farzan Ramzan (attendant), Postdoc @ Imperial
    • Patrick White github: patpatpatpatpatpat
    • Leandro Perao (attendant), PhD Student at ICL, he/him,
      Image Not Showing Possible Reasons
      • The image file may be corrupted
      • The server hosting the image is unavailable
      • The image path is incorrect
      • The image format is not supported
      Learn More →
      , @alpha85
    • Yufei Wang, PhD student at Queen Mary University of London
    • Fernando
    • Kaiming
    • Hai-Van
    • Lucie Studena (attendant), PhD student at ICL, @tomca12
  • Markus Löning and Alessandro Felder (helpers). Room 6
    • Georgina Mills (attendant), Research Assistant at UCL, @GeorgieMills
    • Santosh Atanur (attendant), Postdoc at Imperial College London @santoshatanur
    • Matt Wisdom (attendant), Research Assistant at UCL, @mwisdom04
    • Melanie Hare, UCL MSc
    • john gumbley - ucl masters planetary science
    • Alex Vaideanu (attendant), Postdoc at UCL, @alexvaideanu
    • Will Scotton (attendant). PhD Student at UCL @williamscotton
    • Jasleen Gandhi, Masters UCC, @jasleengandhi
    • Ana Krelling (attendant), PhD in physical oceanograhy, she/her, @apkrelling
    • Sara Lise Underhay, PhD student in geophysics





Breakout groups for Friday (Python 2):

  • Jay DesLauriers and Iain Stenson (helpers). Room 1
    • Niyi Ogunbiyi, PhD student at University of Westminister @etioro
    • Jason Pott, (attendant), Phd student at QMUL C4TS Blizzard @jasonpott
    • Gerard Hernandez (attendant), Postdoctoral Researcher at QMUL, @AlanTheCat
    • Zeena Radwan - Phd student at University of Westminister.
    • Marta Ferreira - PhD student at QMUL
    • Oliver van Zwanenberg, PhD student at University of Westminister @OlivervZ11
    • Sara
    • Charlotte Lindsay - PhD student at QMUL C4TS
  • David Perez-Suarez and Anthony Thomas (helpers). Room 2
    • Floriane Tissot, (attendant), Postdoc at Imperial College, 👩🏻‍🔬, @Flokhi
    • Farzan Ramzan (attendant), Postdoc @ Imperial
    • Patrick White github: patpatpatpatpatpat
    • Leandro Perao (attendant), PhD Student at ICL, he/him,
      Image Not Showing Possible Reasons
      • The image file may be corrupted
      • The server hosting the image is unavailable
      • The image path is incorrect
      • The image format is not supported
      Learn More →
      , @alpha85
    • Yufei Wang, PhD student at Queen Mary University of London
    • Hai-Van
    • Lucie Studena (attendant), PhD student at ICL, @tomca12
  • Anastasis Georgoulas and Tony Yang (helpers). Room 3
    • Georgina Mills (attendant), Research Assistant at UCL, @GeorgieMills
    • Santosh Atanur (attendant), Postdoc at Imperial College London @santoshatanur
    • Matt Wisdom (attendant), Research Assistant at UCL, @mwisdom04
    • Areti Papadopoulu
    • Alex Vaideanu (attendant), Postdoc at UCL, @alexvaideanu
    • Will Scotton (attendant). PhD Student at UCL @williamscotton
    • Jasleen Gandhi, Masters UCC, @jasleengandhi
    • Ana Krelling (attendant), PhD in physical oceanograhy, she/her, @apkrelling
    • Sara Lise Underhay, PhD student in geophysics

New attendees - please add your name below:

The Unix Command line - Chris Cave-Ayland

  • To prepare for the session please:

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
Notes (for everyone to add them together 😉)

  • ls shows the files

    • ls -F shows also a trailing slash for the directories (useful if you've haven't got them already in a different colour). -F is an "option".
    • ls -F / shows what's under the / directory.
    • ls --help shows us how to use it! (a bit cryptic though)
      • [OPTION]... You can provide options,
        • [] means they are optional, the `
        • ` mean that you can provide more than one option.
      • [FILE]... we can ask for a location or many as we want and they are optional.
      • There are short and long versions: -a = --all
    • man ls is similar to the help output. You need to press q to exit. The output is clear out from the screen.
    • Options and everything in the shell is case sensitive! -s and -S are different things.
  • pwd print working directory; first / in the output is called the root directory, the base of all the directories.

  • cd Desktop moves your location to the Desktop directory

  • ~ is a short for /home/username, your Home

    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

  • Paths:

    • absolute: refers from the root, eg., /home/user/Desktop/data-shell
    • relative: refers from the point you are in, if we are in Desktop: data-shell
    • ..: refers to the parent directory
    • .: refers to the current directory
  • nano open a text editor within the shell. ctrl+x to exit.

  • cp copies (and renames if needed) something into somewhere cp quotes.txt thesis/quotations.txt

    • cp -r to copy a directory
  • rm to delete (remove) files.

    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
    there's not a recycle bin
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
    !! so be careful

    • rm -r will allow you to delete directories
    • rm -i will ask you for confirmation before deleting stuff.
  • wc count characters, words and lines

  • > is use to redirect the output of a command into a file

  • cat to display files on the screen

  • sort to sort a file, -n to sort numerically.

  • head shows the first few lines of the file, -n 1 will only show the first line.

  • tail like head but for the end of the file

  • | (pipe) is use to redirect the output of one command as input for the next (wc -l *pdb | sort -n | head -n 1 will give the file with the smaller number of lines named ...pdb )

  • for loops, to repeat an action over multiple files.

    ​​$ for filename in basilisk.dat minotaur.dat unicorn.dat
    ​​> do 
    ​​>   head -n 2 $filename | tail -n 1
    ​​> done
    
  • scripts, files that we put the commands we want to run in sequence. Normally called as some_meaningful_name.sh.

    • if used $@ within the script, it will read all the arguments you pass from the command line.
      example:
    ​​for filename in "$@"
    ​​do
    ​​  head -n 15 "$filename" | tail -n 5
    ​​done
    
  • history shows you all the commands you've run.

  • tab will try to autocomplete the files and directory names.

  • ctrl+c is used to cancel what you are running.

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
Questions about Unix command line

Here you can post any question you have while we are going through this document. Please, use a new bullet point for each question and sub-bullet points for their answers.

For example writing like this:

- Example question
  - [name=student_a] Example answer
  - [name=TA_1] Example answer

produces the following result:

  • Example question

    • student_a Example answer
    • TA_1 Example answer
  • What's the difference between git bash and git cmd?

    • Iain S Git CMD is just like regular Windows command prompt with the git command. Git Bash emulates a bash environment on windows. It lets you use all git features in command line plus most of standard unix commands.
  • Is the sorting (when using ls) displayed in vertical or horizontal order?

    • David it's displayed in columns so left column first, then go through the second column.
  • What if I wanted only the name itself without the first bit of the line (CLASSIFICATION:)?

    • Jeremy : This question was in relation to the example shown for working with loops. We looked at an example that would print the "CLASSIFICATION" lines from the files in the creatures directory:
      for filename in *.dat; do head -n 2 $filename | tail -n 1; done
      As highlighted in the Zoom chat, this is beyond the scope of today's session so we haven't covered the additional commands that can help with this. As with many command line tasks, there are a few different ways to achieve this. Some options might be the use of the cut command or awk command. awk can be particularly confusing to work with but it's worth checking out the man page nonetheless.
    • Another way, with cut, -d for delimeter and -f for the field you want to show:
      ​​​​head "$1" -n 2 | tail -n 1 | cut -d':' -f2
      

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
Feedback

Tell us at least one good thing and something we could improve by leaving feedback as post-its on this interactive board.

Version Control with Git - Iain Barrass

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
Notes

Software Carpentry lesson material for GitHub Remotes: http://swcarpentry.github.io/git-novice/07-github/index.html

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
Questions about Git

  • Example question
    • student_a Example answer
    • TA_1 Example answer

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
Feedback

Tell us at least one good thing and something we could improve by leaving feedback as post-its on this interactive board.

Python - day 1 - Iain Stenson

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
Notes

Download python-novice-inflammation-data.zip.

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
Questions about Python 1/2

  • Example question
    • student_a Example answer
    • TA_1 Example answer

Exercises

Exercise Session 1

You can find tips or answers to most exercises in the lesson notes.

1.

What values do the variables mass and age have after each of the following statements? Test your answer by executing the lines.

mass = 47.5
age = 122
mass = mass * 2.0
age = age - 20

2.

What does the following program print out?

first, second = 'Grace', 'Hopper'
third, fourth = second, first
print(third, fourth)

Exercise Session 2

A section of an array is called a slice. We can take slices of character strings as well:

element = 'oxygen'
print('first three characters:', element[0:3])
print('last three characters:', element[3:6])
  1. What is the value of element[:4]? What about element[4:]? Or element[:]?
  2. What is element[-1]? What is element[-2]?
  3. Given those answers, explain what element[1:-1] does.
  4. How can we rewrite the slice for getting the last three characters of element, so that it works even if we assign a different string to element? Test your solution with the following strings: carpentry, clone, hi.

Exercise Session 3

Why do all of our plots stop just short of the upper end of our graph? Can we adjust the y limit of our graph so that it looks better?

some_plot.set_ylim(min, max)

Can you create your own graph of the standard deviation using

np.std()

Exercise Session 4

1.

Python has a built-in function called range that generates a sequence of numbers. range can accept 1, 2, or 3 parameters. If one parameter is given, range generates a sequence of that length, starting at zero and incrementing by 1. For example, range(3) produces the numbers 0, 1, 2. If two parameters are given, range starts at the first and ends just before the second, incrementing by one. For example, range(2, 5) produces 2, 3, 4. If range is given 3 parameters, it starts at the first one, ends just before the second one, and increments by the third one. For example, range(3, 10, 2) produces 3, 5, 7, 9. Using range, write a loop that prints the first 3 natural numbers:

1
2
3

2.

Given the following loop, how many times is print called? 3, 4, 5, or 6 times?

word = 'oxygen'
for char in word:
    print(char)

3.

Exponentiation is built into Python and is done with **.

print(5 ** 3)  # prints 125

Can you calculate 5 to the power 3 using multiplication (*) and loops instead of the ** operator?

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
Feedback

Tell us at least one good thing and something we could improve by leaving feedback as post-its on this interactive board.

Good things

Things to improve

  • At the very start of the day, the instructions to download the data and start a jupyter notebook is very simple, but the instructor went way too fast. I suspect that if we had gone a little slower, fewer people would have needed to go into breakout rooms. <- Thanks, we'll take that on board.

Python - day 2 - Tom Dowrick

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
Notes

Use a for-loop to convert the string "hello" into a list of letters:

string = "hello" #add your code ['h', 'e', 'l', 'l', 'o'] # To create an empty list my_list = []

Exercise 2

Plot the difference between the average inflammations reported in the first and second datasets (stored in inflammation-01.csv and inflammation-02.csv, correspondingly), i.e., the difference between the leftmost plots of the first two figures.

Don't need to use for loops.

Exercise 3

if 4 > 5: print('A') elif 4 == 5: print('B') elif 4 < 5: print('C')

What would be printed if you run this code?

Exercise 4

Write a function that takes a string, and returns the first and last character.

string = "hello" def my_func(string): # ...... return something x = my_func(string) # x = "ho"

Exercise 5

Write a command line application that takes a string and two numbers, and outputs those two characters from the string.

e.g. hello 1 3
hl

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
Questions about Python 2/2

  • Example question
    • student_a Example answer
    • TA_1 Example answer

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
Feedback

Tell us at least one good thing and something we could improve by leaving feedback as post-its on this interactive board.

tags: swc teaching live-notes
Select a repo