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.

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.

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.
... is a geophysicist by heart. He works at the intersection of machine learning and geoscience. He is the founder of The Way of the Geophysicist and a deep learning enthusiast. Writing mostly about computational geoscience and interesting bits and pieces relevant to post-grad life.

Latest posts by Jesper Dramsch (see all)

Jesper Dramsch

... is a geophysicist by heart. He works at the intersection of machine learning and geoscience. He is the founder of The Way of the Geophysicist and a deep learning enthusiast. Writing mostly about computational geoscience and interesting bits and pieces relevant to post-grad life.

Share

Recent Posts

Juneteenth 2020

Here at The Way of the Geophysicists, we have written about social justice before. Today… Read More

2020-06-19

All About Dashboards – Friday Faves

This Friday we're looking at a machine learning state-of-the-art Dashboard and also a new way… Read More

2020-05-22

Keeping Busy – Friday Faves

It sure is an interesting time. Apologies I kept you waiting with more Friday Faves,… Read More

2020-04-24

2020 Fast Approaching! – Friday Faves

Aaaand it's gone. It's starting out with one of my new projects and then a… Read More

2020-01-03

Machine Learning for Science – A Youtube Series

I'm starting a new project, where I take concepts from machine learning for science and… Read More

2019-12-30

Something for a Long Trip or Unwind during the Holidays – Friday Faves

It's the holiday season, so let's keep this Friday Fave short, with a fave that… Read More

2019-12-20