There’s a lot of buzz right now about the new AI-powered chatbot from OpenAI, ChatGPT. I decided to give it a test drive on a simple coding problem I wanted to solve to see how it might be useful for me. I don’t really have much time to write code these days, so I’m a bit rusty. I’ll take all the help I can get.
The problem: produce a map of the world that shows the distance to the nearest broadband seismic station (I won’t go into why I want this, for now). Anyway, out of the box, ChatGPT was a bit of a letdown:
This is not very helpful. Such a maps doesn’t already exist (at least to my knowledge, although it may do for individual seismic networks).
Undaunted, let’s break this problem up into pieces and see how we go. First thing, find a list of seismic stations. I had to do this myself using the IRIS gmap utility (https://ds.iris.edu/gmap/), searching for all permanent broadband seismic stations, and downloading the list as a TEXT file. This produces a file called gmap-stations.txt.
I’m going to want to read this file into Python so I can start doing some calculations with it. Really don’t immediately remember how to do this. Let’s ask ChatGPT:
I guess I had to know I wanted it as a Pandas dataframe object, but it did the rest! Now I’m going to want to calculate the great circle distance from each of these stations to everywhere on Earth. First, I need a Python function to calculate the distance between two locations. Normally, I’d have to look up the Haversine formula and write this myself or search on Stack Overflow. However, ChatGPT did it for me without any prompting about how to do it:
I’m going to want to call this function on a lot of points at once, so I asked ChatGPT to vectorize it for me.
Now I’m going to define a bunch of points on the sphere and calculate the distance to each one. I actually did this part myself, because I told myself it was quicker to do it that way than think about how to ask ChatGPT to do it (but maybe I just wanted to feel I’d contributed to this effort).
I’m going to skip several steps now. I got to where I had a matrix of distances that I wanted to plot on a map. I can never remember exactly how to do this, so I asked ChatGPT. Needless to say, it delivered.
At this point I’m almost there. I had a few more iterations with ChatGPT to center our map at the longitude of Australia, and draw circles at fixed distances (30 degrees and 95 degrees) from a seismic array in the center of Australia called Warramunga (again, not getting into the details of why…). The map below is the result. It shows the distance (in degrees) to the nearest broadband seismic station. The continents (especially North America and Europe) are well instrumented, but the ocean basins (especially the South Pacific) are less well covered.
My problem is solved. I have what I wanted and it took me less than 1 hour. A couple of times ChatGPT led me astray by writing code using Python that is deprecated, but I quickly fixed it with StackOverflow. The whole process was completed in way less time than it would have taken me without my handy assistant, and we were just getting to know each other. The process was exhilarating and scary, because it’s immediately clear to me that my process of doing research is going to change. While the purpose (and the questions) were mine, the process heavily leveraged the AI. When the AI starts to ask questions itself, I know it’s going to be time for me to pack it in.