Getting Started

This is a summary of how to get started in my research group. At present, we use a few different technologies for carrying out our science and for documenting what we do. Of note, we will be using python and several packages in a standard python distribution. This allows us to analyze numerical data using a suite of Extremely Useful packages. We will also use a version control system called git. Git allows us to develop software collaboratively and keep a good record of how the projects are proceeding. This document is an introduction to these two packages. All this will usually operate on a linux server, and I’ve put an introduction to linux servers here.

Python

We will need to download and install a python distribution. Every user has their own python distribution, which allows you to use whatever packages in python are necessary for your work. Our industry-standard approach is to download the Anaconda python distribution, which bundles all the really important parts of the python universe into one place. The package can be downloaded from here. If you right-click on the link and copy the link in your web-browser, you can usually paste the file into the command line. We’ll want to download the file using the command wget (“web get”, I guess). When I wrote this, you can also get the links here. You can then run the installer with the source command.

wget https://repo.continuum.io/archive/Anaconda3-5.1.0-Linux-x86_64.sh
source Anaconda3-5.1.0-Linux-x86_64.sh

or on a Mac

curl -O https://repo.continuum.io/archive/Anaconda3-5.1.0-MacOSX-x86_64.pkg
open Anaconda3-5.1.0-MacOSX-x86_64.pkg

Make sure you change the location of the python install to be a place where you have ample room. At the end of the installation process, the script may ask if you want to append the startup commands to your .bashrc file. You will want to say “yes” so that the version of python you use is the one that you just installed.

Once you have python installed, you will need to get to know how python works. There are a suite of good tutorials here. We use the main language (python) as well as two packages (1) numpy, which is short for numeric python, which makes python understand big arrays of data and (2) matplotlib which allows us to make gorgeous plots to put into journal articles.

  • Python Tutorial – Up through section 3 is a good first start but useful material is found throughout.
  • Python the Hard Way – Working through Exercise 6 is a good start, but you will be able to use all the material up through Exercise 21 eventually.
  • Numpy – Really, the key section here is “The Basics”
  • Matplotlib – Useful through-and-through.

Git and Github

The server you are working on will have a version control system on it called git which is a program that tracks changes to software that you will be writing. Git interfaces with a website called github, which provides a common location to hold our git repositories. You will use github to check in and share your code with the rest of the group.

  1. Create an account on github.com. You will have to pick an account name. Note that your email can be visible if people know where to look, so feel free to use a throwaway account. Similarly, you will be asked to provide a name, but this can be your Awesome Internet Alias.
  2. Email this account name to me and I will add you to the AstroUA group on github.
  3. Create a repository (green plus button). You can name this whatever you like, but something topical might be good (I use myrepo in the text below. Click on “Initialize this repository with a README” and Select python for the .gitignore which tells the repository to ignore garbage files created by python.
  4. Copy the link for cloning the repository. AttackOfTheClones
  5. On the server where you are working, at the command line, clone your repository using the link. Do this by using the command

    git clone https://github.com/low-sky/myrepo.git

This creates a directory where you can add code.

  1. Create some code! In your homework (see below), you’ll create MySineWave.py. Let’s say you did this. You can push it to github using this series of commands. First, tell git it should care about the file.

    git add MySineWave.py

Then, tell git that you have changes you want to add. Plus a helpful message:

git commit -am "This is my first commit.  So awesome."

Finally send the changes to github:

git push

Note: if you are using git for the first time on a given machine, it will want to know a little bit about you so it can attribute your work to you. You will get an error about needing to set the user.email and user.name variables.

git config --global user.email "your@email.you.used.with.github.com"
git config --global user.name "Your Alias"

Homework

First, write a function that plots a sine wave with a wavelength that is specified on the command line on the range from to .

>>> MySineWave(2.3)

gives a plot of the sine wave with .

Second, create the repository as described above and the file to github. Feel free to ask questions as you go along.

Written on January 5, 2016