Plot temperature from Satlantic’s LOBO server

The Satlantic LOBO is a ocean observatory moored in the North West Arm (Halifax, Nova Scotia, Canada). In this post, we’ll query the LOBO server to create a temperature plot.

Temperature plot from LOBO

# First, specify the start and end dates for the query
startdate = '20121118'
enddate   = '20121125'

# Read data from LOBO
import urllib2
response = urllib2.urlopen(''
data =

# We use StringIO to convert data into a StringIO object
# Learn more:
import StringIO
data = StringIO.StringIO(data)

# read the StringIO object as it was a file
import csv
r = csv.DictReader(data,

# Break the file into two lists
date, temp = [],[]
for row in r:
    date.append(row['date [AST]'])
    temp.append(row['temperature [C]'])

# Change the time strings into datetime objects
from datetime import datetime
DAT = []
for row in date:
    DAT.append(datetime.strptime(row,"%Y-%m-%d %H:%M:%S"))

# Plot the output
import matplotlib.pyplot as plt
fig, ax =plt.subplots(1)
ax.plot_date(DAT, temp, 'r-')
plt.title("Temperature from LOBO (Halifax, Canada)")
plt.ylabel("Temperature (oC)")

2 thoughts on “Plot temperature from Satlantic’s LOBO server

  1. For grabbing the data lists, r[‘temp..’] and r[‘date..’] should already be everything you need date and temp to be. You can save yourself a list traversal that way. Another time-saver would be to just map r[‘temp’] to the datetime converter and pass the list of datetimes to pyplot. It knows how to label axes given a datetime object. You can even customize the date formats based on the total length of the time period, so that short times show minutes:seconds and longer time periods don’t worry about the finer timescales.

  2. this should replace lines 24 – 32

    date, temp = zip(*[(datetime.strptime(x['date [AST]'], "%Y-%m-%d %H:%M:%S"), x['temperature [C]']) for x in r if x['temperature [C]'] is not None])

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s