How to Read and Analyze GDAT Files Using Python

A quick tutorial on how to work with these computer-modelled binary files.

9 min read

3 hours ago

Photo by Werclive 👹 on Unsplash

Data comes in all shapes and sizes.

While many of us spend most of our data education and careers working with data in relatively “friendly” formats, such as spreadsheets and CSV files, there may come a time when you’re confronted with data that isn’t so friendly. You might not even be able to visualize it straight out of the box.

This happened to me recently, when a computer model I was running was outputting data in a gridded binary format. The tricky thing about binary files is figuring out how to read them to access and analyze their contained data. After scouring the edges of the internet for a solution, I cobbled together a simple Python function that allows you to read gridded binary data so that it can later be analyzed using your favorite Python libraries, such as matplotlib, or NumPy.

This niche solution will allow you to read gridded binary data files with GDAT file endings produced from computer models, particularly those modeling natural processes, such as environmental or meteorological phenomena. As such, the code below makes these assumptions:

  • Your GDAT file follows GrADS conventions (though this will likely work for various…