Improve your programming; be a better geophysicist

My personal experience with geophysics is that it’s very heavy-sided towards programming.
For me this is great. I have been quite the nerd in my childhood and learned some very basic C programming on my first computer. However, I can understand if you didn’t have that kind of head start. A lot of my mates in university didn’t and struggled quite a bit to get some assignments done because that knowledge in programming wasn’t already present. Unfortunately, our university doesn’t really have a lot of courses about programming basics or alternatively they’re in FortranFortran is this really old programming language that is still used because no one wants to bother translating the entire code base into another language.

Learn how to program

At one point in your student career, programming will come in handy. A lot of monotonous tasks can be automated by programming, so why not give it a try. Matt Hall over at Agile* has written a piece about why you should learn programming.
Seriously, teach yourself how to get those pieces of code to work. It’s fun to play around, break and again fix your code. And there are various resources you can get started.

If you don’t know which language to pick, I would recommend Python to start with. It’s easy and focuses on readability, so you will have a big advantage when searching for errors in the code. In the end it will be best if you know different styles of programming languages, but as far as I’m concerned, I’m a geophysicist: I put the idea of the physical model into code and a software engineer will be much better translating into a language that is fast than Python. But if you’re ambitious don’t bother to learn something like C or C++ as well.

Getting serious

Once you get over the “just playing around phase” and actually have an assignment to do, you need to get some structure into your ideas. One of my assignments in university was coding a cooling model of a magma chamber using partial differential equations including source points. If you don’t have a structure for this kind of programming laid out, you will probably go mad. Yeah, or get a Nobel prize once you free up the resources you previously needed for structuring it in your head.
You can do this with a mind map or just some pseudo code on paper, just get creative. This will be your guide through the coding jungle. It’s easy to lose sight of the final problem so this road-map is your friend in structuring your creative process.

Kirchhoff Migration program
A roadmap for a simple migration routine

Use git

Now you want to start using git. Don’t worry if you’ve never heard about it before, it’s basically just a program for organizing your creative work. It can be using with any form of data, so coding is just the right thing to use it for.
git does not help you code, it will not provide any value towards your actual program, but it will spare you a hard time. Essentially coding is about starting with the easiest version you can think of. You implement that really small step and make it work. Then you break it and add some more stuff to it that works towards your goal and make it work again. However there were many times that I broke my code late in the night, went to bed opened the code back up and wondered what the hell I was thinking. The computer was switched off over night so there was no way to just revert the changes. I really wish I had known about git before. Git saves snapshots of your data every time you tell it to do so. Then you can save those changes to a remote server like github. It’s a freemium service and you can build a profile that might even get you a job someday, because what’s better than a portfolio of the code you have written?

Use github

Professor Octocat ? 2013 GitHub Inc.
Professor Octocat
? 2013 GitHub Inc.

There are some very good tutorials out there, for you to use github and I will point you there right after a quick introduction what you can do with git.
You can save snapshots of your data every time you see fit with annotations and version tags. If you break something serious, you can always revert the changes and go back to an older version.
Once you have a working version, you can build a “branch” that is a working copy of your code to break and play around while your “master branch” is still up and running.
It’s easy to share and collaborate your programs, this copying is called “forking”. The improvements and changes a collaborator makes to your code can easily be merged into the working code.
All of this can also be used to write papers or a thesis and github is very well aware of this. However, a thesis is a somewhat private matter you don’t necessarily want out in the public. Github knows this and if you set up an account head over to github.com/edu to activate your free pro account so you can set up private corners for your thesis or top secret code you’re working on.
Have a look at the trygit tutorial, it’s a step by step tutorial for a complete beginner with git and github. It takes 15 minutes and needs no software at all! Also this resource always helps me get those git commands straight.

The following two tabs change content below.
JesperDramsch
... is a geophysicist by heart. I work in seismic interpolation. My interest extend to data security, software engineering, geology and science comm. After work I love to go rock climbing and lift some heavy weights. In the evening I endulge in board games with friends and my wonderful partner. The Way of the geophysicist.
Posted in Software and Programming and tagged , , .

One Comment

  1. Not sure about this:
    “But if you’re ambitious don’t bother to learn something like C or C++ as well”. Don’t you mean “do learn C++ as well”?

    C itself is dead unless writing embedded firmware – C++ is the way forward and C++11 is much better than C++03 which preceded it.

Leave a Reply

Your email address will not be published. Required fields are marked *