Experimenting with GTS data from ERDDAP

Exploring use of Python to formulate ERDDAP image and data REST requests and process the responses.

Initialize


In [1]:
import urllib2
import pandas as pd

In [2]:
# dictionary for valid parameter_name 
d={'sea_water_temperature':'ZTMP', 'sea_water_salinity':'ZSAL'}

In [3]:
# Specify variable to retrieve: 
param=d['sea_water_temperature']

# Get data shallower than this water depth:
depth_max = 10   

# Use ERDDAP's built-in relative time functionality to get last 48 hours:
start='now-24hours'
stop='now'
# or specify a specific period:
#start = '2013-05-06T00:00:00Z'
#stop =  '2013-05-07T00:00:00Z'

Retrieve an image from ERDDAP


In [4]:
# Construct URL for large PNG:
url='http://osmc.noaa.gov:8180/erddap/tabledap/OSMC_PROFILERS\
.largePng?longitude,latitude,observation_value\
&time>=%s&time<=%s&parameter_name="%s"&observation_depth<=%d&.trim=5&\
.draw=markers&.marker=5|6&.color=0x000000&.colorBar=|||||' % (start,stop,param,depth_max)

In [5]:
# Read the image
im = imread(urllib2.urlopen(url),format='png')

In [6]:
# Display the image
figure(figsize=(12,8))
imshow(im)   
axis('off');


Obtain data from ERDDAP


In [7]:
# Construct URL for CSV data:
url='http://osmc.noaa.gov:8180/erddap/tabledap/OSMC_PROFILERS\
.csv?time,longitude,latitude,observation_depth,observation_value\
&time>=%s&time<=%s&parameter_name="%s"&observation_depth<=%d' % (start,stop,param,depth_max)

In [8]:
# Load the CSV data directly into Pandas
df = pd.read_csv(url,index_col='time',parse_dates=True,skiprows=[1])  # skip the units row

In [9]:
# List last ten records
df.tail(10)


Out[9]:
longitude latitude observation_depth observation_value
time
2013-05-09 00:34:00 66.963 -15.239 4 27.03
2013-05-09 01:18:00 -16.755 46.913 7 12.94
2013-05-09 03:08:00 151.490 9.769 4 29.13
2013-05-09 04:24:00 127.133 10.454 4 29.99
2013-05-09 05:20:00 124.187 14.595 3 29.82
2013-05-09 05:20:00 124.187 14.595 4 29.82
2013-05-09 02:58:00 153.961 -21.539 8 25.95
2013-05-09 01:56:00 53.990 -15.413 7 26.64
2013-05-09 04:07:00 110.261 -39.374 4 15.49
2013-05-09 05:20:00 124.187 14.595 6 29.85

In [11]:
df['longitude']


Out[11]:
time
2013-05-08 17:32:00    177.147
2013-05-08 20:22:00    162.065
2013-05-08 20:22:00    162.065
2013-05-08 12:38:00      6.598
2013-05-08 12:38:00      6.598
2013-05-08 22:02:00    127.302
2013-05-08 17:32:00    177.147
2013-05-08 17:32:00    177.147
2013-05-08 23:29:00    -21.663
2013-05-08 23:29:00    -21.663
2013-05-08 19:29:00   -170.083
2013-05-08 15:21:00    154.816
2013-05-08 22:47:00    139.343
2013-05-08 18:42:00   -139.713
2013-05-08 13:37:00   -127.738
...
2013-05-09 00:01:00      2.633
2013-05-09 00:01:00      2.633
2013-05-09 02:34:00   -159.244
2013-05-09 08:50:00   -178.964
2013-05-09 02:34:00   -159.244
2013-05-09 00:34:00     66.963
2013-05-09 01:18:00    -16.755
2013-05-09 03:08:00    151.490
2013-05-09 04:24:00    127.133
2013-05-09 05:20:00    124.187
2013-05-09 05:20:00    124.187
2013-05-09 02:58:00    153.961
2013-05-09 01:56:00     53.990
2013-05-09 04:07:00    110.261
2013-05-09 05:20:00    124.187
Name: longitude, Length: 435, dtype: float64

In [ ]: