Retrieving Data from National Data Buoy Center API

Chase Holtan
2 min readAug 8, 2021

--

The National Data Buoy Center allows you to connect to buoys throughout the world as seen in the image above. There are many reasons one may want to connect and use the data from a specific buoy, but for me, it is to determine the swell approaching my favorite surf spots for my own personal surf dashboard in realtime.

The following steps will provide you with necessary steps to obtain realtime buoy information for a given station.

Step 1: Determine the Buoy Station

Visit the National Data Buoy Center to determine the station you would like to retrieve swell data from. You can do so by clicking on this link .

Once you have zoomed into your desired station click on the yellow diamond.

Here you will see the station number at the top followed by the data you will be retrieving. Copy the station number for future use.

Step 2: Install wget utility

If you have not connected to an API previously using wget you will need to install the wget utility. You can do so by typing the following code in your terminal.

pip install wget

Once you have installed the wget utility you will then need to import it into your Python IDE.

import wget

Step 3: Retrieving Buoy Data from National Data Buoy Center

The National Data Buoy Center recommends using either the FTP or HTTP method for retrieving data in realtime. This blog will guide you on how to retrieve data using the HTTP method.

Using the following HTTP address with wget to retrieve your data.

https://www.ndbc.noaa.gov/data/realtime2/YOURSTATION#.txt

My code to retrieve retrive the buoy data as a text file is as follows.

import wget
url = 'https://www.ndbc.noaa.gov/data/realtime2/YOURSTATION#.txt'
filename = wget.download(url)
print(filename)

Please note that YOURSTATION# is the station number of interest as described above.

You have now retrieved your buoy data!

Alternative Method Using Pandas

The above method is great if you are looking to retrieve the information as a .txt file, but if you are looking to plot and or manipulate the data right away you can also use Pandas.

df_buoy =
pd.read_csv('https://www.ndbc.noaa.gov/data/realtime2/46258.txt', delim_whitespace=True)

If you reviewed the .txt file you will see the file is whitespace deliminated. So if you want the datafram to look as follows use delim_whitespace=True`

--

--