A workaround for a common error on NDBC DODS
I’ve long touted the advantages of using NDBC data for introducing students to programming and data analysis, with an oceanographically focused dataset. In particular, their DODS Server makes it fairly easy to access decades of data from hundreds of stations using the xarray library and a few lines of code in Python.
Apparently, people have been listening. Over the last year, we’ve heard from several faculty in our community who have started down this path. But, a few of them have run into the same confusing issue: If you try to request a full dataset from the NDBC DODS server, you often get the (unhelpful) error…
RuntimeError: NetCDF: file not found
Here’s an example of what it might look like.
Yeah…. Errors are never fun when you’re just starting out. And running into an error you don’t know how to deal with (and where googling isn’t helpful either), is even worse. This is a ripe cause for frustration and demotivating for learners.
To be honest, I’m not entirely sure why this error occurs, but there are a few workarounds you can use, which I’ve detailed in the example notebook below. If you use the DODS server with Python, this will hopefully help you understand some of its limitations, as well as some tricks that might help you debug future errors you run into.
Another Approach: Pandas + ERDDAP
Another option is to skip using xarray and DODS altogether, and instead use the Pandas library to access the same dataset on the CoastEatch ERDDAP server. Pandas tends to be a little more intuitive for students, and so this approach might even be preferable for those just starting out.
If you’re interested in this approach, here’s a simple example.
Most of my example notebooks to date have relied on xarray, because it’s required for accessing netcdf data files and multidimensional datasets. Spend any time in oceanography and you’ll definitely have to learn this library, but it’s not necessary on day 1.
More fun with NDBC
If you’re interested in some of our other NDBC dataset examples in Python, you should check out our Python Tutorials (Part 1, Part 2, and Data Analysis), as well as this example on Seasonal Cycles. Just keep in mind, that these examples use the same xarray/DODS technique below, so if you try to load a full dataset, you will need to keep these tricks in mind.
As always, I hope this helps!