Step 1: Using your computer as a tool for astronomical research.
Step 2: Get started with Python.
This looks long, but it's just a lot of text to give you the background you need. If you get error messages, don't worry! Try understanding these messages, then consult your support network.
Part 1: Open a Terminal
The command line in a Terminal is the starting point for astrophysics research. From the command line, you can write/move/copy files and start software.
To open a Terminal in UNIX, double-click on X11
Part 2: Understand the Directory Structure
The directory architecture used by UNIX is a hierarchical tree structure. When you first open a Terminal, you land in your “home” directory. Instead of clicking on folders, you navigate through the directory structure by “changing directories” using the command ‘cd’ at the prompt in your Terminal. The directory that you are currently sitting in at a prompt is your “working directory”.
The top of the tree is the “root” directory, designated with a slash sign (/). Directory names build on the root directory, with a slash designating a new branch in the directory structure. For example, the full (absolute) path name for my home directory would be “/home/trouille/”. Directories can also have relative path names, which are interpreted as starting from the present working directory. If we were in the “/home/” directory, the relative path name to my home directory would be “trouille”.
Part 3: List the Contents of a Directory
The command line accepts commands in a language called “bash&rdquo.
The command ‘ls’ (note: the first letter is an ‘L’) is used to list the contents of a directory. The ‘ls’ command can be invoked with a variety of options, which modify its action. Under Unix, command options are preceded by a hyphen. A few of the more useful forms of ‘ls’ include:
ls #lists all filenames
ls –l #includes dates, sizes, etc. Note: -l is ‘minus L’.
ls –p #distinguishes between directories and regular files
Try each of these 'ls' commands in order and notice the way they indicate your home directory's contents. Note: You can combine different options when executing a UNIX command, for example:
ls –lt
Part 4: Create a Class Folder
Create a new directory in which you will save your class work by using the command ‘mkdir’. You can call this directory anything you’d like, but avoid whitespaces and try to name it something that makes sense, like “REU” (referred to below as “yourClassDirectory”). At the command line in your Terminal, type:
cd
mkdir REU
Now list the contents of your current working directory to verify that your new directory has been created. Type:
ls #Note: directories can be deleted with the ‘rmdir’ command
Part 5: Change Directories
Learn where you are in the directory structure by typing:
pwd # This is an abbreviation for “print working directory”
The “cd” command moves you around in the directory structure, and takes an argument that is the desired destination directory. The argument can be either a relative or an absolute pathname. Type:
cd yourClassDirectory
This will enter you into the directory that you've just created and the system will move your current working directory to “/home/yourname/yourClassDirectory” (or whatever you’ve chosen to call it).
UNIX provides some useful shortcuts for navigating directories. Double dots, “..” refer to the parent directory. You can therefore move from /home/yourname/yourClassDirectory into /home/yourname by simply typing:
cd ..
And you can always get back to your /home directory by typing:
cd
Part 6: Editing, viewing, and copying the contents of a file
When writing programs, we will need to edit files without the forced formatting of programs such as Word or Powerpoint. Most astronomers use Emacs.
To create and edit a text file, go to the directory (/home/yourname/yourClassDirectory) that you created.
cd
cd yourClassDirectory
emacs testEdit.txt &
Write a few lines of your choosing, save, and close the file.
To view the contents of your text file from the command line in the Terminal, be sure you're in the directory where you saved testEdit.txt and type:
pwd
ls
more testEdit.txt
The command “more” prints the contents of a simple text file to the terminal window. Press the Enter key to move down just one line at a time or press the spacebar to see the next screenful of the file.
Part 7: Copy a File
The command “cp” is used to copy files. To make a copy of the text file you just created, type:
cp -i testEdit.txt testEdit2.txt #‘-i’ tells the “cp” command not to overwrite an existing testEdit2.txt
more testEdit2.txt
Part 8: Filenames and Wildcards
Files in the current working directory can be referred to simply by their filename. However, the name of a file includes its full pathname, such as: home/trouille/testEdit.txt, where the last element, “testEdit.txt”, is the file name.
In general, UNIX allows you to select a subset of the objects of interest. For example, to obtain a listing of all files that end in “.txt”, you would type:
ls *.txt
Part 9: Online help for Unix
The on-line documentation for Unix can be accessed through “man pages”, short for manual. To try versions of this out, type:
man cp
info cp
Part 10: Troubleshooting
If you find that the cursor has gone away, with no indication of ever returning, try the old standby CTRL-c. This means hold down the Ctrl key and hit “c”. This ought to kill the hung process. If this fails, try CTRL-z, where you hit “z” instead of “c”. This suspends, rather than kills, the hung process but still might let you recover.
A Quick Reference Guide to Unix.
Congratulations! You've completed CT-1: Part 1. Now go on to CT-1: Part 2 -- Using Python on your computer!
Step 1: Complete CodeAcademy Python Course
If you haven't yet completed the Code Academy Python course, go to http://www.codecademy.com/ and create a login. It is very important to create a login so that you can save your work and keep track of your progress.
Once you are logged in, choose that you are interested in learning ‘Specific Languages’ and click ‘Start’ under Python. The course takes about 13 hours to complete.
If you have a question, first see if you can find an answer on the ‘Q&A Forum’ link at the bottom left of the CodeAcademy website. Then don't hesitate to ask your support network.
The reason we focus on Python here is that it is a widely used language by scientists, engineers, software developers, website designers, etc. It's flexible, fun to use, and the sky is the limit!
Step 2: Install Python and associated libraries on your computer.
To download and install the Anaconda version of Python, go to the website: http://continuum.io/downloads#all
Which file to choose? Make sure you click on your operating system next to the words ‘Choose your installer’. By operating system, I mean which type of computer you’re working on (a Mac, Windows, or Linux machine).
Once you've determined which operating system and version to use, click on the blue words “[Your system] Python [version] Graphical Installer”
Double click on the file that's downloaded to your computer and follow the instructions posted to your screen.
Once you've set up your Anaconda Python folder, double-click on ‘Spyder’. Spyder is the IDE (Interactive/Integrated Development Environment) you'll use when programming in Python. This is a large package and so it can take a few minutes to load. Also, make sure you are still connected to the internet.
Step 3: Test your installation
To test if the installation is successful, follow these instructions.
If you get error messages, don't worry! Try understanding these messages, but if they make no sense, ask your support network.