The 10th International conference on Archaeological Prospection in Vienna involved a small but significant discussion about Open Software. This has continued on Twitter and I've committed myself to helping people start writing OpenSource software in Python.
I've chosen the Python Programming Language, partly because its one i have a working knowledge of but more importantly because it's inherently user readable. We have to remember that primarily we're Scientists, Archaeologists & Geophysicists, not Programmers and by using Python we can concentrate on what we want to happen to our data rather than how to tell the computer what you want to happen to the data.
To Get started with Python you'll need an implementation of Python on your computer. Python is Cross-Platform (It will work on windows, linux, mac ...) but the method of installing it on different platforms can be very different.
I've traditionally used PythonXY and Spyder on Windows and Mac Systems. For the purposes of this introduction i'm going to recommend Anoconda because its entirely Cross-Platform and therefore we should all encounter the same issues at the same time.
The installation method is slightly different between different operating systems but the Anaconda Support documents are detailed enough, i think.
If you dont want to use Anaconda PythonXY or installing Spyder and Python from scratch are suitable alternatives.
It's only during the Writing of this post that i've encountered Anaconda. This was very easy to install on my mac and includes 64Bit support unlike PythonXY. I'm going to try using both Anaconda and PythonXY to see if they both work seamlessly..
Keeping Track of Code Changes
I found one of the hardest and most frustrating things when i started writing code to process my Geophysical data was i changed it so much from day to day it was impossible to know how i'd created a particular dataset. I should have used a revision control system from the start but didn't so i'm going to recommend you do.
I've chosen to use EasyMercurial because its the one favoured by SoftwareCarpentry and completely cross platform, some instructions are available here.
Getting started with Spyder
To start writing some code open up Spyder:
Opening Spyder on Mac OSX
Opening Spyder on Windows
I Like to think Spyder is relatively simple but to the Non-Programmer it probably makes about as much sense as digging does to me. Hence the image below...
This looks the same on whatever Operating System your running and you'll probably find i flick between Mac, Windows and Ipython.
Writing Some Code
Well we've done the boring stuff and got everything we need installed. Now to write some code.
Create a New file in Spyder and you should see something similar to this:
# -*- coding: utf-8 -*-
Created on Sun Jun 9 15:53:31 2013
the """ and # denote that the text is a comment and should not be 'run' as code. On a new line underneath the MetaData Comment section type
print ("Hello World")
Run the Code by pressing F5, save the file as something sensible within your EasyMercurial repository, and accept the default runtime options. You should see the following:
You've just written your first Python program. Its not particularly useful but is good step along the way.
I'm going to write another post soon with more useful python programming (reading, doing something, saving data) and start to move my tools and libraries into ArchaeoPY. For now i'd recommend looking at the information and tutorials on SoftwareCartpentry